Initial commit

This commit is contained in:
2022-09-22 20:23:09 +05:30
commit 94d872efc0
17 changed files with 684 additions and 0 deletions

23
.devcontainer/Dockerfile Normal file
View File

@@ -0,0 +1,23 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.236.0/containers/cpp/.devcontainer/base.Dockerfile
# [Choice] Debian / Ubuntu version (use Debian 11, Ubuntu 18.04/22.04 on local arm64/Apple Silicon): debian-11, debian-10, ubuntu-22.04, ubuntu-20.04, ubuntu-18.04
ARG VARIANT="bullseye"
FROM mcr.microsoft.com/vscode/devcontainers/cpp:0-${VARIANT}
# [Optional] Install CMake version different from what base image has already installed.
# CMake reinstall choices: none, 3.21.5, 3.22.2, or versions from https://cmake.org/download/
ARG REINSTALL_CMAKE_VERSION_FROM_SOURCE="3.22.2"
# Optionally install the cmake for vcpkg
COPY ./reinstall-cmake.sh /tmp/
RUN if [ "${REINSTALL_CMAKE_VERSION_FROM_SOURCE}" != "none" ]; then \
chmod +x /tmp/reinstall-cmake.sh && /tmp/reinstall-cmake.sh ${REINSTALL_CMAKE_VERSION_FROM_SOURCE}; \
fi \
&& rm -f /tmp/reinstall-cmake.sh
# [Optional] Uncomment this section to install additional vcpkg ports.
# RUN su vscode -c "${VCPKG_ROOT}/vcpkg install <your-port-name-here>"
# [Optional] Uncomment this section to install additional packages.
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install git ninja-build gcc-arm-none-eabi build-essential

View File

@@ -0,0 +1,36 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.236.0/containers/cpp
{
"name": "C++",
"build": {
"dockerfile": "Dockerfile",
// Update 'VARIANT' to pick an Debian / Ubuntu OS version: debian-11, debian-10, ubuntu-22.04, ubuntu-20.04, ubuntu-18.04
// Use Debian 11, Ubuntu 18.04 or Ubuntu 22.04 on local arm64/Apple Silicon
"args": { "VARIANT": "ubuntu-22.04" }
},
"runArgs": ["--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"],
// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-vscode.cpptools",
"ms-vscode.cmake-tools"
]
}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
"postStartCommand": "git submodule update --init && git submodule foreach git submodule update --init",
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode",
"features": {
"git": "latest"
}
}

View File

@@ -0,0 +1,58 @@
#!/usr/bin/env bash
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------
#
set -e
CMAKE_VERSION=${1:-"none"}
if [ "${CMAKE_VERSION}" = "none" ]; then
echo "No CMake version specified, skipping CMake reinstallation"
exit 0
fi
# Cleanup temporary directory and associated files when exiting the script.
cleanup() {
EXIT_CODE=$?
set +e
if [[ -n "${TMP_DIR}" ]]; then
echo "Executing cleanup of tmp files"
rm -Rf "${TMP_DIR}"
fi
exit $EXIT_CODE
}
trap cleanup EXIT
echo "Installing CMake..."
apt-get -y purge --auto-remove cmake
mkdir -p /opt/cmake
architecture=$(dpkg --print-architecture)
case "${architecture}" in
arm64)
ARCH=aarch64 ;;
amd64)
ARCH=x86_64 ;;
*)
echo "Unsupported architecture ${architecture}."
exit 1
;;
esac
CMAKE_BINARY_NAME="cmake-${CMAKE_VERSION}-linux-${ARCH}.sh"
CMAKE_CHECKSUM_NAME="cmake-${CMAKE_VERSION}-SHA-256.txt"
TMP_DIR=$(mktemp -d -t cmake-XXXXXXXXXX)
echo "${TMP_DIR}"
cd "${TMP_DIR}"
curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_BINARY_NAME}" -O
curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_CHECKSUM_NAME}" -O
sha256sum -c --ignore-missing "${CMAKE_CHECKSUM_NAME}"
sh "${TMP_DIR}/${CMAKE_BINARY_NAME}" --prefix=/opt/cmake --skip-license
ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake

42
.gitignore vendored Normal file
View File

