app_i2c.h
Go to the documentation of this file.
1
52 #ifndef _APP_I2C_H_
53 #define _APP_I2C_H_
54
55 #include "gr55xx_hal.h"
56 #include "app_io.h"
57 #include "app_drv_error.h"
58 #ifdef ENV_USE_FREERTOS
59 #include "app_rtos_cfg.h"
60 #endif
61
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65
66 #ifdef HAL_I2C_MODULE_ENABLED
67
75 typedef enum
76 {
77 APP_I2C_ID_0,
78 APP_I2C_ID_1,
79 APP_I2C_ID_MAX
80 } app_i2c_id_t;
81
85 typedef enum
86 {
87 APP_I2C_ROLE_MASTER,
88 APP_I2C_ROLE_SLAVE,
89 APP_I2C_ROLE_MAX,
90 } app_i2c_role_t;
91
95 typedef enum
96 {
97 APP_I2C_TYPE_INTERRUPT,
98 APP_I2C_TYPE_POLLING,
99 APP_I2C_TYPE_DMA,
100 APP_I2C_TYPE_MAX,
101 } app_i2c_type_t;
102
106 typedef enum
107 {
108 APP_I2C_EVT_ERROR,
109 APP_I2C_EVT_TX_CPLT,
110 APP_I2C_EVT_RX_DATA,
111 } app_i2c_evt_type_t;
120 typedef struct
121 {
122 app_io_type_t type;
123 app_io_mux_t mux;
124 uint32_t pin;
126 app_io_pull_t pull;
127 } app_i2c_pin_t;
128
132 typedef struct
133 {
134 app_i2c_pin_t scl;
135 app_i2c_pin_t sda;
136 } app_i2c_pin_cfg_t;
137
141 typedef struct
142 {
143 app_i2c_type_t type;
144 dma_channel_t tx_dma_channel;
145 dma_channel_t rx_dma_channel;
146 } app_i2c_mode_t;
147
151 typedef struct
152 {
153 app_i2c_id_t id;
154 app_i2c_role_t role;
155 app_i2c_pin_cfg_t pin_cfg;
156 app_i2c_mode_t use_mode;
157 i2c_init_t init;
158 } app_i2c_params_t;
159
163 typedef struct
164 {
165 app_i2c_evt_type_t type;
166 union
167 {
168 uint32_t error_code;
169 uint16_t size;
170 } data;
171 } app_i2c_evt_t;
172
176 typedef void (*app_i2c_evt_handler_t)(app_i2c_evt_t *p_evt);
177
180 /* Exported functions --------------------------------------------------------*/
198 uint16_t app_i2c_init(app_i2c_params_t *p_params, app_i2c_evt_handler_t evt_handler);
199
209 uint16_t app_i2c_deinit(app_i2c_id_t id);
210
225 uint16_t app_i2c_receive_sync(app_i2c_id_t id, uint16_t target_address, uint8_t *p_data, uint16_t size, uint32_t timeout);
226
240 uint16_t app_i2c_receive_async(app_i2c_id_t id, uint16_t target_address, uint8_t *p_data, uint16_t size);
241
256 uint16_t app_i2c_transmit_sync(app_i2c_id_t id, uint16_t target_address, uint8_t *p_data, uint16_t size, uint32_t timeout);
257
271 uint16_t app_i2c_transmit_async(app_i2c_id_t id, uint16_t target_address, uint8_t *p_data, uint16_t size);
272
288 uint16_t app_i2c_mem_read_sync(app_i2c_id_t id, uint16_t dev_address, uint16_t mem_address, uint16_t mem_addr_size, uint8_t *p_data, uint16_t size, uint32_t timeout);
289
304 uint16_t app_i2c_mem_read_async(app_i2c_id_t id, uint16_t dev_address, uint16_t mem_address, uint16_t mem_addr_size, uint8_t *p_data, uint16_t size);
305
321 uint16_t app_i2c_mem_write_sync(app_i2c_id_t id, uint16_t dev_address, uint16_t mem_address, uint16_t mem_addr_size, uint8_t *p_data, uint16_t size, uint32_t timeout);
322
337 uint16_t app_i2c_mem_write_async(app_i2c_id_t id, uint16_t dev_address, uint16_t mem_address, uint16_t mem_addr_size, uint8_t *p_data, uint16_t size);
338
348 i2c_handle_t *app_i2c_get_handle(app_i2c_id_t id);
349
350 #ifdef ENV_RTOS_USE_SEMP
351
365 uint16_t app_i2c_receive_sem_sync(app_i2c_id_t id, uint16_t target_address, uint8_t *p_data, uint16_t size);
366
380 uint16_t app_i2c_transmit_sem_sync(app_i2c_id_t id, uint16_t target_address, uint8_t *p_data, uint16_t size);
381
382 #endif
383
387 #endif
388
389 #ifdef __cplusplus
390 }
391 #endif
392
393 #endif
394
app_i2c_pin_cfg_t
I2C IO configuration Structures.
Definition: app_i2c.h:133
app_i2c_mode_t
I2C operate mode Enumerations definition.
Definition: app_i2c.h:142
app_i2c_pin_cfg_t::sda
app_i2c_pin_t sda
Definition: app_i2c.h:135
app_i2c_pin_t::pin
uint32_t pin
Definition: app_i2c.h:124
app_i2c_mode_t::rx_dma_channel
dma_channel_t rx_dma_channel
Definition: app_i2c.h:145
APP_I2C_EVT_ERROR
@ APP_I2C_EVT_ERROR
Definition: app_i2c.h:108
app_i2c_evt_t::error_code
uint32_t error_code
Definition: app_i2c.h:168
app_i2c_mode_t::type
app_i2c_type_t type
Definition: app_i2c.h:143
APP_I2C_TYPE_MAX
@ APP_I2C_TYPE_MAX
Definition: app_i2c.h:100
app_i2c_receive_async
uint16_t app_i2c_receive_async(app_i2c_id_t id, uint16_t target_address, uint8_t *p_data, uint16_t size)
Receive in master or slave mode an amount of data in non-blocking mode with Interrupt/DMA.
_i2c_init
I2C Configuration Structure definition.
Definition: gr55xx_hal_i2c.h:167
APP_I2C_ROLE_MASTER
@ APP_I2C_ROLE_MASTER
Definition: app_i2c.h:87
_i2c_handle
I2C handle Structure definition.
Definition: gr55xx_hal_i2c.h:191
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_I2C_TYPE_POLLING
@ APP_I2C_TYPE_POLLING
Definition: app_i2c.h:98
app_i2c_transmit_sync
uint16_t app_i2c_transmit_sync(app_i2c_id_t id, uint16_t target_address, uint8_t *p_data, uint16_t size, uint32_t timeout)
Transmits in master or slave mode an amount of data in blocking mode.
app_i2c_evt_t::size
uint16_t size
Definition: app_i2c.h:169
app_i2c_deinit
uint16_t app_i2c_deinit(app_i2c_id_t id)
De-initialize the APP I2C DRIVER peripheral.
app_i2c_pin_t::mux
app_io_mux_t mux
Definition: app_i2c.h:123
app_i2c_mode_t::tx_dma_channel
dma_channel_t tx_dma_channel
Definition: app_i2c.h:144
app_i2c_pin_t::type
app_io_type_t type
Definition: app_i2c.h:122
app_io.h
Header file containing functions prototypes of GPIO app library.
APP_I2C_ROLE_MAX
@ APP_I2C_ROLE_MAX
Definition: app_i2c.h:89
app_i2c_role_t
app_i2c_role_t
I2C role Enumerations definition.
Definition: app_i2c.h:86
app_i2c_mem_read_sync
uint16_t app_i2c_mem_read_sync(app_i2c_id_t id, uint16_t dev_address, uint16_t mem_address, uint16_t mem_addr_size, uint8_t *p_data, uint16_t size, uint32_t timeout)
Read an amount of data in blocking mode from a specific memory address.
app_i2c_params_t::id
app_i2c_id_t id
Definition: app_i2c.h:153
APP_I2C_TYPE_INTERRUPT
@ APP_I2C_TYPE_INTERRUPT
Definition: app_i2c.h:97
app_i2c_id_t
app_i2c_id_t
I2C module Enumerations definition.
Definition: app_i2c.h:76
app_i2c_pin_t
I2C IO Structures.
Definition: app_i2c.h:121
app_i2c_params_t::pin_cfg
app_i2c_pin_cfg_t pin_cfg
Definition: app_i2c.h:155
app_i2c_params_t::role
app_i2c_role_t role
Definition: app_i2c.h:154
app_i2c_mem_read_async
uint16_t app_i2c_mem_read_async(app_i2c_id_t id, uint16_t dev_address, uint16_t mem_address, uint16_t mem_addr_size, uint8_t *p_data, uint16_t size)
Read an amount of data in non-blocking mode with Interrupt/DMA from a specific memory address.
app_i2c_receive_sync
uint16_t app_i2c_receive_sync(app_i2c_id_t id, uint16_t target_address, uint8_t *p_data, uint16_t size, uint32_t timeout)
Receive in master or slave mode an amount of data in blocking mode.
app_i2c_evt_type_t
app_i2c_evt_type_t
I2C event Enumerations definition.
Definition: app_i2c.h:107
APP_I2C_ID_1
@ APP_I2C_ID_1
Definition: app_i2c.h:78
app_i2c_evt_t
I2C event structure definition.
Definition: app_i2c.h:164
app_i2c_pin_cfg_t::scl
app_i2c_pin_t scl
Definition: app_i2c.h:134
app_i2c_get_handle
i2c_handle_t * app_i2c_get_handle(app_i2c_id_t id)
Return the I2C handle.
gr55xx_hal.h
This file contains all the functions prototypes for the HAL module driver.
app_i2c_transmit_async
uint16_t app_i2c_transmit_async(app_i2c_id_t id, uint16_t target_address, uint8_t *p_data, uint16_t size)
Transmits in master or slave mode an amount of data in non-blocking mode with Interrupt/DMA.
app_i2c_pin_t::pull
app_io_pull_t pull
Definition: app_i2c.h:126
APP_I2C_EVT_TX_CPLT
@ APP_I2C_EVT_TX_CPLT
Definition: app_i2c.h:109
app_i2c_init
uint16_t app_i2c_init(app_i2c_params_t *p_params, app_i2c_evt_handler_t evt_handler)
Initialize the APP I2C DRIVER according to the specified parameters in the app_i2c_params_t and app_i...
app_i2c_evt_handler_t
void(* app_i2c_evt_handler_t)(app_i2c_evt_t *p_evt)
I2C event callback definition.
Definition: app_i2c.h:176
app_i2c_type_t
app_i2c_type_t
I2C operating mode Enumerations definition.
Definition: app_i2c.h:96
app_io_mux_t
app_io_mux_t
GPIO mux Enumerations definition.
Definition: app_io.h:198
APP_I2C_EVT_RX_DATA
@ APP_I2C_EVT_RX_DATA
Definition: app_i2c.h:110
app_i2c_evt_t::type
app_i2c_evt_type_t type
Definition: app_i2c.h:165
app_i2c_params_t
I2C parameters structure definition.
Definition: app_i2c.h:152
app_rtos_cfg.h
Header file of app rtos config code.
app_drv_error.h
Header file of app driver error code.
app_i2c_params_t::init
i2c_init_t init
Definition: app_i2c.h:157
APP_I2C_TYPE_DMA
@ APP_I2C_TYPE_DMA
Definition: app_i2c.h:99
app_i2c_mem_write_sync
uint16_t app_i2c_mem_write_sync(app_i2c_id_t id, uint16_t dev_address, uint16_t mem_address, uint16_t mem_addr_size, uint8_t *p_data, uint16_t size, uint32_t timeout)
Write an amount of data in blocking mode to a specific memory address.
APP_I2C_ID_0
@ APP_I2C_ID_0
Definition: app_i2c.h:77
app_i2c_mem_write_async
uint16_t app_i2c_mem_write_async(app_i2c_id_t id, uint16_t dev_address, uint16_t mem_address, uint16_t mem_addr_size, uint8_t *p_data, uint16_t size)
Write an amount of data in non-blocking mode with Interrupt/DMA to a specific memory address.
app_i2c_params_t::use_mode
app_i2c_mode_t use_mode
Definition: app_i2c.h:156
APP_I2C_ID_MAX
@ APP_I2C_ID_MAX
Definition: app_i2c.h:79
dma_channel_t
dma_channel_t
HAL DMA Channel Enumerations definition.
Definition: gr55xx_hal_dma.h:93
APP_I2C_ROLE_SLAVE
@ APP_I2C_ROLE_SLAVE
Definition: app_i2c.h:88