diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 107 |
1 files changed, 55 insertions, 52 deletions
@@ -1,15 +1,17 @@ #include <stdint.h> #include <stdio.h> -#include "string.h" #include "ch573/gpio.h" #include "ch573/pwr.h" #include "ch573/uart.h" #include "clock.h" #include "spi.h" +#include "string.h" #include "system.h" +#include "ws2812b.h" #define GPIO_PORT_A ch573_gpio__gpio_port_a +#define GPIO_PORT_B ch573_gpio__gpio_port_b #define GPIO_PORT CH573_GPIO__GPIO_PORT_T_INTF #define UART1 ch573_uart__uart1 @@ -121,6 +123,10 @@ static void fast_delay() } } +#define N_LEDS 100 + +extern int uart1_FILE_get(FILE* f); + /* * Main routine. This is called on_reset once everything else has been set up. */ @@ -130,63 +136,60 @@ int main(void) set_system_clock_60Mhz(); + printf("What is your name? "); + char buf[1024]; enable_spi(); - char buf[1024]; - memset(buf, 0xf0, sizeof(buf)); - for (int i = 0; i < 50; ++ i) { - buf[i] = 0xaa; - buf[sizeof(buf) - i] = 0xaa; - } + // char buf[1024]; + // memset(buf, 0xf0, sizeof(buf)); + // for (int i = 0; i < 50; ++ i) { + // buf[i] = 0xaa; + // buf[sizeof(buf) - i] = 0xaa; + // } + + size_t n = sizeof(buf); + struct ws2812b_buf ws_buf; + make_wsb2812b(&ws_buf, buf, n); + rgb_t color; + color.color = 0; + color.r = 0xff; + color.g = 0x00; + color.b = 0x00; + uint8_t time = 0xff; + + // for (size_t i = 0; i < N_LEDS; ++i) { + // char* loc = buf + i * TOTAL_BYTES_PER_LED; + // printf( + // "Bytes: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", + // loc[0], + // loc[1], + // loc[2], + // loc[3], + // loc[4], + // loc[5], + // loc[6], + // loc[7], + // loc[8], + // loc[9], + // loc[10]); + // } + GPIO_PORT.dir.set(GPIO_PORT_B, DIR_OUT, 7); while (1) { - printf("Xfer.\n"); - dma_transfer(buf, sizeof(buf)); + ws_buf.cur = 0; + for (int i = 0; i < N_LEDS; ++i) { + color.r = time; + color.g = 0; + color.b = 0xff - time; + write_rgb(&ws_buf, color); + } + time --; + GPIO_PORT.out.set(GPIO_PORT_B, ON, 7); + // printf("WS_BUF: %p, %zu\n", ws_buf.buf, ws_buf.cur); + start_dma(&ws_buf); wait_for_dma(); + basic_delay(); } - // run_spi(); - - // GPIO_PORT.dir.set(GPIO_PORT_A, DIR_OUT, 8); - // GPIO_PORT.pd_drv.set(GPIO_PORT_A, 0, 8); - // GPIO_PORT.out.set(GPIO_PORT_A, OFF, 8); - - // GPIO_PORT.dir.set(GPIO_PORT_A, DIR_OUT, 11); - // GPIO_PORT.pd_drv.set(GPIO_PORT_A, 0, 11); - - // GPIO_PORT.dir.set(GPIO_PORT_A, DIR_IN, 10); - // GPIO_PORT.pd_drv.set(GPIO_PORT_A, PD_DRV_OPEN_DRAIN, 11); - - // set_system_clock_6Mhz(); - // uint32_t reg = (*(uint32_t*)0x40001008); - // reg &= ~0x1f; - // reg |= 10; - // enter_safe_mode(); - // (*(uint32_t*)0x40001008) = reg; - - - // for (int i = 0;; ++i) { - // GPIO_PORT.out.set(GPIO_PORT_A, ON, 8); - // GPIO_PORT.out.set(GPIO_PORT_A, OFF, 8); - // } - - // clock_cfg_t cfg; - // for (int i = 0;; ++i) { - // if (i % 16 == 0) { - // if (cur_clock) { - // set_system_clock_60Mhz(); - // } else { - // set_system_clock_6Mhz(); - // } - // get_system_clock(&cfg); - // printf("Cur Clock Mhz: %d\n", get_clock_freq(&cfg)); - // cur_clock = !cur_clock; - // } - - // basic_delay(); - // GPIO_PORT.out.set(GPIO_PORT_A, ON, 8); - // basic_delay(); - // GPIO_PORT.out.set(GPIO_PORT_A, OFF, 8); - // } return 0; } |