@@ -0,0 +1,42 @@
# 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
# directories
.vscode
build/**
.cache
# submodules
pico-sdk/**
pimoroni-pico/**
pico-extras/**

12
.gitmodules vendored Normal file
View File

@@ -0,0 +1,12 @@
[submodule "pico-sdk"]
path = pico-sdk
url = https://github.com/raspberrypi/pico-sdk
ignore = dirty
[submodule "pimoroni-pico"]
path = pimoroni-pico
url = https://github.com/pimoroni/pimoroni-pico
ignore = dirty
[submodule "pico-extras"]
path = pico-extras
url = https://github.com/raspberrypi/pico-extras
ignore = dirty

24
CMakeLists.txt Normal file
View File

@@ -0,0 +1,24 @@
# Original boilerplate:
cmake_minimum_required(VERSION 3.20)
# Change your executable name to something creative!
set(NAME badger-project)
# include the dependencies
include(pimoroni_pico_import.cmake)
include(pico_sdk_import.cmake)
include(pico_extras_import.cmake)
# Gooey boilerplate
project(${NAME} C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
# add dependencies as subdirectory
add_subdirectory(pimoroni-pico)
# add_subdirectory(<dependency-directory-name>) # <- add more dependencies like this
# add the project as a subdirectory after bootstrapping
add_subdirectory(programexample)
# add_subdirectory(<program-directory-name>) # <- add more programs like this

29
LICENSE Normal file
View File

@@ -0,0 +1,29 @@
BSD 3-Clause License
Copyright (c) 2022, Avinal Kumar
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

103
README.md Normal file
View File

@@ -0,0 +1,103 @@
# Badger 2040 C++ Boilerplate Project
This repository extends the [boilerplate](https://github.com/pimoroni/pico-boilerplate) project created by Pimoroni specifically to be used as a boilerplate for Badger 2040 C++ projects.
## Prerequisite
I have gathered all the required dependencies for developing C++ programs for Badger 2040 and created a [bootstrap](./bootstrap) script to do the heavy lifting. However, the prerequisites are as listed below.
- Common dependencies
- `git`
- `cmake`
- `make`
- `ninja-build`
- Build dependencies for Fedora
- `gcc-arm-linux-gnu`
- `arm-none-eabi-gcc-cs-c++`
- `arm-none-eabi-gcc-cs`
- `arm-none-eabi-binutils`
- `arm-none-eabi-newlib`
- Build dependencies for Ubuntu
- `gcc-arm-none-eabi`
- `build-essential`
- `gcc-arm-none-eabi`
- Project dependencies
- [pimoroni-pico](https://github.com/pimoroni/pimoroni-pico)
- [pico-extras](https://github.com/raspberrypi/pico-extras)
- [pico-sdk](https://github.com/raspberrypi/pico-sdk)
## Project Related FAQs
### How to create a new Badger 2040 program?
This part explains how to properly arrange source code for a Badger 2040 program for easy compiling and maintenance.
1. Clone the unmodified [programexample](./programexample/) directory and rename it (let it be `example-too`).
2. Add your source code files to the directory.
3. Modify the [CMakeLists.txt](./programexample/CMakeLists.txt) in the new program directory to add source files and required options.
4. Add the following line at the end of this project's [CMakeLists.txt](./CMakeLists.txt)
```cmake
add_subdirectory(example-too)
```
### How to build the program?
If you have used the supplied **bootstrap** script, you should be able to see the build folder, please follow from steps in that case.
1. Install all the build dependencies for your distro and initialize all the submodules. Run the following command in the project root and then inside all three submodules `pico-sdk`, `pico-extras`, `pimoroni-pico`.
```bash
git submodule update --init
```
2. Create a `build` directory.
```bash
mkdir build && cd build
```
3. Generate CMake project. (_Note: using Ninja for speedy compilation._)
```bash
cmake .. -DPICO_BOARD=pimoroni_badger2040 -GNinja
```
4. Compile your project. Do not compile the whole project, only compile the project you need by specifying the name.
```bash
ninja <program-name>
```
### How to flash the programs to Badger 2040?
The Badger 2040 uses `.ef2` files to flash any program. You can upload MicroPython, CircuitPython or custom-built images. Follow these steps to use your custom build images. You can add only one file at a time.
1. Hold `boot/usr` button on your badger and connect to your system. It will get mounted as **RPI-RP2**. There will be two files already, _do not touch them_.
2. Go to the build directory and find the corresponding `<project-name>.ef2` file for your project.
3. Copy this file to the mounted **RPI-RP2**.
4. Your badger screen will flash and the program will load.
5. You can now test your program.
## References
### Where to buy Badger 2040?
- [India](https://theelectronics.shop/product/badger-2040-badger-only/)
- [WorldWide](https://shop.pimoroni.com/products/badger-2040)
### Important Repositories
- [Raspberry Pi Pico SDK](https://github.com/raspberrypi/pico-sdk)
- [Pimoroni Pico Libraries and Examples](https://github.com/pimoroni/pimoroni-pico)
- [Raspberry Pi Pico Additional Library](https://github.com/raspberrypi/pico-extras)
### Acknowledgments
- [Original Pico C++ Boilerplate Project](https://github.com/pimoroni/pico-boilerplate)
- [Compiling Raspberry Pi Pico C/C++ programs on Fedora by John Walicki](https://github.com/johnwalicki/RaspPi-Pico-Examples-Fedora)
- [The Badger Set - small C++ programs for the Badger2040 by Michael Bell](https://github.com/MichaelBell/badger-set)
## License
I've added the BSD 3-Clause License to match the license used in the project dependencies. You should review this and check it's appropriate for your project before publishing your code.

42
bootstrap Executable file
View File

@@ -0,0 +1,42 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# SPDX-FileCopyrightText: 2022 Avinal Kumar <avinal.xlvii@gmail.com>
echo "Installing build dependencies"
DISTRO_NAME=$(lsb_release --id --short)
case "$DISTRO_NAME" in
Debian|Ubuntu)
echo "Installing dependencies for Debian-like distros..."
sudo apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& sudo apt-get -y install gcc g++ cmake git ninja-build make gcc-arm-none-eabi build-essential
;;
Fedora)
echo "Installing dependencies for Fedora..."
sudo dnf install -y gcc g++ cmake git ninja-build make \
gcc-arm-linux-gnu arm-none-eabi-gcc-cs-c++ arm-none-eabi-gcc-cs \
arm-none-eabi-binutils arm-none-eabi-newlib
;;
*) echo "Distro is not recognized, build dependencies won't be installed!!!"
esac
echo "Fetching the submodules..."
git submodule update --init
git submodule foreach git submodule update --init
echo "Creating build directory"
if [ ! -d "build" ]
then
mkdir build
else
echo "build directory exists..."
fi
cd build
echo "Generating CMake project..."
# using ninja for faster build
cmake .. -DPICO_BOARD=pimoroni_badger2040 -GNinja
echo "Bootstrap complete. Please goto build directory and run ninja to compile."

1
pico-extras Submodule

Submodule pico-extras added at 18de33966e

1
pico-sdk Submodule

Submodule pico-sdk added at 426e46126b

68
pico_extras_import.cmake Normal file
View File

@@ -0,0 +1,68 @@
# This is a copy of <PICO_EXTRAS_PATH>/external/pico_extras_import.cmake
# This can be dropped into an external project to help locate pico-extras
# It should be include()ed prior to project()
# HACK add from submodule
if(EXISTS "${CMAKE_SOURCE_DIR}/pico-extras/.git")
set(PICO_EXTRAS_PATH "${CMAKE_SOURCE_DIR}/pico-extras")
message(STATUS "Using PICO_EXTRA_PATH from git submodule.")
endif()
if (DEFINED ENV{PICO_EXTRAS_PATH} AND (NOT PICO_EXTRAS_PATH))
set(PICO_EXTRAS_PATH $ENV{PICO_EXTRAS_PATH})
message(STATUS "Using PICO_EXTRAS_PATH from environment ('${PICO_EXTRAS_PATH}')")
endif ()
if (DEFINED ENV{PICO_EXTRAS_FETCH_FROM_GIT} AND (NOT PICO_EXTRAS_FETCH_FROM_GIT))
set(PICO_EXTRAS_FETCH_FROM_GIT $ENV{PICO_EXTRAS_FETCH_FROM_GIT})
message(STATUS "Using PICO_EXTRAS_FETCH_FROM_GIT from environment ('${PICO_EXTRAS_FETCH_FROM_GIT}')")
endif ()
if (DEFINED ENV{PICO_EXTRAS_FETCH_FROM_GIT_PATH} AND (NOT PICO_EXTRAS_FETCH_FROM_GIT_PATH))
set(PICO_EXTRAS_FETCH_FROM_GIT_PATH $ENV{PICO_EXTRAS_FETCH_FROM_GIT_PATH})
message(STATUS "Using PICO_EXTRAS_FETCH_FROM_GIT_PATH from environment ('${PICO_EXTRAS_FETCH_FROM_GIT_PATH}')")
endif ()
if (NOT PICO_EXTRAS_PATH)
if (PICO_EXTRAS_FETCH_FROM_GIT)
include(FetchContent)
set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR})
if (PICO_EXTRAS_FETCH_FROM_GIT_PATH)
get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_EXTRAS_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}")
endif ()
FetchContent_Declare(
PICO_EXTRAS
GIT_REPOSITORY https://github.com/raspberrypi/pico-extras
GIT_TAG master
)
if (NOT PICO_EXTRAS)
message("Downloading PICO EXTRAS")
FetchContent_Populate(PICO_EXTRAS)
set(PICO_EXTRAS_PATH ${PICO_EXTRAS_SOURCE_DIR})
endif ()
set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE})
else ()
if (PICO_SDK_PATH AND EXISTS "${PICO_SDK_PATH}/../pico-extras")
set(PICO_EXTRAS_PATH ${PICO_SDK_PATH}/../pico-extras)
message("Defaulting PICO_EXTRAS_PATH as sibling of PICO_SDK_PATH: ${PICO_EXTRAS_PATH}")
else()
message(FATAL_ERROR
"PICO EXTRAS location was not specified. Please set PICO_EXTRAS_PATH or set PICO_EXTRAS_FETCH_FROM_GIT to on to fetch from git."
)
endif()
endif ()
endif ()
set(PICO_EXTRAS_PATH "${PICO_EXTRAS_PATH}" CACHE PATH "Path to the PICO EXTRAS")
set(PICO_EXTRAS_FETCH_FROM_GIT "${PICO_EXTRAS_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of PICO EXTRAS from git if not otherwise locatable")
set(PICO_EXTRAS_FETCH_FROM_GIT_PATH "${PICO_EXTRAS_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download EXTRAS")
get_filename_component(PICO_EXTRAS_PATH "${PICO_EXTRAS_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
if (NOT EXISTS ${PICO_EXTRAS_PATH})
message(FATAL_ERROR "Directory '${PICO_EXTRAS_PATH}' not found")
endif ()
set(PICO_EXTRAS_PATH ${PICO_EXTRAS_PATH} CACHE PATH "Path to the PICO EXTRAS" FORCE)
add_subdirectory(${PICO_EXTRAS_PATH} pico_extras)

68
pico_sdk_import.cmake Normal file
View File

@@ -0,0 +1,68 @@
# 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()
# HACK: add from submodules
if(EXISTS "${CMAKE_SOURCE_DIR}/pico-sdk/.git")
set(PICO_SDK_PATH "${CMAKE_SOURCE_DIR}/pico-sdk")
message(STATUS "Using PICO_SDK_PATH from git submodule.")
endif()
if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH))
set(PICO_SDK_PATH $ENV{PICO_SDK_PATH})
message(STATUS "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(STATUS "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(STATUS "Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')")
endif ()
set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the PICO SDK")
set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of PICO 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")
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 ()
FetchContent_Declare(
pico_sdk
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
GIT_TAG master
)
if (NOT pico_sdk)
message(STATUS "Downloading 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
"PICO 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 PICO SDK")
endif ()
set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the PICO SDK" FORCE)
include(${PICO_SDK_INIT_CMAKE_FILE})

1
pimoroni-pico Submodule

Submodule pimoroni-pico added at b41631bc14

View File

@@ -0,0 +1,34 @@
# 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.
# HACK: add from submodules
if(EXISTS "${CMAKE_SOURCE_DIR}/pimoroni-pico/.git")
set(PIMORONI_PICO_PATH "${CMAKE_SOURCE_DIR}/pimoroni-pico")
message(STATUS "Using PIMORONI_PICO_PATH from git submodule.")
endif()
if (NOT PIMORONI_PICO_PATH)
set(PIMORONI_PICO_PATH "../../pimoroni-pico/")
endif()
if(NOT IS_ABSOLUTE ${PIMORONI_PICO_PATH})
get_filename_component(
PIMORONI_PICO_PATH
"${CMAKE_CURRENT_BINARY_DIR}/${PIMORONI_PICO_PATH}"
ABSOLUTE)
endif()
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(STATUS "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})

View File

@@ -0,0 +1,33 @@
# rename your project
project(programexample C CXX)
# Initialize the SDK
pico_sdk_init()
# Add your source files
add_executable(${PROJECT_NAME}
main.cpp # <-- Add source files here!
)
# set pico specific options
pico_set_program_name(${PROJECT_NAME} "${PROJECT_NAME}")
pico_set_program_version(${PROJECT_NAME} "0.1")
pico_enable_stdio_uart(${PROJECT_NAME} 0)
pico_enable_stdio_usb(${PROJECT_NAME} 0)
# Don't forget to link the libraries you need!
target_link_libraries(${PROJECT_NAME}
pico_stdlib
hardware_spi
badger2040 # <-- List libraries here!
)
# create map/bin/hex file etc.
pico_enable_stdio_usb(${PROJECT_NAME} 1)
pico_add_extra_outputs(${PROJECT_NAME})
# include source directories if needed
include_directories(../pimoroni-pico)

109
programexample/main.cpp Normal file
View File

@@ -0,0 +1,109 @@
// Example fetched from:
// https://github.com/pimoroni/pimoroni-pico/tree/main/examples/badger2040
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <string>
#include "badger2040.hpp"
#include "common/pimoroni_common.hpp"
#include "pico/platform.h"
#include "pico/stdlib.h"
#include "pico/time.h"
using namespace pimoroni;
Badger2040 badger;
uint32_t time() {
absolute_time_t t = get_absolute_time();
return to_ms_since_boot(t);
}
std::array<std::string, 8> font_names = {"sans", "sans_bold", "gothic",
"cursive", "cursive_bold", "serif",
"serif_bold", "serif_italic"};
int8_t selected_font = 0;
void draw() {
badger.pen(15);
badger.clear();
badger.font("sans");
for (int i = 0; i < int(font_names.size()); i++) {
std::string name = font_names[i];
if (selected_font == i) {
badger.pen(0);
badger.rectangle(0, i * 16, 80, 16);
badger.pen(15);
} else {
badger.pen(0);
}
badger.text(name, 2, i * 16 + 7, 0.4f);
}
badger.font(font_names[selected_font]);
badger.thickness(2);
badger.text("The quick", 90, 10, 0.80f);
badger.text("brown fox", 90, 32, 0.80f);
badger.text("jumped over", 90, 54, 0.80f);
badger.text("the lazy dog.", 90, 76, 0.80f);
badger.text("0123456789", 90, 98, 0.80f);
badger.text("!\"£$%^&*()", 90, 120, 0.80f);
badger.thickness(1);
badger.update();
}
int main() {
stdio_init_all();
sleep_ms(500);
printf("\n\n=======\nbadger2040 starting up\n\n");
badger.init();
badger.update_speed(1);
uint32_t i = 0;
while (true) {
printf("> drawing..");
draw();
printf("done!\n");
printf("> waiting for a button press..");
badger.wait_for_press();
printf("done!\n");
if (badger.pressed(badger.DOWN)) {
printf("> down pressed\n");
selected_font++;
}
if (badger.pressed(badger.UP)) {
printf("> up pressed\n");
selected_font--;
}
if (badger.pressed(badger.C)) {
printf("> C pressed\n");
badger.halt();
}
selected_font =
selected_font < 0 ? int(font_names.size()) - 1 : selected_font;
selected_font = selected_font >= int(font_names.size()) ? 0 : selected_font;
printf("> newly selected font is %s (%d)\n",
font_names[selected_font].c_str(), selected_font);
i++;
}
}