diff --git a/source/Core/BSP/Defines.h b/source/Core/BSP/Defines.h index b8d4e0cf..c7b5d9ff 100644 --- a/source/Core/BSP/Defines.h +++ b/source/Core/BSP/Defines.h @@ -7,7 +7,7 @@ #ifndef BSP_DEFINES_H_ #define BSP_DEFINES_H_ - +#include "FreeRTOSConfig.h" enum Orientation { ORIENTATION_LEFT_HAND = 0, ORIENTATION_RIGHT_HAND = 1, ORIENTATION_FLAT = 3 }; // It is assumed that all hardware implements an 8Hz update period at this time diff --git a/source/Core/BSP/Miniware/FreeRTOSConfig.h b/source/Core/BSP/Miniware/FreeRTOSConfig.h index 2fc0dc22..dd95674e 100644 --- a/source/Core/BSP/Miniware/FreeRTOSConfig.h +++ b/source/Core/BSP/Miniware/FreeRTOSConfig.h @@ -83,7 +83,9 @@ *----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ -/* Section where include file can be added */ +#ifdef __cplusplus +extern "C" { +#endif /* USER CODE END Includes */ /* Ensure stdint is only used by the compiler, and not the assembler. */ @@ -172,5 +174,7 @@ extern uint32_t SystemCoreClock; #define configTIMER_QUEUE_LENGTH 8 #define configTIMER_TASK_STACK_DEPTH (512 / 4) #endif - +#ifdef __cplusplus +} +#endif #endif /* FREERTOS_CONFIG_H */ diff --git a/source/Core/BSP/Pine64/Vendor/SoC/gd32vf103/Common/Source/Drivers/Usb/usbd_enum.c b/source/Core/BSP/Pine64/Vendor/SoC/gd32vf103/Common/Source/Drivers/Usb/usbd_enum.c index e613d4d7..8b976709 100644 --- a/source/Core/BSP/Pine64/Vendor/SoC/gd32vf103/Common/Source/Drivers/Usb/usbd_enum.c +++ b/source/Core/BSP/Pine64/Vendor/SoC/gd32vf103/Common/Source/Drivers/Usb/usbd_enum.c @@ -93,7 +93,8 @@ usb_reqsta usbd_class_request(usb_core_driver *udev, usb_req *req) { if (USBD_CONFIGURED == udev->dev.cur_status) { if (BYTE_LOW(req->wIndex) <= USBD_ITF_MAX_NUM) { /* call device class handle function */ - return (usb_reqsta)udev->dev.class_core->req_proc(udev, req); + uint8_t res = udev->dev.class_core->req_proc(udev, req); + return (usb_reqsta)res; } } @@ -426,7 +427,10 @@ static usb_reqsta _usb_std_getdescriptor(usb_core_driver *udev, usb_req *req) { case USB_RECPTYPE_ITF: /* get device class special descriptor */ - return (usb_reqsta)(udev->dev.class_core->req_proc(udev, req)); + { + uint8_t res = udev->dev.class_core->req_proc(udev, req); + return (usb_reqsta)res; + } case USB_RECPTYPE_EP: break; diff --git a/source/Core/BSP/Pine64/Vendor/SoC/gd32vf103/Common/Source/Drivers/Usb/usbh_transc.c b/source/Core/BSP/Pine64/Vendor/SoC/gd32vf103/Common/Source/Drivers/Usb/usbh_transc.c index cf6e4c7a..ea7a3626 100644 --- a/source/Core/BSP/Pine64/Vendor/SoC/gd32vf103/Common/Source/Drivers/Usb/usbh_transc.c +++ b/source/Core/BSP/Pine64/Vendor/SoC/gd32vf103/Common/Source/Drivers/Usb/usbh_transc.c @@ -45,7 +45,6 @@ OF SUCH DAMAGE. static uint32_t usbh_request_submit(usb_core_driver *pudev, uint8_t pp_num) { pudev->host.pipe[pp_num].urb_state = URB_IDLE; pudev->host.pipe[pp_num].xfer_count = 0U; - return usb_pipe_xfer(pudev, pp_num); } @@ -63,8 +62,8 @@ usbh_status usbh_ctlsetup_send(usb_core_driver *pudev, uint8_t *buf, uint8_t pp_ pp->DPID = PIPE_DPID_SETUP; pp->xfer_buf = buf; pp->xfer_len = USB_SETUP_PACKET_LEN; - - return (usbh_status)usbh_request_submit(pudev, pp_num); + uint32_t res = usbh_request_submit(pudev, pp_num); + return (usbh_status)res; } /*! diff --git a/source/Core/Drivers/Buttons.cpp b/source/Core/Drivers/Buttons.cpp index 8cc83b88..935478e6 100644 --- a/source/Core/Drivers/Buttons.cpp +++ b/source/Core/Drivers/Buttons.cpp @@ -24,7 +24,7 @@ ButtonState getButtonState() { */ static uint8_t previousState = 0; static uint32_t previousStateChange = 0; - const uint16_t timeout = 400; + const uint16_t timeout = TICKS_100MS * 4; uint8_t currentState; currentState = (getButtonA()) << 0; currentState |= (getButtonB()) << 1; diff --git a/source/Core/Drivers/OLED.cpp b/source/Core/Drivers/OLED.cpp index 3e969132..824c762e 100644 --- a/source/Core/Drivers/OLED.cpp +++ b/source/Core/Drivers/OLED.cpp @@ -162,14 +162,14 @@ void OLED::transitionSecondaryFramebuffer(bool forwardNavigation) { uint8_t *firstBackStripPtr = &secondFrameBuffer[0]; uint8_t *secondBackStripPtr = &secondFrameBuffer[OLED_WIDTH]; - uint32_t totalDuration = 50; // 500ms + uint32_t totalDuration = TICKS_100MS * 5; // 500ms uint32_t duration = 0; uint32_t start = xTaskGetTickCount(); uint8_t offset = 0; while (duration <= totalDuration) { duration = xTaskGetTickCount() - start; - uint8_t progress = duration * TICKS_SECOND / totalDuration; + uint8_t progress = ((duration * 100) / totalDuration); // Percentage of the period we are through for animation progress = easeInOutTiming(progress); progress = lerp(0, OLED_WIDTH, progress); if (progress > OLED_WIDTH) { diff --git a/source/Core/Inc/gui.hpp b/source/Core/Inc/gui.hpp index 772389ad..245f3f16 100644 --- a/source/Core/Inc/gui.hpp +++ b/source/Core/Inc/gui.hpp @@ -11,9 +11,9 @@ #include "Settings.h" #include "Translation.h" -#define PRESS_ACCEL_STEP 30 -#define PRESS_ACCEL_INTERVAL_MIN 100 -#define PRESS_ACCEL_INTERVAL_MAX 300 +#define PRESS_ACCEL_STEP (TICKS_100MS / 3) +#define PRESS_ACCEL_INTERVAL_MIN TICKS_100MS +#define PRESS_ACCEL_INTERVAL_MAX (TICKS_100MS * 3) // GUI holds the menu structure and all its methods for the menu itself diff --git a/source/Core/Src/gui.cpp b/source/Core/Src/gui.cpp index 6d37dbf1..04b00d91 100644 --- a/source/Core/Src/gui.cpp +++ b/source/Core/Src/gui.cpp @@ -276,7 +276,7 @@ static int userConfirmation(const char *message) { bool lcdRefresh = true; for (;;) { - int16_t messageOffset = ((xTaskGetTickCount() - messageStart) / (systemSettings.descriptionScrollSpeed == 1 ? 10 : 20)); + int16_t messageOffset = ((xTaskGetTickCount() - messageStart) / (systemSettings.descriptionScrollSpeed == 1 ? TICKS_100MS : (TICKS_100MS * 2))); messageOffset %= messageWidth; // Roll around at the end if (lastOffset != messageOffset) { @@ -1078,7 +1078,7 @@ void gui_Menu(const menuitem *menu) { OLED::setCursor(0, 0); // If the user has hesitated for >=3 seconds, show the long text // Otherwise "draw" the option - if ((xTaskGetTickCount() - lastButtonTime < 3000) || menu[currentScreen].description == NULL) { + if ((xTaskGetTickCount() - lastButtonTime < (TICKS_SECOND * 3)) || menu[currentScreen].description == NULL) { OLED::clearScreen(); menu[currentScreen].draw(); uint8_t indicatorHeight = OLED_HEIGHT / scrollContentSize; @@ -1095,7 +1095,7 @@ void gui_Menu(const menuitem *menu) { descriptionStart = xTaskGetTickCount(); // lower the value - higher the speed int16_t descriptionWidth = FONT_12_WIDTH * (strlen(menu[currentScreen].description) + 7); - int16_t descriptionOffset = ((xTaskGetTickCount() - descriptionStart) / (systemSettings.descriptionScrollSpeed == 1 ? 10 : 20)); + int16_t descriptionOffset = ((xTaskGetTickCount() - descriptionStart) / (systemSettings.descriptionScrollSpeed == 1 ? (TICKS_100MS / 10) : (TICKS_100MS / 5))); descriptionOffset %= descriptionWidth; // Roll around at the end if (lastOffset != descriptionOffset) { OLED::clearScreen(); @@ -1149,7 +1149,7 @@ void gui_Menu(const menuitem *menu) { descriptionStart = 0; break; case BUTTON_F_LONG: - if ((int)(xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration) > PRESS_ACCEL_INTERVAL_MAX) { + if ((xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration) > PRESS_ACCEL_INTERVAL_MAX) { if ((lastValue = menu[currentScreen].incrementHandler())) autoRepeatTimer = 1000; else @@ -1185,7 +1185,7 @@ void gui_Menu(const menuitem *menu) { osDelay(40); lcdRefresh = false; } - if ((xTaskGetTickCount() - lastButtonTime) > (1000 * 30)) { + if ((xTaskGetTickCount() - lastButtonTime) > (TICKS_SECOND * 30)) { // If user has not pressed any buttons in 30 seconds, exit back a menu layer // This will trickle the user back to the main screen eventually earlyExit = true; diff --git a/source/Core/Threads/GUIThread.cpp b/source/Core/Threads/GUIThread.cpp index f58a1e8c..f6bcd8a5 100644 --- a/source/Core/Threads/GUIThread.cpp +++ b/source/Core/Threads/GUIThread.cpp @@ -256,7 +256,7 @@ static void gui_solderingTempAdjust() { systemSettings.SolderingTemp = 10; } - if (xTaskGetTickCount() - lastChange > 2000) + if (xTaskGetTickCount() - lastChange > (TICKS_SECOND * 2)) return; // exit if user just doesn't press anything for a bit #ifdef OLED_FLIP @@ -645,11 +645,11 @@ void showDebugMenu(void) { break; case 4: // system up time stamp - OLED::printNumber(xTaskGetTickCount() / 100, 5); + OLED::printNumber(xTaskGetTickCount() / TICKS_100MS, 5); break; case 5: // Movement time stamp - OLED::printNumber(lastMovementTime / 100, 5); + OLED::printNumber(lastMovementTime / TICKS_100MS, 5); break; case 6: // Raw Tip @@ -774,7 +774,7 @@ void startGUITask(void const *argument __unused) { getTipRawTemp(1); // reset filter OLED::setRotation(systemSettings.OrientationMode & 1); uint32_t ticks = xTaskGetTickCount(); - ticks += 4000; // 4 seconds from now + ticks += (TICKS_SECOND * 4); // 4 seconds from now while (xTaskGetTickCount() < ticks) { if (showBootLogoIfavailable() == false) ticks = xTaskGetTickCount(); @@ -912,7 +912,7 @@ void startGUITask(void const *argument __unused) { // If we have a tip connected draw the temp, if not we leave it blank if (!tipDisconnectedDisplay) { // draw in the temp - if (!(systemSettings.coolingTempBlink && (xTaskGetTickCount() % 26 < 16))) + if (!(systemSettings.coolingTempBlink && (xTaskGetTickCount() % 260 < 160))) gui_drawTipTemp(false); // draw in the temp } else { // Draw in missing tip symbol diff --git a/source/Core/Threads/MOVThread.cpp b/source/Core/Threads/MOVThread.cpp index f02374c8..22b76f9d 100644 --- a/source/Core/Threads/MOVThread.cpp +++ b/source/Core/Threads/MOVThread.cpp @@ -170,6 +170,6 @@ void startMOVTask(void const *argument __unused) { lastMovementTime = xTaskGetTickCount(); } - osDelay(TICKS_100MS); // Slow down update rate + vTaskDelay(TICKS_100MS); // Slow down update rate } } diff --git a/source/Core/Threads/PIDThread.cpp b/source/Core/Threads/PIDThread.cpp index 5a35e2a3..f16b9b2b 100644 --- a/source/Core/Threads/PIDThread.cpp +++ b/source/Core/Threads/PIDThread.cpp @@ -14,8 +14,8 @@ #include "main.hpp" #include "power.hpp" #include "task.h" -static TickType_t powerPulseRate = 10000; -static TickType_t powerPulseDuration = 250; +static TickType_t powerPulseRate = 10 * TICKS_SECOND; +static TickType_t powerPulseDuration = 3 * TICKS_100MS; TaskHandle_t pidTaskNotification = NULL; uint32_t currentTempTargetDegC = 0; // Current temperature target in C diff --git a/source/Makefile b/source/Makefile index 9636c99c..e3df0e5e 100644 --- a/source/Makefile +++ b/source/Makefile @@ -127,7 +127,7 @@ HEXFILE_DIR=Hexfile OUTPUT_DIR_BASE=Objects OUTPUT_DIR=Objects/$(model) # code optimisation ------------------------------------------------------------ -OPTIM=-Os -flto -finline-small-functions -findirect-inlining -fdiagnostics-color -ffunction-sections -fdata-sections +OPTIM=-Os -flto -finline-small-functions -findirect-inlining -fdiagnostics-color -ffunction-sections -fdata-sections -fshort-enums # global defines --------------------------------------------------------------- GLOBAL_DEFINES += $(DEV_GLOBAL_DEFS) -D USE_RTOS_SYSTICK -D MODEL_$(model) -D VECT_TAB_OFFSET=$(bootldr_size)U