Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: Switch pimoroni-pico branch. #4

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
12 changes: 6 additions & 6 deletions .github/workflows/micropython.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ on:
types: [created]

env:
MICROPYTHON_VERSION: feature/psram
MICROPYTHON_VERSION: feature/psram-and-wifi
MICROPYTHON_FLAVOUR: pimoroni
PIMORONI_PICO_VERSION: feature/presto
PIMORONI_PICO_VERSION: feature/picovector2-and-layers

jobs:
build:
name: ${{ matrix.name }} (${{ matrix.board }} ${{ matrix.variant }} ${{ matrix.modules }})
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
continue-on-error: true
strategy:
matrix:
Expand Down Expand Up @@ -66,7 +66,7 @@ jobs:
- name: Install Arm GNU Toolchain (arm-none-eabi-gcc)
uses: carlosperate/arm-none-eabi-gcc-action@v1
with:
release: '9-2020-q2'
release: '13.3.Rel1'

- name: "CCache: Install"
run: |
Expand All @@ -82,14 +82,14 @@ jobs:
uses: actions/checkout@v4
with:
repository: gadgetoid/py_decl
ref: v0.0.2
ref: v0.0.4
path: py_decl

- name: "dir2uf2: Checkout"
uses: actions/checkout@v4
with:
repository: gadgetoid/dir2uf2
ref: v0.0.7
ref: v0.0.10
path: dir2uf2

- name: "MicroPython: Build MPY Cross"
Expand Down
84 changes: 30 additions & 54 deletions drivers/st7701/st7701.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,16 @@ namespace pimoroni {
CND2BKxSEL = 0xFF,
};


#define DISPLAY_HEIGHT 480
#define TIMING_V_PULSE 8
#define TIMING_V_BACK (5 + TIMING_V_PULSE)
#define TIMING_V_DISPLAY (480 + TIMING_V_BACK)
#define TIMING_V_DISPLAY (DISPLAY_HEIGHT + TIMING_V_BACK)
#define TIMING_V_FRONT (5 + TIMING_V_DISPLAY)
#define TIMING_H_FRONT 4
#define TIMING_H_PULSE 25
#define TIMING_H_BACK 30
#define TIMING_H_DISPLAY 480

#define LOW_PRIO_IRQ0 (NUM_IRQS - NUM_USER_IRQS)

static ST7701* st7701_inst;

// This ISR is triggered whenever the timing SM's FIFO is not full
Expand Down Expand Up @@ -161,24 +159,9 @@ void __no_inline_not_in_flash_func(ST7701::start_line_xfer())
{
hw_clear_bits(&st_pio->irq, 0x1);

dma_channel_abort(st_dma);
dma_channel_wait_for_finish_blocking(st_dma);
pio_sm_set_enabled(st_pio, parallel_sm, false);
pio_sm_clear_fifos(st_pio, parallel_sm);
pio_sm_exec_wait_blocking(st_pio, parallel_sm, pio_encode_mov(pio_osr, pio_null));
pio_sm_exec_wait_blocking(st_pio, parallel_sm, pio_encode_out(pio_null, 32));
pio_sm_exec_wait_blocking(st_pio, parallel_sm, pio_encode_jmp(parallel_offset));
pio_sm_set_enabled(st_pio, parallel_sm, true);

if ((intptr_t)framebuffer >= 0x20000000) {
dma_channel_set_read_addr(st_dma, &framebuffer[width * (display_row >> row_shift)], true);
}
else {
dma_channel_set_read_addr(st_dma, &line_buffer[width * ((display_row >> row_shift) & (NUM_LINE_BUFFERS - 1))], true);
}
++display_row;

irq_set_pending(LOW_PRIO_IRQ0);
if (display_row == DISPLAY_HEIGHT) next_line_addr = 0;
else next_line_addr = &framebuffer[width * (display_row >> row_shift)];
}

void ST7701::start_frame_xfer()
Expand All @@ -192,9 +175,18 @@ void ST7701::start_frame_xfer()
init_framebuffer();
}

next_line_addr = 0;
dma_channel_abort(st_dma);
dma_channel_wait_for_finish_blocking(st_dma);
pio_sm_set_enabled(st_pio, parallel_sm, false);
pio_sm_clear_fifos(st_pio, parallel_sm);
pio_sm_exec_wait_blocking(st_pio, parallel_sm, pio_encode_mov(pio_osr, pio_null));
pio_sm_exec_wait_blocking(st_pio, parallel_sm, pio_encode_out(pio_null, 32));
pio_sm_exec_wait_blocking(st_pio, parallel_sm, pio_encode_jmp(parallel_offset));
pio_sm_set_enabled(st_pio, parallel_sm, true);
display_row = 0;
fill_row = 0;
irq_set_pending(LOW_PRIO_IRQ0);
next_line_addr = framebuffer;
dma_channel_set_read_addr(st_dma, framebuffer, true);

