1
0
mirror of https://github.com/whowechina/aic_pico.git synced 2024-11-14 09:37:35 +01:00

DMA driven RGB led

This commit is contained in:
whowechina 2024-06-10 12:23:38 +08:00
parent 52375d9194
commit 08e1772daf
3 changed files with 21 additions and 5 deletions

Binary file not shown.

View File

@ -15,6 +15,7 @@
#include "hardware/pio.h" #include "hardware/pio.h"
#include "hardware/timer.h" #include "hardware/timer.h"
#include "hardware/pwm.h" #include "hardware/pwm.h"
#include "hardware/dma.h"
#include "ws2812.pio.h" #include "ws2812.pio.h"
@ -26,6 +27,8 @@ static uint8_t led_gpio[] = LED_DEF;
#define RGB_NUM (sizeof(rgb_buf) / sizeof(rgb_buf[0])) #define RGB_NUM (sizeof(rgb_buf) / sizeof(rgb_buf[0]))
#define LED_NUM (sizeof(led_gpio)) #define LED_NUM (sizeof(led_gpio))
static uint8_t led_buf[LED_NUM]; static uint8_t led_buf[LED_NUM];
static int rgb_dma;
static dma_channel_config rgb_dma_cfg;
static inline uint32_t rgb32(uint32_t c1, uint32_t c2, uint32_t c3, bool gamma_fix) static inline uint32_t rgb32(uint32_t c1, uint32_t c2, uint32_t c3, bool gamma_fix)
{ {
@ -407,12 +410,16 @@ static void rainbow_update(uint32_t delta_ms)
static void drive_led() static void drive_led()
{ {
irq_set_enabled(IO_IRQ_BANK0, false); static uint32_t rgbdma[RGB_NUM];
for (int i = 0; i < RGB_NUM; i++) { for (int i = 0; i < RGB_NUM; i++) {
uint32_t color = aic_cfg->light.rgb ? rgb_buf[i] << 8u : 0; rgbdma[i] = aic_cfg->light.rgb ? rgb_buf[i] << 8u : 0;
pio_sm_put_blocking(pio0, 0, color);
} }
irq_set_enabled(IO_IRQ_BANK0, true);
dma_channel_configure(rgb_dma, &rgb_dma_cfg,
&pio0_hw->txf[0],
rgbdma,
RGB_NUM,
true);
for (int i = 0; i < LED_NUM; i++) { for (int i = 0; i < LED_NUM; i++) {
uint8_t level = aic_cfg->light.led ? led_buf[i] : 0; uint8_t level = aic_cfg->light.led ? led_buf[i] : 0;
@ -439,6 +446,12 @@ void light_init()
pwm_init(slice, &cfg, true); pwm_init(slice, &cfg, true);
} }
rgb_dma = dma_claim_unused_channel(true);
rgb_dma_cfg = dma_channel_get_default_config(rgb_dma);
channel_config_set_transfer_data_size(&rgb_dma_cfg, DMA_SIZE_32);
channel_config_set_read_increment(&rgb_dma_cfg, true);
channel_config_set_dreq(&rgb_dma_cfg, DREQ_PIO0_TX0);
generate_color_wheel(); generate_color_wheel();
} }

View File

@ -134,6 +134,8 @@ static void core1_init()
static mutex_t core1_io_lock; static mutex_t core1_io_lock;
static void core1_loop() static void core1_loop()
{ {
uint64_t next_frame = 0;
core1_init(); core1_init();
while (1) { while (1) {
@ -146,7 +148,8 @@ static void core1_loop()
} }
light_mode_update(); light_mode_update();
cli_fps_count(1); cli_fps_count(1);
sleep_us(100); // critical for flash programming sleep_until(next_frame);
next_frame = time_us_64() + 999; // no faster than 1000Hz
} }
} }