changeset 0:a55e39064a71

First commit of code that compiles. Does nothing like it should but has cmake goo to wrap dat files
author Daniel O'Connor <darius@dons.net.au>
date Mon, 29 Mar 2021 13:48:34 +1030
parents
children b9ec45077bff
files .hgignore CMakeLists.txt dac.pio local.cmake modulator.c pico_sdk_import.cmake sgauss.dat shaped-trap.dat
diffstat 8 files changed, 254 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore	Mon Mar 29 13:48:34 2021 +1030
@@ -0,0 +1,1 @@
+build
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CMakeLists.txt	Mon Mar 29 13:48:34 2021 +1030
@@ -0,0 +1,42 @@
+cmake_minimum_required(VERSION 3.12)
+
+# Change your executable name to something creative!
+set(NAME modulator)
+
+include(pico_sdk_import.cmake)
+include(local.cmake)
+
+# Gooey boilerplate
+project(${NAME} C CXX ASM)
+set(CMAKE_C_STANDARD 11)
+set(CMAKE_CXX_STANDARD 17)
+
+# Initialize the SDK
+pico_sdk_init()
+
+add_executable(${NAME}
+    modulator.c
+)
+
+pico_generate_pio_header(${NAME} ${CMAKE_CURRENT_LIST_DIR}/dac.pio)
+
+target_link_libraries(${NAME}
+		pico_stdlib
+		hardware_pio
+)
+
+bin2elf(${NAME} shaped-trap.dat)
+bin2elf(${NAME} sgauss.dat)
+
+# create map/bin/hex file etc.
+pico_add_extra_outputs(${NAME})
+
+# Set up files for the release packages
+install(FILES
+    ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.uf2
+    DESTINATION .
+)
+
+set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF)
+set(CPACK_GENERATOR "ZIP" "TGZ")
+include(CPack)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dac.pio	Mon Mar 29 13:48:34 2021 +1030
@@ -0,0 +1,51 @@
+;
+; Copyright (c) 2021 Raspberry Pi (Trading) Ltd.
+;
+; SPDX-License-Identifier: BSD-3-Clause
+;
+
+.program dac
+
+; Sample bits using an external clock, and push groups of bits into the RX FIFO.
+; - IN pin 0 is the data pin
+; - IN pin 1 is the clock pin
+; - Autopush is enabled, threshold 8
+;
+; This program samples data with each rising clock edge (like mode 0 or mode 3
+; SPI). The data is actually sampled one system clock cycle after the rising
+; edge is observed, so a clock ratio of at least input_clk < clk_sys / 6 is
+; recommended for good sampling alignment.
+
+    wait 0 pin 1
+    wait 1 pin 1
+    in pins, 1
+
+% c-sdk {
+static inline void dac_program_init(PIO pio, uint sm, uint offset, uint pin) {
+    pio_sm_config c = dac_program_get_default_config(offset);
+
+    // Set the IN base pin to the provided `pin` parameter. This is the data
+    // pin, and the next-numbered GPIO is used as the clock pin.
+    sm_config_set_in_pins(&c, pin);
+    // Set the pin directions to input at the PIO
+    pio_sm_set_consecutive_pindirs(pio, sm, pin, 2, false);
+    // Connect these GPIOs to this PIO block
+    pio_gpio_init(pio, pin);
+    pio_gpio_init(pio, pin + 1);
+
+    // Shifting to left matches the customary MSB-first ordering of SPI.
+    sm_config_set_in_shift(
+        &c,
+        false, // Shift-to-right = false (i.e. shift to left)
+        true,  // Autopush enabled
+        8      // Autopush threshold = 8
+    );
+
+    // We only receive, so disable the TX FIFO to make the RX FIFO deeper.
+    sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_RX);
+
+    // Load our configuration, and start the program from the beginning
+    pio_sm_init(pio, sm, offset, &c);
+    pio_sm_set_enabled(pio, sm, true);
+}
+%}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/local.cmake	Mon Mar 29 13:48:34 2021 +1030
@@ -0,0 +1,33 @@
+function(bin2elf TARGET BINFILE)
+    cmake_parse_arguments(bin2elf "" "OUTPUT_DIR" "" ${ARGN})
+    set(FILENAME "${CMAKE_SOURCE_DIR}/${BINFILE}")
+    set(ELFNAME "${CMAKE_CURRENT_BINARY_DIR}/${BINFILE}.o")
+    #message("FILENAME ${FILENAME} ELFNAME ${ELFNAME}")
+
+    # Not sure why but we can't depend directly, have to create this intermediary
+    # Copied idea from pico_generate_pio_header
+    get_filename_component(BIN_GEN_TARGET ${BINFILE} NAME_WE)
+    set(BIN_GEN_TARGET "${TARGET}_${BIN_GEN_TARGET}")
+    add_custom_target(${BIN_GEN_TARGET} DEPENDS ${ELFNAME})
+
+    # Create symbol name for bin file
+    string(MAKE_C_IDENTIFIER ${BINFILE} BIN_SYMNAME)
+    #message("BINFILE ${BINFILE} BIN_SYMNAME ${BIN_SYMNAME}")
+
+    # Get directory name of source file
+    # ld will name the symbol based on the full path so we have to mangle it
+    get_filename_component(BIN_SRC_DIR ${FILENAME} DIRECTORY)
+    string(REPLACE "/" "_" SRC_DIRNAME_MANGLED ${BIN_SRC_DIR})
+    #message("SRC_DIRNAME_MANGLED ${SRC_DIRNAME_MANGLED}")
+
+    add_custom_command(OUTPUT ${ELFNAME}
+      COMMAND arm-none-eabi-ld -r -b binary -o ${ELFNAME}
+ --defsym=${BIN_SYMNAME}_start=_binary_${SRC_DIRNAME_MANGLED}_${BIN_SYMNAME}_start
+ --defsym=${BIN_SYMNAME}_size=_binary_${SRC_DIRNAME_MANGLED}_${BIN_SYMNAME}_size
+ ${FILENAME}
+        DEPENDS ${FILENAME})
+    add_dependencies(${TARGET} ${BIN_GEN_TARGET})
+
+    # Add object file to list of things to be linked
+    target_link_libraries(${TARGET} ${CMAKE_CURRENT_BINARY_DIR}/${ELFNAME})
+endfunction()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modulator.c	Mon Mar 29 13:48:34 2021 +1030
@@ -0,0 +1,65 @@
+/******************************************************************
+*******************************************************************
+**
+** This is proprietary unpublished source code, property
+** of Genesis Software.  Use or disclosure without prior
+** agreement is expressly prohibited.
+**
+** Copyright (c) 2021 Genesis Software, all rights reserved.
+**
+*******************************************************************
+ ******************************************************************/
+
+/*
+** MODULATOR.C
+**
+** Create modulation shape
+**
+*/
+
+#include "pico/stdlib.h"
+#include "hardware/clocks.h"
+#include "hardware/pio.h"
+
+#include "dac.pio.h"
+
+extern void* shaped_trap_dat_size;
+extern void* shaped_trap_dat_start;
+
+extern void* sgauss_dat_size;
+extern void* sgauss_dat_start;
+
+int
+main() {
+    int i;
+    const uint LED_PIN = PICO_DEFAULT_LED_PIN;
+
+    stdio_init_all();
+
+    gpio_init(LED_PIN);
+    gpio_set_dir(LED_PIN, GPIO_OUT);
+
+    // Load the clocked_input program, and configure a free state machine
+    // to run the program.
+    PIO pio = pio0;
+    uint offset = pio_add_program(pio, &dac_program);
+    uint sm = pio_claim_unused_sm(pio, true);
+    dac_program_init(pio, sm, offset, 4);
+
+    while (true) {
+	for (i = 0; i < (int)&shaped_trap_dat_size; i++) {
+	    if (*(uint8_t *)shaped_trap_dat_start)
+		gpio_put(LED_PIN, 1);
+	    else
+		gpio_put(LED_PIN, 0);
+	    sleep_ms(250);
+	}
+	for (i = 0; i < (int)&sgauss_dat_size; i++) {
+	    if (*(uint8_t *)sgauss_dat_start)
+		gpio_put(LED_PIN, 1);
+	    else
+		gpio_put(LED_PIN, 0);
+	    sleep_ms(250);
+	}
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pico_sdk_import.cmake	Mon Mar 29 13:48:34 2021 +1030
@@ -0,0 +1,62 @@
+# 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 ()
+
+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 ()
+
+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")
+
+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("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})
Binary file sgauss.dat has changed
Binary file shaped-trap.dat has changed