Add support for single button and no LED boards
From c4579ff251/micropython/Adafruit_nRF52_Bootloader-dsd6.diff
[daniel@redfelineninja.org.uk: Seperate from raw board support patch]
wasp-os-next
parent
6c2867bc00
commit
282fd12bba
21
src/boards.c
21
src/boards.c
|
@ -68,14 +68,18 @@ void board_init(void)
|
|||
NRF_CLOCK->TASKS_LFCLKSTART = 1UL;
|
||||
|
||||
button_init(BUTTON_DFU);
|
||||
#ifndef BUTTON_FRESET
|
||||
button_init(BUTTON_FRESET);
|
||||
#endif
|
||||
NRFX_DELAY_US(100); // wait for the pin state is stable
|
||||
|
||||
// use PMW0 for LED RED
|
||||
#if LEDS_NUMBER > 0
|
||||
led_pwm_init(LED_PRIMARY, LED_PRIMARY_PIN);
|
||||
#if LEDS_NUMBER > 1
|
||||
#endif
|
||||
#if LEDS_NUMBER > 1
|
||||
led_pwm_init(LED_SECONDARY, LED_SECONDARY_PIN);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// use neopixel for use enumeration
|
||||
#if defined(LED_NEOPIXEL) || defined(LED_RGB_RED_PIN)
|
||||
|
@ -98,12 +102,14 @@ void board_teardown(void)
|
|||
// Disable systick, turn off LEDs
|
||||
SysTick->CTRL = 0;
|
||||
|
||||
#if LEDS_NUMBER > 0
|
||||
// Disable and reset PWM for LEDs
|
||||
led_pwm_teardown();
|
||||
|
||||
#endif
|
||||
#if defined(LED_NEOPIXEL) || defined(LED_RGB_RED_PIN)
|
||||
neopixel_teardown();
|
||||
#endif
|
||||
|
||||
// Button
|
||||
|
||||
// Stop RTC1 used by app_timer
|
||||
|
@ -121,8 +127,9 @@ static uint32_t _systick_count = 0;
|
|||
void SysTick_Handler(void)
|
||||
{
|
||||
_systick_count++;
|
||||
|
||||
#if LEDS_NUMBER > 0
|
||||
led_tick();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -130,6 +137,7 @@ uint32_t tusb_hal_millis(void)
|
|||
{
|
||||
return ( ( ((uint64_t)app_timer_cnt_get())*1000*(APP_TIMER_CONFIG_RTC_FREQUENCY+1)) / APP_TIMER_CLOCK_FREQ );
|
||||
}
|
||||
#if LEDS_NUMBER > 0
|
||||
|
||||
void pwm_teardown(NRF_PWM_Type* pwm )
|
||||
{
|
||||
|
@ -297,6 +305,11 @@ void led_state(uint32_t state)
|
|||
(void) final_color;
|
||||
#endif
|
||||
}
|
||||
#else // LEDS_NUMBER > 0
|
||||
void led_state(uint32_t state)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LED_NEOPIXEL
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
#define BUTTON_DFU BUTTON_1
|
||||
#endif
|
||||
|
||||
#ifndef BUTTON_FRESET
|
||||
#if !defined(BUTTON_FRESET) && BUTTONS_NUMBER > 1
|
||||
#define BUTTON_FRESET BUTTON_2
|
||||
#endif
|
||||
|
||||
|
@ -91,9 +91,10 @@ void led_tick(void);
|
|||
//--------------------------------------------------------------------+
|
||||
// BUTTONS
|
||||
//--------------------------------------------------------------------+
|
||||
// Make sure we have at least two buttons (DFU + FRESET since DFU+FRST=OTA)
|
||||
#if BUTTONS_NUMBER < 2
|
||||
#error "At least two buttons required in the BSP (see 'BUTTONS_NUMBER')"
|
||||
// Make sure we have at least a DFU button (if there is only one button
|
||||
// then we will have OTA DFU only since we cannot have DFU+FRST=OTA)
|
||||
#if BUTTONS_NUMBER < 1
|
||||
#error "At least one button required in the BSP (see 'BUTTONS_NUMBER')"
|
||||
#endif
|
||||
|
||||
void button_init(uint32_t pin);
|
||||
|
|
10
src/main.c
10
src/main.c
|
@ -193,8 +193,10 @@ int main(void)
|
|||
// DFU button pressed
|
||||
dfu_start = dfu_start || button_pressed(BUTTON_DFU);
|
||||
|
||||
#if BUTTONS_NUMBER > 1
|
||||
// DFU + FRESET are pressed --> OTA
|
||||
_ota_dfu = _ota_dfu || ( button_pressed(BUTTON_DFU) && button_pressed(BUTTON_FRESET) ) ;
|
||||
#endif
|
||||
|
||||
bool const valid_app = bootloader_app_is_valid(DFU_BANK_0_REGION_START);
|
||||
|
||||
|
@ -220,6 +222,11 @@ int main(void)
|
|||
|
||||
(*dbl_reset_mem) = 0;
|
||||
|
||||
#if BUTTONS_NUMBER < 2
|
||||
// set BLE/ota DFU by default unless asked for serial as we don't have button to select it
|
||||
_ota_dfu = _ota_dfu || !serial_only_dfu;
|
||||
#endif
|
||||
|
||||
if ( dfu_start || !valid_app )
|
||||
{
|
||||
if ( _ota_dfu )
|
||||
|
@ -246,12 +253,13 @@ int main(void)
|
|||
}
|
||||
}
|
||||
|
||||
#if BUTTONS_NUMBER > 1
|
||||
// Adafruit Factory reset
|
||||
if ( !button_pressed(BUTTON_DFU) && button_pressed(BUTTON_FRESET) )
|
||||
{
|
||||
adafruit_factory_reset();
|
||||
}
|
||||
|
||||
#endif
|
||||
// Reset Board
|
||||
board_teardown();
|
||||
|
||||
|
|
Loading…
Reference in New Issue