mirror of
https://github.com/mck1117/wideband.git
synced 2026-09-30 09:57:06 -04:00
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:
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
*.sh text eol=lf
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "hal.h"
|
||||
|
||||
#include "flash.h"
|
||||
#include "../io_pins.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
8
firmware/boards/f0_module/io_pins.h
Normal file
8
firmware/boards/f0_module/io_pins.h
Normal 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
|
||||
@@ -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<int>(fault); i++)
|
||||
{
|
||||
// Blue is blinking
|
||||
palTogglePad(GPIOB, 5);
|
||||
palTogglePad(BLUE_LED_PORT, BLUE_LED_PIN);
|
||||
|
||||
// fast blink
|
||||
chThdSleepMilliseconds(300);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user