From 97d60f2ea95a7417f3793c1d174b0ee2882f7f74 Mon Sep 17 00:00:00 2001 From: Markus Krause Date: Sat, 25 Mar 2023 20:32:23 +0100 Subject: [PATCH] start making SPI configurable --- src/.vscode/settings.json | 9 +++------ src/app.cpp | 2 +- src/app.h | 2 +- src/config/config.h | 7 +++++++ src/hm/hmRadio.h | 9 ++++++--- src/hm/hmSystem.h | 5 +++-- src/platformio.ini | 10 ++++++++++ 7 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/.vscode/settings.json b/src/.vscode/settings.json index c0becfd1..58a2c3c7 100644 --- a/src/.vscode/settings.json +++ b/src/.vscode/settings.json @@ -4,20 +4,16 @@ "workbench.colorCustomizations": { "editorLineNumber.foreground": "#00ff00" }, - "editor.wordWrap": "off", - "files.eol" : "\n", - "files.trimTrailingWhitespace" : true, - + "files.eol": "\n", + "files.trimTrailingWhitespace": true, "diffEditor.ignoreTrimWhitespace": true, "files.autoSave": "afterDelay", - "editor.tabSize": 4, "editor.insertSpaces": true, // `editor.tabSize` and `editor.insertSpaces` will be detected based on the file contents. // Set to false to keep the values you've explicitly set, above. "editor.detectIndentation": false, - // https://clang.llvm.org/docs/ClangFormatStyleOptions.html "C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: Google, IndentWidth: 4, ColumnLimit: 0}", "files.associations": { @@ -86,4 +82,5 @@ "thread": "cpp" }, "cmake.configureOnOpen": false, + "editor.formatOnSave": false, } \ No newline at end of file diff --git a/src/app.cpp b/src/app.cpp index 23030d76..1dfcf5ef 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -30,7 +30,7 @@ void app::setup() { DBGPRINTLN(F("false")); mSys.enableDebug(); - mSys.setup(mConfig->nrf.amplifierPower, mConfig->nrf.pinIrq, mConfig->nrf.pinCe, mConfig->nrf.pinCs); + mSys.setup(mConfig->nrf.amplifierPower, 47, 38, 37, 36, 35, 48); #if defined(AP_ONLY) mInnerLoopCb = std::bind(&app::loopStandard, this); diff --git a/src/app.h b/src/app.h index cbf7e6a1..55320579 100644 --- a/src/app.h +++ b/src/app.h @@ -162,7 +162,7 @@ class app : public IApp, public ah::Scheduler { } uint8_t getIrqPin(void) { - return mConfig->nrf.pinIrq; + return 47; } String getTimeStr(uint32_t offset = 0) { diff --git a/src/config/config.h b/src/config/config.h index 5bb085f4..6711c1dd 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -47,10 +47,17 @@ #define DEF_CS_PIN 5 #define DEF_CE_PIN 4 #define DEF_IRQ_PIN 16 + #define DEF_MISO_PIN 48 + #define DEF_MOSI_PIN 35 + #define DEF_SCLK_PIN 36 #else #define DEF_CS_PIN 15 #define DEF_CE_PIN 2 #define DEF_IRQ_PIN 0 + // TODO, these below are obviously garbage and just copy paste + #define DEF_MISO_PIN 48 + #define DEF_MOSI_PIN 35 + #define DEF_SCLK_PIN 36 #endif // default NRF24 power, possible values (0 - 3) diff --git a/src/hm/hmRadio.h b/src/hm/hmRadio.h index a9564196..6d6d54b9 100644 --- a/src/hm/hmRadio.h +++ b/src/hm/hmRadio.h @@ -10,6 +10,7 @@ #include #include "../utils/crc.h" #include "../config/config.h" +#include "SPI.h" #define SPI_SPEED 1000000 @@ -47,7 +48,7 @@ const char* const rf24AmpPowerNames[] = {"MIN", "LOW", "HIGH", "MAX"}; //----------------------------------------------------------------------------- // HM Radio class //----------------------------------------------------------------------------- -template +template class HmRadio { public: HmRadio() : mNrf24(CE_PIN, CS_PIN, SPI_SPEED) { @@ -78,7 +79,7 @@ class HmRadio { } ~HmRadio() {} - void setup(uint8_t ampPwr = RF24_PA_LOW, uint8_t irq = IRQ_PIN, uint8_t ce = CE_PIN, uint8_t cs = CS_PIN) { + void setup(uint8_t ampPwr = RF24_PA_LOW, uint8_t irq = IRQ_PIN, uint8_t ce = CE_PIN, uint8_t cs = CS_PIN, uint8_t sclk = SCLK_PIN, uint8_t mosi = MOSI_PIN, uint8_t miso = MISO_PIN) { DPRINTLN(DBG_VERBOSE, F("hmRadio.h:setup")); pinMode(irq, INPUT_PULLUP); @@ -100,7 +101,9 @@ class HmRadio { // change the byte order of the DTU serial number and append the required 0x01 at the end DTU_RADIO_ID = ((uint64_t)(((dtuSn >> 24) & 0xFF) | ((dtuSn >> 8) & 0xFF00) | ((dtuSn << 8) & 0xFF0000) | ((dtuSn << 24) & 0xFF000000)) << 8) | 0x01; - mNrf24.begin(ce, cs); + SPIClass* mSpi = new SPIClass(HSPI); + mSpi->begin(sclk, miso, mosi, cs); + mNrf24.begin(mSpi, ce, cs); mNrf24.setRetries(3, 15); // 3*250us + 250us and 15 loops -> 15ms mNrf24.setChannel(mRfChLst[mRxChIdx]); diff --git a/src/hm/hmSystem.h b/src/hm/hmSystem.h index 3f3b29a7..ff592ca0 100644 --- a/src/hm/hmSystem.h +++ b/src/hm/hmSystem.h @@ -21,9 +21,10 @@ class HmSystem { Radio.setup(); } - void setup(uint8_t ampPwr, uint8_t irqPin, uint8_t cePin, uint8_t csPin) { + void setup(uint8_t ampPwr, uint8_t irqPin, uint8_t cePin, uint8_t csPin, uint8_t sclkPin, uint8_t mosiPin, uint8_t misoPin) { mNumInv = 0; - Radio.setup(ampPwr, irqPin, cePin, csPin); + // Radio.setup(ampPwr, 47, 38, 37, 36, 35, 48); + Radio.setup(ampPwr, irqPin, cePin, csPin, sclkPin, mosiPin, misoPin); } void addInverters(cfgInst_t *config) { diff --git a/src/platformio.ini b/src/platformio.ini index 38e67c95..19e4f376 100644 --- a/src/platformio.ini +++ b/src/platformio.ini @@ -133,3 +133,13 @@ monitor_filters = ;default ; Remove typical terminal control codes from input time ; Add timestamp with milliseconds for each new line log2file ; Log data to a file “platformio-device-monitor-*.log” located in the current working directory + +[env:opendtufusionv1] +platform = espressif32 +board = esp32-s3-devkitc-1 +build_flags = -D RELEASE -std=gnu++14 +build_unflags = -std=gnu++11 +monitor_filters = + ;default ; Remove typical terminal control codes from input + time ; Add timestamp with milliseconds for each new line + ;log2file ; Log data to a file “platformio-device-monitor-*.log” located in the current working directory