summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2023-10-01 11:05:38 +0200
committerThomas White <taw@physics.org>2023-10-01 11:05:38 +0200
commit0d50d18aa4dc78e79d51cad91cb68a6e1dc46d6b (patch)
tree1e90c45685c0ac5619cdecf153410b1738d0d6ed
parent4f7ac4257fb6c347bdbc372b2510dd65c866c1a4 (diff)
Working DMA with DMX!main
-rw-r--r--pixelhub.cpp30
1 files changed, 19 insertions, 11 deletions
diff --git a/pixelhub.cpp b/pixelhub.cpp
index 5ce4f64..8ae6627 100644
--- a/pixelhub.cpp
+++ b/pixelhub.cpp
@@ -20,6 +20,7 @@
*
*/
+#include <cstring>
#include <pico/stdlib.h>
#include <DmxInput.h>
#include <ws2812.pio.h>
@@ -87,8 +88,8 @@ static int64_t next_strip(alarm_id_t id, void *vp)
static void dma_complete()
{
- if ( dma_hw->ints0 & 1<<dma_chan ) {
- dma_hw->ints0 = 1<<dma_chan;
+ if ( dma_hw->ints1 & 1<<dma_chan ) {
+ dma_hw->ints1 = 1<<dma_chan;
add_alarm_in_us(400, next_strip, NULL, true);
}
}
@@ -122,7 +123,7 @@ int main()
int blink = 1;
/* Initialise DMX */
- dmx_in.begin(dmx_rx_pin, 1, 512);
+ dmx_in.begin(dmx_rx_pin, 1, 512, pio1, false);
pxs[0].pin = 2;
pxs[0].num_pixels = 8;
@@ -143,31 +144,38 @@ int main()
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);
- irq_set_exclusive_handler(DMA_IRQ_0, dma_complete);
- dma_channel_set_irq0_enabled(dma_chan, true);
- irq_set_enabled(DMA_IRQ_0, true);
+ irq_set_exclusive_handler(DMA_IRQ_1, dma_complete);
+ dma_channel_set_irq1_enabled(dma_chan, true);
+ irq_set_enabled(DMA_IRQ_1, true);
set_dma();
/* Status LED */
gpio_init(PICO_DEFAULT_LED_PIN);
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
+ memset(dmxbuf, 2, 512);
+
int loop = 0;
while (1) {
- //dmx_in.read(dmxbuf);
+ dmx_in.read(dmxbuf);
- //int dmxpos = 1; /* Numbering starts at 1 */
+ int dmxpos = 1; /* Numbering starts at 1 */
for ( i=0; i<pxs[0].num_pixels; i++) {
- pxs[0].pixelbuf[i] = urgb_u32(32, 0, 0);
+ pxs[0].pixelbuf[i] = urgb_u32(dmxbuf[dmxpos++],
+ dmxbuf[dmxpos++],
+ dmxbuf[dmxpos++]);
}
for ( i=0; i<pxs[1].num_pixels; i++) {
- pxs[1].pixelbuf[i] = wrgb_u32(0, 64, 0, 0);
+ pxs[1].pixelbuf[i] = wrgb_u32(dmxbuf[dmxpos++],
+ dmxbuf[dmxpos++],
+ dmxbuf[dmxpos++],
+ dmxbuf[dmxpos++]);
}
gpio_put(PICO_DEFAULT_LED_PIN, blink);
loop++;
- if ( loop > 1000000 ) {
+ if ( loop > 30 ) {
loop = 0;
blink = 1 - blink;
}