From c69ae134232046b8a6022c0d8e889fdea76181ae Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 19 Dec 2018 18:29:24 +0700 Subject: [PATCH] finished testing led pattern --- src/boards.c | 16 +++++++--------- src/boards.h | 2 -- src/main.c | 7 +++---- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/boards.c b/src/boards.c index 0aaee71..0d6d30a 100644 --- a/src/boards.c +++ b/src/boards.c @@ -154,6 +154,8 @@ void led_pwm_init(uint32_t led_index, uint32_t led_pin) pwm->ENABLE = 0; nrf_gpio_cfg_output(led_pin); + nrf_gpio_pin_write(led_pin, 1 - LED_STATE_ON); + pwm->PSEL.OUT[led_index] = led_pin; pwm->MODE = PWM_MODE_UPDOWN_Up; @@ -170,7 +172,7 @@ void led_pwm_init(uint32_t led_index, uint32_t led_pin) pwm->ENABLE = 1; pwm->EVENTS_SEQEND[0] = 0; - pwm->TASKS_SEQSTART[0] = 1; +// pwm->TASKS_SEQSTART[0] = 1; } void led_pwm_teardown(void) @@ -221,32 +223,28 @@ static uint32_t rgb_color; static bool temp_color_active = false; void led_state(uint32_t state) { - enum { - CYCLE_NORMAL = 4000, - CYCLE_WRITING = 100 - }; uint32_t new_rgb_color = rgb_color; uint32_t temp_color = 0; switch (state) { case STATE_USB_MOUNTED: new_rgb_color = 0x00ff00; - primary_cycle_length = CYCLE_NORMAL; + primary_cycle_length = 3000; break; case STATE_BOOTLOADER_STARTED: case STATE_USB_UNMOUNTED: new_rgb_color = 0xff0000; - primary_cycle_length = CYCLE_NORMAL; + primary_cycle_length = 300; break; case STATE_WRITING_STARTED: temp_color = 0xff0000; - primary_cycle_length = CYCLE_WRITING; + primary_cycle_length = 100; break; case STATE_WRITING_FINISHED: // Empty means to unset any temp colors. - primary_cycle_length = CYCLE_NORMAL; + primary_cycle_length = 3000; break; case STATE_BLE_CONNECTED: diff --git a/src/boards.h b/src/boards.h index 514801c..68b236c 100644 --- a/src/boards.h +++ b/src/boards.h @@ -108,8 +108,6 @@ static inline bool button_pressed(uint32_t pin) return (nrf_gpio_pin_read(pin) == 0) ? true : false; } - - bool is_ota(void); #endif diff --git a/src/main.c b/src/main.c index bd8ae5d..8ac1dba 100644 --- a/src/main.c +++ b/src/main.c @@ -71,7 +71,7 @@ void usb_teardown(void); #else -#define usb_init(x) +#define usb_init(x) led_state(STATE_USB_MOUNTED) // mark nrf52832 as mounted #define usb_teardown() #endif @@ -167,6 +167,8 @@ int main(void) board_init(); bootloader_init(); + led_state(STATE_BOOTLOADER_STARTED); + // When updating SoftDevice, bootloader will reset before swapping SD if (bootloader_dfu_sd_in_progress()) { @@ -209,8 +211,6 @@ int main(void) (*dbl_reset_mem) = 0; - led_state(STATE_BOOTLOADER_STARTED); - if ( dfu_start || !valid_app ) { if ( _ota_dfu ) @@ -222,7 +222,6 @@ int main(void) else { led_state(STATE_USB_UNMOUNTED); - // otherwise USB for Serial & UF2 usb_init(serial_only_dfu); }