@@ -55,7 +55,7 @@ extern "C" {
5555
5656/* Generic definition for series requiring I2C timing calculation */
5757#if !defined (AIR32F1xx ) && !defined (AIRF2xx ) && !defined (AIRF4xx ) && \
58- !defined (AIRL1xx )
58+ !defined (AIRL1xx ) && !defined( AIR001xx )
5959#define I2C_TIMING
6060#endif
6161
@@ -156,7 +156,7 @@ static const I2C_Charac_t I2C_Charac[] = {
156156
157157/* Family specific description for I2C */
158158typedef enum {
159- #if defined(I2C1_BASE )
159+ #if defined(I2C1_BASE ) || (defined( AIR001xx ) && defined( I2C_BASE ))
160160 I2C1_INDEX ,
161161#endif
162162#if defined(I2C2_BASE )
@@ -637,10 +637,10 @@ static uint32_t i2c_getTiming(i2c_t *obj, uint32_t frequency)
637637 */
638638void i2c_init (i2c_t * obj )
639639{
640- #ifdef AIR001xx
641- i2c_custom_init (obj , 100000 , 0xFFFFFFFF , 0x33 );
642- #else
640+ #if !defined(AIR001xx )
643641 i2c_custom_init (obj , 100000 , I2C_ADDRESSINGMODE_7BIT , 0x33 );
642+ #else
643+ i2c_custom_init (obj , 100000 , 0 , 0x33 );
644644#endif
645645}
646646
@@ -675,13 +675,18 @@ void i2c_custom_init(i2c_t *obj, uint32_t timing, uint32_t addressingMode, uint3
675675
676676 } else {
677677
678- #if defined I2C1_BASE
678+ #if defined I2C1_BASE || (defined( AIR001xx ) && defined( I2C_BASE ))
679679 // Enable I2C1 clock if not done
680680 if (obj -> i2c == I2C1 ) {
681+ #if defined(AIR001xx )
682+ __HAL_RCC_I2C_CLK_ENABLE ();
683+ __HAL_RCC_I2C_FORCE_RESET ();
684+ __HAL_RCC_I2C_RELEASE_RESET ();
685+ #else
681686 __HAL_RCC_I2C1_CLK_ENABLE ();
682687 __HAL_RCC_I2C1_FORCE_RESET ();
683688 __HAL_RCC_I2C1_RELEASE_RESET ();
684-
689+ #endif
685690 obj -> irq = I2C1_EV_IRQn ;
686691#if !defined(AIRC0xx ) && !defined(AIR001xx ) && !defined(AIRG0xx ) && !defined(AIRL0xx )
687692 obj -> irqER = I2C1_ER_IRQn ;
@@ -755,16 +760,7 @@ void i2c_custom_init(i2c_t *obj, uint32_t timing, uint32_t addressingMode, uint3
755760
756761 handle -> Instance = obj -> i2c ;
757762#ifdef I2C_TIMING
758- #ifdef AIR001xx
759- handle -> Init .ClockSpeed = timing ;
760- if (timing > 100000 ) {
761- handle -> Init .DutyCycle = I2C_DUTYCYCLE_16_9 ;
762- } else {
763- handle -> Init .DutyCycle = I2C_DUTYCYCLE_2 ;
764- }
765- #else
766763 handle -> Init .Timing = i2c_getTiming (obj , timing );
767- #endif
768764#else
769765 handle -> Init .ClockSpeed = i2c_getTiming (obj , timing );
770766 /* Standard mode (sm) is up to 100kHz, then it's Fast mode (fm) */
@@ -794,7 +790,6 @@ void i2c_custom_init(i2c_t *obj, uint32_t timing, uint32_t addressingMode, uint3
794790 HAL_NVIC_SetPriority (obj -> irqER , I2C_IRQ_PRIO , I2C_IRQ_SUBPRIO );
795791 HAL_NVIC_EnableIRQ (obj -> irqER );
796792#endif /* !AIRC0xx && !AIR001xx && !AIRG0xx && !AIRL0xx */
797-
798793 /* Init the I2C */
799794 if (HAL_I2C_Init (handle ) != HAL_OK ) {
800795 /* Initialization Error */
@@ -835,16 +830,7 @@ void i2c_setTiming(i2c_t *obj, uint32_t frequency)
835830 __HAL_I2C_DISABLE (& (obj -> handle ));
836831
837832#ifdef I2C_TIMING
838- #ifdef AIR001xx
839- obj -> handle .Init .ClockSpeed = frequency ;
840- if (f > 100000 ) {
841- obj -> handle .Init .DutyCycle = I2C_DUTYCYCLE_16_9 ;
842- } else {
843- obj -> handle .Init .DutyCycle = I2C_DUTYCYCLE_2 ;
844- }
845- #else
846833 obj -> handle .Init .Timing = f ;
847- #endif
848834#else
849835 obj -> handle .Init .ClockSpeed = f ;
850836 /* Standard mode (sm) is up to 100kHz, then it's Fast mode (fm) */
0 commit comments