|
3 | 3 | * @brief I2C Driver Private API definition.
|
4 | 4 | *******************************************************************************
|
5 | 5 | * # License
|
6 |
| - * <b>Copyright 2024 Silicon Laboratories Inc. www.silabs.com</b> |
| 6 | + * <b>Copyright 2025 Silicon Laboratories Inc. www.silabs.com</b> |
7 | 7 | *******************************************************************************
|
8 | 8 | *
|
9 | 9 | * SPDX-License-Identifier: Zlib
|
|
31 | 31 | #ifndef SLI_I2C_H
|
32 | 32 | #define SLI_I2C_H
|
33 | 33 |
|
34 |
| -#include "dmadrv.h" |
35 | 34 | #include "sl_i2c.h"
|
36 |
| -#include "sl_status.h" |
37 | 35 |
|
38 | 36 | #ifdef __cplusplus
|
39 | 37 | extern "C" {
|
40 | 38 | #endif
|
41 | 39 |
|
42 | 40 | /*******************************************************************************
|
43 |
| - ******************************* DEFINES *********************************** |
| 41 | + ***************************** PROTOTYPES ********************************** |
44 | 42 | ******************************************************************************/
|
45 |
| -// Max number of descriptors for dma tx and rx operations. |
46 |
| -#define SL_I2C_DMA_MAX_TX_DESCRIPTOR_COUNT 5 |
47 |
| -#define SL_I2C_DMA_MAX_RX_DESCRIPTOR_COUNT 5 |
48 |
| - |
49 |
| -/******************************************************************************* |
50 |
| - ******************************** ENUMS ************************************ |
51 |
| - ******************************************************************************/ |
52 |
| -/// I2C state enum |
53 |
| -SL_ENUM(sli_i2c_transaction_state_t) { |
54 |
| - SLI_I2C_STATE_ERROR = 0, /// Indicates an error occurred. |
55 |
| - SLI_I2C_STATE_SEND_START_AND_ADDR = 1, /// Send start and address byte. |
56 |
| - SLI_I2C_STATE_ADDR_WAIT_FOR_ACK_OR_NACK = 2, /// Wait for ACK/NACK on address byte. |
57 |
| - SLI_I2C_STATE_SEND_REPEATED_START_AND_ADDR = 3, /// Send repeated start and address byte. |
58 |
| - SLI_I2C_STATE_REPEATED_ADDR_WAIT_FOR_ACK_OR_NACK = 4, /// Wait for ACK/NACK for repeated start. |
59 |
| - SLI_I2C_STATE_ADDRESS_MATCH = 5, /// Wait for address matching. |
60 |
| - SLI_I2C_STATE_ADDR_2ND_BYTE_10BIT_WAIT_FOR_ACK_OR_NACK = 6, /// Wait for ACK/NACK on 2nd byte (10-bit). |
61 |
| - SLI_I2C_STATE_10BIT_ADDRESS_MATCH = 7, /// Wait for 10-bit address match. |
62 |
| - SLI_I2C_STATE_REP_ADDR_MATCH = 18, /// Wait for repeated start and address match. |
63 |
| - SLI_I2C_STATE_SEND_DATA = 8, /// Send data byte. |
64 |
| - SLI_I2C_STATE_WAIT_FOR_ACK_OR_NACK = 9, /// Wait for ACK or NACK after sending data. |
65 |
| - SLI_I2C_STATE_RECEIVE_DATA = 11, /// Data to be received. |
66 |
| - SLI_I2C_STATE_SEND_STOP = 13, /// Send stop signal. |
67 |
| - SLI_I2C_STATE_WAIT_FOR_STOP = 14, /// Wait for stop condition. |
68 |
| - SLI_I2C_STATE_DONE = 16, /// Transfer completed. |
69 |
| - SLI_I2C_STATE_TIMEOUT = 19 /// Timeout. |
70 |
| -}; |
71 |
| - |
72 |
| -/// I2C transfer mode enum |
73 |
| -SL_ENUM(sli_i2c_transfer_mode_t) { |
74 |
| - SLI_I2C_BLOCKING_TRANSFER = 0, /// I2C blocking transfer |
75 |
| - SLI_I2C_NON_BLOCKING_TRANSFER = 1, /// I2C non blocking transfer |
76 |
| -}; |
77 |
| - |
78 |
| -/******************************************************************************* |
79 |
| - ******************************* STRUCTS *********************************** |
80 |
| - ******************************************************************************/ |
81 |
| -/** |
82 |
| - * @struct sli_i2c_instance_t |
83 |
| - * @brief This struct represents an I2C instance, holding configuration details |
84 |
| - * for the peripheral, buffers and transaction state. |
85 |
| - * |
86 |
| - * @note Usage of `follower_address` depends on the operating mode: |
87 |
| - * Leader Mode : Used to specify the address of the follower device. |
88 |
| - * Follower Mode : Used to set the I2C device's own (self) address. |
89 |
| - */ |
90 |
| -typedef struct { |
91 |
| - I2C_TypeDef *i2c_base_addr; /// I2C base address. |
92 |
| - sl_i2c_operating_mode_t operating_mode; /// Leader/Follower operating mode. |
93 |
| - uint16_t follower_address; /// Follower address. |
94 |
| - bool is_10bit_addr; /// 7-bit or 10-bit address selection. |
95 |
| - sl_gpio_t scl_gpio; /// SCL GPIO Port and Pin. |
96 |
| - sl_gpio_t sda_gpio; /// SDA GPIO Port and Pin. |
97 |
| - const uint8_t *tx_buffer; /// Transmit data buffer. |
98 |
| - uint8_t *rx_buffer; /// Receive data buffer. |
99 |
| - uint16_t tx_len; /// Transmit buffer length. |
100 |
| - uint16_t rx_len; /// Receive buffer length. |
101 |
| - uint16_t tx_offset; /// Transmit offset in buffer. |
102 |
| - uint16_t rx_offset; /// Receive offset in buffer. |
103 |
| - sl_i2c_transfer_seq_t transfer_seq; /// I2C transaction sequence. |
104 |
| - sli_i2c_transaction_state_t state; /// I2C transaction state. |
105 |
| - sl_i2c_event_t transfer_event; /// I2C transfer event type. |
106 |
| - sli_i2c_transfer_mode_t transfer_mode; /// I2C transfer mode (blocking/non-blocking). |
107 |
| - sl_i2c_dma_channel_info_t dma_channel; /// I2C DMA Channel Info. |
108 |
| -/// DMA descriptor arrays for TX and RX operations. |
109 |
| -#if defined(EMDRV_DMADRV_LDMA) |
110 |
| - LDMA_Descriptor_t tx_desc[SL_I2C_DMA_MAX_TX_DESCRIPTOR_COUNT]; |
111 |
| - LDMA_Descriptor_t rx_desc[SL_I2C_DMA_MAX_RX_DESCRIPTOR_COUNT]; |
112 |
| - #elif defined(EMDRV_DMADRV_LDMA_S3) |
113 |
| - sl_hal_ldma_descriptor_t tx_desc[SL_I2C_DMA_MAX_TX_DESCRIPTOR_COUNT]; |
114 |
| - sl_hal_ldma_descriptor_t rx_desc[SL_I2C_DMA_MAX_RX_DESCRIPTOR_COUNT]; |
115 |
| - #endif |
116 |
| - uint8_t addr_buffer[3]; /// Address buffer. |
117 |
| - sl_i2c_irq_callback_t callback; /// I2C Callback. |
118 |
| - void *context; /// User-defined context. |
119 |
| - uint8_t addr_buffer_write[1]; /// Write address byte |
120 |
| - uint8_t addr_buffer_read[1]; /// Read address byte |
121 |
| - uint8_t rstart; /// Repeated Start. |
122 |
| -} sli_i2c_instance_t; |
123 | 43 |
|
124 | 44 | /***************************************************************************//**
|
125 |
| - * This function is used for the configuring I2C instance. |
| 45 | + * Configure the I2C instance with initialization parameters. |
126 | 46 | *
|
127 |
| - * @param[in] init_params A pointer to Init Params. |
| 47 | + * @details |
| 48 | + * This function resets the I2C peripheral, configures interrupts, sets the |
| 49 | + * operating mode (leader/follower), and sets the clock frequency for leader mode. |
| 50 | + * It is called internally during driver initialization. |
128 | 51 | *
|
129 |
| - * @return return status. |
130 |
| - ******************************************************************************/ |
131 |
| -sl_status_t sli_i2c_instance_configuration(const sl_i2c_init_params_t *init_params); |
132 |
| - |
133 |
| -/***************************************************************************//** |
134 |
| - * This function is used for the setting the follower address for follower. |
| 52 | + * @param[in] i2c_handle Pointer to the I2C instance handle. |
135 | 53 | *
|
136 |
| - * @param[in] i2c_base_addr Pointer to I2C Base Address. |
137 |
| - * @param[in] follower_address Follower address. |
138 |
| - * @param[in] is_10bit_addr Indicates whether the follower address is 7-bit or 10-bit. |
139 |
| - * True if the address is 10-bit, false if it is 7-bit. |
| 54 | + * @return |
| 55 | + * - SL_STATUS_OK on success. |
| 56 | + * - SL_STATUS_NULL_POINTER if init_params is NULL. |
| 57 | + * - SL_STATUS_NOT_SUPPORTED if the peripheral is invalid. |
| 58 | + * - SL_STATUS_FAIL if clock frequency retrieval fails. |
140 | 59 | ******************************************************************************/
|
141 |
| -void sli_i2c_set_follower_address(I2C_TypeDef *i2c_base_addr, |
142 |
| - uint16_t follower_address, |
143 |
| - bool is_10bit_addr); |
| 60 | +sl_status_t sli_i2c_init_core(sl_i2c_handle_t *i2c_handle); |
144 | 61 |
|
145 | 62 | /***************************************************************************//**
|
146 |
| - * This function is used for the configuring GPIOs for I2C instance. |
| 63 | + * Dispatch interrupt handler for the I2C Leader |
147 | 64 | *
|
148 |
| - * @param[in] i2c_base_addr Pointer to I2C Base Address. |
149 |
| - * @param[in] sda_gpio SDA GPIO Port and Pin. |
150 |
| - * @param[in] scl_gpio SCL GPIO Port and Pin. |
151 |
| - * @param[in] enable Enable/Disable the gpio. |
152 |
| - ******************************************************************************/ |
153 |
| -void sli_i2c_configure_gpio(I2C_TypeDef *i2c_base_addr, |
154 |
| - sl_gpio_t sda_gpio, |
155 |
| - sl_gpio_t scl_gpio, |
156 |
| - bool enable); |
157 |
| - |
158 |
| -/***************************************************************************//** |
159 |
| - * This function is used for the initialization of I2C instance. |
| 65 | + * @details Handles all I2C interrupts for leader mode, including ACK/NACK, STOP, |
| 66 | + * arbitration lost, and bus errors. Updates the driver state and event fields. |
| 67 | + * Called from the IRQ handler or internal state machine. |
160 | 68 | *
|
161 |
| - * @param[in] i2c_base_addr Pointer to I2C Base Address. |
162 |
| - * @param[in] operating_mode Operating mode of the i2c instance (Leader/Follower). |
163 |
| - * @param[in] transfer_seq Transfer Sequence. |
| 69 | + * @param[in] i2c_handle Pointer to the I2C instance handle. |
164 | 70 | ******************************************************************************/
|
165 |
| -void sli_i2c_transfer_init(I2C_TypeDef *i2c_base_addr, |
166 |
| - sl_i2c_operating_mode_t operating_mode, |
167 |
| - sl_i2c_transfer_seq_t transfer_seq); |
| 71 | +void sli_i2c_leader_dispatch_interrupt(sl_i2c_handle_t *i2c_handle); |
168 | 72 |
|
169 | 73 | /***************************************************************************//**
|
170 |
| - * This function is used for the initialization of I2C DMA transfer. |
171 |
| - * |
172 |
| - * @param[in] i2c_instance I2C Instance |
| 74 | + * Dispatch interrupt handler for the I2C Follower |
173 | 75 | *
|
174 |
| - * @return return status. |
175 |
| - ******************************************************************************/ |
176 |
| -sl_status_t sli_i2c_dma_transfer_init(sli_i2c_instance_t *i2c_instance); |
177 |
| - |
178 |
| -/***************************************************************************//** |
179 |
| - * Handles the I2C leader mode non-blocking interrupt dispatch. |
| 76 | + * @details Handles all I2C interrupts for follower mode, including address match, |
| 77 | + * RX data, STOP, and error conditions. Updates the driver state and event fields. |
| 78 | + * Called from the IRQ handler or internal state machine. |
180 | 79 | *
|
181 |
| - * @param[in] sl_i2c_instance Pointer to the I2C instance structure. |
| 80 | + * @param[in] i2c_handle Pointer to the I2C instance handle. |
182 | 81 | ******************************************************************************/
|
183 |
| -void sli_i2c_leader_dispatch_interrupt(sli_i2c_instance_t *sl_i2c_instance); |
184 |
| - |
185 |
| -/***************************************************************************//** |
186 |
| - * Handles the I2C follower mode non-blocking interrupt dispatch. |
187 |
| - * |
188 |
| - * @param[in] sl_i2c_instance Pointer to the I2C instance structure. |
189 |
| - ******************************************************************************/ |
190 |
| -void sli_i2c_follower_dispatch_interrupt(sli_i2c_instance_t *sl_i2c_instance); |
| 82 | +void sli_i2c_follower_dispatch_interrupt(sl_i2c_handle_t *i2c_handle); |
191 | 83 |
|
192 | 84 | #ifdef __cplusplus
|
193 | 85 | }
|
194 | 86 | #endif
|
195 | 87 |
|
196 | 88 | #endif // SLI_I2C_H
|
| 89 | + |
0 commit comments