I modified the gpio interrupt on the asset_tracker example of ncs v1.2, modified the following, and the interrupt didn't work:
Where is available should be modified.
I set the interrupt port to 8 feet to enter the interrupt
I set the interrupt port to 15 feet and i can't get into the break.
The default configuration code is as follows:
//Peter add start
//button driver start
#include <drivers/gpio.h>
#include <device.h>
#define ON 1
#define OFF 0
#define DK_PORT "GPIO_0"
#define DK_USER_LED1 2
#define DK_USER_BTN1 15
#define DK_USER_BTN2 9
#define DK_USER_BTN3 6
#define DK_USER_BTN4 7
struct gpio_pin {
const char * const port;
const u8_t number;
};
static const struct gpio_pin led_pins1 = { DK_PORT, DK_USER_LED1 };
static const struct gpio_pin btn_pins1 = { DK_PORT, DK_USER_BTN1 };
static struct device *led_devs1, *btn_devs1;
u32_t key_value, skey_value;
static struct gpio_callback gpio_cb;
static void btn1_pressed(struct device *gpio_dev, struct gpio_callback *cb, u32_t pins)
{
gpio_pin_disable_callback( btn_devs1, btn_pins1.number );
if( !skey_value )
{
gpio_pin_write( led_devs1, (u32_t)led_pins1.number, ON);
}
else
{
gpio_pin_write( led_devs1, (u32_t)led_pins1.number, OFF);
}
skey_value = !skey_value;
gpio_pin_enable_callback( btn_devs1, btn_pins1.number );
}
void main(void)
{
LOG_INF("nrf9160 init\r\n");
k_sleep(1000); //sleep 1s
led_devs1 = device_get_binding( led_pins1.port );
btn_devs1 = device_get_binding( btn_pins1.port );
gpio_pin_configure( led_devs1, led_pins1.number, GPIO_DIR_OUT );
gpio_pin_configure( btn_devs1, btn_pins1.number, GPIO_DIR_IN | GPIO_INT | GPIO_PUD_PULL_UP | GPIO_INT_EDGE | GPIO_INT_ACTIVE_LOW );
gpio_init_callback( &gpio_cb, btn1_pressed, BIT( btn_pins1.number ));
gpio_add_callback( btn_devs1, &gpio_cb);
gpio_pin_enable_callback( btn_devs1, btn_pins1.number );
while(1)
{
//Switch 2
k_sleep(1000); //sleep 1s
}
}
//Peter add end
