1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
|
#ifndef _BFLB_DBI_H
#define _BFLB_DBI_H
#include "bflb_core.h"
/** @addtogroup LHAL
* @{
*/
/** @addtogroup DBI
* @{
*/
#if defined(BL616)
#define DBI_QSPI_SUPPORT 1
#define DBI_YUV_SUPPORT 1
#define DBI_WRITE_DATA_BYTE_MAX 256
#define DBI_READ_DATA_BYTE_MAX 8
#define SPI_FIFO_NUM_MAX 8
#elif defined(BL606P) || defined(BL808)
#define DBI_QSPI_SUPPORT 0
#define DBI_YUV_SUPPORT 0
#define DBI_WRITE_DATA_BYTE_MAX 4
#define DBI_READ_DATA_BYTE_MAX 4
#define SPI_FIFO_NUM_MAX 8
#else
#error "unknown device"
#endif
#define DBI_WRITE_PIXEL_CNT_MAX 0x00FFFFFF
/** @defgroup DBI_MODE dbi working mode definition
* @{
*/
#define DBI_MODE_TYPE_B 0 /* mipi-dbi typeB 8-wire-data mode */
#define DBI_MODE_TYPE_C_4_WIRE 1 /* mipi-dbi typeC 4-wire mode */
#define DBI_MODE_TYPE_C_3_WIRE 2 /* mipi-dbi typeC 3-wire mode */
#if (DBI_QSPI_SUPPORT)
#define DBI_MODE_EX_QSPI 3 /* Not the mipi standard. Extra support for QSPI mode */
#endif
/**
* @}
*/
/** @defgroup DBI_PIXEL_INPUT_FORMAT dbi fifo input pixel format, the FIFO are filled in 32-bits width definition
* @{
*/
#define DBI_PIXEL_INPUT_FORMAT_NBGR_8888 0 /* 32-bit/pixel, memory byte: [0]->pixel[0][R], [1]->pixel[0][G], [2]->pixel[0][B], [3]->invalid, [4]->pixel[1][R], ... */
#define DBI_PIXEL_INPUT_FORMAT_NRGB_8888 1 /* 32-bit/pixel, memory byte: [0]->pixel[0][B], [1]->pixel[0][G], [2]->pixel[0][R], [3]->invalid, [4]->pixel[1][B], ... */
#define DBI_PIXEL_INPUT_FORMAT_BGRN_8888 2 /* 32-bit/pixel, memory byte: [0]->invalid, [1]->pixel[0][R], [2]->pixel[0][G], [3]->pixel[0][B], [4]->invalid, [5]->pixel[1][R], ... */
#define DBI_PIXEL_INPUT_FORMAT_RGBN_8888 3 /* 32-bit/pixel, memory byte: [0]->invalid, [1]->pixel[0][B], [2]->pixel[0][G], [3]->pixel[0][R], [4]->invalid, [5]->pixel[1][B], ... */
#define DBI_PIXEL_INPUT_FORMAT_RGB_888 4 /* 24-bit/pixel, memory byte: [0]->pixel[0][R], [1]->pixel[0][G], [2]->pixel[0][B], [3]->pixel[1][R], [4]->pixel[1][G], ... */
#define DBI_PIXEL_INPUT_FORMAT_BGR_888 5 /* 24-bit/pixel, memory byte: [0]->pixel[0][B], [1]->pixel[0][G], [2]->pixel[0][R], [3]->pixel[1][B], [4]->pixel[1][G], ... */
#define DBI_PIXEL_INPUT_FORMAT_BGR_565 6 /* 16-bit/pixel, */
#define DBI_PIXEL_INPUT_FORMAT_RGB_565 7 /* 16-bit/pixel, */
/**
* @}
*/
/** @defgroup DBI_PIXEL_OUTPUT_FORMAT dbi output pixel format definition
* @{
*/
#define DBI_PIXEL_OUTPUT_FORMAT_RGB_565 0 /* 16-bit/pixel */
#define DBI_PIXEL_OUTPUT_FORMAT_RGB_888 1 /* 24-bit/pixel, Compatible with RGB666 format */
/**
* @}
*/
/** @defgroup DBI_CLOCK_MODE dbi clock phase and polarity definition
* @{
*/
#define DBI_CLOCK_MODE_0 0 /* CPOL=0 CHPHA=0 */
#define DBI_CLOCK_MODE_1 1 /* CPOL=0 CHPHA=1 */
#define DBI_CLOCK_MODE_2 2 /* CPOL=1 CHPHA=0 */
#define DBI_CLOCK_MODE_3 3 /* CPOL=1 CHPHA=1 */
/**
* @}
*/
/** @defgroup DBI_QSPI_WIRE_NUM dbi qspi wire num definition
* @{
*/
#define DBI_QSPI_WIRE_NUM_1 0 /* 1-wire mode */
#define DBI_QSPI_WIRE_NUM_4 1 /* 4-wire mode */
/**
* @}
*/
/** @defgroup SPI_INTSTS dbi interrupt status definition
* @{
*/
#define DBI_INTSTS_TC (1 << 0)
#define SPI_INTSTS_TX_FIFO (1 << 1)
#define SPI_INTSTS_FIFO_ERR (1 << 2)
/**
* @}
*/
/** @defgroup DBI_INTCLR dbi interrupt clear definition
* @{
*/
#define DBI_INTCLR_TC (1 << 0)
/**
* @}
*/
/** @defgroup DBI_CMD dbi feature control cmd definition
* @{
*/
#define DBI_CMD_CLEAR_TX_FIFO (0x01)
#define DBI_CMD_GET_TX_FIFO_CNT (0x02)
#define DBI_CMD_MASK_CMD_PHASE (0x03)
#define DBI_CMD_CS_CONTINUE (0x04)
#define DBI_CMD_SET_DUMMY_CNT (0x05)
#define DBI_CMD_GET_SIZE_OF_PIXEL_CNT (0x06)
#define DBI_CMD_INPUT_PIXEL_FORMAT (0x07)
#define DBI_CMD_OUTPUT_PIXEL_FORMAT (0x08)
#if (DBI_QSPI_SUPPORT)
#define DBI_CMD_YUV_TO_RGB_ENABLE (0x10)
#endif
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @brief DBI configuration structure
*
* @param dbi_mode DBI working mode, use @ref DBI_MODE
* @param pixel_input_format DBI input pixel_format, use @ref DBI_PIXEL_INPUT_FORMAT
* @param pixel_output_format DBI output pixel_format, use @ref DBI_PIXEL_OUTPUT_FORMAT
* @param clk_mode DBI clock phase and polarity, use @ref DBI_CLOCK_MODE
* @param clk_freq_hz DBI clock frequency
* @param tx_fifo_threshold DBI tx fifo threshold, should be less than 16
* @param cmd_wire_mode DBI qspi mode, number of wire in the command phase, use @ref DBI_QSPI_WIRE_NUM
* @param addr_wire_mode DBI qspi mode, number of wire in the address phase, use @ref DBI_QSPI_WIRE_NUM
* @param data_wire_mode DBI qspi mode, number of wire in the data phase, use @ref DBI_QSPI_WIRE_NUM
*/
struct bflb_dbi_config_s {
uint8_t dbi_mode;
uint8_t pixel_input_format;
uint8_t pixel_output_format;
uint8_t clk_mode;
uint32_t clk_freq_hz;
uint8_t tx_fifo_threshold;
#if (DBI_QSPI_SUPPORT)
uint8_t cmd_wire_mode;
uint8_t addr_wire_mode;
uint8_t data_wire_mode;
#endif
};
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Initialize dbi.
*
* @param [in] dev device handle
* @param [in] config pointer to save dbi config
*/
void bflb_dbi_init(struct bflb_device_s *dev, const struct bflb_dbi_config_s *config);
/**
* @brief Deinitialize dbi.
*
* @param [in] dev device handle
*/
void bflb_dbi_deinit(struct bflb_device_s *dev);
#if DBI_QSPI_SUPPORT
/**
* @brief Set the address value and address length of the QSPI
*
* @param [in] dev device handle
* @param [in] addr_byte_size address size(byte), range 1 ~ 4
* @param [in] addr_val address value: [0:7]->addr[0], [8:15]->addr[1], [16:23]->addr[2], [24:31]->addr[3].
*/
void bflb_dbi_qspi_set_addr(struct bflb_device_s *dev, uint8_t addr_byte_size, uint32_t addr_val);
#endif
/**
* @brief Send cmd with pixel data, send cmd -> send address(only QSPI mode) -> send parameter_data.
*
* @param [in] dev device handle
* @param [in] cmd command
* @param [in] data_len Parameter length (byte), The maximum is DBI_WRITE_DATA_BYTE_MAX
* @param [in] data_buff Parameter buffer, Cannot be null
* @return
*/
int bflb_dbi_send_cmd_data(struct bflb_device_s *dev, uint8_t cmd, uint8_t data_len, uint8_t *data_buff);
/**
* @brief To read the data after sending the command, send cmd -> send address(only QSPI mode) -> read parameter_data.
*
* @param [in] dev device handle
* @param [in] cmd command
* @param [in] data_len Length of data to be read (byte), The maximum is DBI_READ_DATA_BYTE_MAX
* @param [in] data_buff Buff of data to be read, discard data if null
* @return
*/
int bflb_dbi_send_cmd_read_data(struct bflb_device_s *dev, uint8_t cmd, uint8_t data_len, uint8_t *data_buff);
/**
* @brief Send cmd with pixel data, send cmd -> send address(only QSPI mode) -> send pixel_data,
*
* @param [in] dev device handle
* @param [in] cmd command
* @param [in] pixel_cnt Number of pixels,The maximum is DBI_WRITE_PIXEL_CNT_MAX
* @param [in] pixel_buff Pixels buffer, NULL when using DMA, in which case data needs to be transferred by DMA later, and wait for the transfer to complete
* @return
*/
int bflb_dbi_send_cmd_pixel(struct bflb_device_s *dev, uint8_t cmd, uint32_t pixel_cnt, void *pixel_buff);
/**
* @brief Enable dbi tx dma.
*
* @param [in] dev device handle
* @param [in] enable true means enable, otherwise disable.
*/
void bflb_dbi_link_txdma(struct bflb_device_s *dev, bool enable);
/**
* @brief Enable or disable dbi rx fifo threhold interrupt.
*
* @param [in] dev device handle
* @param [in] mask true means disable, false means enable
*/
void bflb_dbi_txint_mask(struct bflb_device_s *dev, bool mask);
/**
* @brief Enable or disable dbi transfer completion interrupt.
*
* @param [in] dev device handle
* @param [in] mask true means disable, false means enable
*/
void bflb_dbi_tcint_mask(struct bflb_device_s *dev, bool mask);
/**
* @brief Enable or disable dbi error interrupt.
*
* @param [in] dev device handle
* @param [in] mask true means disable, false means enable
*/
void bflb_dbi_errint_mask(struct bflb_device_s *dev, bool mask);
/**
* @brief Get dbi interrupt status.
*
* @param [in] dev device handle
* @return interrupt status, use @ref DBI_INTSTS
*/
uint32_t bflb_dbi_get_intstatus(struct bflb_device_s *dev);
/**
* @brief Clear dbi interrupt status.
*
* @param [in] dev device handle
* @param [in] int_clear clear value, use @ref SPI_INTCLR
*/
void bflb_dbi_int_clear(struct bflb_device_s *dev, uint32_t int_clear);
/**
* @brief Control dbi feature.
*
* @param [in] dev device handle
* @param [in] cmd feature command, use @ref DBI_CMD
* @param [in] arg user data
* @return A negated errno value on failure.
*/
int bflb_dbi_feature_control(struct bflb_device_s *dev, int cmd, size_t arg);
#ifdef __cplusplus
}
#endif
/**
* @}
*/
/**
* @}
*/
#endif
|