I would like to make a timer to check the GPIO status.
The current code is like below:
// Detect the event
void charge_event_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
if(action == GPIOTE_CONFIG_POLARITY_HiToLo && pin == TYPE_C)
{
nrf_gpio_pin_set(LED_2);
}
if(action == GPIOTE_CONFIG_POLARITY_LoToHi && pin == TYPE_C)
{
nrf_gpio_pin_clear(LED_2);
}
}
void charge_init(void)
{
uint32_t err_code;
//Configure button with pullup and event on both high and low transition
nrf_drv_gpiote_in_config_t config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(false);
config.pull = NRF_GPIO_PIN_PULLUP;
err_code=nrf_drv_gpiote_in_init(TYPE_C, &config, charge_event_handler);
nrf_drv_gpiote_in_event_enable(TYPE_C, true);
APP_ERROR_CHECK(err_code);
}
static void charge_meas_timeout_handler(void * p_context)
{
UNUSED_PARAMETER(p_context);
charge_init();
}
///////////////////////////////////////////////////////////////////////////////////
/**@brief Function for the Timer initialization.
*
* @details Initializes the timer module. This creates and starts application timers.
*/
static void timers_init(void)
{
// Initialize timer module.
ret_code_t err_code = app_timer_init();
APP_ERROR_CHECK(err_code);
err_code = app_timer_create(&m_charge_timer_id,
APP_TIMER_MODE_REPEATED,
charge_meas_timeout_handler);
}
/**@brief Function for starting timers.
*/
static void application_timers_start(void)
{
ret_code_t err_code;
err_code = app_timer_start(m_charge_timer_id, CHARGE_MEAS_INTERVAL, NULL);
APP_ERROR_CHECK(err_code);
}
I already checked that timer function is worked by implant the specific event into the charge_event_handler as below:
charge_event_handler(TYPE_C,GPIOTE_CONFIG_POLARITY_LoToHi );
But not sure how to make it switch from different event.
Or there is any smart way to make it?