66 * Change Logs:
77 * Date Author Notes
88 * 2021-12-20 BruceOu the first version
9- * 2026-01-11 ShiHongchao Fix the I2C master receive mode B software
9+ * 2026-01-11 ShiHongchao Fix the I2C master receive mode B software
1010 * flow and add support for mode A
1111 */
1212
1717#define LOG_TAG "drv.i2c"
1818#include <rtdbg.h>
1919
20- #if !defined(BSP_USING_HARD_I2C0 ) && !defined(BSP_USING_HARD_I2C1 ) && !defined(BSP_USING_HARD_I2C2 ) && !defined(BSP_USING_HARD_I2C3 ) && !defined(BSP_USING_HARD_I2C4 ) && !defined(BSP_USING_HARD_I2C5 )
20+ #if !defined(BSP_USING_HARD_I2C0 ) && !defined(BSP_USING_HARD_I2C1 ) && !defined(BSP_USING_HARD_I2C2 ) && !defined(BSP_USING_HARD_I2C3 ) && !defined(BSP_USING_HARD_I2C4 ) && !defined(BSP_USING_HARD_I2C5 )
2121#error "Please define at least one BSP_USING_I2Cx"
2222/* this driver can be disabled at menuconfig → RT-Thread Components → Device Drivers */
2323#endif
@@ -233,9 +233,9 @@ static uint8_t gd32_i2c_read(rt_uint32_t i2c_periph, rt_uint8_t *p_buffer, rt_ui
233233 if (data_byte == 0 ) return 1 ;
234234
235235#ifdef BSP_USING_RECEIVING_A
236- /*
237- In single-byte reception, disable ACK because the master needs to send
238- NACK after receiving the first byte,indicating no more data will be
236+ /*
237+ In single-byte reception, disable ACK because the master needs to send
238+ NACK after receiving the first byte,indicating no more data will be
239239 received, then immediately send the stop condition
240240 */
241241 if (data_byte == 1 )
@@ -246,17 +246,17 @@ static uint8_t gd32_i2c_read(rt_uint32_t i2c_periph, rt_uint8_t *p_buffer, rt_ui
246246 i2c_stop_on_bus (i2c_periph );
247247 }
248248#endif
249-
249+
250250 /* while there is data to be read */
251251 while (data_byte )
252252 {
253253#if defined (SOC_SERIES_GD32F5xx ) || defined (SOC_SERIES_GD32F4xx )
254254 if (IS_I2C_LEGACY (i2c_periph ))
255255 {
256256#ifdef BSP_USING_RECEIVING_A
257- /*
258- After receiving the second-to-last byte, ACK should be disabled
259- and STOP should be set, to ensure that NACK is sent after receiving
257+ /*
258+ After receiving the second-to-last byte, ACK should be disabled
259+ and STOP should be set, to ensure that NACK is sent after receiving
260260 the last byte and the stop condition is transmitted
261261 */
262262 if (2 == data_byte )
@@ -269,13 +269,13 @@ static uint8_t gd32_i2c_read(rt_uint32_t i2c_periph, rt_uint8_t *p_buffer, rt_ui
269269 i2c_stop_on_bus (i2c_periph );
270270 }
271271#elif defined(BSP_USING_RECEIVING_B )
272- /*
273- For 3-byte reception: Wait for byte transfer completion, then
274- disable ACK so NACK is automatically sent after receiving the
272+ /*
273+ For 3-byte reception: Wait for byte transfer completion, then
274+ disable ACK so NACK is automatically sent after receiving the
275275 last byte
276- For 2-byte reception: Wait for byte transfer completion, then
277- send stop condition to ensure direct stop after receiving the
278- last byte instead of sending ACK
276+ For 2-byte reception: Wait for byte transfer completion, then
277+ send stop condition to ensure direct stop after receiving the
278+ last byte instead of sending ACK
279279 */
280280 if (3 == data_byte )
281281 {
@@ -621,4 +621,3 @@ int rt_hw_i2c_init(void)
621621INIT_BOARD_EXPORT (rt_hw_i2c_init );
622622
623623#endif /* RT_USING_I2C */
624-
0 commit comments