From 71384b631c6d05cfbb0cb31d278925ecfce4c30b Mon Sep 17 00:00:00 2001 From: codetiger Date: Mon, 19 Aug 2024 15:27:56 +0530 Subject: [PATCH 1/2] Added support for GameTiger board and included display support --- .../boards/gametiger_rp2040/board.c | 107 ++++++++++++++++++ .../boards/gametiger_rp2040/mpconfigboard.h | 10 ++ .../boards/gametiger_rp2040/mpconfigboard.mk | 13 +++ .../gametiger_rp2040/pico-sdk-configboard.h | 12 ++ .../boards/gametiger_rp2040/pins.c | 42 +++++++ 5 files changed, 184 insertions(+) create mode 100644 ports/raspberrypi/boards/gametiger_rp2040/board.c create mode 100644 ports/raspberrypi/boards/gametiger_rp2040/mpconfigboard.h create mode 100644 ports/raspberrypi/boards/gametiger_rp2040/mpconfigboard.mk create mode 100644 ports/raspberrypi/boards/gametiger_rp2040/pico-sdk-configboard.h create mode 100644 ports/raspberrypi/boards/gametiger_rp2040/pins.c diff --git a/ports/raspberrypi/boards/gametiger_rp2040/board.c b/ports/raspberrypi/boards/gametiger_rp2040/board.c new file mode 100644 index 0000000000000..93eaedf0227c2 --- /dev/null +++ b/ports/raspberrypi/boards/gametiger_rp2040/board.c @@ -0,0 +1,107 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2021 Scott Shawcroft for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#include "supervisor/board.h" +#include "mpconfigboard.h" +#include "shared-bindings/busio/SPI.h" +#include "shared-bindings/fourwire/FourWire.h" +#include "shared-module/displayio/__init__.h" +#include "shared-module/displayio/mipi_constants.h" +#include "supervisor/shared/board.h" + +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. +#define DELAY 0x80 + +uint8_t display_init_sequence[] = { + 0x01, 0 | DELAY, 120, // SWRESET + 0x11, 0 | DELAY, 120, // SWRESET + + 0x36, 1, 0x70, // MADCTL + 0x3A, 1, 0x55, // COLMOD + 0xB2, 5, 0x0C, 0x0C, 0x00, 0x33, 0x33, // FRMCTR2 + 0xB7, 1, 0x75, // GCTRL + 0xBB, 1, 0x2B, // VCOMS + 0xC0, 1, 0x2C, // LCMCTRL + 0xC2, 1, 0x01, // VDVVRHEN + 0xC3, 1, 0x0B, // VRHS + 0xC4, 1, 0x20, // VDVS + 0xC6, 1, 0x0F, // FRCTRL2 + 0xD0, 2, 0xA4, 0xA1, // PWRCTRL1 + + 0xE0, 14, 0xD0, 0x01, 0x04, 0x09, 0x0B, 0x07, 0x2E, 0x44, 0x43, 0x0B, 0x16, 0x15, 0x17, 0x1D, // GMCTRP1 + 0xE1, 14, 0xD0, 0x01, 0x05, 0x0A, 0x0B, 0x08, 0x2F, 0x44, 0x41, 0x0A, 0x15, 0x14, 0x19, 0x1D, // GMCTRN1 + 0x29, 0 | DELAY, 120, // DISPON + + // 0x2A, 4, 0x00, 0, 0x01, 0x3F, // CASET + // 0x2B, 4, 0x00, 0, 0x00, 0xEF, // RASET + // 0x2C, 0, // RAMWR +}; + +static void display_init(void) { + fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; + busio_spi_obj_t *spi = &bus->inline_bus; + + common_hal_busio_spi_construct( + spi, + &pin_GPIO2, // CLK + &pin_GPIO3, // MOSI + &pin_GPIO0, // MISO + false); // Not half-duplex + + common_hal_busio_spi_never_reset(spi); + + bus->base.type = &fourwire_fourwire_type; + + common_hal_fourwire_fourwire_construct( + bus, + spi, + &pin_GPIO0, // DC + &pin_GPIO1, // CS + &pin_GPIO4, // RST + 62.5 * 1000 * 1000, // baudrate + 0, // polarity + 0 // phase + ); + + busdisplay_busdisplay_obj_t *display = &allocate_display()->display; + display->base.type = &busdisplay_busdisplay_type; + + common_hal_busdisplay_busdisplay_construct( + display, + bus, + 320, // width (after rotation) + 240, // height (after rotation) + 0, // column start + 0, // row start + 0, // rotation + 16, // color depth + false, // grayscale + false, // pixels in a byte share a row. Only valid for depths < 8 + 1, // bytes per cell. Only valid for depths < 8 + false, // reverse_pixels_in_byte. Only valid for depths < 8 + true, // reverse_pixels_in_word + MIPI_COMMAND_SET_COLUMN_ADDRESS, // set column command + MIPI_COMMAND_SET_PAGE_ADDRESS, // set row command + MIPI_COMMAND_WRITE_MEMORY_START, // write memory command + display_init_sequence, + sizeof(display_init_sequence), + NULL, // backlight pin + NO_BRIGHTNESS_COMMAND, + 1.0f, // brightness + false, // single_byte_bounds + false, // data_as_commands + true, // auto_refresh + 60, // native_frames_per_second + true, // backlight_on_high + false, // SH1107_addressing + 50000 // backlight pwm frequency + ); + +} + +void board_init(void) { + display_init(); +} diff --git a/ports/raspberrypi/boards/gametiger_rp2040/mpconfigboard.h b/ports/raspberrypi/boards/gametiger_rp2040/mpconfigboard.h new file mode 100644 index 0000000000000..db347a5d57aa5 --- /dev/null +++ b/ports/raspberrypi/boards/gametiger_rp2040/mpconfigboard.h @@ -0,0 +1,10 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2021 Scott Shawcroft for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#pragma once + +#define MICROPY_HW_BOARD_NAME "GameTiger RP2040" +#define MICROPY_HW_MCU_NAME "rp2040" diff --git a/ports/raspberrypi/boards/gametiger_rp2040/mpconfigboard.mk b/ports/raspberrypi/boards/gametiger_rp2040/mpconfigboard.mk new file mode 100644 index 0000000000000..fbe37864a02b0 --- /dev/null +++ b/ports/raspberrypi/boards/gametiger_rp2040/mpconfigboard.mk @@ -0,0 +1,13 @@ +USB_VID = 0x239A +USB_PID = 0x80F2 +USB_PRODUCT = "GameTiger RP2040" +USB_MANUFACTURER = "ElectroTiger" + +CHIP_VARIANT = RP2040 +CHIP_FAMILY = rp2 + +CIRCUITPY_KEYPAD = 1 + +CIRCUITPY_AUDIOIO = 1 + +EXTERNAL_FLASH_DEVICES = "W25Q64JVxQ" diff --git a/ports/raspberrypi/boards/gametiger_rp2040/pico-sdk-configboard.h b/ports/raspberrypi/boards/gametiger_rp2040/pico-sdk-configboard.h new file mode 100644 index 0000000000000..ce5a7645b4e22 --- /dev/null +++ b/ports/raspberrypi/boards/gametiger_rp2040/pico-sdk-configboard.h @@ -0,0 +1,12 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2021 Scott Shawcroft for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#pragma once + +// Put board-specific pico-sdk definitions here. This file must exist. + +// Allow extra time for xosc to start. +#define PICO_XOSC_STARTUP_DELAY_MULTIPLIER 64 diff --git a/ports/raspberrypi/boards/gametiger_rp2040/pins.c b/ports/raspberrypi/boards/gametiger_rp2040/pins.c new file mode 100644 index 0000000000000..e2ad480acded3 --- /dev/null +++ b/ports/raspberrypi/boards/gametiger_rp2040/pins.c @@ -0,0 +1,42 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2021 Scott Shawcroft for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#include "shared-bindings/board/__init__.h" +#include "shared-module/displayio/__init__.h" + +static const mp_rom_map_elem_t board_module_globals_table[] = { + CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS + + { MP_ROM_QSTR(MP_QSTR_VBUS_DETECT), MP_ROM_PTR(&pin_GPIO16) }, + { MP_ROM_QSTR(MP_QSTR_BAT_SENSE), MP_ROM_PTR(&pin_GPIO26) }, + + { MP_ROM_QSTR(MP_QSTR_LCD_RESET), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_LCD_CS), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_LCD_CLK), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_LCD_DATA), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_LCD_DC), MP_ROM_PTR(&pin_GPIO0) }, + + { MP_ROM_QSTR(MP_QSTR_AUDIO), MP_ROM_PTR(&pin_GPIO5) }, + + { MP_ROM_QSTR(MP_QSTR_KB_UP), MP_ROM_PTR(&pin_GPIO17) }, + { MP_ROM_QSTR(MP_QSTR_KB_DOWN), MP_ROM_PTR(&pin_GPIO20) }, + { MP_ROM_QSTR(MP_QSTR_KB_RIGHT), MP_ROM_PTR(&pin_GPIO18) }, + { MP_ROM_QSTR(MP_QSTR_KB_LEFT), MP_ROM_PTR(&pin_GPIO19) }, + + { MP_ROM_QSTR(MP_QSTR_KB_A), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_KB_B), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_KB_START), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_KB_SELECT), MP_ROM_PTR(&pin_GPIO9) }, + + { MP_ROM_QSTR(MP_QSTR_SD_DETECT), MP_ROM_PTR(&pin_GPIO21) }, + { MP_ROM_QSTR(MP_QSTR_SD_CLK), MP_ROM_PTR(&pin_GPIO22) }, + { MP_ROM_QSTR(MP_QSTR_SD_MISO), MP_ROM_PTR(&pin_GPIO23) }, + { MP_ROM_QSTR(MP_QSTR_SD_MOSI), MP_ROM_PTR(&pin_GPIO24) }, + { MP_ROM_QSTR(MP_QSTR_SD_CS), MP_ROM_PTR(&pin_GPIO25) }, + + { MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display)} +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); From 67c5916c2440969020db1cbcd8f1070aa5ef4ad3 Mon Sep 17 00:00:00 2001 From: codetiger Date: Mon, 19 Aug 2024 16:57:39 +0530 Subject: [PATCH 2/2] Fixed VID PID to default RP2040 circuitpython --- ports/raspberrypi/boards/gametiger_rp2040/mpconfigboard.mk | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ports/raspberrypi/boards/gametiger_rp2040/mpconfigboard.mk b/ports/raspberrypi/boards/gametiger_rp2040/mpconfigboard.mk index fbe37864a02b0..2225e7675fc94 100644 --- a/ports/raspberrypi/boards/gametiger_rp2040/mpconfigboard.mk +++ b/ports/raspberrypi/boards/gametiger_rp2040/mpconfigboard.mk @@ -1,5 +1,5 @@ -USB_VID = 0x239A -USB_PID = 0x80F2 +USB_VID = 0x2E8A +USB_PID = 0x000B USB_PRODUCT = "GameTiger RP2040" USB_MANUFACTURER = "ElectroTiger" @@ -9,5 +9,6 @@ CHIP_FAMILY = rp2 CIRCUITPY_KEYPAD = 1 CIRCUITPY_AUDIOIO = 1 +CIRCUITPY_SDIOIO = 1 EXTERNAL_FLASH_DEVICES = "W25Q64JVxQ"