app_spi.h
Go to the documentation of this file.
1
52 #ifndef _APP_SPI_H_
53 #define _APP_SPI_H_
54
55 #include "gr55xx_hal.h"
56 #include "app_io.h"
57 #include "app_drv_error.h"
58 #include "app_rtos_cfg.h"
59
60 #ifdef __cplusplus
61 extern "C" {
62 #endif
63
64 #ifdef HAL_SPI_MODULE_ENABLED
65
66 #ifdef _APP_SPI_V2_H_
67 #error "NOT Support USING app_spi AND app_spi_v2 AT The Same Time !!!"
68 #endif
69
74 #define APP_SPI_PIN_ENABLE 1
75 #define APP_SPI_PIN_DISABLE 0
86 typedef enum
87 {
88 APP_SPI_ID_SLAVE,
89 APP_SPI_ID_MASTER,
90 APP_SPI_ID_MAX,
91 } app_spi_id_t;
92
96 typedef enum
97 {
98 APP_SPI_TYPE_INTERRUPT,
99 APP_SPI_TYPE_POLLING,
100 APP_SPI_TYPE_DMA,
101 APP_SPI_TYPE_MAX,
102 } app_spi_type_t;
103
107 typedef enum
108 {
109 APP_SPI_EVT_ERROR,
110 APP_SPI_EVT_TX_CPLT,
111 APP_SPI_EVT_RX_DATA,
112 APP_SPI_EVT_TX_RX,
113 } app_spi_evt_type_t;
122 typedef struct
123 {
124 app_io_type_t type;
125 app_io_mux_t mux;
126 uint32_t pin;
128 app_io_pull_t pull;
129 uint8_t enable;
130 } app_spi_pin_t;
131
135 typedef struct
136 {
137 app_spi_pin_t cs;
138 app_spi_pin_t clk;
139 app_spi_pin_t mosi;
140 app_spi_pin_t miso;
141 } app_spi_pin_cfg_t;
142
146 typedef struct
147 {
148 app_spi_type_t type;
149 dma_channel_t tx_dma_channel;
150 dma_channel_t rx_dma_channel;
151 } app_spi_mode_t;
152
156 typedef struct
157 {
158 app_spi_id_t id;
159 app_spi_pin_cfg_t pin_cfg;
160 app_spi_mode_t use_mode;
161 spi_init_t init;
162 } app_spi_params_t;
163
167 typedef struct
168 {
169 app_spi_evt_type_t type;
170 union
171 {
172 uint32_t error_code;
173 uint16_t size;
174 } data;
175 } app_spi_evt_t;
176
180 typedef void (*app_spi_evt_handler_t)(app_spi_evt_t *p_evt);
181
184 /* Exported functions --------------------------------------------------------*/
203 uint16_t app_spi_init(app_spi_params_t *p_params, app_spi_evt_handler_t evt_handler);
204
214 uint16_t app_spi_deinit(app_spi_id_t id);
215
228 uint16_t app_spi_receive_sync(app_spi_id_t id, uint8_t *p_data, uint16_t size, uint32_t timeout);
229
241 uint16_t app_spi_receive_async(app_spi_id_t id, uint8_t *p_data, uint16_t size);
242
255 uint16_t app_spi_transmit_sync(app_spi_id_t id, uint8_t *p_data, uint16_t size, uint32_t timeout);
256
268 uint16_t app_spi_transmit_async(app_spi_id_t id, uint8_t *p_data, uint16_t size);
269
283 uint16_t app_spi_transmit_receive_sync(app_spi_id_t id, uint8_t *p_tx_data, uint8_t *p_rx_data, uint32_t size, uint32_t timeout);
284
297 uint16_t app_spi_transmit_receive_async(app_spi_id_t id, uint8_t *p_tx_data, uint8_t *p_rx_data, uint32_t size);
298
313 uint16_t app_spi_read_eeprom_sync(app_spi_id_t id, uint8_t *p_tx_data, uint8_t *p_rx_data, uint32_t tx_size, uint32_t rx_size, uint32_t timeout);
314
328 uint16_t app_spi_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);
329
343 uint16_t app_spi_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);
344
358 uint16_t app_spi_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);
359
369 spi_handle_t *app_spi_get_handle(app_spi_id_t id);
370
371
372 #ifdef ENV_RTOS_USE_SEMP
373
384 uint16_t app_spi_receive_sem_sync(app_spi_id_t id, uint8_t *p_data, uint16_t size);
385
397 uint16_t app_spi_transmit_sem_sync(app_spi_id_t id, uint8_t *p_data, uint16_t size);
398
411 uint16_t app_spi_transmit_receive_sem_sync(app_spi_id_t id, uint8_t *p_tx_data, uint8_t *p_rx_data, uint32_t size);
412 #endif
413
425 uint16_t app_spi_receive_high_speed_sync(app_spi_id_t id, uint8_t *p_data, uint16_t size);
426
438 uint16_t app_spi_transmit_high_speed_sync(app_spi_id_t id, uint8_t *p_data, uint16_t size);
439
442 #endif
443
444 #ifdef __cplusplus
445 }
446 #endif
447
448 #endif
449
app_spi_pin_cfg_t
SPI IO configuration Structures.
Definition: app_spi.h:136
_spi_handle
SPI handle Structure definition.
Definition: gr55xx_hal_spi.h:135
app_spi_params_t::use_mode
app_spi_mode_t use_mode
Definition: app_spi.h:160
APP_SPI_TYPE_MAX
@ APP_SPI_TYPE_MAX
Definition: app_spi.h:101
app_spi_deinit
uint16_t app_spi_deinit(app_spi_id_t id)
De-initialize the APP SPI DRIVER peripheral.
APP_SPI_ID_MAX
@ APP_SPI_ID_MAX
Definition: app_spi.h:90
app_spi_params_t::pin_cfg
app_spi_pin_cfg_t pin_cfg
Definition: app_spi.h:159
app_spi_receive_high_speed_sync
uint16_t app_spi_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_transmit_high_speed_sync
uint16_t app_spi_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_pin_cfg_t::mosi
app_spi_pin_t mosi
Definition: app_spi.h:139
APP_SPI_ID_SLAVE
@ APP_SPI_ID_SLAVE
Definition: app_spi.h:88
app_spi_read_memory_async
uint16_t app_spi_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_TYPE_DMA
@ APP_SPI_TYPE_DMA
Definition: app_spi.h:100
app_spi_evt_handler_t
void(* app_spi_evt_handler_t)(app_spi_evt_t *p_evt)
SPI event callback definition.
Definition: app_spi.h:180
app_spi_params_t
SPI parameters structure definition.
Definition: app_spi.h:157
_spi_init
SPI init Structure definition.
Definition: gr55xx_hal_spi.h:104
app_spi_evt_t
SPI event structure definition.
Definition: app_spi.h:168
app_io_pull_t
app_io_pull_t
GPIO pull Enumerations definition.
Definition: app_io.h:187
app_io_type_t
app_io_type_t
GPIO type Enumerations definition.
Definition: app_io.h:141
app_spi_init
uint16_t app_spi_init(app_spi_params_t *p_params, app_spi_evt_handler_t evt_handler)
Initialize the APP SPI DRIVER according to the specified parameters in the app_spi_params_t and app_s...
app_spi_pin_cfg_t::clk
app_spi_pin_t clk
Definition: app_spi.h:138
app_spi_evt_t::error_code
uint32_t error_code
Definition: app_spi.h:172
app_spi_transmit_receive_async
uint16_t app_spi_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_write_memory_async
uint16_t app_spi_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_pin_t::type
app_io_type_t type
Definition: app_spi.h:124
app_spi_pin_t::enable
uint8_t enable
Definition: app_spi.h:129
APP_SPI_ID_MASTER
@ APP_SPI_ID_MASTER
Definition: app_spi.h:89
app_spi_transmit_receive_sync
uint16_t app_spi_transmit_receive_sync(app_spi_id_t id, uint8_t *p_tx_data, uint8_t *p_rx_data, uint32_t size, uint32_t timeout)
Transmits and receive in master or slave mode an amount of data in blocking mode.
APP_SPI_TYPE_POLLING
@ APP_SPI_TYPE_POLLING
Definition: app_spi.h:99
app_io.h
Header file containing functions prototypes of GPIO app library.
APP_SPI_EVT_TX_RX
@ APP_SPI_EVT_TX_RX
Definition: app_spi.h:112
app_spi_params_t::id
app_spi_id_t id
Definition: app_spi.h:158
app_spi_get_handle
spi_handle_t * app_spi_get_handle(app_spi_id_t id)
Return the SPI handle.
app_spi_id_t
app_spi_id_t
SPI module Enumerations definition.
Definition: app_spi.h:87
app_spi_transmit_sync
uint16_t app_spi_transmit_sync(app_spi_id_t id, uint8_t *p_data, uint16_t size, uint32_t timeout)
Transmits in master or slave mode an amount of data in blocking mode.
app_spi_pin_cfg_t::cs
app_spi_pin_t cs
Definition: app_spi.h:137
APP_SPI_TYPE_INTERRUPT
@ APP_SPI_TYPE_INTERRUPT
Definition: app_spi.h:98
app_spi_receive_async
uint16_t app_spi_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_evt_t::type
app_spi_evt_type_t type
Definition: app_spi.h:169
app_spi_pin_t
SPI IO Structures.
Definition: app_spi.h:123
app_spi_evt_type_t
app_spi_evt_type_t
SPI event Enumerations definition.
Definition: app_spi.h:108
app_spi_mode_t::rx_dma_channel
dma_channel_t rx_dma_channel
Definition: app_spi.h:150
app_spi_type_t
app_spi_type_t
SPI operating mode Enumerations definition.
Definition: app_spi.h:97
APP_SPI_EVT_TX_CPLT
@ APP_SPI_EVT_TX_CPLT
Definition: app_spi.h:110
app_spi_receive_sync
uint16_t app_spi_receive_sync(app_spi_id_t id, uint8_t *p_data, uint16_t size, uint32_t timeout)
Receive in master or slave mode an amount of data in blocking mode.
APP_SPI_EVT_RX_DATA
@ APP_SPI_EVT_RX_DATA
Definition: app_spi.h:111
app_spi_pin_cfg_t::miso
app_spi_pin_t miso
Definition: app_spi.h:140
gr55xx_hal.h
This file contains all the functions prototypes for the HAL module driver.
app_spi_mode_t::tx_dma_channel
dma_channel_t tx_dma_channel
Definition: app_spi.h:149
app_spi_evt_t::size
uint16_t size
Definition: app_spi.h:173
app_spi_mode_t::type
app_spi_type_t type
Definition: app_spi.h:148
app_io_mux_t
app_io_mux_t
GPIO mux Enumerations definition.
Definition: app_io.h:198
app_spi_pin_t::pull
app_io_pull_t pull
Definition: app_spi.h:128
app_spi_read_eeprom_async
uint16_t app_spi_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_rtos_cfg.h
Header file of app rtos config code.
app_drv_error.h
Header file of app driver error code.
app_spi_params_t::init
spi_init_t init
Definition: app_spi.h:161
APP_SPI_EVT_ERROR
@ APP_SPI_EVT_ERROR
Definition: app_spi.h:109
app_spi_pin_t::mux
app_io_mux_t mux
Definition: app_spi.h:125
app_spi_transmit_async
uint16_t app_spi_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.
dma_channel_t
dma_channel_t
HAL DMA Channel Enumerations definition.
Definition: gr55xx_hal_dma.h:93
app_spi_read_eeprom_sync
uint16_t app_spi_read_eeprom_sync(app_spi_id_t id, uint8_t *p_tx_data, uint8_t *p_rx_data, uint32_t tx_size, uint32_t rx_size, uint32_t timeout)
Read an amount of data from EEPROM in blocking mode.
app_spi_pin_t::pin
uint32_t pin
Definition: app_spi.h:126
app_spi_mode_t
SPI operate mode Enumerations definition.
Definition: app_spi.h:147