From ae99ff59678d80b0fdd0decb172aabd122226d62 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Wed, 14 Apr 2021 15:16:45 -0400 Subject: [PATCH] add-on led support --- source/board/l4/board.h | 2 +- source/main.cpp | 37 ++++++++++++++++++++++++++----------- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/source/board/l4/board.h b/source/board/l4/board.h index ff42cd1..8291664 100644 --- a/source/board/l4/board.h +++ b/source/board/l4/board.h @@ -225,7 +225,7 @@ #define LINE_ARD_A2 PAL_LINE(GPIOA, 4U) #define LINE_ACD12_IN9 PAL_LINE(GPIOA, 4U) #define LINE_ARD_D13 PAL_LINE(GPIOA, 5U) -#define LINE_LED_GREEN PAL_LINE(GPIOA, 5U) +//#define LINE_LED_GREEN PAL_LINE(GPIOA, 5U) #define LINE_ARD_D12 PAL_LINE(GPIOA, 6U) #define LINE_ARD_D11 PAL_LINE(GPIOA, 7U) #define LINE_ARD_D7 PAL_LINE(GPIOA, 8U) diff --git a/source/main.cpp b/source/main.cpp index fbadd23..e151a3d 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -50,11 +50,9 @@ static msg_t conversionMBBuffer[2]; static MAILBOX_DECL(conversionMB, conversionMBBuffer, 2); // Thread for LED status and wakeup hold -#if defined(TARGET_PLATFORM_H7) __attribute__((section(".stacks"))) -static THD_WORKING_AREA(monitorThreadWA, 1024); +static THD_WORKING_AREA(monitorThreadWA, 256); static THD_FUNCTION(monitorThread, arg); -#endif // Thread for managing the conversion task __attribute__((section(".stacks"))) @@ -109,6 +107,12 @@ static void abortAlgorithmFromISR(); static void signal_operate(adcsample_t *buffer, size_t count); static void signal_operate_measure(adcsample_t *buffer, size_t count); +#if defined(TARGET_PLATFORM_L4) +constexpr auto LINE_LED_GREEN = PAL_LINE(GPIOC_BASE, 10U); +constexpr auto LINE_LED_YELLOW = PAL_LINE(GPIOC_BASE, 11U); +constexpr auto LINE_LED_RED = PAL_LINE(GPIOC_BASE, 12U); +#endif + int main() { // Initialize the RTOS @@ -118,7 +122,12 @@ int main() SCB->CPACR |= 0xF << 20; // Enable FPU mpu_setup(); - palSetLineMode(LINE_BUTTON, PAL_MODE_INPUT); +#if defined(TARGET_PLATFORM_L4) + palSetLineMode(LINE_LED_GREEN, PAL_MODE_OUTPUT_PUSHPULL); + palSetLineMode(LINE_LED_YELLOW, PAL_MODE_OUTPUT_PUSHPULL); + palSetLineMode(LINE_LED_RED, PAL_MODE_OUTPUT_PUSHPULL); +#endif + ADC::begin(); DAC::begin(); SClock::begin(); @@ -129,12 +138,10 @@ int main() ADC::setRate(SClock::Rate::R32K); chTMObjectInit(&conversion_time_measurement); -#if defined(TARGET_PLATFORM_H7) chThdCreateStatic( monitorThreadWA, sizeof(monitorThreadWA), LOWPRIO, monitorThread, nullptr); -#endif conversionThreadMonitorHandle = chThdCreateStatic( conversionThreadMonitorWA, sizeof(conversionThreadMonitorWA), NORMALPRIO + 1, @@ -388,12 +395,21 @@ THD_FUNCTION(conversionThread, stack) reinterpret_cast(stack)); } -#if defined(TARGET_PLATFORM_H7) THD_FUNCTION(monitorThread, arg) { (void)arg; palSetLineMode(LINE_BUTTON, PAL_MODE_INPUT_PULLUP); + auto readButton = [] { +#if defined(TARGET_PLATFORM_L4) + return !palReadLine(LINE_BUTTON); +#else + return palReadLine(LINE_BUTTON); +#endif + }; + + palClearLine(LINE_LED_RED); + palClearLine(LINE_LED_YELLOW); while (1) { bool isidle = run_status == RunStatus::Idle; @@ -405,13 +421,13 @@ THD_FUNCTION(monitorThread, arg) palClearLine(led); chThdSleepMilliseconds(delay); - if (run_status == RunStatus::Idle && palReadLine(LINE_BUTTON)) { + if (run_status == RunStatus::Idle && readButton()) { palSetLine(LINE_LED_RED); palSetLine(LINE_LED_YELLOW); chSysLock(); - while (palReadLine(LINE_BUTTON)) + while (readButton()) asm("nop"); - while (!palReadLine(LINE_BUTTON)) + while (!readButton()) asm("nop"); chSysUnlock(); palClearLine(LINE_LED_RED); @@ -429,7 +445,6 @@ THD_FUNCTION(monitorThread, arg) } } } -#endif void conversion_unprivileged_main() {