mirror of
https://github.com/whowechina/aic_pico.git
synced 2024-11-12 00:40:47 +01:00
DMA driven RGB led
This commit is contained in:
parent
52375d9194
commit
08e1772daf
Binary file not shown.
@ -15,6 +15,7 @@
|
||||
#include "hardware/pio.h"
|
||||
#include "hardware/timer.h"
|
||||
#include "hardware/pwm.h"
|
||||
#include "hardware/dma.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 LED_NUM (sizeof(led_gpio))
|
||||
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)
|
||||
{
|
||||
@ -407,13 +410,17 @@ static void rainbow_update(uint32_t delta_ms)
|
||||
|
||||
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++) {
|
||||
uint32_t color = aic_cfg->light.rgb ? rgb_buf[i] << 8u : 0;
|
||||
pio_sm_put_blocking(pio0, 0, color);
|
||||
rgbdma[i] = aic_cfg->light.rgb ? rgb_buf[i] << 8u : 0;
|
||||
}
|
||||
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++) {
|
||||
uint8_t level = aic_cfg->light.led ? led_buf[i] : 0;
|
||||
pwm_set_gpio_level(led_gpio[i], level);
|
||||
@ -439,6 +446,12 @@ void light_init()
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -134,6 +134,8 @@ static void core1_init()
|
||||
static mutex_t core1_io_lock;
|
||||
static void core1_loop()
|
||||
{
|
||||
uint64_t next_frame = 0;
|
||||
|
||||
core1_init();
|
||||
|
||||
while (1) {
|
||||
@ -146,7 +148,8 @@ static void core1_loop()
|
||||
}
|
||||
light_mode_update();
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user