cpu/nrf52: Add i2c reconfigure for use with CryptoAuth devices
This commit is contained in:
parent
c337089de5
commit
40d749644f
@ -14,6 +14,7 @@ config CPU_FAM_NRF52
|
|||||||
select HAS_BLE_NIMBLE_NETIF
|
select HAS_BLE_NIMBLE_NETIF
|
||||||
select HAS_CORTEXM_MPU
|
select HAS_CORTEXM_MPU
|
||||||
select HAS_CPU_NRF52
|
select HAS_CPU_NRF52
|
||||||
|
select HAS_PERIPH_I2C_RECONFIGURE
|
||||||
|
|
||||||
## CPU Models
|
## CPU Models
|
||||||
config CPU_MODEL_NRF52805XXAA
|
config CPU_MODEL_NRF52805XXAA
|
||||||
|
|||||||
@ -20,4 +20,6 @@ FEATURES_PROVIDED += ble_nimble_netif
|
|||||||
# all nrf52 have an MPU
|
# all nrf52 have an MPU
|
||||||
FEATURES_PROVIDED += cortexm_mpu
|
FEATURES_PROVIDED += cortexm_mpu
|
||||||
|
|
||||||
|
FEATURES_PROVIDED += periph_i2c_reconfigure
|
||||||
|
|
||||||
include $(RIOTCPU)/nrf5x_common/Makefile.features
|
include $(RIOTCPU)/nrf5x_common/Makefile.features
|
||||||
|
|||||||
@ -137,6 +137,14 @@ typedef struct {
|
|||||||
#define PERIPH_I2C_NEED_WRITE_REG
|
#define PERIPH_I2C_NEED_WRITE_REG
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @name Define macros for sda and scl pin to be able to reinitialize them
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define i2c_pin_sda(dev) i2c_config[dev].sda
|
||||||
|
#define i2c_pin_scl(dev) i2c_config[dev].scl
|
||||||
|
/** @} */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name The PWM unit on the nRF52 supports 4 channels per device
|
* @name The PWM unit on the nRF52 supports 4 channels per device
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -87,6 +87,14 @@ static int finish(i2c_t dev)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void _init_pins(i2c_t dev)
|
||||||
|
{
|
||||||
|
gpio_init(i2c_config[dev].scl, GPIO_IN_OD_PU);
|
||||||
|
gpio_init(i2c_config[dev].sda, GPIO_IN_OD_PU);
|
||||||
|
bus(dev)->PSEL.SCL = i2c_config[dev].scl;
|
||||||
|
bus(dev)->PSEL.SDA = i2c_config[dev].sda;
|
||||||
|
}
|
||||||
|
|
||||||
void i2c_init(i2c_t dev)
|
void i2c_init(i2c_t dev)
|
||||||
{
|
{
|
||||||
assert(dev < I2C_NUMOF);
|
assert(dev < I2C_NUMOF);
|
||||||
@ -99,22 +107,42 @@ void i2c_init(i2c_t dev)
|
|||||||
/* disable device during initialization, will be enabled when acquire is
|
/* disable device during initialization, will be enabled when acquire is
|
||||||
* called */
|
* called */
|
||||||
bus(dev)->ENABLE = TWIM_ENABLE_ENABLE_Disabled;
|
bus(dev)->ENABLE = TWIM_ENABLE_ENABLE_Disabled;
|
||||||
|
|
||||||
/* configure pins */
|
/* configure pins */
|
||||||
gpio_init(i2c_config[dev].scl, GPIO_IN_OD_PU);
|
_init_pins(dev);
|
||||||
gpio_init(i2c_config[dev].sda, GPIO_IN_OD_PU);
|
|
||||||
bus(dev)->PSEL.SCL = i2c_config[dev].scl;
|
|
||||||
bus(dev)->PSEL.SDA = i2c_config[dev].sda;
|
|
||||||
/* configure dev clock speed */
|
/* configure dev clock speed */
|
||||||
bus(dev)->FREQUENCY = i2c_config[dev].speed;
|
bus(dev)->FREQUENCY = i2c_config[dev].speed;
|
||||||
|
|
||||||
spi_twi_irq_register_i2c(bus(dev), i2c_isr_handler, (void *)dev);
|
spi_twi_irq_register_i2c(bus(dev), i2c_isr_handler, (void *)dev);
|
||||||
|
|
||||||
/* re-enable the device. We expect that the device was being acquired before
|
/* We expect that the device was being acquired before
|
||||||
* the i2c_init_master() function is called, so it should be enabled when
|
* the i2c_init_master() function is called, so it should be enabled when
|
||||||
* exiting this function. */
|
* exiting this function. */
|
||||||
bus(dev)->ENABLE = TWIM_ENABLE_ENABLE_Enabled;
|
bus(dev)->ENABLE = TWIM_ENABLE_ENABLE_Enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef MODULE_PERIPH_I2C_RECONFIGURE
|
||||||
|
void i2c_init_pins(i2c_t dev)
|
||||||
|
{
|
||||||
|
assert(dev < I2C_NUMOF);
|
||||||
|
|
||||||
|
_init_pins(dev);
|
||||||
|
|
||||||
|
bus(dev)->ENABLE = TWIM_ENABLE_ENABLE_Enabled;
|
||||||
|
|
||||||
|
mutex_unlock(&locks[dev]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void i2c_deinit_pins(i2c_t dev)
|
||||||
|
{
|
||||||
|
assert(dev < I2C_NUMOF);
|
||||||
|
|
||||||
|
mutex_lock(&locks[dev]);
|
||||||
|
bus(dev)->ENABLE = TWIM_ENABLE_ENABLE_Disabled;
|
||||||
|
}
|
||||||
|
#endif /* MODULE_PERIPH_I2C_RECONFIGURE */
|
||||||
|
|
||||||
int i2c_acquire(i2c_t dev)
|
int i2c_acquire(i2c_t dev)
|
||||||
{
|
{
|
||||||
assert(dev < I2C_NUMOF);
|
assert(dev < I2C_NUMOF);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user