Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/dmd_counter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#ifndef DMD_COUNTER_H
#define DMD_COUNTER_H

#include "dmd_counter.pio.h"
#include "dmd_reader_pins.h"
#include "hardware/gpio.h"
#include "hardware/pio.h"

void dmd_counter_program_init(PIO pio, uint sm, uint offset) {
pio_sm_config c = dmd_count_dotclk_program_get_default_config(offset);

// Set the IN base pin
sm_config_set_in_pins(&c, DE);

// Set the pin direction at the PIO
pio_sm_set_consecutive_pindirs(pio, sm, DOTCLK, 1, false);
pio_sm_set_consecutive_pindirs(pio, sm, RCLK, 3, false); // RCLK, RDATA, DE

// Connect these GPIOs to this PIO block
pio_gpio_init(pio, DOTCLK);
pio_gpio_init(pio, DE);
pio_gpio_init(pio, RDATA);
pio_gpio_init(pio, RCLK);

// Shifting to left matches the customary MSB-first ordering of SPI.
sm_config_set_in_shift(&c,
false, // Shift-to-right = false
true, // Autopull enabled
32 // Autopull threshold = 32
);

// We only send, so disable the TX FIFO to make the RX FIFO deeper.
sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_RX);

// Load our configuration, do not yet start the program
pio_sm_init(pio, sm, offset, &c);
}

#endif // DMD_COUNTER_H
38 changes: 0 additions & 38 deletions src/dmd_counter.pio
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
jmp x-- clockdecrement
clockdecrement:
wait 1 gpio DOTCLK

.wrap

.program dmd_count_de
Expand All @@ -28,7 +27,6 @@ clockdecrement:
jmp x-- clockdecrement
clockdecrement:
wait 1 gpio DE

.wrap

.program dmd_count_rdata
Expand All @@ -40,7 +38,6 @@ clockdecrement:
jmp x-- clockdecrement
clockdecrement:
wait 1 gpio RDATA

.wrap

.program dmd_count_rclk
Expand All @@ -52,39 +49,4 @@ clockdecrement:
jmp x-- clockdecrement
clockdecrement:
wait 1 gpio RCLK

.wrap


% c-sdk {
static inline void dmd_counter_program_init(PIO pio, uint sm, uint offset) {
pio_sm_config c = dmd_count_dotclk_program_get_default_config(offset);

// Set the IN base pin
sm_config_set_in_pins(&c, 7); // DE

// Set the pin direction at the PIO
pio_sm_set_consecutive_pindirs(pio, sm, 3, 1, false); // DOTCLK
pio_sm_set_consecutive_pindirs(pio, sm, 5, 3, false); // RCLK, RDATA, DE

// Connect these GPIOs to this PIO block
pio_gpio_init(pio, 3); // DOTCLK
pio_gpio_init(pio, 7); // DE
pio_gpio_init(pio, 6); // RDATA
pio_gpio_init(pio, 5); // RCLK

// Shifting to left matches the customary MSB-first ordering of SPI.
sm_config_set_in_shift(
&c,
false, // Shift-to-right = false
true, // Autopull enabled
32 // Autopull threshold = 32
);

// We only send, so disable the TX FIFO to make the RX FIFO deeper.
sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_RX);

// Load our configuration, do not yet start the program
pio_sm_init(pio, sm, offset, &c);
}
%}
54 changes: 54 additions & 0 deletions src/dmd_interface_desega.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#ifndef DMD_INTERFACE_DESEGA_H
#define DMD_INTERFACE_DESEGA_H

#include "dmd_interface_desega.pio.h"
#include "dmd_reader_pins.h"
#include "hardware/gpio.h"
#include "hardware/pio.h"

