Added libraries and firmware skeleton

This commit is contained in:
Emanuele Trabattoni
2026-03-24 17:07:49 +01:00
parent 9240a0be41
commit 948120c001
15 changed files with 1390 additions and 0 deletions

88
RotaxMonitor/src/main.cpp Normal file
View File

@@ -0,0 +1,88 @@
#define DEBUGLOG_DEFAULT_LOG_LEVEL_INFO
// Arduino Libraries
#include <Arduino.h>
#include <DebugLog.h>
#include <DebugLogEnable.h>
#include <SPI.h>
// Definitions
#include <isr.h>
#include <pins.h>
#include <channels.h>
// Device Libraries
#include <ADS1256.h>
#include <AD5292.h>
void pkdtTask(void *pvParameters) {
uint32_t notifiedValue;
while (true) {
// attende eventi
xTaskNotifyWait(
0x00, // non pulire all'ingresso
0xFFFFFFFF, // pulisci tutti i bit all'uscita
&notifiedValue, // valore ricevuto
portMAX_DELAY
);
// 🔥 QUI GIRA SU CORE 0
switch (notifiedValue)
case PKDT_FLAG_AP: {
handlePKDT(PKDT_AP);
break;
}
default:
LOG_ERROR("Invalid Interrupt: ", notifiedValue);
}
}
void setup() {
Serial.begin(9600);
LOG_ATTACH_SERIAL(Serial);
LOG_SET_LEVEL(DebugLogLevel::LVL_INFO);
LOG_INFO("ESP32 Chip:", ESP.getChipModel());
LOG_INFO("ESP32 PSram:", ESP.getPsramSize());
LOG_INFO("ESP32 Flash:", ESP.getFlashChipSize());
LOG_INFO("ESP32 Heap:", ESP.getHeapSize());
LOG_INFO("ESP32 Sketch:", ESP.getFreeSketchSpace());
// Initialize Interrupt pins on peak detectors
pinMode(PKDT_AP, INPUT_PULLDOWN);
pinMode(PKDT_AN, INPUT_PULLDOWN);
pinMode(PKDT_BP, INPUT_PULLDOWN);
pinMode(PKDT_BN, INPUT_PULLDOWN);
// interrupt
attachInterrupt(PKDT_AP, pkdt_isr_ap, RISING);
attachInterrupt(PKDT_AN, pkdt_isr_an, RISING);
attachInterrupt(PKDT_BP, pkdt_isr_bp, RISING);
attachInterrupt(PKDT_BN, pkdt_isr_bn, RISING);
// Init SPI interface
SPI.begin();
// Init ADC
auto adc = ADS1256(ADC_DRDY, ADC_RST, ADC_SYNC, ADC_CS, 0.0, SPI);
ADS1256.
}
void loop() {
// task su core 0
auto isrTask = xTaskCreatePinnedToCore(
pkdtTask,
"pkdtTask",
4096,
NULL,
2, // priorità leggermente più alta
&pkdtTaskHandle,
0
);
if (isrTask != pdPASS){
LOG_ERROR("Unble to initialize ISR task");
}
}