waiting_for_vsync = false;
__sev();
Expand All @@ -213,41 +205,23 @@ void ST7701::init_framebuffer() {
framebuffer += 0x2000000;
}

void __no_inline_not_in_flash_func(line_fill_isr()) {
st7701_inst->fill_next_line();
}

void __no_inline_not_in_flash_func(ST7701::fill_next_line()) {
if ((intptr_t)framebuffer >= 0x20000000) return;
while (fill_row < height && fill_row < (display_row >> row_shift) + NUM_LINE_BUFFERS - 1) {
memcpy(&line_buffer[width * (fill_row & (NUM_LINE_BUFFERS - 1))], &framebuffer[width * fill_row], width << 1);
++fill_row;
}
}

ST7701::ST7701(uint16_t width, uint16_t height, Rotation rotation, SPIPins control_pins, uint16_t* framebuffer, uint16_t* linebuffer,
ST7701::ST7701(uint16_t width, uint16_t height, Rotation rotation, SPIPins control_pins, uint16_t* framebuffer,
uint d0, uint hsync, uint vsync, uint lcd_de, uint lcd_dot_clk) :
DisplayDriver(width, height, rotation),
spi(control_pins.spi),
spi_cs(control_pins.cs), spi_sck(control_pins.sck), spi_dat(control_pins.mosi), lcd_bl(control_pins.bl),
d0(d0), hsync(hsync), vsync(vsync), lcd_de(lcd_de), lcd_dot_clk(lcd_dot_clk),
framebuffer(framebuffer),
line_buffer(linebuffer)
framebuffer(framebuffer)
{
st7701_inst = this;

// Allocate line buffers only if none supplied and frame buffer is not in internal RAM.
if(!line_buffer && (intptr_t)framebuffer < 0x20000000) {
line_buffer = (uint16_t*)malloc(NUM_LINE_BUFFERS * width * sizeof(line_buffer[0]));
}
}

void ST7701::init() {
irq_handler_t current = nullptr;

init_framebuffer();

st_pio = pio2;
st_pio = pio1;
parallel_sm = pio_claim_unused_sm(st_pio, true);

if (width == 480) parallel_offset = pio_add_program(st_pio, &st7701_parallel_program);
Expand Down Expand Up @@ -335,25 +309,25 @@ void __no_inline_not_in_flash_func(ST7701::fill_next_line()) {
pio_sm_set_enabled(st_pio, timing_sm, true);

st_dma = dma_claim_unused_channel(true);
st_dma2 = dma_claim_unused_channel(true);

dma_channel_config config = dma_channel_get_default_config(st_dma);
channel_config_set_transfer_data_size(&config, DMA_SIZE_32);
channel_config_set_high_priority(&config, true);
channel_config_set_dreq(&config, pio_get_dreq(st_pio, parallel_sm, true));
channel_config_set_bswap(&config, true);
dma_channel_configure(st_dma, &config, &st_pio->txf[parallel_sm], line_buffer, width >> 1, false);
channel_config_set_chain_to(&config, st_dma2);
dma_channel_configure(st_dma, &config, &st_pio->txf[parallel_sm], nullptr, width >> 1, false);

hw_set_bits(&bus_ctrl_hw->priority, (BUSCTRL_BUS_PRIORITY_PROC1_BITS | BUSCTRL_BUS_PRIORITY_DMA_R_BITS | BUSCTRL_BUS_PRIORITY_DMA_W_BITS));
config = dma_channel_get_default_config(st_dma2);
channel_config_set_transfer_data_size(&config, DMA_SIZE_32);
channel_config_set_read_increment(&config, false);
dma_channel_configure(st_dma2, &config, &dma_hw->ch[st_dma].al3_read_addr_trig, &next_line_addr, 1, false);

printf("Begin SPI setup\n");

common_init();

printf("Setup screen timing\n");
current = irq_get_exclusive_handler(LOW_PRIO_IRQ0);
if(current) irq_remove_handler(LOW_PRIO_IRQ0, current);
irq_set_exclusive_handler(LOW_PRIO_IRQ0, line_fill_isr);
irq_set_enabled(LOW_PRIO_IRQ0, true);
irq_set_pending(LOW_PRIO_IRQ0);

// Setup timing
hw_set_bits(&st_pio->inte1, 0x010 << timing_sm); // TX not full
Expand Down Expand Up @@ -475,14 +449,16 @@ void __no_inline_not_in_flash_func(ST7701::fill_next_line()) {
current = irq_get_exclusive_handler(pio_get_irq_num(st_pio, 1));
if(current) irq_remove_handler(pio_get_irq_num(st_pio, 1), current);

irq_set_enabled(LOW_PRIO_IRQ0, false);

next_line_addr = 0;
if(dma_channel_is_claimed(st_dma)) {
while (dma_channel_is_busy(st_dma))
;
dma_channel_abort(st_dma);
dma_channel_unclaim(st_dma);
}
if(dma_channel_is_claimed(st_dma2)) {
dma_channel_unclaim(st_dma2);
}

if(pio_sm_is_claimed(st_pio, parallel_sm)) {
pio_sm_set_enabled(st_pio, parallel_sm, false);
Expand Down
7 changes: 3 additions & 4 deletions drivers/st7701/st7701.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace pimoroni {
uint parallel_offset;
uint timing_offset;
uint st_dma;
uint line_dma;
uint st_dma2;

uint d0 = 1; // First pin of 18-bit parallel interface
uint hsync = 19;
Expand All @@ -50,7 +50,7 @@ namespace pimoroni {

public:
// Parallel init
ST7701(uint16_t width, uint16_t height, Rotation rotation, SPIPins control_pins, uint16_t* framebuffer, uint16_t* linebuffer,
ST7701(uint16_t width, uint16_t height, Rotation rotation, SPIPins control_pins, uint16_t* framebuffer,
uint d0=1, uint hsync=19, uint vsync=20, uint lcd_de = 21, uint lcd_dot_clk = 22);

void init();
Expand All @@ -67,7 +67,6 @@ namespace pimoroni {
// Only to be called by ISR
void drive_timing();
void handle_end_of_line();
void fill_next_line();

private:
void common_init();
Expand All @@ -88,7 +87,7 @@ namespace pimoroni {
uint16_t* framebuffer;
uint16_t* next_framebuffer = nullptr;

uint16_t* line_buffer;
uint16_t* next_line_addr;
int display_row = 0;
int row_shift = 0;
int fill_row = 0;
Expand Down
2 changes: 1 addition & 1 deletion modules/c/presto/presto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ mp_obj_t Presto_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw,
presto_debug("m_new_class(ST7701...\n");
ST7701 *presto = m_new_class(ST7701, WIDTH, HEIGHT, ROTATE_0,
SPIPins{spi1, LCD_CS, LCD_CLK, LCD_DAT, PIN_UNUSED, LCD_DC, BACKLIGHT},
self->next_fb, nullptr,
self->next_fb,
LCD_D0);

self->presto = presto;
Expand Down
16 changes: 15 additions & 1 deletion modules/default.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
# https://github.com/micropython/micropython-lib/blob/master/micropython/bundles/bundle-networking/manifest.py
require("bundle-networking")
require("urllib.urequest")
require("umqtt.simple")

# Handy for dealing with APIs
require("datetime")

# SD Card
require("sdcard")

# Bluetooth
require("aioble")

# Include the manifest.py from micropython/ports/rp2/boards/manifest.py
include("$(PORT_DIR)/boards/manifest.py")

# Include the manifest.py from micropython/<board>/manifest.py
include("$(BOARD_DIR)/manifest.py")

# Include pga/modules/py_frozen
freeze("py_frozen/")
freeze("py_frozen/")
27 changes: 27 additions & 0 deletions presto/mpconfigboard.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,30 @@ set(MICROPY_FROZEN_MANIFEST ${MICROPY_BOARD_DIR}/manifest.py)
# If USER_C_MODULES or MicroPython customisations use malloc then
# there needs to be some RAM reserved for the C heap
set(MICROPY_C_HEAP_SIZE 4096)

# Links micropy_lib_lwip and sets MICROPY_PY_LWIP = 1
# Picked up and expanded upon in mpconfigboard.h
set(MICROPY_PY_LWIP ON)

# Links cyw43-driver and sets:
# MICROPY_PY_NETWORK_CYW43 = 1,
# MICROPY_PY_SOCKET_DEFAULT_TIMEOUT_MS = 30000
set(MICROPY_PY_NETWORK_CYW43 ON)

# Adds mpbthciport.c
# And sets:
# MICROPY_PY_BLUETOOTH = 1,
# MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS = 1,
# MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE = 1
set(MICROPY_PY_BLUETOOTH ON)

# Links pico_btstack_hci_transport_cyw43
# And sets:
# MICROPY_BLUETOOTH_BTSTACK = 1,
# MICROPY_BLUETOOTH_BTSTACK_CONFIG_FILE =
set(MICROPY_BLUETOOTH_BTSTACK ON)

# Sets:
# CYW43_ENABLE_BLUETOOTH = 1,
# MICROPY_PY_BLUETOOTH_CYW43 = 1
set(MICROPY_PY_BLUETOOTH_CYW43 ON)
22 changes: 22 additions & 0 deletions presto/mpconfigboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,28 @@
// PGA2350 has 16MB flash, so reserve 2MiB for the firmware and leave 14MiB
#define MICROPY_HW_FLASH_STORAGE_BYTES (14 * 1024 * 1024)

// Set up networking.
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "PPP2"

// Enable WiFi & PPP
#define MICROPY_PY_NETWORK (1)
#define MICROPY_PY_NETWORK_PPP_LWIP (1)

// CYW43 driver configuration.
#define CYW43_USE_SPI (1)
#define CYW43_LWIP (1)
#define CYW43_GPIO (1)
#define CYW43_SPI_PIO (1)

#ifndef CYW43_WL_GPIO_COUNT
#define CYW43_WL_GPIO_COUNT 3
#endif

#define MICROPY_HW_PIN_EXT_COUNT CYW43_WL_GPIO_COUNT

int mp_hal_is_pin_reserved(int n);
#define MICROPY_HW_PIN_RESERVED(i) mp_hal_is_pin_reserved(i)

// Alias the chip select pin specified by presto.h
#define MICROPY_HW_PSRAM_CS_PIN PIMORONI_PRESTO_PSRAM_CS_PIN
#define MICROPY_HW_ENABLE_PSRAM (1)
Expand Down
32 changes: 32 additions & 0 deletions presto/presto.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,38 @@
#define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024)
#endif

// --- WIRELESS ---

// PICO_CONFIG: CYW43_DEFAULT_PIN_WL_REG_ON, gpio pin to power up the cyw43 chip, type=int, default=23, advanced=true, group=pico_cyw43_driver
#ifndef CYW43_DEFAULT_PIN_WL_REG_ON
#define CYW43_DEFAULT_PIN_WL_REG_ON 23u
#endif

// PICO_CONFIG: CYW43_DEFAULT_PIN_WL_DATA_OUT, gpio pin for spi data out to the cyw43 chip, type=int, default=24, advanced=true, group=pico_cyw43_driver
#ifndef CYW43_DEFAULT_PIN_WL_DATA_OUT
#define CYW43_DEFAULT_PIN_WL_DATA_OUT 24u
#endif

// PICO_CONFIG: CYW43_DEFAULT_PIN_WL_DATA_IN, gpio pin for spi data in from the cyw43 chip, type=int, default=24, advanced=true, group=pico_cyw43_driver
#ifndef CYW43_DEFAULT_PIN_WL_DATA_IN
#define CYW43_DEFAULT_PIN_WL_DATA_IN 24u
#endif

// PICO_CONFIG: CYW43_DEFAULT_PIN_WL_HOST_WAKE, gpio (irq) pin for the irq line from the cyw43 chip, type=int, default=24, advanced=true, group=pico_cyw43_driver
#ifndef CYW43_DEFAULT_PIN_WL_HOST_WAKE
#define CYW43_DEFAULT_PIN_WL_HOST_WAKE 24u
#endif

// PICO_CONFIG: CYW43_DEFAULT_PIN_WL_CLOCK, gpio pin for the spi clock line to the cyw43 chip, type=int, default=29, advanced=true, group=pico_cyw43_driver
#ifndef CYW43_DEFAULT_PIN_WL_CLOCK
#define CYW43_DEFAULT_PIN_WL_CLOCK 29u
#endif

// PICO_CONFIG: CYW43_DEFAULT_PIN_WL_CS, gpio pin for the spi chip select to the cyw43 chip, type=int, default=25, advanced=true, group=pico_cyw43_driver
#ifndef CYW43_DEFAULT_PIN_WL_CS
#define CYW43_DEFAULT_PIN_WL_CS 25u
#endif

// no PICO_SMPS_MODE_PIN
// no PICO_VBUS_PIN
// no PICO_VSYS_PIN
Expand Down