Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Dec 12, 2024
0 parents commit 3531d95
Show file tree
Hide file tree
Showing 8 changed files with 450 additions and 0 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: CMake

on:
push:
pull_request:
release:
types: [created]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release

jobs:
build:
name: Linux
runs-on: ubuntu-22.04

env:
CI_PROJECT_ROOT: ${{ github.workspace }}/src-${{ github.sha }}
CI_BUILD_ROOT: ${{ github.workspace }}

steps:
- name: Prepare Code
uses: actions/checkout@v4
with:
path: src-${{ github.sha }}
submodules: true

- name: "Prepare tools & dependencies"
shell: bash
run: |
source $CI_PROJECT_ROOT/ci/cpp.sh && ci_debug
ci_prepare_all
- name: "MicroPython: Configure"
shell: bash
run: |
source $CI_PROJECT_ROOT/ci/cpp.sh && ci_debug
ci_cmake_configure
- name: "MicroPython: Build"
shell: bash
run: |
source $CI_PROJECT_ROOT/ci/cpp.sh && ci_debug
ci_cmake_build
ci_cmake_package
echo "ENV_RELEASE_FILE=$(ls *.uf2 | cut -d. -f1)" >> $GITHUB_ENV
- name: "Artifacts: Upload .uf2"
uses: actions/upload-artifact@v4
with:
name: ${{ env.RELEASE_FILE }}.uf2
path: ${{ env.CI_BUILD_ROOT }}/${{ env.RELEASE_FILE }}.uf2

- name: "Release: Upload .uf2"
if: github.event_name == 'release'
uses: softprops/action-gh-release@v1
with:
files: |
${{ env.CI_BUILD_ROOT }}/${{ env.RELEASE_FILE }}.uf2
${{ env.CI_BUILD_ROOT }}/${{ env.RELEASE_FILE }}.zip
${{ env.CI_BUILD_ROOT }}/${{ env.RELEASE_FILE }}.tar.gz
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
88 changes: 88 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
cmake_minimum_required(VERSION 3.12)

set(PICO_PLATFORM rp2350-arm-s)
set(PICO_BOARD pimoroni_pico_plus2_rp2350)

# Change your executable name to something creative!
set(NAME presto-boilerplate) # <-- Name your project/executable here!

include(pimoroni_pico_import.cmake)
include(pico_sdk_import.cmake)

# Gooey boilerplate
project(${NAME} C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

# Initialize the SDK
pico_sdk_init()

if (NOT PIMORONI_PRESTO_PATH)
set(PIMORONI_PRESTO_PATH ../../presto/)
endif()
if(NOT IS_ABSOLUTE ${PIMORONI_PRESTO_PATH})
get_filename_component(
PIMORONI_PRESTO_PATH
"${CMAKE_CURRENT_BINARY_DIR}/${PIMORONI_PRESTO_PATH}"
ABSOLUTE)
endif()
message("PIMORONI_PRESTO_PATH is ${PIMORONI_PRESTO_PATH}")
set(PIMORONI_PRESTO_PATH ${PIMORONI_PRESTO_PATH} CACHE PATH "Path to the Presto libraries" FORCE)
include_directories(${PIMORONI_PRESTO_PATH})
list(APPEND CMAKE_MODULE_PATH ${PIMORONI_PRESTO_PATH})
include(drivers/st7701/st7701_presto)

include_directories(${CMAKE_CURRENT_LIST_DIR}/uzlib/src)

# Add your source files
add_executable(${NAME}
src/main.cpp # <-- Add source files here!
)

# Include required libraries
# This assumes `pimoroni-pico` is stored alongside your project
include(common/pimoroni_i2c)
include(common/pimoroni_bus)
include(drivers/fatfs/fatfs)
include(drivers/sdcard/sdcard)
include(libraries/pico_graphics/pico_graphics)

# Don't forget to link the libraries you need!
target_link_libraries(${NAME}
st7701_presto
pico_stdlib
pico_multicore
pimoroni_i2c
sdcard
fatfs
hardware_interp
)

# Configure the SD Card library for Presto
target_compile_definitions(${NAME} PRIVATE
SDCARD_SPI_BUS=spi0
SDCARD_PIN_SPI0_CS=39
SDCARD_PIN_SPI0_SCK=34
SDCARD_PIN_SPI0_MOSI=35
SDCARD_PIN_SPI0_MISO=36
PICO_CLOCK_AJDUST_PERI_CLOCK_WITH_SYS_CLOCK=1
)

# create map/bin/hex file etc.
pico_add_extra_outputs(${NAME})

# Enable USB UART output only
pico_enable_stdio_uart(${NAME} 0)
pico_enable_stdio_usb(${NAME} 1)

# Set up files for the release packages
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${NAME}.uf2
${CMAKE_CURRENT_LIST_DIR}/README.md
DESTINATION .
)

set(CPACK_PACKAGE_FILE_NAME ${NAME})
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF)
set(CPACK_GENERATOR "ZIP" "TGZ")
include(CPack)
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Presto C++ Boilerplate

A basic project for getting started with C++ on the RP2350-powered Presto.
95 changes: 95 additions & 0 deletions ci/cpp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
export TERM=${TERM:="xterm-256color"}

if [ -z ${CI_PROJECT_ROOT+x} ]; then
SCRIPT_PATH="$(dirname $0)"
CI_PROJECT_ROOT=$(realpath "$SCRIPT_PATH/..")
fi

if [ -z ${CI_BUILD_ROOT+x} ]; then
CI_BUILD_ROOT=$(pwd)
fi

