From 1c778f020f2b83f84e478a0367c14e12b26907cc Mon Sep 17 00:00:00 2001 From: Glenn Ruben Bakke Date: Sat, 28 Jan 2017 22:54:44 +0100 Subject: [PATCH] nrf5/hal: Updating TWI with frequency enums. --- nrf5/hal/hal_twi.c | 6 ++++++ nrf5/hal/hal_twi.h | 29 +++++++++++++++++++++-------- nrf5/hal/hal_twie.c | 10 ++++++++-- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/nrf5/hal/hal_twi.c b/nrf5/hal/hal_twi.c index d9b7935179..e318d2021f 100644 --- a/nrf5/hal/hal_twi.c +++ b/nrf5/hal/hal_twi.c @@ -29,6 +29,12 @@ #ifdef HAL_TWI_MODULE_ENABLED +static const uint32_t hal_twi_frequency_lookup[] = { + TWI_FREQUENCY_FREQUENCY_K100, // 100 kbps + TWI_FREQUENCY_FREQUENCY_K250, // 250 kbps + TWI_FREQUENCY_FREQUENCY_K400, // 400 kbps +}; + void hal_twi_init(NRF_TWI_Type * p_instance, hal_twi_init_t const * p_twi_init) { } diff --git a/nrf5/hal/hal_twi.h b/nrf5/hal/hal_twi.h index 7151db87d8..5e2d10c31e 100644 --- a/nrf5/hal/hal_twi.h +++ b/nrf5/hal/hal_twi.h @@ -60,25 +60,38 @@ typedef struct { #endif /** - * @brief TWI Configuration Structure definition + * @brief TWI clock frequency type definition */ -typedef struct { -} hal_twi_init_t; +typedef enum { + HAL_TWI_FREQ_100_Kbps = 0, + HAL_TWI_FREQ_250_Kbps, + HAL_TWI_FREQ_400_Kbps +} hal_twi_clk_freq_t; +/** + * @brief TWI role type definition + */ typedef enum { HAL_TWI_MASTER, HAL_TWI_SLAVE -} hal_twi_mode_t; +} hal_twi_role_t; + +/** + * @brief TWI Configuration Structure definition + */ +typedef struct { + uint8_t id; /* TWI instance id */ + hal_twi_role_t role; /* TWI master/slave */ + hal_twi_clk_freq_t freq; /* TWI frequency */ +} hal_twi_init_t; /** * @brief TWI handle Structure definition */ typedef struct __TWI_HandleTypeDef { - NRF_TWI_Type *instance; /* TWI register base address */ - hal_twi_init_t init; /* TWI initialization parameters */ - uint8_t id; /* TWI instance id */ - hal_twi_mode_t mode; /* TWI master/slave */ + NRF_TWI_Type *instance; /* TWI register base address */ + 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); diff --git a/nrf5/hal/hal_twie.c b/nrf5/hal/hal_twie.c index 67897b520d..cc20b2c97d 100644 --- a/nrf5/hal/hal_twie.c +++ b/nrf5/hal/hal_twie.c @@ -27,14 +27,20 @@ #include "mphalport.h" #include "hal_twi.h" -#ifdef HAL_TWIM_MODULE_ENABLED +#ifdef HAL_TWIE_MODULE_ENABLED // EasyDMA variants #define TWI_MASTER_BASE(x) ((NRF_TWIM_Type *)TWI_BASE_POINTERS[x]) #define TWI_SLAVE_BASE(x) ((NRF_TWIS_Type *)TWI_BASE_POINTERS[x]) +static const uint32_t hal_twi_frequency_lookup[] = { + TWIM_FREQUENCY_FREQUENCY_K100, // 100 kbps + TWIM_FREQUENCY_FREQUENCY_K250, // 250 kbps + TWIM_FREQUENCY_FREQUENCY_K400, // 400 kbps +}; + void hal_twi_init(NRF_TWI_Type * p_instance, hal_twi_init_t const * p_twi_init) { } -#endif // HAL_TWIM_MODULE_ENABLED +#endif // HAL_TWIE_MODULE_ENABLED