From 9f4229e2c3a4e44f488482e5c2ab25824d74e928 Mon Sep 17 00:00:00 2001 From: Marcel Ochsendorf Date: Mon, 29 Jul 2024 10:26:15 +0200 Subject: [PATCH] added user button to trigger reading --- src/UnifiedMagBoardFirmware/include/main.h | 6 --- .../include/usf_plattform.h | 25 ++++++++---- src/UnifiedMagBoardFirmware/platformio.ini | 22 +++++++--- src/UnifiedMagBoardFirmware/src/main.cpp | 40 ++++++++++++++++++- 4 files changed, 74 insertions(+), 19 deletions(-) diff --git a/src/UnifiedMagBoardFirmware/include/main.h b/src/UnifiedMagBoardFirmware/include/main.h index 1d6e8f6e..ab9fb56f 100644 --- a/src/UnifiedMagBoardFirmware/include/main.h +++ b/src/UnifiedMagBoardFirmware/include/main.h @@ -22,12 +22,6 @@ #endif -#ifdef ENABLE_HARDWARE_AVERAGING -#define READOUT_SPEED_IN_SINGLEMODE_HZ 500 // Hz // GIVE IT TIME TO FILL UP THE BUFFER - -#else -#define READOUT_SPEED_IN_SINGLEMODE_HZ 100 // Hz -#endif #define READOUT_SPEED_IN_SINGLEMODE_DELAY (1000/READOUT_SPEED_IN_SINGLEMODE_HZ) diff --git a/src/UnifiedMagBoardFirmware/include/usf_plattform.h b/src/UnifiedMagBoardFirmware/include/usf_plattform.h index c783d64f..10629768 100644 --- a/src/UnifiedMagBoardFirmware/include/usf_plattform.h +++ b/src/UnifiedMagBoardFirmware/include/usf_plattform.h @@ -6,13 +6,16 @@ #define ENABLE_HARDWARE_AVERAGING #define CREATE_VIRTUAL_SENSOR_IF_NOT_HARDWARE_SENSORS_FOUND -#ifdef IS_STM32F4_BOARD +#if defined(IS_STM32F4_BOARD) + #define ERROR_LED_PIN PD15 #define STATUS_LED_PIN PD14 #define SINGLE_MODE_PIN PC1 #define SYNC_PIN_IRQ_INPUT PA0 #define SYNC_PIN_STATUS_LED PD13 + + #define USER_BUTTON_TRIGGER_INPUT PA0 // ON STM32F407G-DISC1 // I2C INTERFACE TO COMMUNICATE WITH ATTACHED SENSORS #define SENSOR_WIRE_SCL_PIN PB6 #define SENSOR_WIRE_SDA_PIN PB9 @@ -28,21 +31,25 @@ #define RESET_SYSTEM_FUNCTION() NVIC_SystemReset() #ifdef ENABLE_HARDWARE_AVERAGING - #define MAX_AVERAGING_COUNT 100 // SIZE FOR RING BUFFER LIMITED DUE RAM CAPACITY + #ifdef USER_BUTTON_TRIGGER_INPUT + #define MAX_AVERAGING_COUNT 50 // SIZE FOR RING BUFFER LIMITED DUE RAM CAPACITY + #else + #define MAX_AVERAGING_COUNT 100 // SIZE FOR RING BUFFER LIMITED DUE RAM CAPACITY + #endif + #define READOUT_SPEED_IN_SINGLEMODE_HZ 200 #else #define READOUT_SPEED_IN_SINGLEMODE_HZ 100 #endif -#endif - -#ifdef IS_RP2040_BOARD +#elif defined(IS_RP2040_BOARD) #define ERROR_LED_PIN 25 #define STATUS_LED_PIN 6 #define SINGLE_MODE_PIN 13 #define SYNC_PIN_IRQ_INPUT 8 #define SYNC_PIN_STATUS_LED 9 - + #define USER_BUTTON_TRIGGER_INPUT 15 + //#define USER_BUTTON_TRIGGER_INPUT 15 // I2C INTERFACE TO COMMUNICATE WITH ATTACHED SENSORS #define SENSOR_WIRE Wire // ON RP2040 SDA4/SCL5 @@ -59,7 +66,11 @@ #define RESET_SYSTEM_FUNCTION() #ifdef ENABLE_HARDWARE_AVERAGING - #define MAX_AVERAGING_COUNT 500 // SIZE FOR RING BUFFER LIMITED DUE RAM CAPACITY + #ifdef USER_BUTTON_TRIGGER_INPUT + #define MAX_AVERAGING_COUNT 50 // SIZE FOR RING BUFFER LIMITED DUE RAM CAPACITY + #else + #define MAX_AVERAGING_COUNT 100 // SIZE FOR RING BUFFER LIMITED DUE RAM CAPACITY + #endif #define READOUT_SPEED_IN_SINGLEMODE_HZ 200 #else #define READOUT_SPEED_IN_SINGLEMODE_HZ 100 diff --git a/src/UnifiedMagBoardFirmware/platformio.ini b/src/UnifiedMagBoardFirmware/platformio.ini index 03eec445..20866522 100644 --- a/src/UnifiedMagBoardFirmware/platformio.ini +++ b/src/UnifiedMagBoardFirmware/platformio.ini @@ -1,5 +1,5 @@ [env] -build_flags = -D VERSION=\"2.5.1\" +build_flags = -D VERSION=\"3.0.1\" -D USING_PLATFORMIO=1 #-D ENABLE_HARDWARE_AVERAGING monitor_speed=115200 @@ -9,7 +9,8 @@ debug_init_break = tbreak framework = arduino [env:disco_f407vg_jlink] -build_flags = -D IS_STM32F4_BOARD=1 +build_flags = -D VERSION=\"3.0.1\" + -D IS_STM32F4_BOARD=1 -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC -D USBCON platform = ststm32 @@ -19,7 +20,8 @@ upload_protocol = jlink [env:rp2040_cmsis] -build_flags = -D IS_RP2040_BOARD +build_flags = -D VERSION=\"3.0.1\" + -D IS_RP2040_BOARD -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC -D LIB_PICO_STDIO_USB platform = raspberrypi @@ -38,7 +40,7 @@ debug_server = openocd -f interface/cmsis-dap.cfg -c "transport select swd" -c " [env:rp2040_jlink] -build_flags = -D VERSION=\"3.0.0\" +build_flags = -D VERSION=\"3.0.1\" -D USING_PLATFORMIO=1 -D IS_RP2040_BOARD -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC @@ -47,4 +49,14 @@ platform = raspberrypi board = pico upload_protocol = jlink debug_tool = jlink -platform_packages = tool-openocd@~2.1000.0 \ No newline at end of file +platform_packages = tool-openocd@~2.1000.0 + +[env:rp2040] +build_flags = -D VERSION=\"3.0.1\" + -D USING_PLATFORMIO=1 + -D IS_RP2040_BOARD + -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC + -D LIB_PICO_STDIO_USB +platform = raspberrypi +board = pico +upload_protocol = picotool \ No newline at end of file diff --git a/src/UnifiedMagBoardFirmware/src/main.cpp b/src/UnifiedMagBoardFirmware/src/main.cpp index bddc3c4a..173176d6 100644 --- a/src/UnifiedMagBoardFirmware/src/main.cpp +++ b/src/UnifiedMagBoardFirmware/src/main.cpp @@ -148,6 +148,20 @@ void process_anc_information(DBGCommandParser::Argument *args, char *response) } } + +#ifdef USER_BUTTON_TRIGGER_INPUT + void user_button_trigger_irq(){ + if (system_state == System_State_READOUT_LOOP && !wait_for_readout_ready) + { + readout_triggered_axis = "b"; + readout_triggered_id = 0; + wait_for_readout_ready = true; // SET TO RESPONSE WITH READOUT + readout_index++; + } + } +#endif + + int scan_for_sensors() { // SCAN FOR TLV SENSORS @@ -241,6 +255,9 @@ void setup() system_state = System_State_SETUP; DEBUG_SERIAL.println("sysstate_" + System_State_STR[system_state]); +#ifdef IS_RP2040_BOARD + DEBUG_SERIAL.println("IS_RP2040_BOARD"); +#endif // SETUP DEBUG COMMAND PARSER TO ALLOW SOME DEBUGGING debug_command_parser.registerCommand("help", "", [](DBGCommandParser::Argument *args, char *response) { @@ -352,7 +369,14 @@ void setup() { DEBUG_SERIAL.println("log_singlemodedisabled"); pinMode(SYNC_PIN_IRQ_INPUT, INPUT_PULLUP); - attachInterrupt(digitalPinToInterrupt(SYNC_PIN_IRQ_INPUT), sync_irq_function, CHANGE); + +#if defined(IS_RP2040_BOARD) + attachInterrupt(SYNC_PIN_IRQ_INPUT, sync_irq_function, RISING); +#elif defined(IS_STM32F4_BOARD) + attachInterrupt(SYNC_PIN_IRQ_INPUT, sync_irq_function, RISING); +#else + attachInterrupt(digitalPinToInterrupt(SYNC_PIN_IRQ_INPUT), sync_irq_function, RISING); +#endif } // i2c_scan(SENSOR_WIRE); @@ -394,6 +418,20 @@ void setup() // SETUP ANC SERIAL system_state = System_State_WAIT_FOR_ANC; anc_base_id = -1; + + + //ATTACH IRQ IF ENABLED +#ifdef USER_BUTTON_TRIGGER_INPUT + DEBUG_SERIAL.println("USER_BUTTON_TRIGGER_INPUT ENABLED"); + pinMode(USER_BUTTON_TRIGGER_INPUT, INPUT_PULLUP); + #if defined(IS_RP2040_BOARD) + attachInterrupt(USER_BUTTON_TRIGGER_INPUT, user_button_trigger_irq, RISING); + #elif defined(IS_STM32F4_BOARD) + attachInterrupt(USER_BUTTON_TRIGGER_INPUT, user_button_trigger_irq, RISING); + #else + attachInterrupt(digitalPinToInterrupt(USER_BUTTON_TRIGGER_INPUT)), user_button_trigger_irq, RISING); + #endif +#endif } void loop()