Browse Source

start making SPI configurable

pull/807/head
Markus Krause 2 years ago
parent
commit
97d60f2ea9
  1. 9
      src/.vscode/settings.json
  2. 2
      src/app.cpp
  3. 2
      src/app.h
  4. 7
      src/config/config.h
  5. 9
      src/hm/hmRadio.h
  6. 5
      src/hm/hmSystem.h
  7. 10
      src/platformio.ini

9
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,
}

2
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);

2
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) {

7
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)

9
src/hm/hmRadio.h

@ -10,6 +10,7 @@
#include <RF24.h>
#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 <uint8_t IRQ_PIN = DEF_IRQ_PIN, uint8_t CE_PIN = DEF_CE_PIN, uint8_t CS_PIN = DEF_CS_PIN, uint8_t AMP_PWR = RF24_PA_LOW>
template <uint8_t IRQ_PIN = DEF_IRQ_PIN, uint8_t CE_PIN = DEF_CE_PIN, uint8_t CS_PIN = DEF_CS_PIN, uint8_t AMP_PWR = RF24_PA_LOW, uint8_t SCLK_PIN = DEF_SCLK_PIN, uint8_t MOSI_PIN = DEF_MOSI_PIN, uint8_t MISO_PIN = DEF_MISO_PIN>
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]);

5
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) {

10
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

Loading…
Cancel
Save