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 /include | |
| 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 'include')
| -rw-r--r-- | include/btsel.h | 19 | ||||
| -rw-r--r-- | include/byte_math.h | 21 | ||||
| -rw-r--r-- | include/sysled.h | 6 | ||||
| -rw-r--r-- | include/systick.h | 9 |
4 files changed, 51 insertions, 4 deletions
diff --git a/include/btsel.h b/include/btsel.h new file mode 100644 index 0000000..9d2c676 --- /dev/null +++ b/include/btsel.h @@ -0,0 +1,19 @@ +#pragma once + +// Header file for detecting bootsel button presses. + +#define PASTER(x, y) x##y +#define CONCAT(x, y) PASTER(x, y) + +typedef void (*bootsel_cb_t)(void); +#define On_BootSelPress() \ + static void __local_on_bootsel__(void); \ + __attribute__(( \ + __section__(".bootsel_callbacks"))) static volatile bootsel_cb_t \ + __bootsel__position = __local_on_bootsel__; \ + static void __local_on_bootsel__() + +#undef PASTER +#undef CONCAT + +void enable_bootsel_button(void); diff --git a/include/byte_math.h b/include/byte_math.h index 79f93b8..9be4b67 100644 --- a/include/byte_math.h +++ b/include/byte_math.h @@ -13,3 +13,24 @@ static inline uint8_t byte_sin(uint8_t n) } uint8_t calc_w(uint8_t n); + +static inline uint8_t byte_scale(uint8_t v, uint8_t scale) +{ + uint16_t acc = v; + return (acc * scale) >> 8; +} + +static inline uint8_t clip(int x) +{ + if (x > 240) { + return 240; + } + + if (x < 0) { + return 0; + } + + return (uint8_t)x; +} + +#define AS_BYTE(n) ((n) * 256) diff --git a/include/sysled.h b/include/sysled.h index b1a21c1..fea8f54 100644 --- a/include/sysled.h +++ b/include/sysled.h @@ -6,12 +6,12 @@ static inline void enable_sysled() { - CH573_GPIO__GPIO_PORT_T_INTF.dir.set(ch573_gpio__gpio_port_b, DIR_OUT, 10); - CH573_GPIO__GPIO_PORT_T_INTF.pd_drv.set(ch573_gpio__gpio_port_b, 1, 10); + CH573_GPIO__GPIO_PORT_T_INTF.dir.set(ch573_gpio__gpio_port_a, DIR_OUT, 11); + CH573_GPIO__GPIO_PORT_T_INTF.pd_drv.set(ch573_gpio__gpio_port_a, 1, 11); } static inline void set_sysled(int on) { CH573_GPIO__GPIO_PORT_T_INTF.out.set( - ch573_gpio__gpio_port_b, on ? ON : OFF, 10); + ch573_gpio__gpio_port_a, on ? ON : OFF, 11); } diff --git a/include/systick.h b/include/systick.h index 285b9b8..09c69ec 100644 --- a/include/systick.h +++ b/include/systick.h @@ -10,9 +10,16 @@ uint64_t get_systick(); int systick_interrupt(); + +#define PASTER(x, y) x##y +#define CONCAT(x, y) PASTER(x, y) + #define On_SysTick() \ static void __local_on_systick__(void); \ __attribute__(( \ __section__(".systick_callbacks"))) static volatile systick_cb_t \ - __FILE__##__LINE__ = __local_on_systick__; \ + __systick__position = __local_on_systick__; \ static void __local_on_systick__() + +#undef PASTER +#undef CONCAT |