diff --git a/include/board.h b/include/board.h new file mode 100644 index 0000000..b67ab45 --- /dev/null +++ b/include/board.h @@ -0,0 +1,8 @@ +#ifndef __BOARD_H__ +#define __BOARD_H__ + +#ifdef BOARD_PCA10040 +#include "platform/narf52/narf52_dk.h" +#endif + +#endif diff --git a/include/platform/narf52/narf52_dk.h b/include/platform/narf52/narf52_dk.h index 2fa3a03..312e300 100644 --- a/include/platform/narf52/narf52_dk.h +++ b/include/platform/narf52/narf52_dk.h @@ -6,7 +6,8 @@ #include "driver.h" -struct narf52_gpio narf_led_1 = { +// LEDs +const struct narf52_gpio narf_led_1 = { .pin_number = 17, .dir = NARF_GPIO_DIR_OUT, .input = NARF_GPIO_PIN_INPUT_DISCONNECT, @@ -15,13 +16,13 @@ struct narf52_gpio narf_led_1 = { .sense = NARF_GPIO_PIN_NOSENSE, }; -struct driver led_1 = { +const struct driver led_1 = { .name = "LED_1", .fp = &gpio_fp, .dev = (void *)&narf_led_1, }; -struct narf52_gpio narf_led_2 = { +const struct narf52_gpio narf_led_2 = { .pin_number = 18, .dir = NARF_GPIO_DIR_OUT, .input = NARF_GPIO_PIN_INPUT_DISCONNECT, @@ -30,13 +31,13 @@ struct narf52_gpio narf_led_2 = { .sense = NARF_GPIO_PIN_NOSENSE, }; -struct driver led_2 = { +const struct driver led_2 = { .name = "LED_2", .fp = &gpio_fp, .dev = (void *)&narf_led_2, }; -struct narf52_gpio narf_led_3 = { +const struct narf52_gpio narf_led_3 = { .pin_number = 19, .dir = NARF_GPIO_DIR_OUT, .input = NARF_GPIO_PIN_INPUT_DISCONNECT, @@ -45,13 +46,13 @@ struct narf52_gpio narf_led_3 = { .sense = NARF_GPIO_PIN_NOSENSE, }; -struct driver led_3 = { +const struct driver led_3 = { .name = "LED_3", .fp = &gpio_fp, .dev = (void *)&narf_led_3, }; -struct narf52_gpio narf_led_4 = { +const struct narf52_gpio narf_led_4 = { .pin_number = 20, .dir = NARF_GPIO_DIR_OUT, .input = NARF_GPIO_PIN_INPUT_DISCONNECT, @@ -60,10 +61,71 @@ struct narf52_gpio narf_led_4 = { .sense = NARF_GPIO_PIN_NOSENSE, }; -struct driver led_4 = { +const struct driver led_4 = { .name = "LED_4", .fp = &gpio_fp, .dev = (void *)&narf_led_4, }; +// BUTTONs +const struct narf52_gpio narf_button_1 = { + .pin_number = 13, + .dir = NARF_GPIO_DIR_IN, + .input = NARF_GPIO_PIN_INPUT_CONNECT, + .pull = NARF_GPIO_PIN_PULLUP, + .drive = NARF_GPIO_PIN_S0S1, + .sense = NARF_GPIO_PIN_NOSENSE, +}; + +const struct driver button_1 = { + .name = "BUTTON_1", + .fp = &gpio_fp, + .dev = (void *)&narf_button_1, +}; + +const struct narf52_gpio narf_button_2 = { + .pin_number = 14, + .dir = NARF_GPIO_DIR_IN, + .input = NARF_GPIO_PIN_INPUT_CONNECT, + .pull = NARF_GPIO_PIN_PULLUP, + .drive = NARF_GPIO_PIN_S0S1, + .sense = NARF_GPIO_PIN_NOSENSE, +}; + +const struct driver button_2 = { + .name = "BUTTON_2", + .fp = &gpio_fp, + .dev = (void *)&narf_button_2, +}; + +const struct narf52_gpio narf_button_3 = { + .pin_number = 15, + .dir = NARF_GPIO_DIR_IN, + .input = NARF_GPIO_PIN_INPUT_CONNECT, + .pull = NARF_GPIO_PIN_PULLUP, + .drive = NARF_GPIO_PIN_S0S1, + .sense = NARF_GPIO_PIN_NOSENSE, +}; + +const struct driver button_3 = { + .name = "BUTTON_3", + .fp = &gpio_fp, + .dev = (void *)&narf_button_3, +}; + +const struct narf52_gpio narf_button_4 = { + .pin_number = 16, + .dir = NARF_GPIO_DIR_IN, + .input = NARF_GPIO_PIN_INPUT_CONNECT, + .pull = NARF_GPIO_PIN_PULLUP, + .drive = NARF_GPIO_PIN_S0S1, + .sense = NARF_GPIO_PIN_NOSENSE, +}; + +const struct driver button_4 = { + .name = "BUTTON_4", + .fp = &gpio_fp, + .dev = (void *)&narf_button_4, +}; + #endif diff --git a/src/main.c b/src/main.c index 0801464..e3b73d8 100644 --- a/src/main.c +++ b/src/main.c @@ -1,10 +1,7 @@ #include #include -#include "nrf_delay.h" -#include "boards.h" - -#include "platform/narf52/narf52_dk.h" +#include "board.h" #include "driver.h" int main(void) @@ -15,14 +12,23 @@ int main(void) drv_open(&led_3); drv_open(&led_4); + drv_open(&button_1); + drv_open(&button_2); + drv_open(&button_3); + drv_open(&button_4); + while(true) { - for(uint32_t i = 0; i < UINT32_MAX; i++) { - char x = 0x30 | (char)(1 & i); - drv_write(&led_1, &x, 1); - drv_write(&led_2, &x, 1); - drv_write(&led_3, &x, 1); - drv_write(&led_4, &x, 1); - nrf_delay_ms(500); - } + char x; + drv_read(&button_1, &x, 1); + drv_write(&led_1, &x, 1); + + drv_read(&button_2, &x, 1); + drv_write(&led_2, &x, 1); + + drv_read(&button_3, &x, 1); + drv_write(&led_3, &x, 1); + + drv_read(&button_4, &x, 1); + drv_write(&led_4, &x, 1); } }