close


#include <stdbool.h>
#include <stdint.h>
#include "nrf_delay.h"
#include "nrf_gpio.h"
#include "boards.h"

static void gpiote_init(void);
void GPIOTE_IRQHandler(void);



static void gpiote_init(void)
{
NRF_GPIOTE->CONFIG[0] = (GPIOTE_CONFIG_MODE_Event << GPIOTE_CONFIG_MODE_Pos) |
(BUTTON_0 << GPIOTE_CONFIG_PSEL_Pos) |
(GPIOTE_CONFIG_POLARITY_LoToHi << GPIOTE_CONFIG_POLARITY_Pos);
NRF_GPIOTE->CONFIG[1] = (GPIOTE_CONFIG_MODE_Event << GPIOTE_CONFIG_MODE_Pos) |
(BUTTON_1 << GPIOTE_CONFIG_PSEL_Pos) |
(GPIOTE_CONFIG_POLARITY_LoToHi << GPIOTE_CONFIG_POLARITY_Pos);

NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_IN0_Msk;
NRF_GPIOTE->EVENTS_IN[0] = 0;

NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_IN1_Msk;
NRF_GPIOTE->EVENTS_IN[1] = 0;

NVIC_SetPriority(GPIOTE_IRQn, 3);
NVIC_ClearPendingIRQ(GPIOTE_IRQn);
NVIC_EnableIRQ(GPIOTE_IRQn);
}

 

void GPIOTE_IRQHandler(void)
{
if (NRF_GPIOTE->EVENTS_IN[0])
{
NRF_GPIOTE->EVENTS_IN[0] = 0;
nrf_gpio_pin_set(LED_1);

}else if (NRF_GPIOTE->EVENTS_IN[1]) //Enter BTLE mode
{
NRF_GPIOTE->EVENTS_IN[1] = 0;
nrf_gpio_pin_clear(LED_1);

}else if (NRF_GPIOTE->EVENTS_IN[2]) //Enter system OFF
{
NRF_GPIOTE->EVENTS_IN[2] = 0;

}else if (NRF_GPIOTE->EVENTS_IN[3]) //Exit system OFF
{
NRF_GPIOTE->EVENTS_IN[3] = 0;

}else if (NRF_GPIOTE->EVENTS_PORT)
{
NRF_GPIOTE->EVENTS_PORT = 0;
}
}


int main(void)
{
// Configure LED-pins as outputs.
nrf_gpio_cfg_output(LED_0);
nrf_gpio_cfg_output(LED_1);
nrf_gpio_cfg_output(LED_2);

nrf_gpio_cfg_input(BUTTON_0,NRF_GPIO_PIN_NOPULL);
nrf_gpio_cfg_input(BUTTON_1,NRF_GPIO_PIN_NOPULL);
gpiote_init();


while (true)
{

nrf_gpio_pin_clear(LED_0);
nrf_delay_ms(500);
nrf_gpio_pin_set(LED_0);
nrf_delay_ms(500);

}
}

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 matt 的頭像
    matt

    My的部落格

    matt 發表在 痞客邦 留言(0) 人氣()