void dmd_reader_desega_program_init(PIO pio, uint sm,
uint offset) {
pio_sm_config c = dmd_reader_desega_program_get_default_config(offset);

// Set the IN pin, we don't use any other
sm_config_set_in_pins(&c, SDATA);

// Set the pin direction at the PIO
pio_sm_set_consecutive_pindirs(pio, sm, SDATA, 2,
false); // SDATA, DOTCLK

// Connect these GPIOs to this PIO block
pio_gpio_init(pio, DOTCLK);
pio_gpio_init(pio, SDATA);

// Shifting to left matches the customary MSB-first ordering of SPI.
sm_config_set_in_shift(&c,
false, // Shift-to-right = false
true, // Autopull enabled
32 // Autopull threshold
);

// We only send, so disable the TX FIFO to make the RX FIFO deeper.
sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_RX);

// Load our configuration, do not yet start the program
pio_sm_init(pio, sm, offset, &c);
}

void dmd_framedetect_desega_program_init(PIO pio, uint sm,
uint offset) {
pio_sm_config c = dmd_framedetect_desega_program_get_default_config(offset);
// DE is used for jump control
sm_config_set_jmp_pin(&c, DE);

// Set the pin direction at the PIO
pio_sm_set_consecutive_pindirs(pio, sm, DE, 1, false);

// Connect this GPIO to this PIO block
pio_gpio_init(pio, DE);

// Load our configuration, do not yet start the program
pio_sm_init(pio, sm, offset, &c);
}

#endif // DMD_INTERFACE_DESEGA_H
58 changes: 1 addition & 57 deletions src/dmd_interface_desega.pio
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,8 @@
.define COLLAT 4
.define DOTCLK 3
.define SDATA 2

.define FRAME_START_IRQ 4

.define PUBLIC desega_DE DE
.define PUBLIC desega_DOTCLK DOTCLK
.define PUBLIC desega_SDATA SDATA


.program dmd_reader_desega
; initialize y with 8191, number of pixels ((128 x LSB + 128 x MSB) x 32) - 1 because counting starts at 0.
set x, 31 ; x = 31 (max 5-bit value)
Expand All @@ -36,10 +30,9 @@ dotloop:
wait 1 gpio DOTCLK ; raising edge
in pins 1 ; read pin data
jmp x-- dotloop

.wrap


; Frame detection program runs in parallel to the reader program and signals the start of a new frame using an IRQ.
.program dmd_framedetect_desega
.wrap_target

Expand All @@ -62,53 +55,4 @@ delay_loop:

wait 1 gpio DE ; Wait again for it to go high before restarting cycle
jmp wait_low ; went high, time to go back to wait_low

.wrap


% c-sdk {
static inline void dmd_reader_desega_program_init(PIO pio, uint sm, uint offset) {
pio_sm_config c = dmd_reader_desega_program_get_default_config(offset);

// Set the IN pin, we don't use any other
sm_config_set_in_pins(&c, desega_SDATA);

// Set the pin direction at the PIO
pio_sm_set_consecutive_pindirs(pio, sm, desega_SDATA, 2, false); // SDATA, DOTCLK

// Connect these GPIOs to this PIO block
pio_gpio_init(pio, desega_DOTCLK);
pio_gpio_init(pio, desega_SDATA);

// Shifting to left matches the customary MSB-first ordering of SPI.
sm_config_set_in_shift(
&c,
false, // Shift-to-right = false
true, // Autopull enabled
32 // Autopull threshold
);

// We only send, so disable the TX FIFO to make the RX FIFO deeper.
sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_RX);

// Load our configuration, do not yet start the program
pio_sm_init(pio, sm, offset, &c);
}
%}

% c-sdk {
static inline void dmd_framedetect_desega_program_init(PIO pio, uint sm, uint offset) {
pio_sm_config c = dmd_framedetect_desega_program_get_default_config(offset);
// DE is used for jump control
sm_config_set_jmp_pin(&c, desega_DE);

// Set the pin direction at the PIO
pio_sm_set_consecutive_pindirs(pio, sm, desega_DE, 1, false);

// Connect this GPIO to this PIO block
pio_gpio_init(pio, desega_DE);

// Load our configuration, do not yet start the program
pio_sm_init(pio, sm, offset, &c);
}
%}
50 changes: 50 additions & 0 deletions src/dmd_interface_sam.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#ifndef DMD_INTERFACE_SAM_H
#define DMD_INTERFACE_SAM_H

