diff --git a/.github/workflows/micropython.yml b/.github/workflows/micropython.yml new file mode 100644 index 0000000..5026a8d --- /dev/null +++ b/.github/workflows/micropython.yml @@ -0,0 +1,129 @@ +name: MicroPython + +on: + push: + pull_request: + release: + types: [created] + +env: + MICROPYTHON_VERSION: feature/psram + MICROPYTHON_FLAVOUR: pimoroni + PIMORONI_PICO_VERSION: feature/sdk-2.0.0 + +jobs: + build: + name: ${{ matrix.name }} (${{ matrix.board }} ${{ matrix.variant }} ${{ matrix.modules }}) + runs-on: ubuntu-20.04 + continue-on-error: true + strategy: + matrix: + include: + - name: pga2040 + board: pga2040 + modules: default + - name: pga2350 + board: pga2350 + modules: default + - name: pga2350-psram # Friendly-name for output files + board: pga2350 # / + variant: PSRAM # //mpconfigvariant_.cmake + modules: default # /modules/.cmake + + env: + # MicroPython version will be contained in github.event.release.tag_name for releases + RELEASE_FILE: ${{ matrix.name }}-${{ github.event.release.tag_name || github.sha }}-micropython + PIMORONI_PICO_DIR: "${{ github.workspace }}/pimoroni-pico" + MICROPY_BOARD_DIR: "${{ github.workspace }}/src-${{ github.sha }}/${{ matrix.BOARD }}" + USER_C_MODULES: "${{ github.workspace }}/src-${{ github.sha }}/modules/${{ matrix.modules }}.cmake" + TAG_OR_SHA: ${{ github.event.release.tag_name || github.sha }} + MICROPY_BOARD: ${{ matrix.board }} + MICROPY_BOARD_VARIANT: ${{ matrix.variant }} + BOARD_NAME: ${{ matrix.name }} + BUILD_TOOLS: src-${{ github.sha }}/ci/micropython.sh + + steps: + - name: "CCache: Restore saved cache" + uses: actions/cache@v4 + with: + path: /home/runner/.ccache + key: ccache-micropython-${{ matrix.name }}-${{ github.ref }}-${{ github.sha }} + restore-keys: | + ccache-micropython-${{ matrix.name }}-${{ github.ref }} + ccache-micropython-${{ matrix.name }}- + + - name: "Src: Checkout" + uses: actions/checkout@v4 + with: + submodules: true + path: src-${{ github.sha }} + + - name: "Pimoroni Pico: Checkout" + uses: actions/checkout@v4 + with: + repository: pimoroni/pimoroni-pico + ref: ${{env.PIMORONI_PICO_VERSION}} + submodules: true + path: pimoroni-pico + + - name: Install Arm GNU Toolchain (arm-none-eabi-gcc) + uses: carlosperate/arm-none-eabi-gcc-action@v1 + with: + release: '9-2020-q2' + + - name: "CCache: Install" + run: | + source $BUILD_TOOLS + apt_install_build_deps + + - name: "MicroPython: Checkout" + run: | + source $BUILD_TOOLS + micropython_clone + + - name: "Py_Decl: Checkout py_decl" + uses: actions/checkout@v4 + with: + repository: gadgetoid/py_decl + ref: v0.0.2 + path: py_decl + + - name: "MicroPython: Build MPY Cross" + run: | + source $BUILD_TOOLS + micropython_build_mpy_cross + + - name: "MicroPython: Configure" + shell: bash + run: | + source $BUILD_TOOLS + micropython_version + cmake_configure + + - name: "MicroPython: Build" + shell: bash + run: | + source $BUILD_TOOLS + cmake_build + + - name: "Py_Decl: Verify UF2" + shell: bash + run: | + python3 py_decl/py_decl.py --to-json --verify build-${{ matrix.name }}/${{ env.RELEASE_FILE }}.uf2 + + - name: Store .uf2 as artifact + uses: actions/upload-artifact@v4 + with: + name: ${{ env.RELEASE_FILE }}.uf2 + path: build-${{ matrix.name }}/${{ env.RELEASE_FILE }}.uf2 + + - name: Upload .uf2 + if: github.event_name == 'release' + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + asset_path: build-${{ matrix.name }}/firmware.uf2 + upload_url: ${{ github.event.release.upload_url }} + asset_name: ${{ env.RELEASE_FILE }}.uf2 + asset_content_type: application/octet-stream \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..920b6f1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,39 @@ +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +**/build +.vscode + +# Apple filesystem cruft +.DS_Store +venv \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..009bbe1 --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# Pimoroni PGA Boilerplate + +This repository is intended to provide a baseline MicroPython build for PGA2040 +and PGA2350, in addition to being a minimal example of how you might set up your +own custom MicroPython flavour to support your PGA-based project. + +Use this repository as a boilerplate to set up your own project, and GitHub actions +should automatically handle building MicroPython for you. + +## Contents + +* pga2040 - MicroPython and Pico SDK board definitions for PGA2040 +* pga2350 - MicroPython and Pico SDK board definitions for PGA2350, with PSRAM variant +* modules/c/example - An example MicroPython C++ module, demonstrating C class bindings +* modules/py_frozen - Python files intended to be frozen into the firmware +* modules/py_littlefs - Python files intended to be visible/editable in the LittleFS user filesystem \ No newline at end of file diff --git a/ci/micropython.sh b/ci/micropython.sh new file mode 100644 index 0000000..0a4b53a --- /dev/null +++ b/ci/micropython.sh @@ -0,0 +1,65 @@ +export TERM=${TERM:="xterm-256color"} + +function log_success { + echo -e "$(tput setaf 2)$1$(tput sgr0)" +} + +function log_inform { + echo -e "$(tput setaf 6)$1$(tput sgr0)" +} + +function log_warning { + echo -e "$(tput setaf 1)$1$(tput sgr0)" +} + +function micropython_clone { + log_inform "Using MicroPython $MICROPYTHON_VERSION" + git clone https://github.com/$MICROPYTHON_FLAVOUR/micropython + cd micropython + git checkout $MICROPYTHON_VERSION + git submodule update --init lib/pico-sdk + git submodule update --init lib/cyw43-driver + git submodule update --init lib/lwip + git submodule update --init lib/mbedtls + git submodule update --init lib/micropython-lib + git submodule update --init lib/tinyusb + git submodule update --init lib/btstack + cd ../ +} + +function micropython_build_mpy_cross { + cd micropython/mpy-cross + ccache --zero-stats || true + CROSS_COMPILE="ccache " make + ccache --show-stats || true + cd ../../ +} + +function apt_install_build_deps { + sudo apt update && sudo apt install ccache +} + +function micropython_version { + echo "MICROPY_GIT_TAG=$MICROPYTHON_VERSION, $BOARD_NAME $TAG_OR_SHA" >> $GITHUB_ENV + echo "MICROPY_GIT_HASH=$MICROPYTHON_VERSION-$TAG_OR_SHA" >> $GITHUB_ENV +} + +function cmake_configure { + cmake -S micropython/ports/rp2 -B build-$BOARD_NAME \ + -DPICO_BUILD_DOCS=0 \ + -DPICO_NO_COPRO_DIS=1 \ + -DUSER_C_MODULES=$USER_C_MODULES \ + -DMICROPY_BOARD_DIR=$MICROPY_BOARD_DIR \ + -DMICROPY_BOARD=$MICROPY_BOARD \ + -DMICROPY_BOARD_VARIANT=$MICROPY_BOARD_VARIANT \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache +} + +function cmake_build { + ccache --zero-stats || true + cmake --build build-$BOARD_NAME -j 2 + ccache --show-stats || true + cd build-$BOARD_NAME + cp firmware.uf2 $RELEASE_FILE.uf2 +} \ No newline at end of file diff --git a/modules/c/example/example.c b/modules/c/example/example.c new file mode 100644 index 0000000..68156b8 --- /dev/null +++ b/modules/c/example/example.c @@ -0,0 +1,37 @@ +#include + +MP_DEFINE_CONST_FUN_OBJ_1(example__del__obj, example__del__); + +MP_DEFINE_CONST_FUN_OBJ_3(example_method_obj, example_method); + +// Class Methods +static const mp_rom_map_elem_t example_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&example__del__obj) }, + { MP_ROM_QSTR(MP_QSTR_mul), MP_ROM_PTR(&example_method_obj) } +}; + +static MP_DEFINE_CONST_DICT(example_locals_dict, example_locals_dict_table); + +MP_DEFINE_CONST_OBJ_TYPE( + Example_type, + MP_QSTR_Example, + MP_TYPE_FLAG_NONE, + make_new, example_make_new, + locals_dict, (mp_obj_dict_t*)&example_locals_dict +); + +// Module Methods +static const mp_map_elem_t example_globals_table[] = { + { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_example) }, // Module name + { MP_OBJ_NEW_QSTR(MP_QSTR_Example), (mp_obj_t)&Example_type }, // Class name & type +}; + +static MP_DEFINE_CONST_DICT(mp_module_example_globals, example_globals_table); + +const mp_obj_module_t example_user_c_module = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t*)&mp_module_example_globals, +}; + +// First argument should match the __name__ given in the globals table +MP_REGISTER_MODULE(MP_QSTR_example, example_user_c_module); \ No newline at end of file diff --git a/modules/c/example/example.cpp b/modules/c/example/example.cpp new file mode 100644 index 0000000..b65268f --- /dev/null +++ b/modules/c/example/example.cpp @@ -0,0 +1,67 @@ +#include // Required for allocating C classes into MicroPython heap with placement new + +class Example { + public: + Example () { + + } + + int mul(int a, int b) { + return a * b; + } + + ~Example () { + + } +}; + +// Explicitly typed variant of MP_OBJ_TO_PTR to make C++ happy +#define MP_OBJ_TO_PTR_T(o, t) ((t *)(o)) + +// Macro for assigning *self in class methods +#define __self__ MP_OBJ_TO_PTR_T(self_in, Example_obj_t) + + +extern "C" { +#include "example.h" + +typedef struct Example_obj_t { + mp_obj_base_t base; + void *pins; + Example *cls; +} Example_obj_t; + +mp_obj_t example_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { + Example_obj_t *self = mp_obj_malloc_with_finaliser(Example_obj_t, &Example_type); + + // Use C++ "placement new" to place an instance of our C++ class in + // memory allocated by MicroPython's m_new. + self->cls = new(m_new(Example, 1)) Example(); + + return MP_OBJ_FROM_PTR(self); +} + +mp_obj_t example__del__(mp_obj_t self_in) { + // Explicitly call the destructor + // self->class->~Example(); + + // Or use delete + delete(__self__->cls); + + // Explicitly inform the GC that the memory is free + // Usually this object is deleted and the pointer goes out of scope + // and gets GC'd anyway so we don't *need* to do this. + m_del(Example, __self__->cls, 1); + + return mp_const_none; +} + +mp_obj_t example_method(mp_obj_t self_in, mp_obj_t a_in, mp_obj_t b_in) { + int a = mp_obj_get_int(a_in); + int b = mp_obj_get_int(b_in); + + int c = __self__->cls->mul(a, b); + + return mp_obj_new_int(c); +} +}; \ No newline at end of file diff --git a/modules/c/example/example.h b/modules/c/example/example.h new file mode 100644 index 0000000..085dcb2 --- /dev/null +++ b/modules/c/example/example.h @@ -0,0 +1,8 @@ +#include "py/runtime.h" + +extern const mp_obj_type_t Example_type; + +extern mp_obj_t example_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args); +extern mp_obj_t example__del__(mp_obj_t self_in); + +extern mp_obj_t example_method(mp_obj_t self_in, mp_obj_t a_in, mp_obj_t b_in); \ No newline at end of file diff --git a/modules/c/example/micropython.cmake b/modules/c/example/micropython.cmake new file mode 100644 index 0000000..853de6e --- /dev/null +++ b/modules/c/example/micropython.cmake @@ -0,0 +1,16 @@ +# Create an INTERFACE library for our CPP module. +add_library(usermod_pga_example INTERFACE) + +# Add our source files to the library. +target_sources(usermod_pga_example INTERFACE + ${CMAKE_CURRENT_LIST_DIR}/example.cpp + ${CMAKE_CURRENT_LIST_DIR}/example.c +) + +# Add the current directory as an include directory. +target_include_directories(usermod_pga_example INTERFACE + ${CMAKE_CURRENT_LIST_DIR} +) + +# Link our INTERFACE library to the usermod target. +target_link_libraries(usermod INTERFACE usermod_pga_example) \ No newline at end of file diff --git a/modules/default.cmake b/modules/default.cmake new file mode 100644 index 0000000..37272f6 --- /dev/null +++ b/modules/default.cmake @@ -0,0 +1,26 @@ +if(NOT DEFINED PIMORONI_PICO_PATH) +set(PIMORONI_PICO_PATH ../pimoroni-pico) +endif() +include(${CMAKE_CURRENT_LIST_DIR}/../pimoroni_pico_import.cmake) + +include_directories(${PIMORONI_PICO_PATH}/micropython) + +list(APPEND CMAKE_MODULE_PATH "${PIMORONI_PICO_PATH}/micropython") +list(APPEND CMAKE_MODULE_PATH "${PIMORONI_PICO_PATH}/micropython/modules") + +# Allows us to find /pga/modules/c//micropython +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") + +set(CMAKE_C_STANDARD 11) +set(CMAKE_CXX_STANDARD 17) + +include(c/example/micropython) + +# include(micropython-common) +# enable_ulab() + +# C++ Magic Memory +# include(cppmem/micropython) + +# Disable build-busting C++ exceptions +include(micropython-disable-exceptions) \ No newline at end of file diff --git a/modules/frozen.py b/modules/frozen.py new file mode 100644 index 0000000..e69de29 diff --git a/modules/littlefs.txt b/modules/littlefs.txt new file mode 100644 index 0000000..f2e897a --- /dev/null +++ b/modules/littlefs.txt @@ -0,0 +1 @@ +lib/*/*.py \ No newline at end of file diff --git a/pga2040/manifest.py b/pga2040/manifest.py new file mode 100644 index 0000000..8505dcb --- /dev/null +++ b/pga2040/manifest.py @@ -0,0 +1,5 @@ +# Include the manifest.py from micropython/ports/rp2/boards/manifest.py +include("$(PORT_DIR)/boards/manifest.py") + +# Include frozen.py from pga/modules/frozen.py +include("../modules/frozen.py") \ No newline at end of file diff --git a/pga2040/mpconfigboard.cmake b/pga2040/mpconfigboard.cmake new file mode 100644 index 0000000..c2bc3c5 --- /dev/null +++ b/pga2040/mpconfigboard.cmake @@ -0,0 +1,13 @@ +# cmake file for the Pimoroni PGA2040 +set(PICO_BOARD "pga2040") +set(PICO_PLATFORM "rp2040") + +# Make sure we find pga2040.h (PICO_BOARD) in the current dir +set(PICO_BOARD_HEADER_DIRS ${CMAKE_CURRENT_LIST_DIR}) + +# Board specific version of the frozen manifest +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) diff --git a/pga2040/mpconfigboard.h b/pga2040/mpconfigboard.h new file mode 100644 index 0000000..6cfced4 --- /dev/null +++ b/pga2040/mpconfigboard.h @@ -0,0 +1,6 @@ +// Board and hardware specific configuration +#define MICROPY_HW_BOARD_NAME "PGA2040" + +// Portion of onboard flash to reserve for the user filesystem +// PGA2040 has 8MB flash, so reserve 1MiB for the firmware and leave 7MiB +#define MICROPY_HW_FLASH_STORAGE_BYTES (7 * 1024 * 1024) diff --git a/pga2040/pga2040.h b/pga2040/pga2040.h new file mode 100644 index 0000000..25b9dd2 --- /dev/null +++ b/pga2040/pga2040.h @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +// ----------------------------------------------------- +// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO +// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES +// ----------------------------------------------------- + +// pico_cmake_set PICO_PLATFORM=rp2040 + +#ifndef _BOARDS_PIMORONI_PGA2040_H +#define _BOARDS_PIMORONI_PGA2040_H + +// For board detection +#define PIMORONI_PGA2040 + +// --- UART --- +#ifndef PICO_DEFAULT_UART +#define PICO_DEFAULT_UART 0 +#endif + +#ifndef PICO_DEFAULT_UART_TX_PIN +#define PICO_DEFAULT_UART_TX_PIN 0 +#endif + +#ifndef PICO_DEFAULT_UART_RX_PIN +#define PICO_DEFAULT_UART_RX_PIN 1 +#endif + +// --- LED --- +// no PICO_DEFAULT_LED_PIN +// no PICO_DEFAULT_WS2812_PIN + +// --- I2C --- +#ifndef PICO_DEFAULT_I2C +#define PICO_DEFAULT_I2C 0 +#endif +#ifndef PICO_DEFAULT_I2C_SDA_PIN +#define PICO_DEFAULT_I2C_SDA_PIN 4 +#endif +#ifndef PICO_DEFAULT_I2C_SCL_PIN +#define PICO_DEFAULT_I2C_SCL_PIN 5 +#endif + +// --- SPI --- +#ifndef PICO_DEFAULT_SPI +#define PICO_DEFAULT_SPI 0 +#endif +#ifndef PICO_DEFAULT_SPI_SCK_PIN +#define PICO_DEFAULT_SPI_SCK_PIN 18 +#endif +#ifndef PICO_DEFAULT_SPI_TX_PIN +#define PICO_DEFAULT_SPI_TX_PIN 19 +#endif +#ifndef PICO_DEFAULT_SPI_RX_PIN +#define PICO_DEFAULT_SPI_RX_PIN 16 +#endif +#ifndef PICO_DEFAULT_SPI_CSN_PIN +#define PICO_DEFAULT_SPI_CSN_PIN 17 +#endif + +// --- FLASH --- +#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 + +#ifndef PICO_FLASH_SPI_CLKDIV +#define PICO_FLASH_SPI_CLKDIV 2 +#endif + +// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (8 * 1024 * 1024) +#ifndef PICO_FLASH_SIZE_BYTES +#define PICO_FLASH_SIZE_BYTES (8 * 1024 * 1024) +#endif +// All boards have B1 RP2040 +#ifndef PICO_RP2040_B0_SUPPORTED +#define PICO_RP2040_B0_SUPPORTED 0 +#endif + +#endif diff --git a/pga2040/pins.csv b/pga2040/pins.csv new file mode 100644 index 0000000..16e3340 --- /dev/null +++ b/pga2040/pins.csv @@ -0,0 +1,28 @@ +GP0,GPIO0 +GP1,GPIO1 +GP2,GPIO2 +GP3,GPIO3 +GP4,GPIO4 +GP5,GPIO5 +GP6,GPIO6 +GP7,GPIO7 +GP8,GPIO8 +GP9,GPIO9 +GP10,GPIO10 +GP11,GPIO11 +GP12,GPIO12 +GP13,GPIO13 +GP14,GPIO14 +GP15,GPIO15 +GP16,GPIO16 +GP17,GPIO17 +GP18,GPIO18 +GP19,GPIO19 +GP20,GPIO20 +GP21,GPIO21 +GP22,GPIO22 +GP25,GPIO25 +GP26,GPIO26 +GP27,GPIO27 +GP28,GPIO28 +LED,GPIO25 diff --git a/pga2350/manifest.py b/pga2350/manifest.py new file mode 100644 index 0000000..8505dcb --- /dev/null +++ b/pga2350/manifest.py @@ -0,0 +1,5 @@ +# Include the manifest.py from micropython/ports/rp2/boards/manifest.py +include("$(PORT_DIR)/boards/manifest.py") + +# Include frozen.py from pga/modules/frozen.py +include("../modules/frozen.py") \ No newline at end of file diff --git a/pga2350/mpconfigboard.cmake b/pga2350/mpconfigboard.cmake new file mode 100644 index 0000000..d25ae32 --- /dev/null +++ b/pga2350/mpconfigboard.cmake @@ -0,0 +1,14 @@ +# cmake file for the Pimoroni PGA2350 +set(PICO_BOARD "pga2350") +set(PICO_PLATFORM "rp2350-arm-s") +set(PICO_NUM_GPIOS 48) + +# Make sure we find pga2350.h (PICO_BOARD) in the current dir +set(PICO_BOARD_HEADER_DIRS ${CMAKE_CURRENT_LIST_DIR}) + +# Board specific version of the frozen manifest +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) \ No newline at end of file diff --git a/pga2350/mpconfigboard.h b/pga2350/mpconfigboard.h new file mode 100644 index 0000000..802a1a4 --- /dev/null +++ b/pga2350/mpconfigboard.h @@ -0,0 +1,14 @@ +// Board and hardware specific configuration + +// Board and hardware specific configuration +#ifndef MICROPY_HW_BOARD_NAME +// Might be defined by mpconfigvariant_VARIANT.cmake +#define MICROPY_HW_BOARD_NAME "PGA2350" +#endif + +// Portion of onboard flash to reserve for the user filesystem +// PGA2350 has 16MB flash, so reserve 2MiB for the firmware and leave 14MiB +#define MICROPY_HW_FLASH_STORAGE_BYTES (14 * 1024 * 1024) + +// Alias the chip select pin specified by pga2350.h +#define MICROPY_HW_PSRAM_CS_PIN PIMORONI_PGA2350_PSRAM_CS_PIN diff --git a/pga2350/mpconfigvariant.cmake b/pga2350/mpconfigvariant.cmake new file mode 100644 index 0000000..e69de29 diff --git a/pga2350/mpconfigvariant_PSRAM.cmake b/pga2350/mpconfigvariant_PSRAM.cmake new file mode 100644 index 0000000..8bee1f2 --- /dev/null +++ b/pga2350/mpconfigvariant_PSRAM.cmake @@ -0,0 +1,5 @@ +# Override the MicroPython board name +list(APPEND MICROPY_DEF_BOARD + "MICROPY_HW_ENABLE_PSRAM=1" + "MICROPY_HW_BOARD_NAME=\"PGA2350 (PSRAM)\"" +) diff --git a/pga2350/pga2350.h b/pga2350/pga2350.h new file mode 100644 index 0000000..9690f13 --- /dev/null +++ b/pga2350/pga2350.h @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +// ----------------------------------------------------- +// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO +// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES +// ----------------------------------------------------- + +// This header may be included by other board headers as "boards/pimoroni_pga2350.h" + +// pico_cmake_set PICO_PLATFORM=rp2350 + +#ifndef _BOARDS_PIMORONI_PGA2350_H +#define _BOARDS_PIMORONI_PGA2350_H + +// For board detection +#define PIMORONI_PGA2350 +#define PIMORONI_PGA2350_16MB + +// --- BOARD SPECIFIC --- +#define PIMORONI_PGA2350_PSRAM_CS_PIN 47 + +// --- UART --- +#ifndef PICO_DEFAULT_UART +#define PICO_DEFAULT_UART 0 +#endif +#ifndef PICO_DEFAULT_UART_TX_PIN +#define PICO_DEFAULT_UART_TX_PIN 0 +#endif +#ifndef PICO_DEFAULT_UART_RX_PIN +#define PICO_DEFAULT_UART_RX_PIN 1 +#endif + +// --- LED --- +#ifndef PICO_DEFAULT_LED_PIN +#define PICO_DEFAULT_LED_PIN 25 +#endif +// no PICO_DEFAULT_WS2812_PIN + +// --- I2C --- +#ifndef PICO_DEFAULT_I2C +#define PICO_DEFAULT_I2C 0 +#endif +#ifndef PICO_DEFAULT_I2C_SDA_PIN +#define PICO_DEFAULT_I2C_SDA_PIN 4 +#endif +#ifndef PICO_DEFAULT_I2C_SCL_PIN +#define PICO_DEFAULT_I2C_SCL_PIN 5 +#endif + +// --- SPI --- +#ifndef PICO_DEFAULT_SPI +#define PICO_DEFAULT_SPI 0 +#endif +#ifndef PICO_DEFAULT_SPI_SCK_PIN +#define PICO_DEFAULT_SPI_SCK_PIN 18 +#endif +#ifndef PICO_DEFAULT_SPI_TX_PIN +#define PICO_DEFAULT_SPI_TX_PIN 19 +#endif +#ifndef PICO_DEFAULT_SPI_RX_PIN +#define PICO_DEFAULT_SPI_RX_PIN 16 +#endif +#ifndef PICO_DEFAULT_SPI_CSN_PIN +#define PICO_DEFAULT_SPI_CSN_PIN 17 +#endif + +// --- FLASH --- + +#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 + +#ifndef PICO_FLASH_SPI_CLKDIV +#define PICO_FLASH_SPI_CLKDIV 2 +#endif + +// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +#ifndef PICO_FLASH_SIZE_BYTES +#define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) +#endif + +// no PICO_SMPS_MODE_PIN +// no PICO_VBUS_PIN +// no PICO_VSYS_PIN + +#ifndef PICO_RP2350_A2_SUPPORTED +#define PICO_RP2350_A2_SUPPORTED 1 +#endif + +#endif diff --git a/pga2350/pins.csv b/pga2350/pins.csv new file mode 100644 index 0000000..9d58ee8 --- /dev/null +++ b/pga2350/pins.csv @@ -0,0 +1,47 @@ +GP0,GPIO0 +GP1,GPIO1 +GP2,GPIO2 +GP3,GPIO3 +GP4,GPIO4 +GP5,GPIO5 +GP6,GPIO6 +GP7,GPIO7 +GP8,GPIO8 +GP9,GPIO9 +GP10,GPIO10 +GP11,GPIO11 +GP12,GPIO12 +GP13,GPIO13 +GP14,GPIO14 +GP15,GPIO15 +GP16,GPIO16 +GP17,GPIO17 +GP18,GPIO18 +GP19,GPIO19 +GP20,GPIO20 +GP21,GPIO21 +GP22,GPIO22 +GP25,GPIO25 +GP26,GPIO26 +GP27,GPIO27 +GP28,GPIO28 +GP29,GPIO29 +GP30,GPIO30 +GP31,GPIO31 +GP32,GPIO32 +GP33,GPIO33 +GP34,GPIO34 +GP35,GPIO35 +GP36,GPIO36 +GP37,GPIO37 +GP38,GPIO38 +GP39,GPIO39 +GP40,GPIO40 +GP41,GPIO41 +GP42,GPIO42 +GP43,GPIO43 +GP44,GPIO44 +GP45,GPIO45 +GP46,GPIO46 +GP47,GPIO47 +LED,GPIO25 \ No newline at end of file diff --git a/pimoroni_pico_import.cmake b/pimoroni_pico_import.cmake new file mode 100644 index 0000000..97a72ec --- /dev/null +++ b/pimoroni_pico_import.cmake @@ -0,0 +1,56 @@ +# This file can be dropped into a project to help locate the Pimoroni Pico libraries +# It will also set up the required include and module search paths. + +if (DEFINED ENV{PIMORONI_PICO_FETCH_FROM_GIT} AND (NOT PIMORONI_PICO_FETCH_FROM_GIT)) + set(PIMORONI_PICO_FETCH_FROM_GIT $ENV{PIMORONI_PICO_FETCH_FROM_GIT}) + message("Using PIMORONI_PICO_FETCH_FROM_GIT from environment ('${PIMORONI_PICO_FETCH_FROM_GIT}')") +endif () + +if (DEFINED ENV{PIMORONI_PICO_FETCH_FROM_GIT_PATH} AND (NOT PIMORONI_PICO_FETCH_FROM_GIT_PATH)) + set(PIMORONI_PICO_FETCH_FROM_GIT_PATH $ENV{PIMORONI_PICO_FETCH_FROM_GIT_PATH}) + message("Using PIMORONI_PICO_FETCH_FROM_GIT_PATH from environment ('${PIMORONI_PICO_FETCH_FROM_GIT_PATH}')") +endif () + +if (NOT PIMORONI_PICO_PATH) + if (PIMORONI_PICO_FETCH_FROM_GIT) + include(FetchContent) + set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR}) + if (PIMORONI_PICO_FETCH_FROM_GIT_PATH) + get_filename_component(FETCHCONTENT_BASE_DIR "${PIMORONI_PICO_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}") + endif () + FetchContent_Declare( + pimoroni_pico + GIT_REPOSITORY https://github.com/pimoroni/pimoroni-pico + GIT_TAG main + ) + if (NOT pimoroni_pico) + message("Downloading PIMORONI_PICO SDK") + FetchContent_Populate(pimoroni_pico) + set(PIMORONI_PICO_PATH ${pimoroni_pico_SOURCE_DIR}) + endif () + set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE}) + elseif(PICO_SDK_PATH AND EXISTS "${PICO_SDK_PATH}/../pimoroni-pico") + set(PIMORONI_PICO_PATH ${PICO_SDK_PATH}/../pimoroni-pico) + message("Defaulting PIMORONI_PICO_PATH as sibling of PICO_SDK_PATH: ${PIMORONI_PICO_PATH}") + elseif(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/../../pimoroni-pico/") + set(PIMORONI_PICO_PATH ${CMAKE_CURRENT_BINARY_DIR}/../../pimoroni-pico/) + else() + message(FATAL_ERROR "Pimoroni Pico location was not specified. Please set PIMORONI_PICO_PATH.") + endif() +endif() + +get_filename_component(PIMORONI_PICO_PATH "${PIMORONI_PICO_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}") +if (NOT EXISTS ${PIMORONI_PICO_PATH}) + message(FATAL_ERROR "Directory '${PIMORONI_PICO_PATH}' not found") +endif () + +if (NOT EXISTS ${PIMORONI_PICO_PATH}/pimoroni_pico_import.cmake) + message(FATAL_ERROR "Directory '${PIMORONI_PICO_PATH}' does not appear to contain the Pimoroni Pico libraries") +endif () + +message("PIMORONI_PICO_PATH is ${PIMORONI_PICO_PATH}") + +set(PIMORONI_PICO_PATH ${PIMORONI_PICO_PATH} CACHE PATH "Path to the Pimoroni Pico libraries" FORCE) + +include_directories(${PIMORONI_PICO_PATH}) +list(APPEND CMAKE_MODULE_PATH ${PIMORONI_PICO_PATH}) \ No newline at end of file