Skip to content

Commit

Permalink
MicroPython: Make DV display us fixed pio/dma.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Jun 26, 2023
1 parent 71a7c25 commit a40cff4
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 57 deletions.
17 changes: 13 additions & 4 deletions drivers/aps6404/aps6404.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
#include "hardware/clocks.h"
#include "pico/stdlib.h"
#include "aps6404.pio.h"
#ifndef MICROPY_BUILD_TYPE
#define mp_printf(_, ...) printf(__VA_ARGS__);
#else
extern "C" {
#include "py/runtime.h"
}
#endif

namespace pimoroni {
APS6404::APS6404(uint pin_csn, uint pin_d0, PIO pio)
Expand All @@ -20,17 +27,19 @@ namespace pimoroni {
}

pio_prog = &sram_reset_program;
pio_clear_instruction_memory(pio);
pio_offset = pio_add_program(pio, &sram_reset_program);
pio_sm = pio_claim_unused_sm(pio, true);
pio_sm = 0; //pio_claim_unused_sm(pio, true);

// Claim DMA channels
dma_channel = dma_claim_unused_channel(true);
read_cmd_dma_channel = dma_claim_unused_channel(true);
dma_channel = 0;// dma_claim_unused_channel(true);
read_cmd_dma_channel = 1;// dma_claim_unused_channel(true);
}

void APS6404::init() {
pio_sm_set_enabled(pio, pio_sm, false);
pio_remove_program(pio, pio_prog, pio_offset);
pio_clear_instruction_memory(pio);
//pio_remove_program(pio, pio_prog, pio_offset);

pio_prog = &sram_reset_program;
pio_offset = pio_add_program(pio, &sram_reset_program);
Expand Down
15 changes: 11 additions & 4 deletions drivers/dv_display/dv_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
#include <cstdlib>
#include <math.h>
#include <string.h>
#ifndef MICROPY_BUILD_TYPE
#define mp_printf(_, ...) printf(__VA_ARGS__);
#else
extern "C" {
#include "py/runtime.h"
}
#endif

namespace pimoroni {

Expand Down Expand Up @@ -43,7 +50,7 @@ namespace pimoroni {
}

if (res_mode == 0xFF) {
printf("Resolution %dx%d is not supported. Will use 720x480.\n", width, height);
mp_printf(&mp_plat_print, "Resolution %dx%d is not supported. Will use 720x480.\n", width, height);
}

gpio_init(RAM_SEL);
Expand Down Expand Up @@ -71,14 +78,14 @@ namespace pimoroni {
gpio_put(RAM_SEL, 0);
sleep_ms(100);

printf("Start I2C\n");
mp_printf(&mp_plat_print, "Start I2C\n");

if (res_mode != 0xFF) {
i2c.reg_write_uint8(I2C_ADDR, I2C_REG_SET_RES, res_mode);
}

i2c.reg_write_uint8(I2C_ADDR, I2C_REG_START, 1);
printf("Started\n");
mp_printf(&mp_plat_print, "Started\n");
}

void DVDisplay::flip() {
Expand Down Expand Up @@ -355,7 +362,7 @@ namespace pimoroni {
uint32_t buf[8];
uint addr = 4 * 7;
uint line_type = 0x80000000u + ((uint)mode << 28);
printf("Write header, line type %08x\n", line_type);
mp_printf(&mp_plat_print, "Write header, line type %08x\n", line_type);
for (int i = 0; i < height; i += 8) {
for (int j = 0; j < 8; ++j) {
buf[j] = line_type + ((uint32_t)h_repeat << 24) + ((i + j) * width * 6) + base_address;
Expand Down
Loading

0 comments on commit a40cff4

Please sign in to comment.