attemting to use dma not working

This commit is contained in:
matthias wagner
2023-05-13 20:27:38 +02:00
parent 29c6d4ac96
commit 2c4cfe8e27
24 changed files with 13370 additions and 11517 deletions

View File

@@ -39,6 +39,7 @@ static inline pio_sm_config tft_program_get_default_config(uint offset) {
// For optimal use of DMA bandwidth we would use an autopull threshold of 32,
// but we are using a threshold of 8 here (consume 1 byte from each FIFO entry
// and discard the remainder) to make things easier for software on the other side
#include <stdlib.h>
static inline void tft_program_init(PIO pio, uint sm, uint offset, uint data_pin, uint clk_pin, float clk_div) {
pio_gpio_init(pio, data_pin);
pio_gpio_init(pio, clk_pin);
@@ -49,7 +50,7 @@ static inline void tft_program_init(PIO pio, uint sm, uint offset, uint data_pin
sm_config_set_out_pins(&c, data_pin, 1);
sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX);
sm_config_set_clkdiv(&c, clk_div);
sm_config_set_out_shift(&c, false, true, 8);
sm_config_set_out_shift(&c, false, true, 32);
pio_sm_init(pio, sm, offset, &c);
pio_sm_set_enabled(pio, sm, true);
}
@@ -60,6 +61,17 @@ static inline void tft_put(PIO pio, uint sm, uint8_t x) {
;
*(volatile uint8_t*)&pio->txf[sm] = x;
}
static inline void tft_push(PIO pio, uint sm, int dma_chan, uint16_t* pixels, size_t size) {
size_t new_size = size / 2;
uint32_t* x = malloc(new_size * sizeof(uint32_t));
for (size_t i = 0, j = 0; i < size; i += 2, j++) {
uint32_t combinedValue = ((uint32_t)pixels[i] << 16) | pixels[i + 1];
x[j] = combinedValue;
}
dma_channel_set_read_addr(dma_chan, x, true);
sleep_ms(100);
free(x);
}
// SM is done when it stalls on an empty FIFO
static inline void tft_wait_idle(PIO pio, uint sm) {
uint32_t sm_stall_mask = 1u << (sm + PIO_FDEBUG_TXSTALL_LSB);