@@ -67,7 +67,7 @@ static inline void gd32_i2c_xfer_read(struct gd32_i2c *i2c_obj)
6767 rt_uint8_t read_byte ;
6868
6969 i2c_obj -> current -> len -- ;
70- read_byte = I2C_DATA (cfg -> i2c_periph );
70+ read_byte = I2C_DATA (cfg -> i2c_periph );
7171 * i2c_obj -> current -> buf = read_byte ;
7272
7373 LOG_D ("[%s] < Read byte: 0x%02X" , cfg -> device_name , read_byte );
@@ -313,7 +313,7 @@ static rt_ssize_t gd32_i2c_master_xfer(struct rt_i2c_bus_device *bus, struct rt_
313313
314314 i2c_dev = rt_container_of (bus , struct gd32_i2c , parent );
315315 cfg = i2c_dev -> config ;
316-
316+
317317 LOG_D ("[%s] master_xfer: num_msgs=%d" , cfg -> device_name , num );
318318
319319 for (i = 0 ; i < num ; i ++ )
@@ -323,6 +323,7 @@ static rt_ssize_t gd32_i2c_master_xfer(struct rt_i2c_bus_device *bus, struct rt_
323323 LOG_E ("[%s] Only the last message can have a STOP signal" , cfg -> device_name );
324324 return - RT_EINVAL ;
325325 }
326+
326327 if (msgs [i ].len == 0 || msgs [i ].buf == RT_NULL )
327328 {
328329 LOG_E ("[%s] Invalid message buffer or length at index %d" , cfg -> device_name , i );
@@ -361,7 +362,7 @@ static rt_ssize_t gd32_i2c_master_xfer(struct rt_i2c_bus_device *bus, struct rt_
361362 result = - RT_EBUSY ;
362363 break ;
363364 }
364-
365+
365366 if (i2c_dev -> current -> flags & RT_I2C_ADDR_10BIT )
366367 {
367368 i2c_dev -> addr1 = 0xF0 | ((current_addr >> 8 ) & 0x03 );
@@ -372,11 +373,11 @@ static rt_ssize_t gd32_i2c_master_xfer(struct rt_i2c_bus_device *bus, struct rt_
372373 {
373374 i2c_dev -> addr1 = current_addr & 0x7F ;
374375 }
375-
376+
376377 i2c_dev -> errs = 0 ;
377378 i2c_dev -> is_restart = RT_FALSE ;
378379 rt_completion_init (& i2c_dev -> sync_sem );
379-
380+
380381 I2C_CTL0 (cfg -> i2c_periph ) |= I2C_CTL0_ACKEN ;
381382
382383 if ((i2c_dev -> current -> flags & RT_I2C_RD ) && (i2c_dev -> current -> flags & RT_I2C_ADDR_10BIT ))
@@ -391,7 +392,7 @@ static rt_ssize_t gd32_i2c_master_xfer(struct rt_i2c_bus_device *bus, struct rt_
391392 LOG_D ("[%s] N=2 read, setting POAP." , cfg -> device_name );
392393 I2C_CTL0 (cfg -> i2c_periph ) |= I2C_CTL0_POAP ;
393394 }
394-
395+
395396 LOG_D ("[%s] Generating START, enabling IRQs, waiting for completion..." , cfg -> device_name );
396397 i2c_enable_interrupts (cfg -> i2c_periph );
397398 I2C_CTL0 (cfg -> i2c_periph ) |= I2C_CTL0_START ;
@@ -402,17 +403,18 @@ static rt_ssize_t gd32_i2c_master_xfer(struct rt_i2c_bus_device *bus, struct rt_
402403 {
403404 i2c_dev -> current -> flags |= RT_I2C_RD ;
404405 }
405-
406+
406407 I2C_CTL0 (cfg -> i2c_periph ) &= ~I2C_CTL0_POAP ;
407408 i2c_disable_interrupts (cfg -> i2c_periph );
408-
409+
409410 if (result != RT_EOK )
410411 {
411412 LOG_E ("[%s] I2C transaction timeout!" , cfg -> device_name );
412413 result = - RT_ETIMEOUT ;
413414 I2C_CTL0 (cfg -> i2c_periph ) |= I2C_CTL0_STOP ;
414415 break ;
415416 }
417+
416418 if (i2c_dev -> errs != 0 )
417419 {
418420 LOG_E ("[%s] Hardware error detected by ISR." , cfg -> device_name );
@@ -437,11 +439,11 @@ static rt_ssize_t gd32_i2c_master_xfer(struct rt_i2c_bus_device *bus, struct rt_
437439 LOG_D ("[%s] Last message has NO_STOP flag, leaving bus active." , cfg -> device_name );
438440 }
439441 }
440-
442+
441443 I2C_CTL0 (cfg -> i2c_periph ) &= ~I2C_CTL0_I2CEN ;
442-
444+
443445 rt_mutex_release (& i2c_dev -> bus_mutex );
444-
446+
445447 LOG_D ("[%s] master_xfer exiting with code: %d" , cfg -> device_name , (result == RT_EOK ) ? i : result );
446448 if (result == RT_EOK )
447449 {
@@ -472,7 +474,7 @@ static struct gd32_i2c *_get_i2c_obj(uint32_t i2c_periph)
472474void I2C0_EV_IRQHandler (void )
473475{
474476 rt_interrupt_enter ();
475-
477+
476478 struct gd32_i2c * i2c_obj = _get_i2c_obj (I2C0 );
477479 if (i2c_obj )
478480 {
@@ -507,7 +509,7 @@ void I2C1_EV_IRQHandler(void)
507509 {
508510 gd32_i2c_event_handler (i2c_obj );
509511 }
510-
512+
511513 rt_interrupt_leave ();
512514}
513515
@@ -592,4 +594,5 @@ int rt_hw_i2c_init(void)
592594}
593595INIT_BOARD_EXPORT (rt_hw_i2c_init );
594596
595- #endif /* RT_USING_I2C */
597+ #endif /* RT_USING_I2C */
598+
0 commit comments