Badger2040: Move startup block on held buttons to launcher.py
Blocking on held buttons is bad for MicroPython, since it makes nothing happen on startup- We need the button to be held but are waiting for a button release after some arbitrary amount of time. Additionally running code while holding down a button would block normal MicroPython event execution and crash the host's USB bus quite severely.
This commit is contained in:
parent
167bfbb781
commit
a4f7d05fe5
|
@ -41,6 +41,7 @@ namespace pimoroni {
|
||||||
gpio_set_dir(VBUS_DETECT, GPIO_IN);
|
gpio_set_dir(VBUS_DETECT, GPIO_IN);
|
||||||
gpio_put(VBUS_DETECT, 1);
|
gpio_put(VBUS_DETECT, 1);
|
||||||
|
|
||||||
|
/*
|
||||||
// read initial button states
|
// read initial button states
|
||||||
uint32_t mask = (1UL << A) | (1UL << B) | (1UL << C) | (1UL << D) | (1UL << E);
|
uint32_t mask = (1UL << A) | (1UL << B) | (1UL << C) | (1UL << D) | (1UL << E);
|
||||||
_wake_button_states |= gpio_get_all() & mask;
|
_wake_button_states |= gpio_get_all() & mask;
|
||||||
|
@ -49,6 +50,7 @@ namespace pimoroni {
|
||||||
while(gpio_get_all() & mask) {
|
while(gpio_get_all() & mask) {
|
||||||
tight_loop_contents();
|
tight_loop_contents();
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// led control pin
|
// led control pin
|
||||||
pwm_config cfg = pwm_get_default_config();
|
pwm_config cfg = pwm_get_default_config();
|
||||||
|
|
|
@ -25,8 +25,9 @@ button_c = machine.Pin(badger2040.BUTTON_C, machine.Pin.IN, machine.Pin.PULL_DOW
|
||||||
button_up = machine.Pin(badger2040.BUTTON_UP, machine.Pin.IN, machine.Pin.PULL_DOWN)
|
button_up = machine.Pin(badger2040.BUTTON_UP, machine.Pin.IN, machine.Pin.PULL_DOWN)
|
||||||
button_down = machine.Pin(badger2040.BUTTON_DOWN, machine.Pin.IN, machine.Pin.PULL_DOWN)
|
button_down = machine.Pin(badger2040.BUTTON_DOWN, machine.Pin.IN, machine.Pin.PULL_DOWN)
|
||||||
|
|
||||||
# Early exit if a button is pressed
|
# Early exit if b + c button is pressed
|
||||||
if button_a.value() or button_b.value() or button_c.value():
|
# A button must be held briefly to power on, so we use a combo instead
|
||||||
|
if button_b.value() and button_c.value():
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
@ -94,13 +95,19 @@ def button(pin):
|
||||||
render()
|
render()
|
||||||
|
|
||||||
|
|
||||||
|
render()
|
||||||
|
|
||||||
|
# Wait for wakeup button to be released
|
||||||
|
while button_a.value() or button_b.value() or button_c.value() or button_up.value() or button_down.value():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
button_a.irq(trigger=machine.Pin.IRQ_RISING, handler=button)
|
button_a.irq(trigger=machine.Pin.IRQ_RISING, handler=button)
|
||||||
button_b.irq(trigger=machine.Pin.IRQ_RISING, handler=button)
|
button_b.irq(trigger=machine.Pin.IRQ_RISING, handler=button)
|
||||||
button_c.irq(trigger=machine.Pin.IRQ_RISING, handler=button)
|
button_c.irq(trigger=machine.Pin.IRQ_RISING, handler=button)
|
||||||
button_up.irq(trigger=machine.Pin.IRQ_RISING, handler=button)
|
button_up.irq(trigger=machine.Pin.IRQ_RISING, handler=button)
|
||||||
button_down.irq(trigger=machine.Pin.IRQ_RISING, handler=button)
|
button_down.irq(trigger=machine.Pin.IRQ_RISING, handler=button)
|
||||||
|
|
||||||
render()
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
time.sleep(1.0)
|
time.sleep(1.0)
|
||||||
|
|
Loading…
Reference in New Issue