@@ -32,14 +32,18 @@ static I2C_Type *const i2c_addrs[] = I2C_BASE_PTRS;
32
32
/* Array of I2C bus clock frequencies */
33
33
static clock_name_t const i2c_clocks [] = I2C_CLOCK_FREQS ;
34
34
35
- void i2c_init (i2c_t * obj , PinName sda , PinName scl )
35
+ #if EXPLICIT_PINMAP_READY
36
+ #define I2C_INIT_DIRECT i2c_init_direct
37
+ void i2c_init_direct (i2c_t * obj , const i2c_pinmap_t * pinmap )
38
+ #else
39
+ #define I2C_INIT_DIRECT _i2c_init_direct
40
+ static void _i2c_init_direct (i2c_t * obj , const i2c_pinmap_t * pinmap )
41
+ #endif
36
42
{
37
- uint32_t i2c_sda = pinmap_peripheral (sda , PinMap_I2C_SDA );
38
- uint32_t i2c_scl = pinmap_peripheral (scl , PinMap_I2C_SCL );
39
43
PORT_Type * port_addrs [] = PORT_BASE_PTRS ;
40
- PORT_Type * base = port_addrs [sda >> GPIO_PORT_SHIFT ];
44
+ PORT_Type * base = port_addrs [pinmap -> sda_pin >> GPIO_PORT_SHIFT ];
41
45
42
- obj -> instance = pinmap_merge ( i2c_sda , i2c_scl ) ;
46
+ obj -> instance = ( uint32_t ) pinmap -> peripheral ;
43
47
obj -> next_repeated_start = 0 ;
44
48
MBED_ASSERT ((int )obj -> instance != NC );
45
49
@@ -49,19 +53,36 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl)
49
53
I2C_MasterInit (i2c_addrs [obj -> instance ], & master_config , CLOCK_GetFreq (i2c_clocks [obj -> instance ]));
50
54
I2C_EnableInterrupts (i2c_addrs [obj -> instance ], kI2C_GlobalInterruptEnable );
51
55
52
- pinmap_pinout (sda , PinMap_I2C_SDA );
53
- pinmap_pinout (scl , PinMap_I2C_SCL );
56
+ pin_function (pinmap -> sda_pin , pinmap -> sda_function );
57
+ pin_mode (pinmap -> sda_pin , PullNone );
58
+ pin_function (pinmap -> scl_pin , pinmap -> scl_function );
59
+ pin_mode (pinmap -> scl_pin , PullNone );
54
60
55
61
/* Enable internal pullup resistor */
56
- base -> PCR [sda & 0xFF ] |= (PORT_PCR_PE_MASK | PORT_PCR_PS_MASK );
57
- base -> PCR [scl & 0xFF ] |= (PORT_PCR_PE_MASK | PORT_PCR_PS_MASK );
62
+ base -> PCR [pinmap -> sda_pin & 0xFF ] |= (PORT_PCR_PE_MASK | PORT_PCR_PS_MASK );
63
+ base -> PCR [pinmap -> scl_pin & 0xFF ] |= (PORT_PCR_PE_MASK | PORT_PCR_PS_MASK );
58
64
59
65
#if defined(FSL_FEATURE_PORT_HAS_OPEN_DRAIN ) && FSL_FEATURE_PORT_HAS_OPEN_DRAIN
60
- base -> PCR [sda & 0xFF ] |= PORT_PCR_ODE_MASK ;
61
- base -> PCR [scl & 0xFF ] |= PORT_PCR_ODE_MASK ;
66
+ base -> PCR [pinmap -> sda_pin & 0xFF ] |= PORT_PCR_ODE_MASK ;
67
+ base -> PCR [pinmap -> scl_pin & 0xFF ] |= PORT_PCR_ODE_MASK ;
62
68
#endif
63
69
}
64
70
71
+ void i2c_init (i2c_t * obj , PinName sda , PinName scl )
72
+ {
73
+ uint32_t i2c_sda = pinmap_peripheral (sda , PinMap_I2C_SDA );
74
+ uint32_t i2c_scl = pinmap_peripheral (scl , PinMap_I2C_SCL );
75
+
76
+ int peripheral = (int )pinmap_merge (i2c_sda , i2c_scl );
77
+
78
+ int sda_function = (int )pinmap_find_function (sda , PinMap_I2C_SDA );
79
+ int scl_function = (int )pinmap_find_function (scl , PinMap_I2C_SCL );
80
+
81
+ const i2c_pinmap_t explicit_i2c_pinmap = {peripheral , sda , sda_function , scl , scl_function };
82
+
83
+ I2C_INIT_DIRECT (obj , & explicit_i2c_pinmap );
84
+ }
85
+
65
86
int i2c_start (i2c_t * obj )
66
87
{
67
88
I2C_Type * base = i2c_addrs [obj -> instance ];
0 commit comments