commit d8f669a4657b967e03c4597c3febd9d9c477a153 Author: danial23 Date: Tue Jan 14 23:16:19 2025 -0500 Initial commit diff --git a/.clangd b/.clangd new file mode 100644 index 0000000..ec0b890 --- /dev/null +++ b/.clangd @@ -0,0 +1,2 @@ +CompileFlags: + CompilationDatabase: build diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a4fb4fb --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +build/ +.cache/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..ac968f6 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,24 @@ +cmake_minimum_required(VERSION 3.13) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +# initialize the SDK based on PICO_SDK_PATH +# note: this must happen before project() +include(pico_sdk_import.cmake) + +project(police_colors) + +# initialize the Raspberry Pi Pico SDK +pico_sdk_init() + +# rest of your project +# + +add_executable(police_colors + police_colors.c + ) + +# pull in common dependencies +target_link_libraries(police_colors pico_stdlib) + +# create map/bin/hex file etc. +pico_add_extra_outputs(police_colors) diff --git a/README.md b/README.md new file mode 100644 index 0000000..613616d --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +> [!NOTE] +> If we want to use clangd, we need to modify the cmake command like so: +> `cmake -DCMAKE_BUILD_TYPE=Debug -DPICO_BOARD=pico ..` +> clangd needs the option `--query-driver=/usr/bin/arm-none-eabi-g*` to process includes properly, which cannot be set in the .clangd file due to security issues. This needs to be added to the lsp config. + +> [!NOTE] +> Enable debug symbols with `make -j4` + +> [!NOTE] +> Run `echo "adapter speed 10000" | nc localhost 4444` once (after starting the openocd server with `openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg`) to get faster upload speeds + +`tio /dev/ttyACM#` to monitor UART diff --git a/debug.fish b/debug.fish new file mode 100755 index 0000000..3730769 --- /dev/null +++ b/debug.fish @@ -0,0 +1,6 @@ +#!/bin/fish +cd build +#cmake -DCMAKE_BUILD_TYPE=Debug -DPICO_BOARD=pico .. +make -j4 +#echo "adapter speed 10000" | nc localhost 4444 +echo "program build/police_colors.elf verify reset" | nc -N localhost 4444 &>/dev/null diff --git a/pico_sdk_import.cmake b/pico_sdk_import.cmake new file mode 100644 index 0000000..a0721d0 --- /dev/null +++ b/pico_sdk_import.cmake @@ -0,0 +1,84 @@ +# 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 () + +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}) diff --git a/police_colors.c b/police_colors.c new file mode 100644 index 0000000..251bca0 --- /dev/null +++ b/police_colors.c @@ -0,0 +1,62 @@ +#include "pico/stdlib.h" +#include +#include + +#define LED_DELAY_MS 80 +#define LED_WHITE 2 +#define LED_BLUE 3 +#define LED_GREEN 4 +#define LED_RED 5 + +int pico_led_init(void) { + gpio_init(PICO_DEFAULT_LED_PIN); + gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT); + gpio_init(LED_WHITE); + gpio_set_dir(LED_WHITE, GPIO_OUT); + gpio_init(LED_BLUE); + gpio_set_dir(LED_BLUE, GPIO_OUT); + gpio_init(LED_GREEN); + gpio_set_dir(LED_GREEN, GPIO_OUT); + gpio_init(LED_RED); + gpio_set_dir(LED_RED, GPIO_OUT); + return PICO_OK; +} + +void pico_set_led(bool led_on) {} + +int main() { + int rc = pico_led_init(); + hard_assert(rc == PICO_OK); + + // Set up our UART with the required speed. + stdio_uart_init(); + + // Normally, a call to sleep_ms would freeze the device + // while connected to a debugger. We could use busy_wait_ms + // as a work-around, but we'll disable this feature instead. + timer_get_instance(0)->dbgpause = 0; + + gpio_put(PICO_DEFAULT_LED_PIN, true); + + for (int i = 0; i < 1000000; i++) { + // Send out a string, with CR/LF conversions + printf("BEEP BOOP POLICE!!! %d \n\r", i); + gpio_put(LED_RED, true); + sleep_ms(2); + gpio_put(LED_RED, false); + sleep_ms(LED_DELAY_MS); + gpio_put(LED_RED, true); + sleep_ms(2); + gpio_put(LED_RED, false); + sleep_ms(LED_DELAY_MS); + gpio_put(LED_BLUE, true); + sleep_ms(2); + gpio_put(LED_BLUE, false); + sleep_ms(LED_DELAY_MS); + gpio_put(LED_BLUE, true); + sleep_ms(2); + gpio_put(LED_BLUE, false); + sleep_ms(LED_DELAY_MS); + } + return 0; +} diff --git a/test.fish b/test.fish new file mode 100755 index 0000000..16198d3 --- /dev/null +++ b/test.fish @@ -0,0 +1,5 @@ +#!/bin/fish +cd build +make +#echo "adapter speed 10000" | nc localhost 4444 +echo "program build/police_colors.elf verify reset" | nc -N localhost 4444 &>/dev/null