diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2024-12-08 14:22:05 -0700 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2024-12-08 14:22:05 -0700 |
commit | f89f75b5616de99865448f41b068a2783cd3648e (patch) | |
tree | 1e7599b8915d3fbb9a1a10892ba58fd44bea3f5d /src/main.c | |
parent | 546a5ccdba66dd8d8c19ce6d8486f46c84637cf2 (diff) | |
download | ch573-f89f75b5616de99865448f41b068a2783cd3648e.tar.gz ch573-f89f75b5616de99865448f41b068a2783cd3648e.tar.bz2 ch573-f89f75b5616de99865448f41b068a2783cd3648e.zip |
Cleaned up GPIO code quite a bit.
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 38 |
1 files changed, 18 insertions, 20 deletions
@@ -18,6 +18,7 @@ #include "system.h" #include "systick.h" #include "ws2812b.h" +#include "gpio.h" #ifndef LED_BYTE_ORDER #define LED_BYTE_ORDER GRB @@ -61,7 +62,6 @@ uint8_t amp(uint8_t in, uint8_t n) return min(out, 255); } - static void set_system_clock_60Mhz(void) { clock_cfg_t clk_cfg = {0}; @@ -74,7 +74,7 @@ static void set_system_clock_60Mhz(void) } #define N_LEDS 255 -#define N_DMA_XFER 3 +#define N_DMA_XFER 4 extern int uart1_FILE_get(FILE* f); @@ -89,24 +89,26 @@ static size_t debounce = 0; On_SysTick() { if (debounce > 0) { - debounce --; + debounce--; } time++; spin_lock = 0; } -On_BootSelPress() +On_Gpio(gpio_pin_t pin) { - if (debounce > 0) return; - debounce = 10; - - size_t tmp = current_pattern_idx; - tmp ++; - if (tmp >= n_patterns) { - tmp = 0; + if (pin == PIN_PB7) { + if (debounce > 0) return; + debounce = 10; + + size_t tmp = current_pattern_idx; + tmp++; + if (tmp >= n_patterns) { + tmp = 0; + } + current_pattern_idx = tmp; + printf("Switch to '%s'\n", patterns[current_pattern_idx].name); } - current_pattern_idx = tmp; - printf("Switch to '%s'\n", patterns[current_pattern_idx].name); } /* @@ -117,12 +119,6 @@ int main(void) char buf[N_LEDS * TOTAL_BYTES_PER_LED]; PFIC_I.vector_table_control.set(PFIC, 1); - PFIC->interrupt_priority_threshold = 0x10; - PFIC->interrupt_enable |= IRQ_SysTick; - PFIC->interrupt_priority_threshold = 0x10; - PFIC->interrupt_enable |= IRQ_GpioA; - PFIC->interrupt_priority_threshold = 0x10; - PFIC->interrupt_enable |= IRQ_GpioB; set_system_clock_60Mhz(); set_systick(250000); @@ -148,7 +144,9 @@ int main(void) printf("\nRunning Pattern '%s'\n", patterns[current_pattern_idx].name); - enable_bootsel_button(); + configure_gpio(PIN_PB7, PIN_CFG_INPUT_PULL_UP); + enable_gpio_interrupt(PIN_PB7, INT_MODE_FALLING_EDGE); + // enable_bootsel_button(); size_t n = sizeof(buf); struct ws2812b_buf ws_buf; |