Skip to content

Commit

Permalink
Add support for Teensy 4.0:
Browse files Browse the repository at this point in the history
- Add env in platformio.ini
- Add conditional compilation checks for ARDUINO_TEENSY40
- Add workaround for bug in Teensyduino (#undef abs before #include <cmath>)
  • Loading branch information
Compizfox committed Nov 22, 2023
1 parent 3c45d61 commit 722c3ba
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
7 changes: 7 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,10 @@ board = teensylc
; for floating point support in printf
build_flags = ${env.build_flags} -Wl,-u,_printf_float
upload_protocol = teensy-cli

[env:teensy40]
platform = teensy
board = teensy40
; for floating point support in printf
build_flags = ${env.build_flags} -Wl,-u,_printf_float
upload_protocol = teensy-cli
2 changes: 1 addition & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ namespace config {
const uint8_t PIN_T4 = A4;
///@}
#endif
#ifdef ARDUINO_TEENSYLC
#if defined(ARDUINO_TEENSYLC) || defined(ARDUINO_TEENSY40)
const uint8_t PIN_DHT = 17;
const uint8_t PIN_BTN = A0;
const uint8_t PIN_S1 = 3;
Expand Down
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ButtonReader buttonReader(config::PIN_BTN, &voltLadder);
EEPROMConfig eepromConfig;

// PWM frequency and resolution: MCU-dependent
#ifdef ARDUINO_TEENSYLC
#if defined(ARDUINO_TEENSYLC) || defined(ARDUINO_TEENSY40)
const uint8_t pwmRes = 16;
#else
const uint8_t pwmRes = 8;
Expand Down Expand Up @@ -82,7 +82,7 @@ void setup() {
// See: https://arduinoinfo.mywikis.net/wiki/Arduino-PWM-Frequency
TCCR2B = TCCR2B & B11111000 | B00000100;
#endif
#ifdef ARDUINO_TEENSYLC
#if defined(ARDUINO_TEENSYLC) || defined(ARDUINO_TEENSY40)
// Set PWM frequency to 250 Hz
analogWriteFrequency(config::PIN_S1, 500);
// Increase PWM resolution from default 8-bits
Expand Down
1 change: 1 addition & 0 deletions src/ui/GraphicalDisplayUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <U8g2lib.h>
#include <SPI.h>
#include <etl/span.h>
#undef abs
#include <cmath>

#include CONFIG_HEADER
Expand Down

0 comments on commit 722c3ba

Please sign in to comment.