diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2024-12-07 13:58:46 -0700 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2024-12-07 13:58:46 -0700 |
commit | 546a5ccdba66dd8d8c19ce6d8486f46c84637cf2 (patch) | |
tree | 95b52da91414c1bfbad745c6b55617011012813e /src/btsel.c | |
parent | 9182b65ae2045c5087257751d30409deecf9520a (diff) | |
download | ch573-546a5ccdba66dd8d8c19ce6d8486f46c84637cf2.tar.gz ch573-546a5ccdba66dd8d8c19ce6d8486f46c84637cf2.tar.bz2 ch573-546a5ccdba66dd8d8c19ce6d8486f46c84637cf2.zip |
Add way to toggle the default pattern and a way to switch the pattern.
Diffstat (limited to 'src/btsel.c')
-rw-r--r-- | src/btsel.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/btsel.c b/src/btsel.c new file mode 100644 index 0000000..873b20a --- /dev/null +++ b/src/btsel.c @@ -0,0 +1,38 @@ +#include "btsel.h" + +#include "ch573/gpio.h" +#include "isr_vector.h" + +#define GPIO ch573_gpio__gpio +#define GPIO_I CH573_GPIO__GPIO_T_INTF +#define GPIO_PORT CH573_GPIO__GPIO_PORT_T_INTF +#define GPIO_PORT_A ch573_gpio__gpio_port_a +#define GPIO_PORT_B ch573_gpio__gpio_port_b + +extern bootsel_cb_t BOOTSEL_LISTENERS_START; +extern bootsel_cb_t BOOTSEL_LISTENERS_END; + +#define BOOTSEL_PIN 7 + +void enable_bootsel_button(void) +{ + GPIO_PORT.dir.set(GPIO_PORT_B, DIR_IN, BOOTSEL_PIN); + GPIO_PORT.pu.set(GPIO_PORT_B, ENABLED, BOOTSEL_PIN); + // GPIO_PORT.pd_drv.set(GPIO_PORT_B, PD_DRV_OPEN_DRAIN, BOOTSEL_PIN); + GPIO_PORT.out.set(GPIO_PORT_B, OFF, BOOTSEL_PIN); + GPIO_PORT.clr.set(GPIO_PORT_B, 1 << BOOTSEL_PIN); + + GPIO_I.pb_interrupt_mode.set(GPIO, 1 << BOOTSEL_PIN); + GPIO_I.pb_interrupt_flag.set(GPIO, 1 << BOOTSEL_PIN); + GPIO_I.pb_interrupt_enable.set(GPIO, 1 << BOOTSEL_PIN); +} + +IRQ(gpio_b) +{ + bootsel_cb_t* cur = &BOOTSEL_LISTENERS_START; + while (cur != &BOOTSEL_LISTENERS_END) { + (*cur)(); + ++cur; + } + GPIO_I.pb_interrupt_flag.set(GPIO, 1 << BOOTSEL_PIN); +} |