finished testing led pattern

This commit is contained in:
hathach 2018-12-19 18:29:24 +07:00
parent 5c6bbaca47
commit c69ae13423
3 changed files with 10 additions and 15 deletions

View File

@ -154,6 +154,8 @@ void led_pwm_init(uint32_t led_index, uint32_t led_pin)
pwm->ENABLE = 0; pwm->ENABLE = 0;
nrf_gpio_cfg_output(led_pin); nrf_gpio_cfg_output(led_pin);
nrf_gpio_pin_write(led_pin, 1 - LED_STATE_ON);
pwm->PSEL.OUT[led_index] = led_pin; pwm->PSEL.OUT[led_index] = led_pin;
pwm->MODE = PWM_MODE_UPDOWN_Up; 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->ENABLE = 1;
pwm->EVENTS_SEQEND[0] = 0; pwm->EVENTS_SEQEND[0] = 0;
pwm->TASKS_SEQSTART[0] = 1; // pwm->TASKS_SEQSTART[0] = 1;
} }
void led_pwm_teardown(void) void led_pwm_teardown(void)
@ -221,32 +223,28 @@ static uint32_t rgb_color;
static bool temp_color_active = false; static bool temp_color_active = false;
void led_state(uint32_t state) void led_state(uint32_t state)
{ {
enum {
CYCLE_NORMAL = 4000,
CYCLE_WRITING = 100
};
uint32_t new_rgb_color = rgb_color; uint32_t new_rgb_color = rgb_color;
uint32_t temp_color = 0; uint32_t temp_color = 0;
switch (state) { switch (state) {
case STATE_USB_MOUNTED: case STATE_USB_MOUNTED:
new_rgb_color = 0x00ff00; new_rgb_color = 0x00ff00;
primary_cycle_length = CYCLE_NORMAL; primary_cycle_length = 3000;
break; break;
case STATE_BOOTLOADER_STARTED: case STATE_BOOTLOADER_STARTED:
case STATE_USB_UNMOUNTED: case STATE_USB_UNMOUNTED:
new_rgb_color = 0xff0000; new_rgb_color = 0xff0000;
primary_cycle_length = CYCLE_NORMAL; primary_cycle_length = 300;
break; break;
case STATE_WRITING_STARTED: case STATE_WRITING_STARTED:
temp_color = 0xff0000; temp_color = 0xff0000;
primary_cycle_length = CYCLE_WRITING; primary_cycle_length = 100;
break; break;
case STATE_WRITING_FINISHED: case STATE_WRITING_FINISHED:
// Empty means to unset any temp colors. // Empty means to unset any temp colors.
primary_cycle_length = CYCLE_NORMAL; primary_cycle_length = 3000;
break; break;
case STATE_BLE_CONNECTED: case STATE_BLE_CONNECTED:

View File

@ -108,8 +108,6 @@ static inline bool button_pressed(uint32_t pin)
return (nrf_gpio_pin_read(pin) == 0) ? true : false; return (nrf_gpio_pin_read(pin) == 0) ? true : false;
} }
bool is_ota(void); bool is_ota(void);
#endif #endif

View File

@ -71,7 +71,7 @@ void usb_teardown(void);
#else #else
#define usb_init(x) #define usb_init(x) led_state(STATE_USB_MOUNTED) // mark nrf52832 as mounted
#define usb_teardown() #define usb_teardown()
#endif #endif
@ -167,6 +167,8 @@ int main(void)
board_init(); board_init();
bootloader_init(); bootloader_init();
led_state(STATE_BOOTLOADER_STARTED);
// When updating SoftDevice, bootloader will reset before swapping SD // When updating SoftDevice, bootloader will reset before swapping SD
if (bootloader_dfu_sd_in_progress()) if (bootloader_dfu_sd_in_progress())
{ {
@ -209,8 +211,6 @@ int main(void)
(*dbl_reset_mem) = 0; (*dbl_reset_mem) = 0;
led_state(STATE_BOOTLOADER_STARTED);
if ( dfu_start || !valid_app ) if ( dfu_start || !valid_app )
{ {
if ( _ota_dfu ) if ( _ota_dfu )
@ -222,7 +222,6 @@ int main(void)
else else
{ {
led_state(STATE_USB_UNMOUNTED); led_state(STATE_USB_UNMOUNTED);
// otherwise USB for Serial & UF2
usb_init(serial_only_dfu); usb_init(serial_only_dfu);
} }