Go to the documentation of this file.
52 #ifndef __GR55xx_HAL_I2C_H__
53 #define __GR55xx_HAL_I2C_H__
266 #define HAL_I2C_ERROR_NONE (0x00000000U)
267 #define HAL_I2C_ERROR_INVALID_PARAM (0x00000001U)
268 #define HAL_I2C_ERROR_ARB_LOST (0x00000002U)
269 #define HAL_I2C_ERROR_NOACK (0x00000004U)
270 #define HAL_I2C_ERROR_OVER (0x00000008U)
271 #define HAL_I2C_ERROR_SCL_STUCK_AT_LOW (0x00000010U)
272 #define HAL_I2C_ERROR_SDA_STUCK_AT_LOW (0x00000020U)
273 #define HAL_I2C_ERROR_DMA (0x00000040U)
274 #define HAL_I2C_ERROR_TIMEOUT (0x00000080U)
275 #define HAL_I2C_ERROR_NOTE (0x00000100U)
282 #define I2C_SPEED_100K LL_I2C_SPEED_100K
283 #define I2C_SPEED_400K LL_I2C_SPEED_400K
284 #define I2C_SPEED_1000K LL_I2C_SPEED_1000K
285 #define I2C_SPEED_2000K LL_I2C_SPEED_2000K
291 #define I2C_ADDRESSINGMODE_7BIT (0x00000001U)
292 #define I2C_ADDRESSINGMODE_10BIT (0x00000002U)
298 #define I2C_GENERALCALL_DISABLE (0x00000000U)
299 #define I2C_GENERALCALL_ENABLE (0x00000001U)
305 #define I2C_MEMADD_SIZE_8BIT (0x00000001U)
306 #define I2C_MEMADD_SIZE_16BIT (0x00000002U)
312 #define I2C_FIRST_FRAME (0x00000000U)
313 #define I2C_FIRST_AND_NEXT_FRAME (0x00000001U)
314 #define I2C_NEXT_FRAME (0x00000002U)
315 #define I2C_FIRST_AND_LAST_FRAME (0x00000003U)
316 #define I2C_LAST_FRAME (0x00000004U)
322 #define I2C_TIMING_SS_SCL_LOW (0x00000000U)
323 #define I2C_TIMING_SS_SCL_HIGH (0x00000001U)
324 #define I2C_TIMING_FS_SCL_LOW (0x00000002U)
325 #define I2C_TIMING_FS_SCL_HIGH (0x00000003U)
326 #define I2C_TIMING_HS_SCL_LOW (0x00000004U)
327 #define I2C_TIMING_HS_SCL_HIGH (0x00000005U)
328 #define I2C_TIMING_FS_SPK (0x00000006U)
329 #define I2C_TIMING_HS_SPK (0x00000007U)
330 #define I2C_TIMING_SDA_TX_HOLD (0x00000008U)
331 #define I2C_TIMING_SDA_RX_HOLD (0x00000009U)
337 #define I2C_DEFAULT_CONFIG \
339 .speed = I2C_SPEED_400K, \
340 .own_address = 0x55U, \
341 .addressing_mode = I2C_ADDRESSINGMODE_7BIT, \
342 .general_call_mode = I2C_GENERALCALL_DISABLE, \
358 #define __HAL_I2C_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->state = HAL_I2C_STATE_RESET)
371 #define IS_I2C_SPEED(__SPEED__) (((__SPEED__) == I2C_SPEED_100K) || \
372 ((__SPEED__) == I2C_SPEED_400K) || \
373 ((__SPEED__) == I2C_SPEED_1000K) || \
374 ((__SPEED__) == I2C_SPEED_2000K))
381 #define IS_I2C_ADDRESSING_MODE(__MODE__) (((__MODE__) == I2C_ADDRESSINGMODE_7BIT) || \
382 ((__MODE__) == I2C_ADDRESSINGMODE_10BIT))
389 #define IS_I2C_GENERAL_CALL(__CALL__) (((__CALL__) == I2C_GENERALCALL_DISABLE) || \
390 ((__CALL__) == I2C_GENERALCALL_ENABLE))
397 #define IS_I2C_MEMADD_SIZE(__SIZE__) (((__SIZE__) == I2C_MEMADD_SIZE_8BIT) || \
398 ((__SIZE__) == I2C_MEMADD_SIZE_16BIT))
405 #define IS_TRANSFER_REQUEST(__REQUEST__) (((__REQUEST__) == I2C_CMD_SLV_NONE) || \
406 ((__REQUEST__) == I2C_CMD_MST_WRITE) || \
407 ((__REQUEST__) == I2C_CMD_MST_READ) || \
408 ((__REQUEST__) == I2C_CMD_MST_GEN_STOP) || \
409 ((__REQUEST__) == I2C_CMD_MST_GEN_RESTART))
416 #define IS_I2C_TRANSFER_OPTIONS_REQUEST(__REQUEST__) (((__REQUEST__) == I2C_FIRST_FRAME) || \
417 ((__REQUEST__) == I2C_FIRST_AND_NEXT_FRAME) || \
418 ((__REQUEST__) == I2C_NEXT_FRAME) || \
419 ((__REQUEST__) == I2C_FIRST_AND_LAST_FRAME) || \
420 ((__REQUEST__) == I2C_LAST_FRAME))
427 #define IS_I2C_SLV_ADDRESS(__ADDRESS__) ((__ADDRESS__) < 0x03FFU)
434 #define IS_I2C_OWN_ADDRESS(__ADDRESS__) ((((__ADDRESS__) > 0x0007U) && ((__ADDRESS__) < 0x0078U)) || \
435 (((__ADDRESS__) > 0x007FU) && ((__ADDRESS__) < 0x03FFU)))
442 #define I2C_MEM_ADD_MSB(__ADDRESS__) ((uint8_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)(0xFF00U))) >> 8U)))
449 #define I2C_MEM_ADD_LSB(__ADDRESS__) ((uint8_t)((uint16_t)((__ADDRESS__) & (uint16_t)(0x00FFU))))
void(* i2c_msp_init)(i2c_handle_t *p_i2c)
hal_status_t hal_i2c_slave_receive_dma_sg_llp(i2c_handle_t *p_i2c, uint8_t *p_data, uint16_t size, dma_sg_llp_config_t *sg_llp_config)
Receive in slave mode an amount of data in non-blocking mode with DMA.
void(* i2c_slave_tx_cplt_callback)(i2c_handle_t *p_i2c)
hal_lock_t
HAL Lock structures definition.
hal_status_t hal_i2c_mem_read_it(i2c_handle_t *p_i2c, 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 from a specific memory address.
Header file containing functions prototypes of I2C LL library.
hal_status_t hal_i2c_deinit(i2c_handle_t *p_i2c)
De-initialize the I2C peripheral.
uint32_t hal_i2c_get_error(i2c_handle_t *p_i2c)
Return the I2C error code.
hal_status_t hal_i2c_master_receive_dma(i2c_handle_t *p_i2c, uint16_t dev_address, uint8_t *p_data, uint16_t size)
Receive in master mode an amount of data in non-blocking mode with DMA.
hal_status_t hal_i2c_init(i2c_handle_t *p_i2c)
Initializes the I2C according to the specified parameters in the i2c_init_t and initialize the associ...
hal_status_t(* xfer_isr)(struct _i2c_handle *p_i2c, uint32_t it_source, uint32_t abort_sources)
hal_status_t hal_i2c_slave_receive_it(i2c_handle_t *p_i2c, uint8_t *p_data, uint16_t size)
Receive in slave mode an amount of data in non-blocking mode with Interrupt.
hal_status_t hal_i2c_master_receive(i2c_handle_t *p_i2c, uint16_t dev_address, uint8_t *p_data, uint16_t size, uint32_t timeout)
Receives in master mode an amount of data in blocking mode.
void hal_i2c_master_tx_cplt_callback(i2c_handle_t *p_i2c)
Master Tx Transfer completed callback.
I2C Configuration Structure definition.
struct _hal_i2c_callback hal_i2c_callback_t
HAL_I2C Callback function definition.
hal_status_t hal_i2c_slave_receive_dma(i2c_handle_t *p_i2c, uint8_t *p_data, uint16_t size)
Receive in slave mode an amount of data in non-blocking mode with DMA.
I2C handle Structure definition.
__IO uint32_t previous_state
hal_status_t hal_i2c_mem_write_it(i2c_handle_t *p_i2c, 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 to a specific memory address.
HAL_I2C Callback function definition.
hal_status_t hal_i2c_master_transmit_it(i2c_handle_t *p_i2c, uint16_t dev_address, uint8_t *p_data, uint16_t size)
Transmit in master mode an amount of data in non-blocking mode with Interrupt.
void(* i2c_error_callback)(i2c_handle_t *p_i2c)
LL DMA sg and llp config definition.
hal_status_t hal_i2c_slave_transmit_dma(i2c_handle_t *p_i2c, uint8_t *p_data, uint16_t size)
Transmit in slave mode an amount of data in non-blocking mode with DMA.
hal_status_t hal_i2c_timing_get(i2c_handle_t *p_i2c, uint32_t timing_type, uint32_t *p_timing_value)
Get the I2C timing value.
struct _i2c_init i2c_init_t
I2C Configuration Structure definition.
hal_status_t hal_i2c_speed_config(i2c_handle_t *p_i2c, uint32_t speed, uint32_t scl_fall_time, uint32_t scl_rise_time)
Configure the I2C transmit rate for I2C.
void(* i2c_abort_cplt_callback)(i2c_handle_t *p_i2c)
struct _i2c_handle i2c_handle_t
I2C handle Structure definition.
hal_status_t hal_i2c_master_transmit_dma(i2c_handle_t *p_i2c, uint16_t dev_address, uint8_t *p_data, uint16_t size)
Transmit in master mode an amount of data in non-blocking mode with DMA.
void(* i2c_slave_rx_cplt_callback)(i2c_handle_t *p_i2c)
void(* i2c_msp_deinit)(i2c_handle_t *p_i2c)
hal_status_t hal_i2c_mem_read_dma(i2c_handle_t *p_i2c, uint16_t dev_address, uint16_t mem_address, uint16_t mem_addr_size, uint8_t *p_data, uint16_t size)
Reads an amount of data in non-blocking mode with DMA from a specific memory address.
void hal_i2c_slave_rx_cplt_callback(i2c_handle_t *p_i2c)
Slave Rx Transfer completed callback.
hal_i2c_state_t
HAL I2C State Enumerations definition.
__IO hal_i2c_state_t state
hal_status_t hal_i2c_slave_transmit_dma_sg_llp(i2c_handle_t *p_i2c, uint8_t *p_data, uint16_t size, dma_sg_llp_config_t *sg_llp_config)
Transmit in slave mode an amount of data in non-blocking mode with DMA.
uint32_t general_call_mode
hal_status_t hal_i2c_suspend_reg(i2c_handle_t *p_i2c)
Suspend some registers related to I2C configuration before sleep.
hal_status_t hal_i2c_slave_transmit(i2c_handle_t *p_i2c, uint8_t *p_data, uint16_t size, uint32_t timeout)
Transmits in slave mode an amount of data in blocking mode.
void hal_i2c_master_rx_cplt_callback(i2c_handle_t *p_i2c)
Master Rx Transfer completed callback.
hal_status_t hal_i2c_slave_receive(i2c_handle_t *p_i2c, uint8_t *p_data, uint16_t size, uint32_t timeout)
Receive in slave mode an amount of data in blocking mode.
hal_status_t hal_i2c_slave_transmit_it(i2c_handle_t *p_i2c, uint8_t *p_data, uint16_t size)
Transmit in slave mode an amount of data in non-blocking mode with Interrupt.
void hal_i2c_irq_handler(i2c_handle_t *p_i2c)
This function handles I2C event interrupt request.
void(* i2c_master_rx_cplt_callback)(i2c_handle_t *p_i2c)
void(* i2c_master_tx_cplt_callback)(i2c_handle_t *p_i2c)
hal_i2c_mode_t
HAL I2C Mode Enumerations definition.
hal_status_t hal_i2c_master_abort_it(i2c_handle_t *p_i2c)
Abort a master I2C IT or DMA process communication with Interrupt.
hal_status_t hal_i2c_timing_adjust(i2c_handle_t *p_i2c, uint32_t timing_type, int32_t delta)
Adjust I2C timing value to adapt to real load.
hal_status_t hal_i2c_mem_write_dma_sg_llp(i2c_handle_t *p_i2c, uint16_t dev_address, uint16_t mem_address, uint16_t mem_addr_size, uint8_t *p_data, uint16_t size, dma_sg_llp_config_t *sg_llp_config)
Write an amount of data in non-blocking mode with DMA to a specific memory address.
hal_status_t hal_i2c_mem_write_dma(i2c_handle_t *p_i2c, 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 DMA to a specific memory address.
hal_status_t
HAL Status structures definition.
hal_status_t hal_i2c_mem_write(i2c_handle_t *p_i2c, 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.
hal_status_t hal_i2c_mem_read(i2c_handle_t *p_i2c, 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.
hal_status_t hal_i2c_master_transmit(i2c_handle_t *p_i2c, uint16_t dev_address, uint8_t *p_data, uint16_t size, uint32_t timeout)
Transmits in master mode an amount of data in blocking mode.
void hal_i2c_msp_init(i2c_handle_t *p_i2c)
Initialize the I2C MSP.
hal_i2c_mode_t hal_i2c_get_mode(i2c_handle_t *p_i2c)
Returns the I2C Master, Slave, Memory or no mode.
void hal_i2c_error_callback(i2c_handle_t *p_i2c)
I2C error callback.
hal_status_t hal_i2c_master_receive_it(i2c_handle_t *p_i2c, uint16_t dev_address, uint8_t *p_data, uint16_t size)
Receive in master mode an amount of data in non-blocking mode with Interrupt.
hal_i2c_state_t hal_i2c_get_state(i2c_handle_t *p_i2c)
Return the I2C handle state.
hal_status_t hal_i2c_resume_reg(i2c_handle_t *p_i2c)
Restore some registers related to I2C configuration after sleep. This function must be used in conjun...
void hal_i2c_abort_cplt_callback(i2c_handle_t *p_i2c)
I2C abort callback.
__IO uint32_t xfer_options
uint32_t hal_i2c_sda_at_low_is_not_recovered(i2c_handle_t *p_i2c)
Return i2c sda at low is not recovered flag.
void hal_i2c_slave_tx_cplt_callback(i2c_handle_t *p_i2c)
Slave Tx Transfer completed callback.
__IO uint16_t master_ack_count
void hal_i2c_msp_deinit(i2c_handle_t *p_i2c)
De-initialize the I2C MSP.
DMA handle Structure definition.
This file contains HAL common definitions, enumeration, macros and structures definitions.
hal_status_t hal_i2c_master_transmit_dma_sg_llp(i2c_handle_t *p_i2c, uint16_t dev_address, uint8_t *p_data, uint16_t size, dma_sg_llp_config_t *sg_llp_config)
Transmit in master mode an amount of data in non-blocking mode with DMA.