├── .github ├── FUNDING.yml └── workflows │ ├── audio-test.yml │ ├── basic-test.yml │ ├── eeprom-test.yml │ ├── spi-test.yml │ └── vector.yml ├── .gitignore ├── .vscode ├── cmake-kits.json └── settings.json ├── CMakeLists.include.txt ├── LICENSE ├── README.md └── tests ├── audio ├── CMakeLists.txt └── audio.cpp ├── basic ├── CMakeLists.txt └── basic.cpp ├── eeprom ├── .vscode │ ├── cmake-kits.json │ └── settings.json ├── CMakeLists.txt └── eepromapp.cpp ├── spi ├── .vscode │ ├── cmake-kits.json │ └── settings.json ├── CMakeLists.txt └── spiapp.cpp ├── teensy41.toolchain.cmake └── vector ├── CMakeLists.txt └── vector.cpp /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [newdigate] 2 | patreon: teensy_eurorack 3 | custom: ["paypal.me/nicnewdigate"] 4 | -------------------------------------------------------------------------------- /.github/workflows/audio-test.yml: -------------------------------------------------------------------------------- 1 | name: audio-test 2 | on: 3 | push: 4 | paths: 5 | - '**' 6 | - '!**.md' 7 | 8 | jobs: 9 | build: 10 | 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - uses: actions/checkout@v2 15 | 16 | - name: download toolchain 17 | run: | 18 | curl -L "https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2019q4/RC2.1/gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2" --output /tmp/gcc-arm-none-eabi.tar.bz2 19 | mkdir -p /opt 20 | cd /opt 21 | tar xjf /tmp/gcc-arm-none-eabi.tar.bz2 22 | rm /tmp/gcc-arm-none-eabi.tar.bz2 23 | echo "/opt/gcc-arm-none-eabi-9-2019-q4-major/bin" 24 | 25 | - name: build 26 | run: cd tests/audio && mkdir cmake-build-debug && cd cmake-build-debug && cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE:FILEPATH=../teensy41.toolchain.cmake -Wno-dev .. && make -------------------------------------------------------------------------------- /.github/workflows/basic-test.yml: -------------------------------------------------------------------------------- 1 | name: basic-test 2 | on: 3 | push: 4 | paths: 5 | - '**' 6 | - '!**.md' 7 | 8 | jobs: 9 | build: 10 | 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - uses: actions/checkout@v2 15 | 16 | - name: download toolchain 17 | run: | 18 | curl -L "https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2019q4/RC2.1/gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2" --output /tmp/gcc-arm-none-eabi.tar.bz2 19 | mkdir -p /opt 20 | cd /opt 21 | tar xjf /tmp/gcc-arm-none-eabi.tar.bz2 22 | rm /tmp/gcc-arm-none-eabi.tar.bz2 23 | echo "/opt/gcc-arm-none-eabi-9-2019-q4-major/bin" 24 | 25 | - name: build 26 | run: cd tests/basic && mkdir cmake-build-debug && cd cmake-build-debug && cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE:FILEPATH=../teensy41.toolchain.cmake -Wno-dev .. && make -------------------------------------------------------------------------------- /.github/workflows/eeprom-test.yml: -------------------------------------------------------------------------------- 1 | name: eeprom-test 2 | on: 3 | push: 4 | paths: 5 | - '**' 6 | - '!**.md' 7 | 8 | jobs: 9 | build: 10 | 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - uses: actions/checkout@v2 15 | 16 | - name: download toolchain 17 | run: | 18 | curl -L "https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2019q4/RC2.1/gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2" --output /tmp/gcc-arm-none-eabi.tar.bz2 19 | mkdir -p /opt 20 | cd /opt 21 | tar xjf /tmp/gcc-arm-none-eabi.tar.bz2 22 | rm /tmp/gcc-arm-none-eabi.tar.bz2 23 | echo "/opt/gcc-arm-none-eabi-9-2019-q4-major/bin" 24 | 25 | - name: build 26 | run: cd tests/eeprom && mkdir cmake-build-debug && cd cmake-build-debug && cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE:FILEPATH=../teensy41.toolchain.cmake -Wno-dev .. && make -------------------------------------------------------------------------------- /.github/workflows/spi-test.yml: -------------------------------------------------------------------------------- 1 | name: spi-test 2 | on: 3 | push: 4 | paths: 5 | - '**' 6 | - '!**.md' 7 | 8 | jobs: 9 | build: 10 | 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - uses: actions/checkout@v2 15 | 16 | - name: download toolchain 17 | run: | 18 | curl -L "https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2019q4/RC2.1/gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2" --output /tmp/gcc-arm-none-eabi.tar.bz2 19 | mkdir -p /opt 20 | cd /opt 21 | tar xjf /tmp/gcc-arm-none-eabi.tar.bz2 22 | rm /tmp/gcc-arm-none-eabi.tar.bz2 23 | echo "/opt/gcc-arm-none-eabi-9-2019-q4-major/bin" 24 | 25 | - name: build 26 | run: cd tests/spi && mkdir cmake-build-debug && cd cmake-build-debug && cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE:FILEPATH=../teensy41.toolchain.cmake -Wno-dev .. && make -------------------------------------------------------------------------------- /.github/workflows/vector.yml: -------------------------------------------------------------------------------- 1 | name: vector-test 2 | on: 3 | push: 4 | paths: 5 | - '**' 6 | - '!**.md' 7 | 8 | jobs: 9 | build: 10 | 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - uses: actions/checkout@v2 15 | 16 | - name: download toolchain 17 | run: | 18 | curl -L "https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2019q4/RC2.1/gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2" --output /tmp/gcc-arm-none-eabi.tar.bz2 19 | mkdir -p /opt 20 | cd /opt 21 | tar xjf /tmp/gcc-arm-none-eabi.tar.bz2 22 | rm /tmp/gcc-arm-none-eabi.tar.bz2 23 | echo "/opt/gcc-arm-none-eabi-9-2019-q4-major/bin" 24 | 25 | - name: build 26 | run: cd tests/vector && mkdir cmake-build-debug && cd cmake-build-debug && cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE:FILEPATH=../teensy41.toolchain.cmake -Wno-dev .. && make -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | cmake-build-debug 2 | cmake-build-release 3 | -------------------------------------------------------------------------------- /.vscode/cmake-kits.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "Teensy-4.1", 4 | "toolchainFile": "${workspaceFolder}/tests/teensy41.toolchain.cmake" 5 | } 6 | ] -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "cmake.generator": "Unix Makefiles" 3 | } -------------------------------------------------------------------------------- /CMakeLists.include.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | # * you will need to define the following properies: (frmo https://github.com/newdigate/teensy-cmake-macros) 3 | #set(TEENSY_VERSION 41 CACHE STRING "Set to the Teensy version corresponding to your board (40 or 41 allowed)" FORCE) 4 | #set(CPU_CORE_SPEED 600000000 CACHE STRING "Set to 24000000, 48000000, 72000000 or 96000000 to set CPU core speed" FORCE) # Derived variables 5 | #set(COMPILERPATH "/opt/gcc-arm-none-eabi-9-2019-q4-major/bin/") 6 | 7 | include(FetchContent) 8 | FetchContent_Declare(teensy_cores 9 | GIT_REPOSITORY https://github.com/PaulStoffregen/cores 10 | GIT_TAG master 11 | ) 12 | FetchContent_MakeAvailable(teensy_cores) 13 | # * core path will be set as below by default. you can change if necessary 14 | set(COREPATH "${teensy_cores_SOURCE_DIR}/teensy4/") 15 | 16 | if (APPLE) 17 | set(CMAKE_OSX_SYSROOT "") 18 | endif() 19 | 20 | # ignore cmake macro idf_component_register 21 | macro(idf_component_register) 22 | return() 23 | endmacro() 24 | 25 | if (PROJECT_IS_TOP_LEVEL) 26 | set(Arduino_libraries_List "" CACHE INTERNAL "") 27 | endif () 28 | 29 | # static configuration 30 | set(runtime_ide_version 159) 31 | set(arduino_ide_version 10607) 32 | set(build_command_gcc arm-none-eabi-gcc) 33 | set(build_command_g++ arm-none-eabi-g++) 34 | set(build_command_ar arm-none-eabi-gcc-ar) 35 | set(build_command_objcopy arm-none-eabi-objcopy) 36 | set(build_command_objdump arm-none-eabi-objdump) 37 | set(build_command_linker arm-none-eabi-gcc) 38 | set(build_command_size arm-none-eabi-size) 39 | set(CMAKE_SYSTEM_NAME Generic) 40 | SET(CMAKE_CXX_ARCHIVE_CREATE "${COMPILERPATH}/${build_command_ar} rcs ") 41 | SET(CMAKE_C_ARCHIVE_CREATE "${COMPILERPATH}/${build_command_ar} rcs ") 42 | 43 | function(teensy_set_dynamic_properties) 44 | if (NOT DEFINED teensy_set_dynamic_properties_has_executed) 45 | set(teensy_set_dynamic_properties_has_executed 1 CACHE INTERNAL "teensy_set_dynamic_properties_has_executed") 46 | message(STATUS "teensy_set_dynamic_properties()") 47 | 48 | if (NOT DEFINED CPU_CORE_SPEED) 49 | message(FATAL_ERROR "CPU_CORE_SPEED is UNDEFINED") 50 | else() 51 | message(STATUS "CPU_CORE_SPEED: ${CPU_CORE_SPEED}") 52 | endif() 53 | 54 | set(build_fcpu ${CPU_CORE_SPEED}) 55 | 56 | if (NOT DEFINED COMPILERPATH) 57 | message(FATAL_ERROR "COMPILERPATH is UNDEFINED") 58 | else() 59 | message(STATUS "COMPILERPATH: ${COMPILERPATH}") 60 | endif() 61 | 62 | set(build_toolchain ${COMPILERPATH}) 63 | 64 | if (NOT DEFINED ${build_usbtype}) 65 | set(build_usbtype USB_SERIAL) 66 | set(build_usbtype ${build_usbtype} CACHE INTERNAL "build_usbtype") 67 | message(STATUS "build_usbtype: ${build_usbtype}" ) 68 | endif() 69 | 70 | if (NOT DEFINED ${build_usbtype}) 71 | set(build_keylayout US_ENGLISH) 72 | set(build_keylayout ${build_keylayout} CACHE INTERNAL "build_keylayout") 73 | message(STATUS "build_keylayout: ${build_keylayout}" ) 74 | endif() 75 | 76 | if(TEENSY_VERSION EQUAL 40) 77 | set(CPU_DEFINE __IMXRT1062__) 78 | set(LINKER_FILE ${COREPATH}imxrt1062.ld) 79 | set(build_board TEENSY40) 80 | set(build_flags_ld "-nostdlib -Wl,--gc-sections,--relax ") 81 | set(build_core teensy4) 82 | set(build_mcu imxrt1062) 83 | set(build_warn_data_percentage 99) 84 | set(build_flags_common "-g -Wall -ffunction-sections -fdata-sections ") 85 | set(build_flags_dep "-MMD") 86 | set(build_flags_optimize "-Os") 87 | set(build_flags_cpu "-mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 ") 88 | set(build_flags_defs "-D${CPU_DEFINE} -DTEENSYDUINO=159 ") 89 | set(build_flags_cpp "-std=gnu++17 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing") 90 | set(build_flags_c "") 91 | set(build_flags_S "-x assembler-with-cpp") 92 | set(build_flags_libs "-lm") 93 | elseif(TEENSY_VERSION EQUAL 41) 94 | message(STATUS "building for teensy 4.1") 95 | set(CPU_DEFINE __IMXRT1062__) 96 | set(LINKER_FILE ${COREPATH}imxrt1062_t41.ld) 97 | set(build_board TEENSY41) 98 | set(build_flags_ld " -Wl,--gc-sections,--relax ") 99 | set(build_core teensy4) 100 | set(build_mcu imxrt1062) 101 | set(build_warn_data_percentage 99) 102 | set(build_flags_common "-g -Wall -ffunction-sections -fdata-sections ") 103 | set(build_flags_dep "-MMD") 104 | set(build_flags_optimize "-O2") 105 | set(build_flags_cpu "-mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 ") 106 | set(build_flags_defs "-D${CPU_DEFINE} -DTEENSYDUINO=159 ") 107 | set(build_flags_cpp "-std=gnu++17 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing") 108 | set(build_flags_c "") 109 | set(build_flags_S "-x assembler-with-cpp") 110 | #set(build_flags_libs "-larm_cortexM7lfsp_math -lm -lstdc++") 111 | set(build_flags_libs "-lm") 112 | else() 113 | message(FATAL_ERROR "Teensy version not defined") 114 | endif() 115 | 116 | # search for programs in the build host directories 117 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER CACHE INTERNAL "CMAKE_FIND_ROOT_PATH_MODE_PROGRAM") 118 | 119 | # for libraries and headers in the target directories 120 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY CACHE INTERNAL "CMAKE_FIND_ROOT_PATH_MODE_LIBRARY") 121 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY CACHE INTERNAL "CMAKE_FIND_ROOT_PATH_MODE_INCLUDE") 122 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY CACHE INTERNAL "CMAKE_FIND_ROOT_PATH_MODE_PACKAGE") 123 | 124 | set(CPP_COMPILE_FLAGS "${build_flags_optimize} ${build_flags_common} ${build_flags_dep} ${build_flags_cpp} ${build_flags_cpu} ${build_flags_defs} -DARDUINO=${arduino_ide_version} -DARDUINO_${build_board} -DF_CPU=${build_fcpu} -D${build_usbtype} -DLAYOUT_${build_keylayout}") 125 | set(C_COMPILE_FLAGS "${build_flags_optimize} ${build_flags_common} ${build_flags_dep} ${build_flags_c} ${build_flags_cpu} ${build_flags_defs} -DARDUINO=${arduino_ide_version} -DARDUINO_${build_board} -DF_CPU=${build_fcpu} -D${build_usbtype} -DLAYOUT_${build_keylayout}") 126 | set(S_COMPILE_FLAGS "${build_flags_optimize} ${build_flags_common} ${build_flags_dep} ${build_flags_S} ${build_flags_cpu} ${build_flags_defs} -DARDUINO=${arduino_ide_version} -DARDUINO_${build_board} -DF_CPU=${build_fcpu} -D${build_usbtype} -DLAYOUT_${build_keylayout}") 127 | set(LINK_FLAGS "${build_flags_optimize} ${build_flags_ld} ${build_flags_ldspecs} ${build_flags_cpu} -T${LINKER_FILE} ${build_flags_libs}") 128 | 129 | set(CPP_COMPILE_FLAGS ${CPP_COMPILE_FLAGS} CACHE INTERNAL "CPP_COMPILE_FLAGS") 130 | set(C_COMPILE_FLAGS ${C_COMPILE_FLAGS} CACHE INTERNAL "C_COMPILE_FLAGS") 131 | set(S_COMPILE_FLAGS ${S_COMPILE_FLAGS} CACHE INTERNAL "S_COMPILE_FLAGS") 132 | set(LINK_FLAGS ${LINK_FLAGS} CACHE INTERNAL "LINK_FLAGS") 133 | 134 | #message(STATUS "S_COMPILE_FLAGS: ${S_COMPILE_FLAGS}") 135 | #message(STATUS "CPP_COMPILE_FLAGS: ${CPP_COMPILE_FLAGS}") 136 | endif() 137 | endfunction() 138 | 139 | function(import_teensy_cores) 140 | message(STATUS "import_teensy_cores()") 141 | 142 | file(GLOB_RECURSE TEENSY_C_FILES ABSOLUTE ${COREPATH}**.c) 143 | foreach(SOURCE_C ${TEENSY_C_FILES}) 144 | set_source_files_properties(${SOURCE_C} PROPERTIES COMPILE_FLAGS "${C_COMPILE_FLAGS}") 145 | #message(STATUS " .c: ${SOURCE_C} ${C_COMPILE_FLAGS}") 146 | endforeach(SOURCE_C ${SOURCES_C}) 147 | 148 | file(GLOB_RECURSE TEENSY_CPP_FILES ${COREPATH}**.cpp) 149 | foreach(SOURCE_CPP ${TEENSY_CPP_FILES}) 150 | set_source_files_properties(${SOURCE_CPP} PROPERTIES COMPILE_FLAGS "${CPP_COMPILE_FLAGS}") 151 | #message(STATUS " .cpp: ${SOURCE_CPP} ${CPP_COMPILE_FLAGS}") 152 | endforeach(SOURCE_CPP ${SOURCES_CPP}) 153 | 154 | set(TEENSY_SOURCES ${TEENSY_C_FILES} ${TEENSY_CPP_FILES} PARENT_SCOPE) 155 | endfunction() 156 | 157 | # Macros to wrap add_[executable|library] for seamless Teensy integration 158 | function(teensy_add_executable TARGET) 159 | 160 | message(STATUS "teensy_add_executable(${TARGET} ${ARGN})") 161 | 162 | teensy_set_dynamic_properties() 163 | 164 | set(ELFTARGET ${TARGET}.elf) 165 | foreach(arg IN LISTS ARGN) 166 | file(GLOB TEST_SOURCE RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${arg}) 167 | list(FILTER TEST_SOURCE INCLUDE REGEX ".cpp$") 168 | set(TEENSY_EXE_CPP_SOURCES ${TEENSY_EXE_CPP_SOURCES} ${TEST_SOURCE}) 169 | 170 | file(GLOB INO_SOURCE RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${arg}) 171 | list(FILTER INO_SOURCE INCLUDE REGEX ".ino$") 172 | set(TEENSY_EXE_INO_SOURCES ${TEENSY_EXE_INO_SOURCES} ${INO_SOURCE}) 173 | endforeach() 174 | 175 | foreach(SOURCE_CPP ${TEENSY_EXE_CPP_SOURCES}) 176 | set_source_files_properties(${SOURCE_CPP} PROPERTIES COMPILE_FLAGS "${CPP_COMPILE_FLAGS} ${INCLUDE_DIRECTORIES}") 177 | endforeach(SOURCE_CPP ${TEENSY_EXE_CPP_SOURCES}) 178 | 179 | #foreach(SOURCE_C ${TEENSY_LIB_C_SOURCES}) 180 | # set_source_files_properties(${SOURCE_C} PROPERTIES COMPILE_FLAGS "${C_COMPILE_FLAGS} ${INCLUDE_DIRECTORIES}") 181 | #endforeach(SOURCE_C ${TEENSY_LIB_C_SOURCES}) 182 | 183 | #foreach(SOURCE_S ${TEENSY_LIB_S_SOURCES}) 184 | # set_property(SOURCE ${SOURCE_S} PROPERTY LANGUAGE C) 185 | # set_source_files_properties(${SOURCE_S} PROPERTIES COMPILE_FLAGS "${S_COMPILE_FLAGS} ${INCLUDE_DIRECTORIES}") 186 | #endforeach(SOURCE_S ${TEENSY_LIB_S_SOURCES}) 187 | 188 | foreach(SOURCE_INO ${TEENSY_EXE_INO_SOURCES}) 189 | set_property(SOURCE ${SOURCE_INO} PROPERTY LANGUAGE CXX) 190 | set_source_files_properties(${SOURCE_INO} PROPERTIES COMPILE_FLAGS "${CPP_COMPILE_FLAGS} ${INCLUDE_DIRECTORIES} -x c++") 191 | endforeach(SOURCE_INO ${TEENSY_EXE_INO_SOURCES}) 192 | 193 | add_executable(${ELFTARGET} ${ARGN}) 194 | # add_executable(${ELFTARGET} ${ARGN} ${TEENSY_SOURCES} ${TEENSY_LIB_CPP_SOURCES} ${TEENSY_LIB_C_SOURCES} ${TEENSY_LIB_S_SOURCES}) 195 | 196 | set_target_properties(${ELFTARGET} PROPERTIES INCLUDE_DIRECTORIES "${COREPATH}") 197 | set_target_properties(${ELFTARGET} PROPERTIES LINK_FLAGS "${LINK_FLAGS}") 198 | 199 | add_custom_command(OUTPUT ${TARGET}.hex 200 | COMMAND ${COMPILERPATH}arm-none-eabi-size ${ELFTARGET} 201 | COMMAND ${COMPILERPATH}arm-none-eabi-objcopy -O ihex -R .eeprom ${ELFTARGET} ${TARGET}.hex 202 | DEPENDS ${ELFTARGET} 203 | COMMENT "Creating HEX file for ${ELFTARGET}") 204 | 205 | add_custom_target(${TARGET}_hex ALL DEPENDS ${TARGET}.hex) 206 | endfunction() 207 | 208 | function(teensy_add_library TARGET) 209 | message(STATUS "teensy_add_library(${TARGET} ${ARGN})") 210 | 211 | teensy_set_dynamic_properties() 212 | 213 | set(ELFTARGET ${TARGET}.o) 214 | 215 | set(TEENSY_LIB_CPP_SOURCES "") 216 | set(TEENSY_LIB_C_SOURCES "") 217 | set(TEENSY_LIB_S_SOURCES "") 218 | 219 | foreach(arg ${ARGN}) 220 | file(GLOB TEST_CPP_SOURCE RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${arg}) 221 | list(FILTER TEST_CPP_SOURCE INCLUDE REGEX ".cpp$") 222 | set(TEENSY_LIB_CPP_SOURCES ${TEENSY_LIB_CPP_SOURCES} ${TEST_CPP_SOURCE}) 223 | 224 | file(GLOB TEST_C_SOURCE RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${arg}) 225 | list(FILTER TEST_C_SOURCE INCLUDE REGEX ".c$") 226 | set(TEENSY_LIB_C_SOURCES ${TEENSY_LIB_C_SOURCES} ${TEST_C_SOURCE}) 227 | 228 | file(GLOB TEST_S_SOURCE RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${arg}) 229 | list(FILTER TEST_S_SOURCE INCLUDE REGEX ".S$") 230 | set(TEENSY_LIB_S_SOURCES ${TEENSY_LIB_S_SOURCES} ${TEST_S_SOURCE}) 231 | endforeach() 232 | #message(STATUS TEENSY_LIB_S_SOURCES: ${TEENSY_LIB_S_SOURCES}) 233 | #message(STATUS TEENSY_LIB_C_SOURCES: ${TEENSY_LIB_C_SOURCES}) 234 | #message(STATUS TEENSY_LIB_CPP_SOURCES: ${TEENSY_LIB_CPP_SOURCES}) 235 | 236 | foreach(SOURCE_CPP ${TEENSY_LIB_CPP_SOURCES}) 237 | set_source_files_properties(${SOURCE_CPP} PROPERTIES COMPILE_FLAGS "${CPP_COMPILE_FLAGS} ${INCLUDE_DIRECTORIES}") 238 | endforeach(SOURCE_CPP ${SOURCES_CPP}) 239 | 240 | foreach(SOURCE_C ${TEENSY_LIB_C_SOURCES}) 241 | set_source_files_properties(${SOURCE_C} PROPERTIES COMPILE_FLAGS "${C_COMPILE_FLAGS} ${INCLUDE_DIRECTORIES}") 242 | endforeach(SOURCE_C ${SOURCES_C}) 243 | 244 | foreach(SOURCE_S ${TEENSY_LIB_S_SOURCES}) 245 | set_property(SOURCE ${SOURCE_S} PROPERTY LANGUAGE C) 246 | set_source_files_properties(${SOURCE_S} PROPERTIES COMPILE_FLAGS "${S_COMPILE_FLAGS} ${INCLUDE_DIRECTORIES}") 247 | endforeach(SOURCE_S ${SOURCES_S}) 248 | 249 | if (("${TEENSY_SOURCES}" STREQUAL "") AND ("${TEENSY_LIB_CPP_SOURCES}" STREQUAL "") AND ("${TEENSY_LIB_C_SOURCES}" STREQUAL "") AND ("${TEENSY_LIB_S_SOURCES}" STREQUAL "")) 250 | message(WARN " Empty library (No sources - possibly a header-only library ) - ${TARGET} ") 251 | else() 252 | add_library(${ELFTARGET} STATIC ${ARGN} ${TEENSY_SOURCES} ${TEENSY_LIB_CPP_SOURCES} ${TEENSY_LIB_C_SOURCES} ${TEENSY_LIB_S_SOURCES}) 253 | if (COREPATH) 254 | set_target_properties(${ELFTARGET} PROPERTIES INCLUDE_DIRECTORIES ${COREPATH}) 255 | endif () 256 | set_target_properties(${ELFTARGET} PROPERTIES LINK_FLAGS "${LINK_FLAGS}") 257 | 258 | add_custom_command(OUTPUT ${TARGET}.hex 259 | COMMAND ${COMPILERPATH}arm-none-eabi-size ${ELFTARGET} 260 | COMMAND ${COMPILERPATH}arm-none-eabi-objcopy -O ihex -R .eeprom ${ELFTARGET} ${TARGET}.hex 261 | DEPENDS ${ELFTARGET} 262 | COMMENT "Creating HEX file for ${ELFTARGET}") 263 | endif() 264 | endfunction() 265 | 266 | macro(import_arduino_library LIB_NAME LIB_ROOT) 267 | if ("**${LIB_NAME}**" IN_LIST Arduino_libraries_List) 268 | #message(INFO "-- import_arduino_library -- ${LIB_NAME} is already imported...") 269 | else () 270 | list(APPEND Arduino_libraries_List "**${LIB_NAME}**") 271 | set(Arduino_libraries_List ${Arduino_libraries_List} CACHE INTERNAL "") 272 | message(STATUS "import_arduino_library(${LIB_NAME} ${LIB_ROOT} ${ARGN})") 273 | 274 | # Check if we can find the library. 275 | if(NOT EXISTS "${LIB_ROOT}") 276 | message(STATUS "Could not find the directory for library '${LIB_ROOT}' -- ignoring (its possible that the library is not used for the target you are calling) !!!!!") 277 | else() 278 | set(INCLUDE_DIRECTORIES "${INCLUDE_DIRECTORIES} -I${LIB_ROOT} ") 279 | include_directories("${LIB_ROOT}") 280 | 281 | set(IMPORT_LIB_CPP_SOURCES "") 282 | set(IMPORT_LIB_C_SOURCES "") 283 | set(IMPORT_LIB_S_SOURCES "") 284 | 285 | # Mark source files to be built along with the sketch code. 286 | file(GLOB SOURCES_CPP ABSOLUTE "${LIB_ROOT}/*.cpp") 287 | foreach(SOURCE_CPP ${SOURCES_CPP}) 288 | set(IMPORT_LIB_CPP_SOURCES ${IMPORT_LIB_CPP_SOURCES} ${SOURCE_CPP}) 289 | endforeach(SOURCE_CPP ${SOURCES_CPP}) 290 | 291 | file(GLOB SOURCES_C ABSOLUTE "${LIB_ROOT}/*.c") 292 | foreach(SOURCE_C ${SOURCES_C}) 293 | set(IMPORT_LIB_C_SOURCES ${IMPORT_LIB_C_SOURCES} ${SOURCE_C}) 294 | endforeach(SOURCE_C ${SOURCES_C}) 295 | 296 | file(GLOB SOURCES_S ABSOLUTE "${LIB_ROOT}/*.S") 297 | foreach(SOURCE_S ${SOURCES_S}) 298 | set(IMPORT_LIB_S_SOURCES ${IMPORT_LIB_S_SOURCES} ${SOURCE_S}) 299 | endforeach(SOURCE_S ${SOURCES_S}) 300 | 301 | foreach(arg ${ARGN}) 302 | #message(status " checking for ${LIB_ROOT}/${arg}") 303 | if(NOT EXISTS ${LIB_ROOT}/${arg}) 304 | message(FATAL_ERROR "Could not find the Arduino library directory ${LIB_ROOT}/${arg}") 305 | endif(NOT EXISTS ${LIB_ROOT}/${arg}) 306 | include_directories("${LIB_ROOT}/${arg}") 307 | set(INCLUDE_DIRECTORIES "${INCLUDE_DIRECTORIES} -I${LIB_ROOT}/${arg} ") 308 | 309 | # Mark source files to be built along with the sketch code. 310 | file(GLOB SOURCES_CPP ABSOLUTE "${LIB_ROOT}/${arg}/*.cpp") 311 | foreach(SOURCE_CPP ${SOURCES_CPP}) 312 | set(IMPORT_LIB_CPP_SOURCES ${IMPORT_LIB_CPP_SOURCES} ${SOURCE_CPP}) 313 | endforeach(SOURCE_CPP ${SOURCES_CPP}) 314 | 315 | file(GLOB SOURCES_C ABSOLUTE "${LIB_ROOT}/${arg}/*.c") 316 | foreach(SOURCE_C ${SOURCES_C}) 317 | set(IMPORT_LIB_C_SOURCES ${IMPORT_LIB_C_SOURCES} ${SOURCE_C}) 318 | endforeach(SOURCE_C ${SOURCES_C}) 319 | 320 | file(GLOB SOURCES_S ABSOLUTE "${LIB_ROOT}/${arg}/*.S") 321 | foreach(SOURCE_S ${SOURCES_S}) 322 | set(IMPORT_LIB_S_SOURCES ${IMPORT_LIB_S_SOURCES} ${SOURCE_S}) 323 | endforeach(SOURCE_S ${SOURCES_S}) 324 | endforeach() 325 | 326 | teensy_add_library(${LIB_NAME} ${IMPORT_LIB_CPP_SOURCES} ${IMPORT_LIB_C_SOURCES} ${IMPORT_LIB_S_SOURCES}) 327 | 328 | endif(NOT EXISTS "${LIB_ROOT}") 329 | endif () 330 | endmacro(import_arduino_library) 331 | 332 | macro(teensy_remove_sources LIB_DIR) 333 | file(GLOB_RECURSE FILES_TO_REMOVE ABSOLUTE "${LIB_DIR}/**.*") 334 | foreach(FILE_TO_REMOVE ${FILES_TO_REMOVE}) 335 | list(REMOVE_ITEM TEENSY_LIB_SOURCES ${FILE_TO_REMOVE}) 336 | message("REMOVED ${FILE_TO_REMOVE}") 337 | endforeach(FILE_TO_REMOVE ${FILES_TO_REMOVE}) 338 | endmacro(teensy_remove_sources) 339 | 340 | macro(teensy_include_directories) 341 | set(list_var "${ARGN}") 342 | foreach(loop_var IN LISTS list_var) 343 | set(INCLUDE_DIRECTORIES "${INCLUDE_DIRECTORIES} -I${CMAKE_CURRENT_SOURCE_DIR}/${loop_var} ") 344 | endforeach() 345 | endmacro(teensy_include_directories) 346 | 347 | macro(teensy_target_link_libraries TARGET) 348 | set(list_var "${ARGN}") 349 | foreach(loop_var IN LISTS list_var) 350 | target_link_libraries(${TARGET}.elf ${loop_var}.o) 351 | endforeach() 352 | endmacro(teensy_target_link_libraries) 353 | 354 | macro(import_arduino_library_git LIB_NAME LIB_URL LIB_BRANCH LIB_PATH) 355 | include(FetchContent) 356 | FetchContent_Declare(${LIB_NAME} 357 | GIT_REPOSITORY ${LIB_URL} 358 | GIT_TAG ${LIB_BRANCH} 359 | ) 360 | FetchContent_Populate(${LIB_NAME}) 361 | string(TOLOWER ${LIB_NAME} LIB_NAME_LOWER) 362 | set(LIB_ROOT "${${LIB_NAME_LOWER}_SOURCE_DIR}/${LIB_PATH}") 363 | 364 | # Check if we can find the library. 365 | if(NOT EXISTS "${LIB_ROOT}") 366 | message(STATUS "Could not find the directory for library '${LIB_ROOT}' -- ignoring (its possible that the library is not used for the target you are calling) !!!!!") 367 | else() 368 | import_arduino_library(${LIB_NAME} ${LIB_ROOT} ${ARGN}) 369 | endif(NOT EXISTS "${LIB_ROOT}") 370 | 371 | endmacro(import_arduino_library_git) 372 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Nic Newdigate 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # teensy cmake macros 2 | 3 | [![audio-test](https://github.com/newdigate/teensy-cmake-macros/actions/workflows/audio-test.yml/badge.svg)](https://github.com/newdigate/teensy-cmake-macros/actions/workflows/audio-test.yml) 4 | [![basic-test](https://github.com/newdigate/teensy-cmake-macros/actions/workflows/basic-test.yml/badge.svg)](https://github.com/newdigate/teensy-cmake-macros/actions/workflows/basic-test.yml) 5 | [![vector-test](https://github.com/newdigate/teensy-cmake-macros/actions/workflows/vector.yml/badge.svg)](https://github.com/newdigate/teensy-cmake-macros/actions/workflows/vector.yml) 6 | [![eeprom-test](https://github.com/newdigate/teensy-cmake-macros/actions/workflows/eeprom-test.yml/badge.svg)](https://github.com/newdigate/teensy-cmake-macros/actions/workflows/eeprom-test.yml) 7 | [![spi-test](https://github.com/newdigate/teensy-cmake-macros/actions/workflows/spi-test.yml/badge.svg)](https://github.com/newdigate/teensy-cmake-macros/actions/workflows/spi-test.yml) 8 | 9 | minimal dependency cmake toolchain to easily compile your teensy sketches and libraries, and optionally link with c++ std libraries. 10 | * custom teensy toolchain using ```cmake``` and ```arm-none-eabi-gcc``` 11 | * based on [ronj/teensy-cmake-template](https://github.com/ronj/teensy-cmake-template) 12 | * targetting Teensy 4.x, tested on Teensy 4.1 (should be easy to extend for 3.x) 13 | * compiles library code to .a archive files to avoid unnecessary recompiling 14 | 15 | # Usage 16 | * add a toolchain cmake file `cmake\toolchains\teensy41.cmake` 17 | * update ```COMPILERPATH``` to [arm-none-eabi-gcc](https://developer.arm.com/downloads/-/gnu-rm/10-3-2021-10) bin folder 18 | ```cmake 19 | set(TEENSY_VERSION 41 CACHE STRING "Set to the Teensy version corresponding to your board (30 or 31 allowed)" FORCE) 20 | set(CPU_CORE_SPEED 600000000 CACHE STRING "Set to 24000000, 48000000, 72000000 or 96000000 to set CPU core speed" FORCE) # Derived variables 21 | set(CMAKE_EXE_LINKER_FLAGS "--specs=nosys.specs" CACHE INTERNAL "") 22 | # set(CMAKE_EXE_LINKER_FLAGS "--specs=nano.specs" CACHE INTERNAL "") # if you plan on using std 23 | 24 | #teensy compiler options 25 | set(COMPILERPATH "/Applications/ARM/bin/") 26 | 27 | set(BUILD_FOR_TEENSY ON) 28 | set(CMAKE_SYSTEM_NAME Generic) 29 | set(CMAKE_SYSTEM_PROCESSOR arm) 30 | set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY") 31 | set(CMAKE_C_COMPILER ${COMPILERPATH}arm-none-eabi-gcc) 32 | set(CMAKE_CXX_COMPILER ${COMPILERPATH}arm-none-eabi-g++) 33 | set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_C_COMPILER} -o ") 34 | ``` 35 | * add include in your CMakeLists.txt file 36 | ```cmake 37 | include(FetchContent) 38 | FetchContent_Declare(teensy_cmake_macros 39 | GIT_REPOSITORY https://github.com/newdigate/teensy-cmake-macros 40 | GIT_TAG main 41 | ) 42 | FetchContent_MakeAvailable(teensy_cmake_macros) 43 | include(${teensy_cmake_macros_SOURCE_DIR}/CMakeLists.include.txt) 44 | ``` 45 | * specify toolchain file in cmake configuration stage 46 | ```shell 47 | > cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE:FILEPATH="../cmake/toolchains/teensy41.cmake` 48 | ``` 49 | 50 | # install build dependencies 51 | 52 | * [arm-none-eabi-gcc](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads) 53 | * [cmake](https://cmake.org/) 54 | 55 | # add CMakeLists.txt to your project root 56 | * create a ```CMakeLists.txt``` file in the root directory of your project 57 | ```cmake 58 | cmake_minimum_required(VERSION 3.5) 59 | project(midi_smf_reader C CXX) 60 | 61 | include(FetchContent) 62 | FetchContent_Declare(teensy_cmake_macros 63 | GIT_REPOSITORY https://github.com/newdigate/teensy-cmake-macros 64 | GIT_TAG main 65 | ) 66 | FetchContent_MakeAvailable(teensy_cmake_macros) 67 | include(${teensy_cmake_macros_SOURCE_DIR}/CMakeLists.include.txt) 68 | 69 | import_arduino_library(cores ${teensy_cores_SOURCE_DIR}/teensy4 avr util) 70 | 71 | import_arduino_library_git(SPI https://github.com/PaulStoffregen/SPI.git master "") 72 | import_arduino_library_git(SdFat https://github.com/PaulStoffregen/SdFat.git master "src" common DigitalIO ExFatLib FatLib FsLib iostream SdCard SpiDriver) 73 | import_arduino_library_git(SD https://github.com/PaulStoffregen/SD.git Juse_Use_SdFat src) 74 | import_arduino_library_git(Encoder https://github.com/PaulStoffregen/Encoder.git master "") 75 | import_arduino_library_git(Bounce2 https://github.com/PaulStoffregen/Bounce2.git master src) 76 | import_arduino_library_git(SerialFlash https://github.com/PaulStoffregen/SerialFlash.git master "" util) 77 | import_arduino_library_git(Wire https://github.com/PaulStoffregen/Wire.git master "" utility) 78 | import_arduino_library_git(arm_math https://github.com/PaulStoffregen/arm_math.git master src) 79 | import_arduino_library_git(TeensyGFX https://github.com/newdigate/teensy-gfx.git main src) 80 | 81 | # add custom library 82 | teensy_add_library(my_teensy_library my_teensy_library.cpp) 83 | 84 | # add custom executable 85 | teensy_add_executable(my_firmware sketch.ino) 86 | teensy_target_link_libraries(my_firmware my_teensy_library SD SdFat SPI cores) # order is IMPORTANT because we are garbage collecting symbols --gc-collect 87 | 88 | # if you need to link to std library (using , etc) 89 | set(CMAKE_EXE_LINKER_FLAGS "--specs=nano.specs" CACHE INTERNAL "") 90 | target_link_libraries(my_firmware.elf stdc++) 91 | ``` 92 | 93 | # build 94 | * run from a terminal in your repository root directory 95 | 96 | ```shell 97 | > mkdir cmake-build-debug 98 | > cd cmake-build-debug 99 | > cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE:FILEPATH="../cmake/toolchains/teensy41.toolchain.cmake" 100 | > make 101 | ``` 102 | 103 | ## detail 104 | * ```teensy_add_executable``` ( ```TARGET``` ```files...``` ) 105 | ```cmake 106 | teensy_add_executable(myapplication midiread.cpp) 107 | ``` 108 | * ```teensy_add_library``` ( ```TARGET``` ```files...``` ) 109 | ```cmake 110 | teensy_add_library(mylibrary library1.cpp) 111 | ``` 112 | 113 | * ```import_arduino_library``` ( ```LibraryName``` ```LibraryPath``` ```additionalRelativeSourceFolders```) 114 | ```cmake 115 | import_arduino_library(cores ${COREPATH} avr util) 116 | import_arduino_library(SPI ${DEPSPATH}/SPI) # SPI@Juse_Use_SdFat 117 | import_arduino_library(SdFat ${DEPSPATH}/SdFat/src common DigitalIO ExFatLib FatLib FsLib iostream SdCard SpiDriver) 118 | import_arduino_library(SD ${DEPSPATH}/SD/src) 119 | ``` 120 | * ```teensy_target_link_libraries``` ( ```TARGET``` ```libraries...```) 121 | ``` 122 | teensy_target_link_libraries(my_firmware mylibrary SD SdFat SPI cores) 123 | ``` 124 | 125 | * ```import_arduino_library_git``` ( ```LibraryName``` ```LibraryUrl``` ```Branch``` ```SourcePath``` ```additionalRelativeSourceFolders```) 126 | ```cmake 127 | import_arduino_library_git(SPI https://github.com/PaulStoffregen/SPI.git master "") 128 | import_arduino_library_git(SdFat https://github.com/PaulStoffregen/SdFat.git master "src" common DigitalIO ExFatLib FatLib FsLib iostream SdCard SpiDriver) 129 | import_arduino_library_git(SD https://github.com/PaulStoffregen/SD.git Juse_Use_SdFat src) 130 | import_arduino_library_git(Encoder https://github.com/PaulStoffregen/Encoder.git master "") 131 | import_arduino_library_git(Bounce2 https://github.com/PaulStoffregen/Bounce2.git master src) 132 | import_arduino_library_git(SerialFlash https://github.com/PaulStoffregen/SerialFlash.git master "" util) 133 | import_arduino_library_git(Wire https://github.com/PaulStoffregen/Wire.git master "" utility) 134 | import_arduino_library_git(arm_math https://github.com/PaulStoffregen/arm_math.git master src) 135 | import_arduino_library_git(TeensyGFX https://github.com/newdigate/teensy-gfx.git main src) 136 | ``` 137 | * link to std library 138 | ``` 139 | set(CMAKE_EXE_LINKER_FLAGS "--specs=nano.specs" CACHE INTERNAL "") 140 | target_link_libraries(my_firmware.elf stdc++) 141 | ``` 142 | * ```teensy_include_directories``` ( ```paths...```) 143 | ``` 144 | teensy_include_directories(../../src) 145 | ``` 146 | 147 | ## used in 148 | * [midi-smf-reader](https://github.com/newdigate/midi-smf-reader) 149 | * [teensy-quencer](https://github.com/newdigate/teensy-quencer) 150 | -------------------------------------------------------------------------------- /tests/audio/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | project(test_teensy_project_audio) 3 | 4 | include(FetchContent) 5 | FetchContent_Declare(teensy_cmake_macros 6 | GIT_REPOSITORY https://github.com/newdigate/teensy-cmake-macros 7 | GIT_TAG main 8 | ) 9 | FetchContent_MakeAvailable(teensy_cmake_macros) 10 | include(${teensy_cmake_macros_SOURCE_DIR}/CMakeLists.include.txt) 11 | 12 | import_arduino_library(cores ${teensy_cores_SOURCE_DIR}/teensy4 avr util) 13 | import_arduino_library_git(SPI https://github.com/PaulStoffregen/SPI master "") 14 | import_arduino_library_git(SdFat https://github.com/PaulStoffregen/SdFat master src common DigitalIO ExFatLib FatLib FsLib iostream SdCard SpiDriver) 15 | import_arduino_library_git(SD https://github.com/PaulStoffregen/SD Juse_Use_SdFat src) 16 | import_arduino_library_git(SerialFlash https://github.com/PaulStoffregen/SerialFlash master "" util) 17 | import_arduino_library_git(Wire https://github.com/PaulStoffregen/Wire master "" utility) 18 | import_arduino_library_git(arm_math https://github.com/PaulStoffregen/arm_math master src) 19 | import_arduino_library_git(Audio https://github.com/PaulStoffregen/Audio master "" utility) 20 | 21 | teensy_add_executable(audio_app audio.cpp) 22 | teensy_target_link_libraries(audio_app Audio cores Wire SPI SdFat SD SerialFlash arm_math ) -------------------------------------------------------------------------------- /tests/audio/audio.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | // GUItool: begin automatically generated code 8 | AudioInputI2S i2s1; //xy=99,60 9 | AudioFilterBiquad biquad1; //xy=257,60 10 | AudioOutputI2S i2s2; //xy=416,60 11 | AudioConnection patchCord1(i2s1, 0, biquad1, 0); 12 | AudioConnection patchCord2(biquad1, 0, i2s2, 0); 13 | AudioConnection patchCord3(biquad1, 0, i2s2, 1); 14 | AudioControlSGTL5000 sgtl5000_1; //xy=305,132 15 | // GUItool: end automatically generated code 16 | 17 | 18 | const int myInput = AUDIO_INPUT_LINEIN; 19 | //const int myInput = AUDIO_INPUT_MIC; 20 | 21 | void setup() { 22 | AudioMemory(12); 23 | 24 | sgtl5000_1.enable(); // Enable the audio shield 25 | sgtl5000_1.inputSelect(myInput); 26 | sgtl5000_1.volume(0.5); 27 | 28 | // Butterworth filter, 12 db/octave 29 | biquad1.setLowpass(0, 800, 0.707); 30 | 31 | // Linkwitz-Riley filter, 48 dB/octave 32 | //biquad1.setLowpass(0, 800, 0.54); 33 | //biquad1.setLowpass(1, 800, 1.3); 34 | //biquad1.setLowpass(2, 800, 0.54); 35 | //biquad1.setLowpass(3, 800, 1.3); 36 | } 37 | 38 | 39 | void loop() { 40 | } -------------------------------------------------------------------------------- /tests/basic/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | project(test_teensy_project_basic) 3 | 4 | include(FetchContent) 5 | FetchContent_Declare(teensy_cmake_macros 6 | GIT_REPOSITORY https://github.com/newdigate/teensy-cmake-macros 7 | GIT_TAG main 8 | ) 9 | FetchContent_MakeAvailable(teensy_cmake_macros) 10 | include(${teensy_cmake_macros_SOURCE_DIR}/CMakeLists.include.txt) 11 | 12 | import_arduino_library(cores ${teensy_cores_SOURCE_DIR}/teensy4 avr util) 13 | teensy_add_executable(basic basic.cpp) 14 | teensy_target_link_libraries(basic cores) 15 | -------------------------------------------------------------------------------- /tests/basic/basic.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void loop() { 4 | delay(1000); 5 | Serial.println("heelo"); 6 | } 7 | 8 | void setup() { 9 | Serial.begin(9600); 10 | } -------------------------------------------------------------------------------- /tests/eeprom/.vscode/cmake-kits.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "Teensy-4.1", 4 | "toolchainFile": "${workspaceFolder}/../teensy41.toolchain.cmake" 5 | } 6 | ] -------------------------------------------------------------------------------- /tests/eeprom/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "cmake.generator": "Unix Makefiles", 3 | "files.associations": { 4 | "stdint.h": "c" 5 | } 6 | } -------------------------------------------------------------------------------- /tests/eeprom/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | project(test_teensy_eeprom) 3 | 4 | include(FetchContent) 5 | FetchContent_Declare(teensy_cmake_macros 6 | GIT_REPOSITORY https://github.com/newdigate/teensy-cmake-macros 7 | GIT_TAG main 8 | ) 9 | FetchContent_MakeAvailable(teensy_cmake_macros) 10 | include(${teensy_cmake_macros_SOURCE_DIR}/CMakeLists.include.txt) 11 | 12 | import_arduino_library(cores ${teensy_cores_SOURCE_DIR}/teensy4 avr util) 13 | import_arduino_library_git(EEPROM https://github.com/PaulStoffregen/EEPROM master "") 14 | teensy_add_executable(eepromapp eepromapp.cpp) 15 | teensy_target_link_libraries(eepromapp EEPROM cores) 16 | -------------------------------------------------------------------------------- /tests/eeprom/eepromapp.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void loop() { 5 | delay(1000); 6 | Serial.println("heelo"); 7 | } 8 | 9 | void setup() { 10 | Serial.begin(9600); 11 | } -------------------------------------------------------------------------------- /tests/spi/.vscode/cmake-kits.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "Teensy-4.1", 4 | "toolchainFile": "${workspaceFolder}/../teensy41.toolchain.cmake" 5 | } 6 | ] -------------------------------------------------------------------------------- /tests/spi/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "cmake.generator": "Unix Makefiles", 3 | } -------------------------------------------------------------------------------- /tests/spi/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | project(test_teensy_eeprom) 3 | 4 | include(FetchContent) 5 | FetchContent_Declare(teensy_cmake_macros 6 | GIT_REPOSITORY https://github.com/newdigate/teensy-cmake-macros 7 | GIT_TAG main 8 | ) 9 | FetchContent_MakeAvailable(teensy_cmake_macros) 10 | include(${teensy_cmake_macros_SOURCE_DIR}/CMakeLists.include.txt) 11 | 12 | import_arduino_library(cores ${teensy_cores_SOURCE_DIR}/teensy4 avr util) 13 | import_arduino_library_git(SPI https://github.com/PaulStoffregen/SPI master "") 14 | teensy_add_executable(spiapp spiapp.cpp) 15 | teensy_target_link_libraries(spiapp SPI cores) -------------------------------------------------------------------------------- /tests/spi/spiapp.cpp: -------------------------------------------------------------------------------- 1 | // this example is reading samples captured from AD7606 8 channel 16bit analig to digital converter via SPI bus 2 | #include 3 | #include 4 | 5 | #define SCALE_FACTOR 0.000152587890625 // 10/(2^16) = 0.000152587890625 6 | 7 | #define BUSY 3 8 | #define RESET 4 9 | #define START_CONVERSION 5 10 | #define CHIP_SELECT 10 11 | #define MISO 12 12 | #define MOSI 11 13 | #define LED 13 14 | #define TOTAL_RAW_BYTES 16 15 | 16 | int bytesToRead = TOTAL_RAW_BYTES; 17 | byte raw[TOTAL_RAW_BYTES]; 18 | uint16_t parsed[8]; 19 | int x = 0; 20 | 21 | void parseRawBytes() { 22 | parsed[0] = (raw[0] << 8) + raw[1]; 23 | parsed[1] = (raw[2] << 8) + raw[3]; 24 | parsed[2] = (raw[4] << 8) + raw[5]; 25 | parsed[3] = (raw[6] << 8) + raw[7]; 26 | parsed[4] = (raw[8] << 8) + raw[9]; 27 | parsed[5] = (raw[10] << 8) + raw[11]; 28 | parsed[6] = (raw[12] << 8) + raw[13]; 29 | parsed[7] = (raw[14] << 8) + raw[15]; 30 | } 31 | 32 | void setup() { 33 | SPI.begin(); 34 | pinMode(BUSY, INPUT); 35 | pinMode(RESET, OUTPUT); 36 | pinMode(START_CONVERSION, OUTPUT); 37 | pinMode(CHIP_SELECT, OUTPUT); 38 | 39 | Serial.begin(115200); 40 | 41 | digitalWrite(START_CONVERSION, HIGH); 42 | digitalWrite(CHIP_SELECT, HIGH); 43 | digitalWrite(RESET, HIGH); 44 | delay(100); 45 | digitalWrite(RESET, LOW); 46 | delay(100); 47 | } 48 | 49 | void loop() { 50 | digitalWrite(START_CONVERSION, LOW); 51 | delayMicroseconds(100); 52 | digitalWrite(START_CONVERSION, HIGH); 53 | 54 | while (digitalRead(BUSY) == HIGH) { 55 | // wait for conversion to complete 56 | delayMicroseconds(1); 57 | } 58 | SPISettings _spiSettings; 59 | SPI.beginTransaction(_spiSettings); 60 | digitalWrite(CHIP_SELECT, LOW); 61 | while (bytesToRead > 0) { 62 | raw[TOTAL_RAW_BYTES - bytesToRead] = SPI.transfer(0x00); 63 | bytesToRead--; 64 | } 65 | digitalWrite(CHIP_SELECT, HIGH); 66 | SPI.endTransaction(); 67 | bytesToRead = TOTAL_RAW_BYTES; 68 | 69 | parseRawBytes(); 70 | Serial.printf("%x, %x, %x, %x, %x, %x, %x, %x\n", parsed[0], parsed[1], parsed[2], parsed[3], parsed[4], parsed[5], parsed[6], parsed[7] ); 71 | delay(1000); 72 | } 73 | 74 | -------------------------------------------------------------------------------- /tests/teensy41.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(TEENSY_VERSION 41 CACHE STRING "Set to the Teensy version corresponding to your board (30 or 31 allowed)" FORCE) 2 | set(CPU_CORE_SPEED 600000000 CACHE STRING "Set to 24000000, 48000000, 72000000 or 96000000 to set CPU core speed" FORCE) # Derived variables 3 | set(CMAKE_EXE_LINKER_FLAGS "--specs=nosys.specs" CACHE INTERNAL "") 4 | 5 | #teensy compiler options 6 | set(COMPILERPATH "/opt/gcc-arm-none-eabi-9-2019-q4-major/bin/") 7 | #set(COMPILERPATH "/Applications/ARM/bin/") 8 | 9 | set(BUILD_FOR_TEENSY ON) 10 | set(CMAKE_SYSTEM_NAME Generic) 11 | set(CMAKE_SYSTEM_PROCESSOR arm) 12 | set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY") 13 | set(CMAKE_C_COMPILER ${COMPILERPATH}arm-none-eabi-gcc) 14 | set(CMAKE_CXX_COMPILER ${COMPILERPATH}arm-none-eabi-g++) 15 | set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_C_COMPILER} -o ") 16 | -------------------------------------------------------------------------------- /tests/vector/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | project(test_teensy_project_vector) 3 | 4 | include(FetchContent) 5 | FetchContent_Declare(teensy_cmake_macros 6 | GIT_REPOSITORY https://github.com/newdigate/teensy-cmake-macros 7 | GIT_TAG main 8 | ) 9 | FetchContent_MakeAvailable(teensy_cmake_macros) 10 | include(${teensy_cmake_macros_SOURCE_DIR}/CMakeLists.include.txt) 11 | 12 | set(CMAKE_EXE_LINKER_FLAGS "--specs=nano.specs" CACHE INTERNAL "") 13 | import_arduino_library(cores ${teensy_cores_SOURCE_DIR}/teensy4 avr util) 14 | teensy_add_executable(vector vector.cpp) 15 | target_link_libraries(vector.elf stdc++) 16 | teensy_target_link_libraries(vector cores) 17 | -------------------------------------------------------------------------------- /tests/vector/vector.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | std::vector floats; 5 | 6 | void loop() { 7 | delay(1000); 8 | floats.push_back(1.2345); 9 | Serial.println("heelo"); 10 | } 11 | 12 | void setup() { 13 | Serial.begin(9600); 14 | } --------------------------------------------------------------------------------