summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2023-10-01 09:57:01 +0200
committerThomas White <taw@physics.org>2023-10-01 09:57:01 +0200
commit4f7ac4257fb6c347bdbc372b2510dd65c866c1a4 (patch)
treea306ab9ab5ac96e34e0ed3cd0fb0f61b7a731439
parentf32a4f9e24711e20390977503068c42a9f0b92a2 (diff)
Working DMA
-rw-r--r--pixelhub.cpp55
1 files changed, 25 insertions, 30 deletions
diff --git a/pixelhub.cpp b/pixelhub.cpp
index 6a1e36b..5ce4f64 100644
--- a/pixelhub.cpp
+++ b/pixelhub.cpp
@@ -66,13 +66,12 @@ int cur_strip = 0;
static void set_dma()
{
- struct pixel_strip *p = &pxs[cur_strip];
channel_config_set_dreq(&dma_conf,
- pio_get_dreq(p->pio, p->pio_sm, true));
- dma_channel_configure(p->dma_chan, &dma_conf,
- &p->pio->txf[p->pio_sm], /* Dest */
- &p->pixelbuf, /* Source */
- p->num_pixels,
+ pio_get_dreq(pxs[cur_strip].pio, pxs[cur_strip].pio_sm, true));
+ dma_channel_configure(dma_chan, &dma_conf,
+ &pxs[cur_strip].pio->txf[pxs[cur_strip].pio_sm],
+ pxs[cur_strip].pixelbuf,
+ pxs[cur_strip].num_pixels,
true);
}
@@ -99,15 +98,15 @@ static void init_pixel_strip(struct pixel_strip *p, PIO pio, int sm)
{
int i;
+ for ( i=0; i<p->num_pixels; i++ ) {
+ p->pixelbuf[i] = 0;
+ }
+
p->pio = pio;
p->pio_sm = sm;
p->offset = pio_add_program(p->pio, &ws2812_program);
ws2812_program_init(p->pio, p->pio_sm, p->offset, p->pin, 800000, p->rgbw);
- for ( i=0; i<p->num_pixels; i++ ) {
- p->pixelbuf[i] = urgb_u32(32, 0, 32);
- }
-
pio_sm_set_enabled(pio, sm, false);
pio_sm_clear_fifos(pio, sm);
pio_sm_restart(pio, sm);
@@ -122,6 +121,9 @@ int main()
int i;
int blink = 1;
+ /* Initialise DMX */
+ dmx_in.begin(dmx_rx_pin, 1, 512);
+
pxs[0].pin = 2;
pxs[0].num_pixels = 8;
pxs[0].rgbw = false;
@@ -130,27 +132,21 @@ int main()
pxs[1].num_pixels = 1;
pxs[1].rgbw = true;
- n_pxs = 1;
-
- /* Initialise DMX */
- dmx_in.begin(dmx_rx_pin, 1, 512);
+ n_pxs = 2;
/* Initialise Neopixels */
init_pixel_strip(&pxs[0], pio0, 0);
- //init_pixel_strip(&pxs[1]);
+ init_pixel_strip(&pxs[1], pio0, 1);
/* Start DMA */
dma_chan = dma_claim_unused_channel(true);
dma_conf = dma_channel_get_default_config(dma_chan);
channel_config_set_read_increment(&dma_conf, true);
channel_config_set_write_increment(&dma_conf, false);
- channel_config_set_dreq(&dma_conf,
- pio_get_dreq(pxs[0].pio, pxs[0].pio_sm, true));
- dma_channel_configure(dma_chan, &dma_conf,
- &pxs[0].pio->txf[pxs[0].pio_sm], /* Dest */
- pxs[0].pixelbuf, /* Source */
- pxs[0].num_pixels,
- true);
+ irq_set_exclusive_handler(DMA_IRQ_0, dma_complete);
+ dma_channel_set_irq0_enabled(dma_chan, true);
+ irq_set_enabled(DMA_IRQ_0, true);
+ set_dma();
/* Status LED */
gpio_init(PICO_DEFAULT_LED_PIN);
@@ -162,17 +158,16 @@ int main()
//dmx_in.read(dmxbuf);
//int dmxpos = 1; /* Numbering starts at 1 */
- //for ( i=0; i<pxs[0].num_pixels; i++) {
- // put_pixel(&pxs[0], urgb_u32(32, 0, 0));
- //}
- //sleep_ms(10);
- //for ( i=0; i<pxs[1].num_pixels; i++) {
- // pxs[1].pixelbuf[i] = wrgb_u32(0, 64, 0, 0);
- //}
+ for ( i=0; i<pxs[0].num_pixels; i++) {
+ pxs[0].pixelbuf[i] = urgb_u32(32, 0, 0);
+ }
+ for ( i=0; i<pxs[1].num_pixels; i++) {
+ pxs[1].pixelbuf[i] = wrgb_u32(0, 64, 0, 0);
+ }
gpio_put(PICO_DEFAULT_LED_PIN, blink);
loop++;
- if ( loop > 3000000 ) {
+ if ( loop > 1000000 ) {
loop = 0;
blink = 1 - blink;
}