From 3749c43aa6ab462c89a070a176e226ce2f5b12e9 Mon Sep 17 00:00:00 2001 From: Ivan Zorin Date: Sat, 22 Jul 2023 04:30:17 +0300 Subject: [PATCH 1/2] clang-format: add ./Core/Drivers (except usb-pd) to the scope of style check --- source/Core/Drivers/HUB238.cpp | 2 +- source/Core/Drivers/OLED.cpp | 70 +++++++++++++++----------- source/Core/Drivers/TipThermoModel.cpp | 8 +-- source/Core/Drivers/USBPD.cpp | 15 +++--- source/Makefile | 2 - 5 files changed, 57 insertions(+), 40 deletions(-) diff --git a/source/Core/Drivers/HUB238.cpp b/source/Core/Drivers/HUB238.cpp index 3a88c18579..6d2940b009 100644 --- a/source/Core/Drivers/HUB238.cpp +++ b/source/Core/Drivers/HUB238.cpp @@ -215,6 +215,6 @@ uint8_t hub238_source_currentX100() { temp &= 0b1111; return pdo_slot_to_currentx100(temp); } - return 10;//Failsafe to 0.1 amp + return 10; // Failsafe to 0.1 amp } #endif diff --git a/source/Core/Drivers/OLED.cpp b/source/Core/Drivers/OLED.cpp index c6e7ce675b..27f103fc5c 100644 --- a/source/Core/Drivers/OLED.cpp +++ b/source/Core/Drivers/OLED.cpp @@ -33,19 +33,19 @@ uint32_t OLED::displayChecksum; */ I2C_CLASS::I2C_REG OLED_Setup_Array[] = { /**/ - {0x80, OLED_OFF, 0}, /* Display off */ - {0x80, OLED_DIVIDER, 0}, /* Set display clock divide ratio / osc freq */ - {0x80, 0x52, 0}, /* Divide ratios */ - {0x80, 0xA8, 0}, /* Set Multiplex Ratio */ - {0x80, OLED_HEIGHT - 1, 0}, /* Multiplex ratio adjusts how far down the matrix it scans */ - {0x80, 0xC0, 0}, /* Set COM Scan direction */ - {0x80, 0xD3, 0}, /* Set vertical Display offset */ - {0x80, 0x00, 0}, /* 0 Offset */ - {0x80, 0x40, 0}, /* Set Display start line to 0 */ + {0x80, OLED_OFF, 0}, /* Display off */ + {0x80, OLED_DIVIDER, 0}, /* Set display clock divide ratio / osc freq */ + {0x80, 0x52, 0}, /* Divide ratios */ + {0x80, 0xA8, 0}, /* Set Multiplex Ratio */ + {0x80, OLED_HEIGHT - 1, 0}, /* Multiplex ratio adjusts how far down the matrix it scans */ + {0x80, 0xC0, 0}, /* Set COM Scan direction */ + {0x80, 0xD3, 0}, /* Set vertical Display offset */ + {0x80, 0x00, 0}, /* 0 Offset */ + {0x80, 0x40, 0}, /* Set Display start line to 0 */ #ifdef OLED_SEGMENT_MAP_REVERSED - {0x80, 0xA1, 0}, /* Set Segment remap to normal */ + {0x80, 0xA1, 0}, /* Set Segment remap to normal */ #else - {0x80, 0xA0, 0}, /* Set Segment remap to normal */ + {0x80, 0xA0, 0}, /* Set Segment remap to normal */ #endif {0x80, 0x8D, 0}, /* Charge Pump */ {0x80, 0x14, 0}, /* Charge Pump settings */ @@ -547,8 +547,9 @@ void OLED::printNumber(uint16_t number, uint8_t places, FontStyle fontStyle, boo } buffer[0] = 2 + number % 10; - if (noLeaderZeros) + if (noLeaderZeros) { stripLeaderZeros(buffer, places); + } print(buffer, fontStyle); } @@ -574,10 +575,12 @@ void OLED::drawSymbol(uint8_t symbolID) { // Draw an area, but y must be aligned on 0/8 offset void OLED::drawArea(int16_t x, int8_t y, uint8_t wide, uint8_t height, const uint8_t *ptr) { // Splat this from x->x+wide in two strides - if (x <= -wide) + if (x <= -wide) { return; // cutoffleft - if (x > 96) + } + if (x > 96) { return; // cutoff right + } uint8_t visibleStart = 0; uint8_t visibleEnd = wide; @@ -609,10 +612,12 @@ void OLED::drawArea(int16_t x, int8_t y, uint8_t wide, uint8_t height, const uin // For data which has octets swapped in a 16-bit word. void OLED::drawAreaSwapped(int16_t x, int8_t y, uint8_t wide, uint8_t height, const uint8_t *ptr) { // Splat this from x->x+wide in two strides - if (x <= -wide) + if (x <= -wide) { return; // cutoffleft - if (x > 96) + } + if (x > 96) { return; // cutoff right + } uint8_t visibleStart = 0; uint8_t visibleEnd = wide; @@ -643,10 +648,12 @@ void OLED::drawAreaSwapped(int16_t x, int8_t y, uint8_t wide, uint8_t height, co void OLED::fillArea(int16_t x, int8_t y, uint8_t wide, uint8_t height, const uint8_t value) { // Splat this from x->x+wide in two strides - if (x <= -wide) + if (x <= -wide) { return; // cutoffleft - if (x > 96) + } + if (x > 96) { return; // cutoff right + } uint8_t visibleStart = 0; uint8_t visibleEnd = wide; @@ -682,30 +689,37 @@ void OLED::drawFilledRect(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, bool c uint8_t mask = 0xFF; if (y0) { mask = mask << (y0 % 8); - for (uint8_t col = x0; col < x1; col++) - if (clear) + for (uint8_t col = x0; col < x1; col++) { + if (clear) { stripPointers[0][(y0 / 8) * 96 + col] &= ~mask; - else + } else { stripPointers[0][(y0 / 8) * 96 + col] |= mask; + } + } } // Next loop down the line the total number of solids - if (y0 / 8 != y1 / 8) - for (uint8_t col = x0; col < x1; col++) + if (y0 / 8 != y1 / 8) { + for (uint8_t col = x0; col < x1; col++) { for (uint8_t r = (y0 / 8); r < (y1 / 8); r++) { // This gives us the row index r - if (clear) + if (clear) { stripPointers[0][(r * 96) + col] = 0; - else + } else { stripPointers[0][(r * 96) + col] = 0xFF; + } } + } + } // Finally draw the tail mask = ~(mask << (y1 % 8)); - for (uint8_t col = x0; col < x1; col++) - if (clear) + for (uint8_t col = x0; col < x1; col++) { + if (clear) { stripPointers[0][(y1 / 8) * 96 + col] &= ~mask; - else + } else { stripPointers[0][(y1 / 8) * 96 + col] |= mask; + } + } } void OLED::drawHeatSymbol(uint8_t state) { diff --git a/source/Core/Drivers/TipThermoModel.cpp b/source/Core/Drivers/TipThermoModel.cpp index c71f23323e..ea6a0c747d 100644 --- a/source/Core/Drivers/TipThermoModel.cpp +++ b/source/Core/Drivers/TipThermoModel.cpp @@ -44,10 +44,11 @@ uint32_t TipThermoModel::convertTipRawADCTouV(uint16_t rawADC, bool ski if (getSettingValue(SettingsOptions::CalibrationOffset) && skipCalOffset == false) { // Remove uV tipOffset - if (valueuV > getSettingValue(SettingsOptions::CalibrationOffset)) + if (valueuV > getSettingValue(SettingsOptions::CalibrationOffset)) { valueuV -= getSettingValue(SettingsOptions::CalibrationOffset); - else + } else { valueuV = 0; + } } lastuv = valueuV; return valueuV; @@ -78,8 +79,9 @@ uint32_t TipThermoModel::getTipInC(bool sampleNow) { // I found a number that doesn't unbalance the existing PID, causing overshoot. // This could be tuned in concert with PID parameters... - if (currentTipTempInC < 0) + if (currentTipTempInC < 0) { return 0; + } return currentTipTempInC; } diff --git a/source/Core/Drivers/USBPD.cpp b/source/Core/Drivers/USBPD.cpp index b621ab2cc5..d360b94018 100644 --- a/source/Core/Drivers/USBPD.cpp +++ b/source/Core/Drivers/USBPD.cpp @@ -46,7 +46,7 @@ void USBPowerDelivery::IRQOccured() { pe.IRQOccured(); } bool USBPowerDelivery::negotiationHasWorked() { return pe.pdHasNegotiated(); } uint8_t USBPowerDelivery::getStateNumber() { return pe.currentStateCode(true); } void USBPowerDelivery::step() { - while (pe.thread()) {} + while (pe.thread()) {} } void USBPowerDelivery::PPSTimerCallback() { pe.TimersCallback(); } @@ -93,18 +93,22 @@ uint32_t *USBPowerDelivery::getLastSeenCapabilities() { return lastCapabilities; static unsigned int sqrtI(unsigned long sqrtArg) { unsigned int answer, x; unsigned long temp; - if (sqrtArg == 0) + if (sqrtArg == 0) { return 0; // undefined result - if (sqrtArg == 1) + } + if (sqrtArg == 1) { return 1; // identity + } answer = 0; // integer square root for (x = 0x8000; x > 0; x = x >> 1) { // 16 bit shift answer |= x; // possible bit in root temp = answer * answer; // - if (temp == sqrtArg) + if (temp == sqrtArg) { break; // exact, found it - if (temp > sqrtArg) + } + if (temp > sqrtArg) { answer ^= x; // too large, reverse bit + } } return answer; // approximate root } @@ -225,7 +229,6 @@ bool EPREvaluateCapabilityFunc(const epr_pd_msg *capabilities, pd_msg *request) request->hdr = PD_MSGTYPE_EPR_REQUEST | PD_NUMOBJ(2); request->obj[1] = lastCapabilities[bestIndex]; // Copy PDO into slot 2 - if (bestIsAVS) { request->obj[0] = PD_RDO_PROG_CURRENT_SET(PD_CA2PAI(bestIndexCurrent)) | PD_RDO_PROG_VOLTAGE_SET(PD_MV2APS(bestIndexVoltage)); } else if (bestIsPPS) { diff --git a/source/Makefile b/source/Makefile index 49b8653200..f6f36b3ad2 100644 --- a/source/Makefile +++ b/source/Makefile @@ -178,7 +178,6 @@ PD_DRIVER_DIR=./Core/Drivers/usb-pd ALL_INCLUDES_EXCEPT:=-path $(BRIEFLZ_INC_DIR) \ -o -path $(PD_DRIVER_DIR) \ -o -path $(PINECILV2_SDK_DIR) \ - -o -path $(DRIVER_INC_DIR) \ -o -path $(MINIWARE_HAL_INC_DIR) \ -o -path $(S60_HAL_INC_DIR) \ -o -path $(MHP30_HAL_INC_DIR) \ @@ -193,7 +192,6 @@ ALL_INCLUDES_EXCEPT:=-path $(BRIEFLZ_INC_DIR) \ ALL_SOURCE_EXCEPT:=-path $(SOURCE_BRIEFLZ_DIR) \ -o -path $(PD_DRIVER_DIR) \ -o -path $(PINECILV2_SDK_DIR) \ - -o -path $(SOURCE_DRIVERS_DIR) \ -o -path $(MINIWARE_HAL_SRC_DIR) \ -o -path $(S60_HAL_SRC_DIR) \ -o -path $(MHP30_HAL_SRC_DIR) \ From 01a5a3bce1b14e9009acc1c549fe8ce80dea55b1 Mon Sep 17 00:00:00 2001 From: Ivan Zorin Date: Sat, 22 Jul 2023 04:35:12 +0300 Subject: [PATCH 2/2] Fix missed suggestion --- source/Core/Drivers/USBPD.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Core/Drivers/USBPD.cpp b/source/Core/Drivers/USBPD.cpp index d360b94018..6613bb9d87 100644 --- a/source/Core/Drivers/USBPD.cpp +++ b/source/Core/Drivers/USBPD.cpp @@ -97,7 +97,7 @@ static unsigned int sqrtI(unsigned long sqrtArg) { return 0; // undefined result } if (sqrtArg == 1) { - return 1; // identity + return 1; // identity } answer = 0; // integer square root for (x = 0x8000; x > 0; x = x >> 1) { // 16 bit shift