#include "stdint.h"
#include "nrf_delay.h"
#include "nrfx_gpiote.h"
#include "nrf_drv_gpiote.h"
#include "nrf_log.h"
#include "app_bsp.h"
#define CHARGE_STATE NRF_GPIO_PIN_MAP(0, 29)
#define CHARGE_LED NRF_GPIO_PIN_MAP(1, 11)
void bsp_gpio_init(void)
{
ret_code_t err_code;
if (!nrf_drv_gpiote_is_init())
{
err_code = nrf_drv_gpiote_init();
APP_ERROR_CHECK(err_code);
}
nrf_drv_gpiote_in_config_t init_config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(true);
init_config.pull = NRF_GPIO_PIN_PULLUP;
err_code = nrf_drv_gpiote_in_init(CHARGE_STATE, &init_config, pwr_monitoring_event_callback);
APP_ERROR_CHECK(err_code);
nrf_drv_gpiote_in_event_enable(CHARGE_STATE, true);
nrf_delay_ms(10);
nrf_gpio_cfg_output(CHARGE_LED);
nrf_gpio_pin_write(CHARGE_LED, 0);
}
void pwr_monitoring_event_callback(nrf_drv_gpiote_pin_t pin,nrf_gpiote_polarity_t action)
{
uint32_t pin_level;
UNUSED_PARAMETER(pin_level);
pin_level = nrf_gpio_pin_read(pin);
if (NRF_GPIOTE_POLARITY_HITOLO == action)
{
NRF_LOG_INFO("NRF_GPIOTE_POLARITY_HITOLO");
}
else if (NRF_GPIOTE_POLARITY_LOTOHI == action)
{
NRF_LOG_INFO("NRF_GPIOTE_POLARITY_LOTOHI");
}
else if(NRF_GPIOTE_POLARITY_TOGGLE == action)
{
nrf_gpio_pin_toggle(CHARGE_LED);
}
}