1
0
Fork 0

pio-based everything 8-bit color work!

sd2
radex 2024-06-02 11:02:47 +02:00
parent 99f4f36d31
commit 62a69a4c6d
Signed by: radex
SSH Key Fingerprint: SHA256:hvqRXAGG1h89yqnS+cyFTLKQbzjWD4uXIqw7Y+0ws30
4 changed files with 19 additions and 17 deletions

View File

@ -12,6 +12,8 @@ uint pusher_sm = 255; // invalid
uint delay_sm = 255; // invalid
uint row_sm = 255; // invalid
#define LEDS_PIO_CLKDIV 1
// NOTE: RCLK, SRCLK capture on *rising* edge
inline void pulsePin(uint8_t pin) {
gpio_put(pin, HIGH);
@ -36,7 +38,7 @@ inline void outputEnable(uint8_t pin, bool enable) {
uint8_t brightnessPhase = 0;
// delays in nanoseconds
#define NS_TO_DELAY(ns) ns / NS_PER_CYCLE
#define NS_TO_DELAY(ns) (ns / NS_PER_CYCLE / LEDS_PIO_CLKDIV)
uint32_t brightnessPhaseDelays[COLOR_BITS] = {
NS_TO_DELAY(50),
NS_TO_DELAY(100),
@ -104,18 +106,18 @@ void leds_set_framebuffer(uint8_t *buffer) {
}
// set row shifting data
bool firstRow = y == (ROW_COUNT - 1);
uint32_t rowPulses = 1;
bool firstRow = y == 0;
uint32_t extraPulses = 0;
if (moduleY == 0) {
rowPulses++;
extraPulses++;
}
if (moduleY == 7 || moduleY == 14 || (moduleY == 0 && yModule != 0)) {
rowPulses++;
extraPulses++;
}
uint32_t rowData = firstRow | (rowPulses << 1);
uint32_t rowData = firstRow | (extraPulses << 1);
ledBuffer[bi][outputYOffset + COL_MODULES] = rowData;
}
}
@ -224,7 +226,7 @@ void leds_initPusher() {
uint offset = pio_add_program(pio, &leds_px_pusher_program);
pio_sm_config config = leds_px_pusher_program_get_default_config(offset);
sm_config_set_clkdiv_int_frac(&config, 1, 0);
sm_config_set_clkdiv_int_frac(&config, LEDS_PIO_CLKDIV, 0);
// Shift OSR to the right, autopull
sm_config_set_out_shift(&config, true, true, 32);
@ -264,7 +266,7 @@ void leds_initRowSelector() {
uint offset = pio_add_program(pio, &leds_row_selector_program);
pio_sm_config config = leds_row_selector_program_get_default_config(offset);
sm_config_set_clkdiv_int_frac(&config, 1, 0);
sm_config_set_clkdiv_int_frac(&config, LEDS_PIO_CLKDIV, 0);
// Shift OSR to the right, autopull
sm_config_set_out_shift(&config, true, true, 32);
@ -293,7 +295,7 @@ void leds_initDelay() {
uint offset = pio_add_program(pio, &leds_delay_program);
pio_sm_config config = leds_delay_program_get_default_config(offset);
sm_config_set_clkdiv_int_frac(&config, 1, 0);
sm_config_set_clkdiv_int_frac(&config, LEDS_PIO_CLKDIV, 0);
// Shift OSR to the right, autopull
sm_config_set_out_shift(&config, true, true, 32);

View File

@ -24,10 +24,10 @@
#define COLOR_BITS 8
#define FPS 30
#define MS_PER_FRAME 1000 / FPS
#define MS_PER_FRAME (1000 / FPS)
#define CPU_MHZ 125
#define NS_PER_CYCLE 1000 / CPU_MHZ
#define NS_PER_CYCLE (1000 / CPU_MHZ)
void leds_init();
void leds_initRenderer();

View File

@ -1,6 +1,6 @@
.define public irq_did_latch 0
.define public irq_delaying 1
.define public irq_row_selected 1
.define public irq_delaying 2
; TODO: check if delays can be lowered with a PCB
.define public srclk_0_delay 1
@ -48,7 +48,7 @@ entry_point:
.wrap_target
; LSB=1 indicates first (bottom) row, ergo, high SER for the first pulse
out pins, 1 side 0 [srclk_0_delay]
; The rest of the word indicates number of SRCLK pulses
; The rest of the word indicates number of extra SRCLK pulses
out x, 31
loop:
; pulse SRCLK x times

View File

@ -9,8 +9,8 @@
#endif
#define irq_did_latch 0
#define irq_delaying 1
#define irq_row_selected 1
#define irq_delaying 2
#define srclk_0_delay 1
#define srclk_1_delay 2
#define rclk_1_delay 3
@ -29,7 +29,7 @@ static const uint16_t leds_px_pusher_program_instructions[] = {
0x1a41, // 2: jmp x--, 1 side 1 [2]
0x7028, // 3: out x, 8 side 0
0x0020, // 4: jmp !x, 0
0x2041, // 5: wait 0 irq, 1
0x2042, // 5: wait 0 irq, 2
0x20c1, // 6: wait 1 irq, 1
0xc000, // 7: irq nowait 0
0xe301, // 8: set pins, 1 [3]
@ -98,10 +98,10 @@ static inline pio_sm_config leds_row_selector_program_get_default_config(uint of
static const uint16_t leds_delay_program_instructions[] = {
// .wrap_target
0x20c0, // 0: wait 1 irq, 0
0xc001, // 1: irq nowait 1
0xc002, // 1: irq nowait 2
0x6020, // 2: out x, 32
0x1043, // 3: jmp x--, 3 side 0
0xd841, // 4: irq clear 1 side 1
0xd842, // 4: irq clear 2 side 1
// .wrap
};