diff options
-rw-r--r-- | include/sysled.h | 10 | ||||
-rw-r--r-- | src/main.c | 119 |
2 files changed, 23 insertions, 106 deletions
diff --git a/include/sysled.h b/include/sysled.h index b9556f1..b1a21c1 100644 --- a/include/sysled.h +++ b/include/sysled.h @@ -6,14 +6,12 @@ static inline void enable_sysled() { - CH573_GPIO__GPIO_PORT_T_INTF.dir.set(ch573_gpio__gpio_port_a, DIR_OUT, 8); - CH573_GPIO__GPIO_PORT_T_INTF.pd_drv.set(ch573_gpio__gpio_port_a, 0, 8); + 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); } -// If "on" then turn on the sysled (which counter-intuitively means turning off -// the GPIO). static inline void set_sysled(int on) { -// CH573_GPIO__GPIO_PORT_T_INTF.out.set( -// ch573_gpio__gpio_port_a, on ? OFF : ON, 8); + CH573_GPIO__GPIO_PORT_T_INTF.out.set( + ch573_gpio__gpio_port_b, on ? ON : OFF, 10); } @@ -60,92 +60,14 @@ uint32_t collatz(uint32_t n) return c; } -static void print_reg(uint32_t reg) -{ - // 0x40001008 - printf("register @0x%08x = 0x%08x\n", reg, *(uint32_t*)reg); -} - -static void set_system_clock_6Mhz(void) -{ - print_reg(0x40001008); - printf("Setting system clock to 6Mhz...\n"); - clock_cfg_t clk_cfg = {0}; - clk_cfg.sel = CLOCK_SELECTION_HSE; - clk_cfg.pll_clock_divisor = 5; - if (set_system_clock(&clk_cfg)) { - printf("Failed to set system clock.\n"); - } - print_reg(0x40001008); - printf("Done\n"); -} - -static void set_system_clock_3Mhz(void) -{ - print_reg(0x40001008); - printf("Setting system clock to 3Mhz...\n"); - clock_cfg_t clk_cfg = {0}; - clk_cfg.sel = CLOCK_SELECTION_HSE; - clk_cfg.pll_clock_divisor = 10; - if (set_system_clock(&clk_cfg)) { - printf("Failed to set system clock.\n"); - } - print_reg(0x40001008); - printf("Done\n"); -} - static void set_system_clock_60Mhz(void) { - print_reg(0x40001008); - printf("Setting system clock to 60Mhz...\n"); clock_cfg_t clk_cfg = {0}; clk_cfg.sel = CLOCK_SELECTION_PLL; clk_cfg.pll_clock_divisor = 8; if (set_system_clock(&clk_cfg)) { printf("Failed to set system clock.\n"); - } - print_reg(0x40001008); - printf("Done\n"); -} - -static void set_system_clock_30Mhz(void) -{ - print_reg(0x40001008); - printf("Setting system clock to 30Mhz...\n"); - clock_cfg_t clk_cfg = {0}; - clk_cfg.sel = CLOCK_SELECTION_PLL; - clk_cfg.pll_clock_divisor = 16; - if (set_system_clock(&clk_cfg)) { - printf("Failed to set system clock.\n"); - } - print_reg(0x40001008); - printf("Done\n"); -} - -static void set_system_clock_32kHz() -{ - print_reg(0x40001008); - printf("Setting system clock to 32kHz...\n"); - clock_cfg_t clk_cfg = {0}; - clk_cfg.sel = CLOCK_SELECTION_LSE; - if (set_system_clock(&clk_cfg)) { - printf("Failed to set system clock.\n"); - } -} - -static void basic_delay() -{ - set_sysled(1); - for (int i = 0; i < 30000; ++i) { - asm volatile(""); - } - set_sysled(0); -} - -static void fast_delay() -{ - for (int i = 0; i < 1000; ++i) { - asm volatile(""); + panic(0xff); } } @@ -185,12 +107,6 @@ rgb_t get_rgb(uint32_t time, size_t x) r = 0xff; g = byte_scale(byte_sin(time8 * TIME_STEP + x * 2), 0x90); b = byte_scale(byte_sin(time8 * TIME_STEP + x * 2), 0x20); - // r = byte_scale(byte_sin(time8 * TIME_STEP + x * 2), AS_BYTE(0.25)) + - // AS_BYTE(0.75); - // b = 0x40; - // g = byte_scale( - // 0xff - byte_sin(time8 * TIME_STEP + x * 7 + 0x80), AS_BYTE(0.5)) + - // AS_BYTE(0.5); rgb_t color; color.color = 0; @@ -200,6 +116,15 @@ rgb_t get_rgb(uint32_t time, size_t x) return color; } + +static volatile uint32_t time = 0; +static volatile int spin_lock = 0; + +On_SysTick() { + time ++; + spin_lock = 0; +} + /* * Main routine. This is called on_reset once everything else has been set up. */ @@ -211,12 +136,7 @@ int main(void) PFIC->interrupt_priority_threshold = 0x10; PFIC->interrupt_enable |= IRQ_SysTick; - printf( - "PFIC enable status 1: %08x\n", - (uint32_t)(PFIC->interrupt_enable_status)); - set_system_clock_60Mhz(); - set_systick(250000); enable_sysled(); @@ -228,29 +148,28 @@ int main(void) ws_buf.byte_order = BYTE_ORDER_GRB; rgb_t color; - uint32_t time = 0; GPIO_PORT.dir.set(GPIO_PORT_B, DIR_OUT, 7); + while (1) { - // Fill the buffer with calculated rgb colors. ws_buf.cur = 0; for (int i = 0; i < N_LEDS; ++i) { rgb_t rgb = get_rgb(time, i); write_rgb(&ws_buf, rgb); } - time++; - GPIO_PORT.out.set(GPIO_PORT_B, ON, 7); - for (int i = 0; i < N_DMA_XFER; ++i) { + while (spin_lock) { + set_sysled(1); // Setting the sysled helps me to measure down time. + } + set_sysled(0); + + spin_lock = 1; + + for (int j = 0; j < N_DMA_XFER; ++ j) { wait_for_dma(); start_dma(&ws_buf); } - basic_delay(); } return 0; } - -On_SysTick() { - printf("Systick BOI!\n"); -} |