if [ -z ${CI_BUILD_TYPE+x} ]; then
CI_BUILD_TYPE="Release"
fi


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 ci_clone {
NAME=$1
USER=$2
REPO=$3
BRANCH=$4
log_inform "Cloning $NAME $USER/$REPO/$BRANCH"
git clone https://github.com/$USER/$REPO "$CI_BUILD_ROOT/$REPO"
cd "$CI_BUILD_ROOT/$REPO" || return 1
git checkout $BRANCH
git submodule update --init
cd "$CI_BUILD_ROOT"
}

function ci_apt_install_build_deps {
sudo apt update && sudo apt install ccache
}

function ci_prepare_all {
mkdir -p $CI_BUILD_ROOT
ci_clone "Pimoroni Pico" "pimoroni" "pimoroni-pico" "feature/picovector2-and-layers"
ci_clone "Pico SDK" "raspberrypi" "pico-sdk" "master"
ci_clone "Pico Extras" "raspberrypi" "pico-extras" "master"
ci_clone "Presto" "pimoroni" "presto" "main"
}

function ci_debug {
log_inform "Project root: $CI_PROJECT_ROOT"
log_inform "Build root: $CI_BUILD_ROOT"
}

function ci_cmake_vars {
BUILD_DIR="$CI_BUILD_ROOT/build"
PIMORONI_PICO_PATH="$CI_BUILD_ROOT/pimoroni-pico"
PICO_SDK_PATH="$CI_BUILD_ROOT/pico-sdk"
PIMORONI_PRESTO_PATH="$CI_BUILD_ROOT/presto"
CMAKE_INSTALL_PREFIX="$CI_BUILD_ROOT/out"

cmake -L -N $CI_PROJECT_ROOT \
-DPICOTOOL_FORCE_FETCH_FROM_GIT=1 \
-DCMAKE_BUILD_TYPE=$CI_BUILD_TYPE \
-DPIMORONI_PICO_PATH=$PIMORONI_PICO_PATH \
-DPICO_SDK_PATH=$PICO_SDK_PATH \
-DPIMORONI_PRESTO_PATH=$PIMORONI_PRESTO_PATH \
-DCMAKE_INSTALL_PREFIX=$CMAKE_INSTALL_PREFIX
}

function ci_cmake_configure {
PIMORONI_PICO_PATH="$CI_BUILD_ROOT/pimoroni-pico"
PICO_SDK_PATH="$CI_BUILD_ROOT/pico-sdk"
PIMORONI_PRESTO_PATH="$CI_BUILD_ROOT/presto"
CMAKE_INSTALL_PREFIX="$CI_BUILD_ROOT/out"

cmake $CI_PROJECT_ROOT -B "$CI_BUILD_ROOT" \
-DPICOTOOL_FORCE_FETCH_FROM_GIT=1 \
-DCMAKE_BUILD_TYPE=$CI_BUILD_TYPE \
-DPIMORONI_PICO_PATH=$PIMORONI_PICO_PATH \
-DPICO_SDK_PATH=$PICO_SDK_PATH \
-DPIMORONI_PRESTO_PATH=$PIMORONI_PRESTO_PATH
}

function ci_cmake_build {
cmake --build $CI_BUILD_ROOT -j 2
}

function ci_cmake_package {
cmake --build $CI_BUILD_ROOT --target package -j 2
}
84 changes: 84 additions & 0 deletions pico_sdk_import.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# This is a copy of <PICO_SDK_PATH>/external/pico_sdk_import.cmake

# This can be dropped into an external project to help locate this SDK
# It should be include()ed prior to project()

if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH))
set(PICO_SDK_PATH $ENV{PICO_SDK_PATH})
message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')")
endif ()

if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT))
set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT})
message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')")
endif ()

if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH))
set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH})
message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')")
endif ()

if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_TAG} AND (NOT PICO_SDK_FETCH_FROM_GIT_TAG))
set(PICO_SDK_FETCH_FROM_GIT_TAG $ENV{PICO_SDK_FETCH_FROM_GIT_TAG})
message("Using PICO_SDK_FETCH_FROM_GIT_TAG from environment ('${PICO_SDK_FETCH_FROM_GIT_TAG}')")
endif ()

if (PICO_SDK_FETCH_FROM_GIT AND NOT PICO_SDK_FETCH_FROM_GIT_TAG)
set(PICO_SDK_FETCH_FROM_GIT_TAG "master")
message("Using master as default value for PICO_SDK_FETCH_FROM_GIT_TAG")
endif()

set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK")
set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of SDK from git if not otherwise locatable")
set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK")
set(PICO_SDK_FETCH_FROM_GIT_TAG "${PICO_SDK_FETCH_FROM_GIT_TAG}" CACHE FILEPATH "release tag for SDK")

if (NOT PICO_SDK_PATH)
if (PICO_SDK_FETCH_FROM_GIT)
include(FetchContent)
set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR})
if (PICO_SDK_FETCH_FROM_GIT_PATH)
get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}")
endif ()
# GIT_SUBMODULES_RECURSE was added in 3.17
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0")
FetchContent_Declare(
pico_sdk
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG}
GIT_SUBMODULES_RECURSE FALSE
)
else ()
FetchContent_Declare(
pico_sdk
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG}
)
endif ()

if (NOT pico_sdk)
message("Downloading Raspberry Pi Pico SDK")
FetchContent_Populate(pico_sdk)
set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR})
endif ()
set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE})
else ()
message(FATAL_ERROR
"SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git."
)
endif ()
endif ()

get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
if (NOT EXISTS ${PICO_SDK_PATH})
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found")
endif ()

set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake)
if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE})
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK")
endif ()

set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE)

include(${PICO_SDK_INIT_CMAKE_FILE})
56 changes: 56 additions & 0 deletions pimoroni_pico_import.cmake
Original file line number Diff line number Diff line change
@@ -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})
Loading

0 comments on commit 3531d95

Please sign in to comment.