diff options
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); +} |