From b1372e47f66b0a3476cfddde7379a61e1b82bb36 Mon Sep 17 00:00:00 2001 From: rusefillc <48498823+rusefillc@users.noreply.github.com> Date: Mon, 8 Nov 2021 01:52:13 -0500 Subject: [PATCH] Extract io (#25) * LEDs for BL * more reuse * Windows exists * extract NERNST pin * Matt is asking to move Co-authored-by: rusefillc --- .gitattributes | 2 ++ .../boards/f0_module/bootloader/bootloader.cpp | 18 +++++++++--------- firmware/boards/f0_module/io_pins.h | 8 ++++++++ firmware/main.cpp | 7 ++++--- firmware/sampling.cpp | 9 +++++---- 5 files changed, 28 insertions(+), 16 deletions(-) create mode 100644 .gitattributes create mode 100644 firmware/boards/f0_module/io_pins.h diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..6007d2e --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ + +*.sh text eol=lf diff --git a/firmware/boards/f0_module/bootloader/bootloader.cpp b/firmware/boards/f0_module/bootloader/bootloader.cpp index 53ef9cd..08e12dd 100644 --- a/firmware/boards/f0_module/bootloader/bootloader.cpp +++ b/firmware/boards/f0_module/bootloader/bootloader.cpp @@ -2,6 +2,7 @@ #include "hal.h" #include "flash.h" +#include "../io_pins.h" #include @@ -244,24 +245,23 @@ int main(void) { chThdCreateStatic(waBootloaderThread, sizeof(waBootloaderThread), NORMALPRIO + 1, BootloaderThread, nullptr); - // PB5 is blue LED - palSetPadMode(GPIOB, 5, PAL_MODE_OUTPUT_PUSHPULL); - // PB6 is green LED - palSetPadMode(GPIOB, 6, PAL_MODE_OUTPUT_PUSHPULL); - palTogglePad(GPIOB, 6); + palSetPadMode(BLUE_LED_PORT, BLUE_LED_PIN, PAL_MODE_OUTPUT_PUSHPULL); + + palSetPadMode(GREEN_LED_PORT, GREEN_LED_PIN, PAL_MODE_OUTPUT_PUSHPULL); + palTogglePad(GREEN_LED_PORT, GREEN_LED_PIN); for (size_t i = 0; i < 20; i++) { - palTogglePad(GPIOB, 5); - palTogglePad(GPIOB, 6); + palTogglePad(BLUE_LED_PORT, BLUE_LED_PIN); + palTogglePad(GREEN_LED_PORT, GREEN_LED_PIN); chThdSleepMilliseconds(40); } // Block until booting the app is allowed and CRC matches while (bootloaderBusy || !isAppValid()) { - palTogglePad(GPIOB, 5); - palTogglePad(GPIOB, 6); + palTogglePad(BLUE_LED_PORT, BLUE_LED_PIN); + palTogglePad(GREEN_LED_PORT, GREEN_LED_PIN); chThdSleepMilliseconds(200); } diff --git a/firmware/boards/f0_module/io_pins.h b/firmware/boards/f0_module/io_pins.h new file mode 100644 index 0000000..79293e1 --- /dev/null +++ b/firmware/boards/f0_module/io_pins.h @@ -0,0 +1,8 @@ +#define BLUE_LED_PORT GPIOB +#define BLUE_LED_PIN 5 + +#define GREEN_LED_PORT GPIOB +#define GREEN_LED_PIN 6 + +#define NERNST_ESR_DRIVER_PORT GPIOB +#define NERNST_ESR_DRIVER_PIN 7 diff --git a/firmware/main.cpp b/firmware/main.cpp index 5e69b87..7fca755 100644 --- a/firmware/main.cpp +++ b/firmware/main.cpp @@ -8,6 +8,7 @@ #include "pump_dac.h" #include "sampling.h" #include "uart.h" +#include "io_pins.h" /* @@ -33,10 +34,10 @@ int main() { if (fault == Fault::None) { // blue is off - palClearPad(GPIOB, 5); + palClearPad(BLUE_LED_PORT, BLUE_LED_PIN); // Green is blinking - palTogglePad(GPIOB, 6); + palTogglePad(GREEN_LED_PORT, GREEN_LED_PIN); // Slow blink if closed loop, fast if not chThdSleepMilliseconds(IsRunningClosedLoop() ? 700 : 50); @@ -50,7 +51,7 @@ int main() { for (int i = 0; i < 2 * static_cast(fault); i++) { // Blue is blinking - palTogglePad(GPIOB, 5); + palTogglePad(BLUE_LED_PORT, BLUE_LED_PIN); // fast blink chThdSleepMilliseconds(300); diff --git a/firmware/sampling.cpp b/firmware/sampling.cpp index 577a859..b861d89 100644 --- a/firmware/sampling.cpp +++ b/firmware/sampling.cpp @@ -6,11 +6,12 @@ #include "wideband_config.h" #include "port.h" +#include "io_pins.h" // Stored results -float nernstAc = 0; -float nernstDc = 0; -volatile float pumpCurrentSenseVoltage = 0; +static float nernstAc = 0; +static float nernstDc = 0; +static volatile float pumpCurrentSenseVoltage = 0; constexpr float f_abs(float x) { @@ -29,7 +30,7 @@ static void SamplingThread(void*) auto result = AnalogSample(); // Toggle the pin after sampling so that any switching noise occurs while we're doing our math instead of when sampling - palTogglePad(GPIOB, 7); + palTogglePad(NERNST_ESR_DRIVER_PORT, NERNST_ESR_DRIVER_PIN); float r_1 = result.NernstVoltage;