#include "dmd_interface_sam.pio.h"
#include "dmd_reader_pins.h"
#include "hardware/gpio.h"
#include "hardware/pio.h"

void dmd_reader_sam_program_init(PIO pio, uint sm, uint offset) {
pio_sm_config c = dmd_reader_sam_program_get_default_config(offset);

// Set the IN pin, we don't use any other
sm_config_set_in_pins(&c, SDATA);

// Set the pin direction at the PIO
pio_sm_set_consecutive_pindirs(pio, sm, SDATA, 2, false); // SDATA, DOTCLK

// Connect these GPIOs to this PIO block
pio_gpio_init(pio, DOTCLK);
pio_gpio_init(pio, SDATA);

// Shifting to left matches the customary MSB-first ordering of SPI.
sm_config_set_in_shift(&c,
false, // Shift-to-right = false
true, // Autopull enabled
32 // Autopull threshold
);

// We only send, so disable the TX FIFO to make the RX FIFO deeper.
sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_RX);

// Load our configuration, do not yet start the program
pio_sm_init(pio, sm, offset, &c);
}

void dmd_framedetect_sam_program_init(PIO pio, uint sm,
uint offset) {
pio_sm_config c = dmd_framedetect_sam_program_get_default_config(offset);

// Set the pin direction at the PIO
pio_sm_set_consecutive_pindirs(pio, sm, RDATA, 1, false);

// Connect these GPIOs to this PIO block
pio_gpio_init(pio, RDATA);

// Load our configuration, do not yet start the program
pio_sm_init(pio, sm, offset, &c);
}

#endif // DMD_INTERFACE_SAM_H
54 changes: 1 addition & 53 deletions src/dmd_interface_sam.pio
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,8 @@
.define COLLAT 4
.define DOTCLK 3
.define SDATA 2

.define FRAME_START_IRQ 4

.define PUBLIC sam_RCLK RCLK
.define PUBLIC sam_RDATA RDATA
.define PUBLIC sam_DOTCLK DOTCLK
.define PUBLIC sam_SDATA SDATA

.program dmd_reader_sam
; initialize y with 16383, number of pixels (128x32x4) - 1 because counting starts at 0.
set x, 31 ; x = 31 (max 5-bit value)
Expand All @@ -37,56 +31,10 @@ dotloop:
jmp x-- dotloop
.wrap


; Frame detection program runs in parallel to the reader program and signals the start of a new frame using an IRQ.
.program dmd_framedetect_sam
.wrap_target
wait 0 gpio RDATA
wait 1 gpio RDATA
irq FRAME_START_IRQ
.wrap


% c-sdk {
static inline void dmd_reader_sam_program_init(PIO pio, uint sm, uint offset) {
pio_sm_config c = dmd_reader_sam_program_get_default_config(offset);

// Set the IN pin, we don't use any other
sm_config_set_in_pins(&c, sam_SDATA);

// Set the pin direction at the PIO
pio_sm_set_consecutive_pindirs(pio, sm, sam_SDATA, 2, false); // SDATA, DOTCLK

// Connect these GPIOs to this PIO block
pio_gpio_init(pio, sam_DOTCLK);
pio_gpio_init(pio, sam_SDATA);

// Shifting to left matches the customary MSB-first ordering of SPI.
sm_config_set_in_shift(
&c,
false, // Shift-to-right = false
true, // Autopull enabled
32 // Autopull threshold
);

// We only send, so disable the TX FIFO to make the RX FIFO deeper.
sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_RX);

// Load our configuration, do not yet start the program
pio_sm_init(pio, sm, offset, &c);
}
%}

% c-sdk {
static inline void dmd_framedetect_sam_program_init(PIO pio, uint sm, uint offset) {
pio_sm_config c = dmd_framedetect_sam_program_get_default_config(offset);

// Set the pin direction at the PIO
pio_sm_set_consecutive_pindirs(pio, sm, sam_RDATA, 1, false);

// Connect these GPIOs to this PIO block
pio_gpio_init(pio, sam_RDATA);

// Load our configuration, do not yet start the program
pio_sm_init(pio, sm, offset, &c);
}
%}
Loading