]> git.scottworley.com Git - tattlekey/commitdiff
client: Start with the 'blink' example
authorScott Worley <scottworley@scottworley.com>
Thu, 28 Sep 2023 00:46:26 +0000 (17:46 -0700)
committerScott Worley <scottworley@scottworley.com>
Wed, 11 Oct 2023 01:47:04 +0000 (18:47 -0700)
client/CMakeLists.txt [new file with mode: 0644]
client/default.nix [new file with mode: 0644]
client/pico_sdk_import.cmake [new file with mode: 0644]
client/tattlekey.c [new file with mode: 0644]

diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt
new file mode 100644 (file)
index 0000000..d07ff63
--- /dev/null
@@ -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 (file)
index 0000000..37fc8f1
--- /dev/null
@@ -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 (file)
index 0000000..8ceca57
--- /dev/null
@@ -0,0 +1,29 @@
+# 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 ()
+
+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 (file)
index 0000000..f34552b
--- /dev/null
@@ -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
+}