From 5ec2b60aca31cb3f8f0da44017885bc08b72a6b2 Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Wed, 27 Sep 2023 17:46:26 -0700 Subject: [PATCH 1/1] client: Start with the 'blink' example --- client/CMakeLists.txt | 16 ++++++++++++++++ client/default.nix | 27 +++++++++++++++++++++++++++ client/pico_sdk_import.cmake | 29 +++++++++++++++++++++++++++++ client/tattlekey.c | 23 +++++++++++++++++++++++ 4 files changed, 95 insertions(+) create mode 100644 client/CMakeLists.txt create mode 100644 client/default.nix create mode 100644 client/pico_sdk_import.cmake create mode 100644 client/tattlekey.c diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt new file mode 100644 index 0000000..d07ff63 --- /dev/null +++ b/client/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.13) # Per https://datasheets.raspberrypi.com/pico/getting-started-with-pico.pdf p30 +include(pico_sdk_import.cmake) + +project(tattlekey C CXX ASM) + +set(CMAKE_C_STANDARD 11) +set(CMAKE_CXX_STANDARD 17) +pico_sdk_init() + +add_executable(tattlekey tattlekey.c) + +pico_add_extra_outputs(tattlekey) + +target_link_libraries(tattlekey pico_stdlib) + +install(TARGETS tattlekey RUNTIME LIBRARY ARCHIVE) diff --git a/client/default.nix b/client/default.nix new file mode 100644 index 0000000..37fc8f1 --- /dev/null +++ b/client/default.nix @@ -0,0 +1,27 @@ +{ pkgs ? import ~/devel/nixpkgs { }, }: +let + cc = pkgs.pkgsCross.arm-embedded.stdenv.cc; + tattlekey = { lib, stdenv, cmake, pico-sdk, python3 }: + stdenv.mkDerivation { + pname = "tattlekey"; + version = "0.0.1"; + src = lib.cleanSource ./.; + nativeBuildInputs = [ cmake python3 ]; + cmakeFlags = [ + "-DCMAKE_C_COMPILER=${cc}/bin/arm-none-eabi-cc" + "-DCMAKE_CXX_COMPILER=${cc}/bin/arm-none-eabi-c++" + "-DPICO_SDK_PATH=${pico-sdk.override { minimal = false; }}/lib/pico-sdk" + "-DPICO_TOOLCHAIN_PATH=${cc}/bin" + ]; + /* + installPhase = '' + runHook preInstall + + mkdir $out + mv build/tattlekey.* $out + + runHook postInstall + ''; + */ + }; +in pkgs.callPackage tattlekey {} diff --git a/client/pico_sdk_import.cmake b/client/pico_sdk_import.cmake new file mode 100644 index 0000000..8ceca57 --- /dev/null +++ b/client/pico_sdk_import.cmake @@ -0,0 +1,29 @@ +# This is a copy of /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 () + +set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK") + +if (NOT PICO_SDK_PATH) + message(FATAL_ERROR "SDK location was not specified. Please set PICO_SDK_PATH.") +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}) diff --git a/client/tattlekey.c b/client/tattlekey.c new file mode 100644 index 0000000..f34552b --- /dev/null +++ b/client/tattlekey.c @@ -0,0 +1,23 @@ +/** + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "pico/stdlib.h" + +int main() { +#ifndef PICO_DEFAULT_LED_PIN +#warning blink example requires a board with a regular LED +#else + const uint LED_PIN = PICO_DEFAULT_LED_PIN; + gpio_init(LED_PIN); + gpio_set_dir(LED_PIN, GPIO_OUT); + while (true) { + gpio_put(LED_PIN, 1); + sleep_ms(250); + gpio_put(LED_PIN, 0); + sleep_ms(250); + } +#endif +} -- 2.44.1