Skip to content

Commit

Permalink
added user button to trigger reading
Browse files Browse the repository at this point in the history
  • Loading branch information
RBEGamer committed Jul 29, 2024
1 parent fdce762 commit 9f4229e
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 19 deletions.
6 changes: 0 additions & 6 deletions src/UnifiedMagBoardFirmware/include/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
25 changes: 18 additions & 7 deletions src/UnifiedMagBoardFirmware/include/usf_plattform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down
22 changes: 17 additions & 5 deletions src/UnifiedMagBoardFirmware/platformio.ini
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -47,4 +49,14 @@ platform = raspberrypi
board = pico
upload_protocol = jlink
debug_tool = jlink
platform_packages = tool-openocd@~2.1000.0
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
40 changes: 39 additions & 1 deletion src/UnifiedMagBoardFirmware/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 9f4229e

Please sign in to comment.