mirror of https://github.com/ARMmbed/mbed-os.git
I2C: Add explicit pinmap support
parent
2185e80e08
commit
80b46769aa
|
@ -101,6 +101,12 @@ public:
|
|||
*/
|
||||
I2C(PinName sda, PinName scl);
|
||||
|
||||
/** Create an I2C Master interface, connected to the specified pins
|
||||
*
|
||||
* @param explicit_pinmap reference to strucure which holds static pinmap.
|
||||
*/
|
||||
I2C(const i2c_pinmap_t &explicit_pinmap);
|
||||
|
||||
/** Set the frequency of the I2C interface
|
||||
*
|
||||
* @param hz The bus frequency in hertz
|
||||
|
|
|
@ -86,6 +86,12 @@ public:
|
|||
*/
|
||||
I2CSlave(PinName sda, PinName scl);
|
||||
|
||||
/** Create an I2C Slave interface, connected to the specified pins.
|
||||
*
|
||||
* @param explicit_pinmap reference to strucure which holds static pinmap.
|
||||
*/
|
||||
I2CSlave(const i2c_pinmap_t &explicit_pinmap);
|
||||
|
||||
/** Set the frequency of the I2C interface.
|
||||
*
|
||||
* @param hz The bus frequency in Hertz.
|
||||
|
|
|
@ -47,6 +47,23 @@ I2C::I2C(PinName sda, PinName scl) :
|
|||
unlock();
|
||||
}
|
||||
|
||||
I2C::I2C(const i2c_pinmap_t &explicit_pinmap) :
|
||||
#if DEVICE_I2C_ASYNCH
|
||||
_irq(this), _usage(DMA_USAGE_NEVER), _deep_sleep_locked(false),
|
||||
#endif
|
||||
_i2c(), _hz(100000)
|
||||
{
|
||||
lock();
|
||||
// The init function also set the frequency to 100000
|
||||
_sda = explicit_pinmap.sda_pin;
|
||||
_scl = explicit_pinmap.scl_pin;
|
||||
recover(explicit_pinmap.sda_pin, explicit_pinmap.scl_pin);
|
||||
i2c_init_direct(&_i2c, &explicit_pinmap);
|
||||
// Used to avoid unnecessary frequency updates
|
||||
_owner = this;
|
||||
unlock();
|
||||
}
|
||||
|
||||
void I2C::frequency(int hz)
|
||||
{
|
||||
lock();
|
||||
|
|
|
@ -27,6 +27,13 @@ I2CSlave::I2CSlave(PinName sda, PinName scl) : _i2c()
|
|||
i2c_slave_mode(&_i2c, 1);
|
||||
}
|
||||
|
||||
I2CSlave::I2CSlave(const i2c_pinmap_t &explicit_pinmap) : _i2c()
|
||||
{
|
||||
i2c_init_direct(&_i2c, &explicit_pinmap);
|
||||
i2c_frequency(&_i2c, 100000);
|
||||
i2c_slave_mode(&_i2c, 1);
|
||||
}
|
||||
|
||||
void I2CSlave::frequency(int hz)
|
||||
{
|
||||
i2c_frequency(&_i2c, hz);
|
||||
|
|
Loading…
Reference in New Issue