diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore index be8d07a..aa17621 100644 --- a/.gitignore +++ b/.gitignore @@ -150,3 +150,7 @@ dkms.conf *.out *.app +# direnv cache +.direnv +# build directory +build diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..643f237 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "pico-sdk"] + path = pico-sdk + url = https://github.com/raspberrypi/pico-sdk diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..a006037 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,22 @@ +cmake_minimum_required(VERSION 3.13...3.27) + +# initialize pico-sdk from submodule +# note: this must happen before project() +include(pico-sdk/pico_sdk_init.cmake) + +project(my_project) + +# initialize the Raspberry Pi Pico SDK +set(PICO_BOARD, "pico") +pico_sdk_init() + +# rest of your project +add_executable(hello_world + hello_world.c +) + +# Add pico_stdlib library which aggregates commonly used features +target_link_libraries(hello_world pico_stdlib) + +# create map/bin/hex/uf2 file in addition to ELF. +pico_add_extra_outputs(hello_world) diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..5e6deae --- /dev/null +++ b/flake.lock @@ -0,0 +1,64 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": [ + "systems" + ] + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1737255904, + "narHash": "sha256-r3fxHvh+M/mBgCZXOACzRFPsJdix2QSsKazb7VCXXo0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "eacdab35066b0bb1c9413c96898e326b76398a81", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "release-24.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "systems": "systems" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..252e013 --- /dev/null +++ b/flake.nix @@ -0,0 +1,33 @@ +{ + description = "flake for rp2040 dev"; + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/release-24.11"; + systems.url = "github:nix-systems/default"; + flake-utils = { + url = "github:numtide/flake-utils"; + inputs.systems.follows = "systems"; + }; + }; + + outputs = + { nixpkgs, flake-utils, ... }: + flake-utils.lib.eachDefaultSystem ( + system: + let + pkgs = nixpkgs.legacyPackages.${system}; + in + { + devShells.default = pkgs.mkShell { + packages = with pkgs; [ + gcc + cmake + gnumake + python312Full + gcc-arm-embedded + newlib + ]; + }; + } + ); +} + diff --git a/hello_world.c b/hello_world.c new file mode 100644 index 0000000..e588b0e --- /dev/null +++ b/hello_world.c @@ -0,0 +1,53 @@ +/** + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "pico/stdlib.h" + +// Pico W devices use a GPIO on the WIFI chip for the LED, +// so when building for Pico W, CYW43_WL_GPIO_LED_PIN will be defined +#ifdef CYW43_WL_GPIO_LED_PIN +#include "pico/cyw43_arch.h" +#endif + +#ifndef LED_DELAY_MS +#define LED_DELAY_MS 250 +#endif + +// Perform initialisation +int pico_led_init(void) { +#if defined(PICO_DEFAULT_LED_PIN) + // A device like Pico that uses a GPIO for the LED will define PICO_DEFAULT_LED_PIN + // so we can use normal GPIO functionality to turn the led on and off + gpio_init(PICO_DEFAULT_LED_PIN); + gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT); + return PICO_OK; +#elif defined(CYW43_WL_GPIO_LED_PIN) + // For Pico W devices we need to initialise the driver etc + return cyw43_arch_init(); +#endif +} + +// Turn the led on or off +void pico_set_led(bool led_on) { +#if defined(PICO_DEFAULT_LED_PIN) + // Just set the GPIO on or off + gpio_put(PICO_DEFAULT_LED_PIN, led_on); +#elif defined(CYW43_WL_GPIO_LED_PIN) + // Ask the wifi "driver" to set the GPIO on or off + cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, led_on); +#endif +} + +int main() { + int rc = pico_led_init(); + hard_assert(rc == PICO_OK); + while (true) { + pico_set_led(true); + sleep_ms(LED_DELAY_MS); + pico_set_led(false); + sleep_ms(LED_DELAY_MS); + } +} diff --git a/pico-sdk b/pico-sdk new file mode 160000 index 0000000..95ea6ac --- /dev/null +++ b/pico-sdk @@ -0,0 +1 @@ +Subproject commit 95ea6acad131124694cda1c162c52cd30e0aece0