Extract io (#25)

* LEDs for BL

* more reuse

* Windows exists

* extract NERNST pin

* Matt is asking to move

Co-authored-by: rusefillc <sdfsdfqsf2334234234>
This commit is contained in:
rusefillc 2021-11-08 01:52:13 -05:00 committed by GitHub
parent 89b272e3b1
commit b1372e47f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 16 deletions

2
.gitattributes vendored Normal file
View File

@ -0,0 +1,2 @@
*.sh text eol=lf

View File

@ -2,6 +2,7 @@
#include "hal.h" #include "hal.h"
#include "flash.h" #include "flash.h"
#include "../io_pins.h"
#include <cstring> #include <cstring>
@ -244,24 +245,23 @@ int main(void) {
chThdCreateStatic(waBootloaderThread, sizeof(waBootloaderThread), NORMALPRIO + 1, BootloaderThread, nullptr); chThdCreateStatic(waBootloaderThread, sizeof(waBootloaderThread), NORMALPRIO + 1, BootloaderThread, nullptr);
// PB5 is blue LED palSetPadMode(BLUE_LED_PORT, BLUE_LED_PIN, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(GPIOB, 5, PAL_MODE_OUTPUT_PUSHPULL);
// PB6 is green LED palSetPadMode(GREEN_LED_PORT, GREEN_LED_PIN, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(GPIOB, 6, PAL_MODE_OUTPUT_PUSHPULL); palTogglePad(GREEN_LED_PORT, GREEN_LED_PIN);
palTogglePad(GPIOB, 6);
for (size_t i = 0; i < 20; i++) for (size_t i = 0; i < 20; i++)
{ {
palTogglePad(GPIOB, 5); palTogglePad(BLUE_LED_PORT, BLUE_LED_PIN);
palTogglePad(GPIOB, 6); palTogglePad(GREEN_LED_PORT, GREEN_LED_PIN);
chThdSleepMilliseconds(40); chThdSleepMilliseconds(40);
} }
// Block until booting the app is allowed and CRC matches // Block until booting the app is allowed and CRC matches
while (bootloaderBusy || !isAppValid()) while (bootloaderBusy || !isAppValid())
{ {
palTogglePad(GPIOB, 5); palTogglePad(BLUE_LED_PORT, BLUE_LED_PIN);
palTogglePad(GPIOB, 6); palTogglePad(GREEN_LED_PORT, GREEN_LED_PIN);
chThdSleepMilliseconds(200); chThdSleepMilliseconds(200);
} }

View File

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

View File

@ -8,6 +8,7 @@
#include "pump_dac.h" #include "pump_dac.h"
#include "sampling.h" #include "sampling.h"
#include "uart.h" #include "uart.h"
#include "io_pins.h"
/* /*
@ -33,10 +34,10 @@ int main() {
if (fault == Fault::None) if (fault == Fault::None)
{ {
// blue is off // blue is off
palClearPad(GPIOB, 5); palClearPad(BLUE_LED_PORT, BLUE_LED_PIN);
// Green is blinking // Green is blinking
palTogglePad(GPIOB, 6); palTogglePad(GREEN_LED_PORT, GREEN_LED_PIN);
// Slow blink if closed loop, fast if not // Slow blink if closed loop, fast if not
chThdSleepMilliseconds(IsRunningClosedLoop() ? 700 : 50); chThdSleepMilliseconds(IsRunningClosedLoop() ? 700 : 50);
@ -50,7 +51,7 @@ int main() {
for (int i = 0; i < 2 * static_cast<int>(fault); i++) for (int i = 0; i < 2 * static_cast<int>(fault); i++)
{ {
// Blue is blinking // Blue is blinking
palTogglePad(GPIOB, 5); palTogglePad(BLUE_LED_PORT, BLUE_LED_PIN);
// fast blink // fast blink
chThdSleepMilliseconds(300); chThdSleepMilliseconds(300);

View File

@ -6,11 +6,12 @@
#include "wideband_config.h" #include "wideband_config.h"
#include "port.h" #include "port.h"
#include "io_pins.h"
// Stored results // Stored results
float nernstAc = 0; static float nernstAc = 0;
float nernstDc = 0; static float nernstDc = 0;
volatile float pumpCurrentSenseVoltage = 0; static volatile float pumpCurrentSenseVoltage = 0;
constexpr float f_abs(float x) constexpr float f_abs(float x)
{ {
@ -29,7 +30,7 @@ static void SamplingThread(void*)
auto result = AnalogSample(); auto result = AnalogSample();
// Toggle the pin after sampling so that any switching noise occurs while we're doing our math instead of when sampling // 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; float r_1 = result.NernstVoltage;