nrf5/hal: Adding members to TWI config struct, device address and scl/sda pin. Renaming and adding function such that twi slave and master has seperate init function. Started implementation of master init function for nrf52 using DMA (hal_twie.c).
This commit is contained in:
parent
9787c4af7b
commit
97a3fd4f3a
|
@ -35,7 +35,10 @@ static const uint32_t hal_twi_frequency_lookup[] = {
|
|||
TWI_FREQUENCY_FREQUENCY_K400, // 400 kbps
|
||||
};
|
||||
|
||||
void hal_twi_init(NRF_TWI_Type * p_instance, hal_twi_init_t const * p_twi_init) {
|
||||
void hal_twi_master_init(NRF_TWI_Type * p_instance, hal_twi_init_t const * p_twi_init) {
|
||||
}
|
||||
|
||||
void hal_twi_slave_init(NRF_TWI_Type * p_instance, hal_twi_init_t const * p_twi_init) {
|
||||
}
|
||||
|
||||
#endif // HAL_TWI_MODULE_ENABLED
|
||||
|
|
|
@ -81,8 +81,11 @@ typedef enum {
|
|||
*/
|
||||
typedef struct {
|
||||
uint8_t id; /* TWI instance id */
|
||||
const pin_obj_t * scl_pin; /* TWI SCL pin */
|
||||
const pin_obj_t * sda_pin; /* TWI SDA pin */
|
||||
hal_twi_role_t role; /* TWI master/slave */
|
||||
hal_twi_clk_freq_t freq; /* TWI frequency */
|
||||
uint32_t dev_addr; /* TWI master device address */
|
||||
} hal_twi_init_t;
|
||||
|
||||
/**
|
||||
|
@ -94,6 +97,9 @@ typedef struct __TWI_HandleTypeDef
|
|||
hal_twi_init_t init; /* TWI initialization parameters */
|
||||
} TWI_HandleTypeDef;
|
||||
|
||||
void hal_twi_init(NRF_TWI_Type * p_instance, hal_twi_init_t const * p_twi_init);
|
||||
void hal_twi_master_init(NRF_TWI_Type * p_instance, hal_twi_init_t const * p_twi_init);
|
||||
|
||||
void hal_twi_slave_init(NRF_TWI_Type * p_instance, hal_twi_init_t const * p_twi_init);
|
||||
|
||||
|
||||
#endif // HAL_TWI_H__
|
||||
|
|
|
@ -39,7 +39,26 @@ static const uint32_t hal_twi_frequency_lookup[] = {
|
|||
TWIM_FREQUENCY_FREQUENCY_K400, // 400 kbps
|
||||
};
|
||||
|
||||
void hal_twi_init(NRF_TWI_Type * p_instance, hal_twi_init_t const * p_twi_init) {
|
||||
void hal_twi_master_init(NRF_TWI_Type * p_instance, hal_twi_init_t const * p_twi_init) {
|
||||
// cast to master type
|
||||
NRF_TWIM_Type * twim_instance = (NRF_TWIM_Type *)p_instance;
|
||||
|
||||
twim_instance->PSEL.SCL = p_twi_init->scl_pin->pin;
|
||||
twim_instance->PSEL.SDA = p_twi_init->sda_pin->pin;
|
||||
|
||||
#if NRF52840_XXAA
|
||||
twim_instance->PSEL.SCL |= (p_twi_init->scl_pin->port << TWIM_PSEL_SCL_PORT_Pos);
|
||||
twim_instance->PSEL.SDA |= (p_twi_init->sda_pin->port << TWIM_PSEL_SDA_PORT_Pos);
|
||||
#endif
|
||||
twim_instance->ADDRESS = p_twi_init->dev_addr;
|
||||
twim_instance->FREQUENCY = hal_twi_frequency_lookup[p_twi_init->freq];
|
||||
|
||||
}
|
||||
|
||||
void hal_twi_slave_init(NRF_TWI_Type * p_instance, hal_twi_init_t const * p_twi_init) {
|
||||
// cast to slave type
|
||||
NRF_TWIS_Type * twis_instance = (NRF_TWIS_Type *)p_instance;
|
||||
(void)twis_instance;
|
||||
}
|
||||
|
||||
#endif // HAL_TWIE_MODULE_ENABLED
|
||||
|
|
Loading…
Reference in New Issue