app_spi_dma.h
Go to the documentation of this file.
1 /**
2  ****************************************************************************************
3  *
4  * @file app_spi_dma.h
5  * @author BLE Driver Team
6  * @brief Header file containing functions prototypes of SPI app library.
7  *
8  ****************************************************************************************
9  * @attention
10  #####Copyright (c) 2019 GOODIX
11  All rights reserved.
12 
13  Redistribution and use in source and binary forms, with or without
14  modification, are permitted provided that the following conditions are met:
15  * Redistributions of source code must retain the above copyright
16  notice, this list of conditions and the following disclaimer.
17  * Redistributions in binary form must reproduce the above copyright
18  notice, this list of conditions and the following disclaimer in the
19  documentation and/or other materials provided with the distribution.
20  * Neither the name of GOODIX nor the names of its contributors may be used
21  to endorse or promote products derived from this software without
22  specific prior written permission.
23 
24  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  POSSIBILITY OF SUCH DAMAGE.
35  ****************************************************************************************
36  */
37 
38 /** @addtogroup PERIPHERAL Peripheral Driver
39  * @{
40  */
41 
42 /** @addtogroup APP_DRIVER APP DRIVER
43  * @{
44  */
45 
46 /** @defgroup APP_SPI SPI
47  * @brief SPI APP module driver.
48  * @{
49  */
50 
51 
52 #ifndef _APP_SPI_DMA_H_
53 #define _APP_SPI_DMA_H_
54 
55 #include "app_io.h"
56 #include "app_dma.h"
57 #include "app_spi.h"
58 #include "app_drv_error.h"
59 #include "app_drv_config.h"
60 #include <stdbool.h>
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
64 
65 #ifdef HAL_SPI_MODULE_ENABLED
66 
67 /** @addtogroup APP_SPI_STRUCTURES Structures
68  * @{
69  */
70 /**
71  * @brief SPI SCreen Config Structures
72  */
73 typedef struct {
74  uint8_t instruction; /**< screen instruction, such as 0x02 */
75  uint32_t leading_address; /**< control address started from origin, such as 0x002C00 */
76  uint32_t ongoing_address; /**< control address started from last position, such as 0x003C00 */
77  uint32_t data_xfer_width; /**< data width, @ref SPI_DATASIZE_8BIT SPI_DATASIZE_16BIT */
78  uint32_t buff_pixel_stride; /**< row stride in pixel */
79  uint32_t buff_pixel_width; /**< show width in pixel, usually buff_pixel_width <= buff_pixel_stride */
80  uint32_t buff_pixel_height; /**< column height in pixel */
81  uint32_t buff_pixel_depth; /**< Just support 2 now (means 16bit). */
83 
84 /** @} */
85 
86 
87 /* Exported functions --------------------------------------------------------*/
88 /** @addtogroup APP_SPI_DRIVER_FUNCTIONS Functions
89  * @{
90  */
91 /**
92  ****************************************************************************************
93  * @brief Initialize the APP SPI DRIVER according to the specified parameters
94  * in the app_spi_params_t and app_spi_evt_handler_t.
95  * @note If interrupt mode is set, you can use blocking mode. Conversely, if blocking mode
96  * is set, you can't use interrupt mode.
97  *
98  * @param[in] p_params: Pointer to app_spi_params_t parameter which contains the
99  * configuration information for the specified SPI module.
100  *
101  *
102  * @return Result of initialization.
103  ****************************************************************************************
104  */
105 uint16_t app_spi_dma_init(app_spi_params_t *p_params);
106 
107 /**
108  ****************************************************************************************
109  * @brief De-initialize the APP SPI DRIVER peripheral.
110  *
111  * @param[in] id: De-initialize for a specific ID.
112  *
113  * @return Result of De-initialization.
114  ****************************************************************************************
115  */
117 /**
118  ****************************************************************************************
119  * @brief SPI master transmit with 1-byte inst and 3-byte addr, can use to write flash/display/eeprom, etc
120  * @note DO NOT Support interrupt mode
121  * @param[in] id : just support APP_SPI_ID_MASTER
122  * @param[in] instruction : 1-byte instruction phase
123  * @param[in] address : 3-byte address phase
124  * @param[in] p_data : pointer to transmit buffer
125  * @param[in] data_length : length of buffer, unit in byte
126  *
127  * @return APP_DRV_* in app_drv_error.h
128  ****************************************************************************************
129  */
130 uint16_t app_spim_dma_transmit_with_ia(app_spi_id_t id, uint8_t instruction, uint32_t address, uint8_t * p_data, uint16_t data_length);
131 
132 #if (APP_DRIVER_CHIP_TYPE == APP_DRIVER_GR5526X)
133 /**
134  ****************************************************************************************
135  * @brief SPI master transmit with 1-byte inst and 4-byte addr, can use to write flash/display/eeprom, etc
136  * @note DO NOT Support interrupt mode
137  * @param[in] id : just support APP_SPI_ID_MASTER
138  * @param[in] instruction : 1-byte instruction phase
139  * @param[in] address : 3-byte address phase
140  * @param[in] p_data : pointer to transmit buffer
141  * @param[in] data_length : length of buffer, unit in byte
142  *
143  * @return APP_DRV_* in app_drv_error.h
144  ****************************************************************************************
145  */
146 uint16_t app_spim_dma_transmit_with_ia_32addr(app_spi_id_t id, uint8_t instruction, uint32_t address, uint8_t * p_data, uint16_t data_length);
147 #endif
148 
149 /**
150  ****************************************************************************************
151  * @brief SPI master receive with 1-byte inst and 3-byte addr and 0~4 dummy Byte, can use to read flash/display/eeprom, etc
152  *
153  * @param[in] id : just support APP_SPI_ID_MASTER
154  * @param[in] instruction : 1-byte instruction phase
155  * @param[in] address : 3-byte address phase
156  * @param[in] dummy_bytes : dummy bytes, 0 ~ 4
157  * @param[in] p_data : pointer to transmit buffer
158  * @param[in] data_length : length of buffer, unit in byte
159  *
160  * @return APP_DRV_* in app_drv_error.h
161  ****************************************************************************************
162  */
163 uint16_t app_spim_dma_receive_with_ia(app_spi_id_t id, uint8_t instruction, uint32_t address, uint8_t dummy_bytes, uint8_t * p_data, uint16_t data_length);
164 
165 /**
166  ****************************************************************************************
167  * @brief Receive in master or slave mode an amount of data in non-blocking mode with Interrupt
168  *
169  * @param[in] id: which SPI module want to receive.
170  * @param[in] p_data: Pointer to data buffer
171  * @param[in] size: Amount of data to be sent
172  *
173  * @return Result of operation.
174  ****************************************************************************************
175  */
176 uint16_t app_spi_dma_receive_async(app_spi_id_t id, uint8_t *p_data, uint16_t size);
177 
178 /**
179  ****************************************************************************************
180  * @brief Transmits in master or slave mode an amount of data in non-blocking mode with Interrupt
181  *
182  * @param[in] id: which SPI module want to transmit.
183  * @param[in] p_data: Pointer to data buffer
184  * @param[in] size: Amount of data to be sent
185  *
186  * @return Result of operation.
187  ****************************************************************************************
188  */
189 uint16_t app_spi_dma_transmit_async(app_spi_id_t id, uint8_t *p_data, uint16_t size);
190 
191 /**
192  ****************************************************************************************
193  * @brief Transmits and receive in master or slave mode an amount of data in non-blocking mode with Interrupt
194  *
195  * @param[in] id: which SPI module want to transmit.
196  * @param[in] p_tx_data: Pointer to tx data buffer
197  * @param[in] p_rx_data: Pointer to rx data buffer
198  * @param[in] size: Amount of data to be sent and receive
199  *
200  * @return Result of operation.
201  ****************************************************************************************
202  */
203 uint16_t app_spi_dma_transmit_receive_async(app_spi_id_t id, uint8_t *p_tx_data, uint8_t *p_rx_data, uint32_t size);
204 
205 /**
206  ****************************************************************************************
207  * @brief Read an amount of data from EEPROM in non-blocking mode with Interrupt.
208  *
209  * @param[in] id: which SPI module want to transmit.
210  * @param[in] p_tx_data: Pointer to transmission data buffer
211  * @param[out] p_rx_data: Pointer to reception data buffer
212  * @param[in] tx_size: Amount of data to be sent in bytes
213  * @param[in] rx_size: Amount of data to be received in bytes
214  *
215  * @return Result of operation.
216  ****************************************************************************************
217  */
218 uint16_t app_spi_dma_read_eeprom_async(app_spi_id_t id, uint8_t *p_tx_data, uint8_t *p_rx_data, uint32_t tx_size, uint32_t rx_size);
219 
220 #if (APP_DRIVER_CHIP_TYPE == APP_DRIVER_GR551X)
221 /**
222  ****************************************************************************************
223  * @brief Transmits in master or slave mode an amount of data in non-blocking mode with DMA
224  *
225  * @param[in] id: which SPI module want to transmit.
226  * @param[in] p_cmd_data: Pointer to command data buffer
227  * @param[in] p_tx_data: Pointer to transmission data buffer
228  * @param[in] cmd_size: Amount of command data to be sent in bytes
229  * @param[in] tx_size: Amount of data to be sent in bytes
230  *
231  * @return Result of operation.
232  ****************************************************************************************
233  */
234 uint16_t app_spi_dma_write_memory_async(app_spi_id_t id, uint8_t *p_cmd_data, uint8_t *p_tx_data, uint32_t cmd_size, uint32_t tx_size);
235 
236 /**
237  ****************************************************************************************
238  * @brief Read an amount of data from EEPROM in non-blocking mode with DMA.
239  *
240  * @param[in] id: which SPI module want to transmit.
241  * @param[in] p_cmd_data: Pointer to command data buffer
242  * @param[out] p_rx_data: Pointer to reception data buffer
243  * @param[in] cmd_size: Amount of command data to be sent in bytes
244  * @param[in] rx_size: Amount of data to be received in bytes
245  *
246  * @return Result of operation.
247  ****************************************************************************************
248  */
249 uint16_t app_spi_dma_read_memory_async(app_spi_id_t id, uint8_t *p_cmd_data, uint8_t *p_rx_data, uint32_t cmd_size, uint32_t rx_size);
250 
251 /**
252  ****************************************************************************************
253  * @brief [High speed] Receive in master or slave mode an amount of data in blocking mode.
254  *
255  * @param[in] id: which SPI module want to receive.
256  * @param[in] p_data: Pointer to data buffer
257  * @param[in] size: Amount of data to be sent
258  *
259  * @return Result of operation.
260  ****************************************************************************************
261  */
262 uint16_t app_spi_dma_receive_high_speed_sync(app_spi_id_t id, uint8_t *p_data, uint16_t size);
263 
264 /**
265  ****************************************************************************************
266  * @brief [High speed] Transmit in master or slave mode an amount of data in blocking mode.
267  *
268  * @param[in] id: which SPI module want to receive.
269  * @param[in] p_data: Pointer to data buffer
270  * @param[in] size: Amount of data to be sent
271  *
272  * @return Result of operation.
273  ****************************************************************************************
274  */
275 uint16_t app_spi_dma_transmit_high_speed_sync(app_spi_id_t id, uint8_t *p_data, uint16_t size);
276 #endif
277 
278 
279 #if (APP_DRIVER_CHIP_TYPE == APP_DRIVER_GR5525X) || (APP_DRIVER_CHIP_TYPE == APP_DRIVER_GR5526X)
280 /**
281  ****************************************************************************************
282  * @brief transfer big block data from sram to screen device in dma llp mode. Must override _v_malloc and _v_free in application layer
283  *
284  * @param[in] id: which SPI module want to transmit.
285  * @param[in] p_scrn_info: Pointer to screen configure information
286  * @param[in] p_buff: Pointer to data buffer to transfer
287  *
288  * @return Result of operation.
289  ****************************************************************************************
290  */
291 uint16_t app_spi_send_display_frame(app_spi_id_t id, app_spi_screen_config_t * p_scrn_info, void * p_buff) ;
292 #endif
293 
294 /** @} */
295 
296 #endif
297 
298 #ifdef __cplusplus
299 }
300 #endif
301 
302 #endif
303 
304 /** @} */
305 
306 /** @} */
307 
308 /** @} */
309 
app_spi_dma_transmit_high_speed_sync
uint16_t app_spi_dma_transmit_high_speed_sync(app_spi_id_t id, uint8_t *p_data, uint16_t size)
[High speed] Transmit in master or slave mode an amount of data in blocking mode.
app_spi_params_t
SPI parameters structure definition.
Definition: app_spi.h:219
app_spi_dma_read_memory_async
uint16_t app_spi_dma_read_memory_async(app_spi_id_t id, uint8_t *p_cmd_data, uint8_t *p_rx_data, uint32_t cmd_size, uint32_t rx_size)
Read an amount of data from EEPROM in non-blocking mode with DMA.
app_spi_dma_init
uint16_t app_spi_dma_init(app_spi_params_t *p_params)
Initialize the APP SPI DRIVER according to the specified parameters in the app_spi_params_t and app_s...
app_spi_dma_transmit_receive_async
uint16_t app_spi_dma_transmit_receive_async(app_spi_id_t id, uint8_t *p_tx_data, uint8_t *p_rx_data, uint32_t size)
Transmits and receive in master or slave mode an amount of data in non-blocking mode with Interrupt.
app_spi_screen_config_t
SPI SCreen Config Structures.
Definition: app_spi_dma.h:73
app_io.h
Header file containing functions prototypes of GPIO app library.
app_spi_screen_config_t::leading_address
uint32_t leading_address
control address started from origin, such as 0x002C00
Definition: app_spi_dma.h:75
app_spi_dma_receive_high_speed_sync
uint16_t app_spi_dma_receive_high_speed_sync(app_spi_id_t id, uint8_t *p_data, uint16_t size)
[High speed] Receive in master or slave mode an amount of data in blocking mode.
app_spi_dma_transmit_async
uint16_t app_spi_dma_transmit_async(app_spi_id_t id, uint8_t *p_data, uint16_t size)
Transmits in master or slave mode an amount of data in non-blocking mode with Interrupt.
app_spi_screen_config_t::instruction
uint8_t instruction
screen instruction, such as 0x02
Definition: app_spi_dma.h:74
app_spi_id_t
app_spi_id_t
SPI module Enumerations definition.
Definition: app_spi.h:83
app_spi_dma_write_memory_async
uint16_t app_spi_dma_write_memory_async(app_spi_id_t id, uint8_t *p_cmd_data, uint8_t *p_tx_data, uint32_t cmd_size, uint32_t tx_size)
Transmits in master or slave mode an amount of data in non-blocking mode with DMA.
app_spi_dma_read_eeprom_async
uint16_t app_spi_dma_read_eeprom_async(app_spi_id_t id, uint8_t *p_tx_data, uint8_t *p_rx_data, uint32_t tx_size, uint32_t rx_size)
Read an amount of data from EEPROM in non-blocking mode with Interrupt.
app_spi_screen_config_t::buff_pixel_depth
uint32_t buff_pixel_depth
Just support 2 now (means 16bit).
Definition: app_spi_dma.h:81
app_spi_screen_config_t::ongoing_address
uint32_t ongoing_address
control address started from last position, such as 0x003C00
Definition: app_spi_dma.h:76
app_spi_dma_deinit
uint16_t app_spi_dma_deinit(app_spi_id_t id)
De-initialize the APP SPI DRIVER peripheral.
app_dma.h
Header file containing functions prototypes of DMA app library.
app_spi_dma_receive_async
uint16_t app_spi_dma_receive_async(app_spi_id_t id, uint8_t *p_data, uint16_t size)
Receive in master or slave mode an amount of data in non-blocking mode with Interrupt.
app_spi_screen_config_t::buff_pixel_width
uint32_t buff_pixel_width
show width in pixel, usually buff_pixel_width <= buff_pixel_stride
Definition: app_spi_dma.h:79
app_spi_screen_config_t::buff_pixel_stride
uint32_t buff_pixel_stride
row stride in pixel
Definition: app_spi_dma.h:78
app_spim_dma_receive_with_ia
uint16_t app_spim_dma_receive_with_ia(app_spi_id_t id, uint8_t instruction, uint32_t address, uint8_t dummy_bytes, uint8_t *p_data, uint16_t data_length)
SPI master receive with 1-byte inst and 3-byte addr and 0~4 dummy Byte, can use to read flash/display...
app_spi.h
Header file containing functions prototypes of SPI app library.
app_spi_screen_config_t::data_xfer_width
uint32_t data_xfer_width
data width, SPI_DATASIZE_8BIT SPI_DATASIZE_16BIT
Definition: app_spi_dma.h:77
app_spim_dma_transmit_with_ia
uint16_t app_spim_dma_transmit_with_ia(app_spi_id_t id, uint8_t instruction, uint32_t address, uint8_t *p_data, uint16_t data_length)
SPI master transmit with 1-byte inst and 3-byte addr, can use to write flash/display/eeprom,...
app_drv_error.h
Header file of app driver error code.
app_drv_config.h
Header file of app driver config code.
app_spi_screen_config_t::buff_pixel_height
uint32_t buff_pixel_height
column height in pixel
Definition: app_spi_dma.h:80