Skip to content

Commit

Permalink
Fix compilation warning
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisxhe committed Oct 17, 2023
1 parent 2715d95 commit 21eddf2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
6 changes: 4 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ build_flags =
; -DCONFIG_PMU_IRQ=40
; -UARDUINO_USB_CDC_ON_BOOT
; -DARDUINO_USB_CDC_ON_BOOT=1


-Wtype-limits
-Wall
-Werror

[env:esp32dev]
platform = espressif32
framework = arduino
Expand Down
19 changes: 16 additions & 3 deletions src/PowersSY6970.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,12 @@ public:
log_e("Mistake ! The steps is must %u mA", POWERS_SY6970_PRE_CHG_CUR_STEP);
return false;
}
XPOWERS_CHECK_RANGE(milliampere, POWERS_PRE_CHG_CURRENT_MIN, POWERS_PRE_CHG_CURRENT_MAX, false);
if (milliampere < POWERS_PRE_CHG_CURRENT_MIN) {
milliampere = POWERS_PRE_CHG_CURRENT_MIN;
}
if (milliampere > POWERS_PRE_CHG_CURRENT_MAX) {
milliampere = POWERS_PRE_CHG_CURRENT_MAX;
}
int val = readRegister(POWERS_SY6970_REG_05H);
val &= 0x0F;
milliampere = ((milliampere - POWERS_SY6970_PRE_CHG_CUR_BASE) / POWERS_SY6970_PRE_CHG_CUR_STEP);
Expand Down Expand Up @@ -449,7 +454,10 @@ public:
log_e("Mistake ! The steps is must %u mA", POWERS_SY6970_FAST_CHG_CUR_STEP);
return false;
}
XPOWERS_CHECK_RANGE(milliampere, POWERS_FAST_CHG_CURRENT_MIN, POWERS_FAST_CHG_CURRENT_MAX, false);
if (milliampere > POWERS_FAST_CHG_CURRENT_MAX) {
milliampere = POWERS_FAST_CHG_CURRENT_MAX;
}

int val = readRegister(POWERS_SY6970_REG_04H);
val &= 0x80;
val |= (milliampere / POWERS_SY6970_FAST_CHG_CUR_STEP);
Expand All @@ -473,7 +481,12 @@ public:
log_e("Mistake ! The steps is must %u mV", POWERS_SY6970_CHG_VOL_STEP);
return false;
}
XPOWERS_CHECK_RANGE(millivolt, POWERS_FAST_CHG_VOL_MIN, POWERS_FAST_CHG_VOL_MAX, false);
if (millivolt < POWERS_FAST_CHG_VOL_MIN) {
millivolt = POWERS_FAST_CHG_VOL_MIN;
}
if (millivolt > POWERS_FAST_CHG_VOL_MAX) {
millivolt = POWERS_FAST_CHG_VOL_MAX;
}
int val = readRegister(POWERS_SY6970_REG_06H);
val &= 0x03;
val |= (((millivolt - POWERS_SY6970_CHG_VOL_BASE) / POWERS_SY6970_CHG_VOL_STEP) << 2);
Expand Down
1 change: 0 additions & 1 deletion src/XPowersCommon.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
#endif

#define XPOWERS_CHECK_RANGE(VAR, MIN, MAX, ERR) { if(!(((VAR) >= (MIN)) && ((VAR) <= (MAX)))) { return(ERR); } }


#define XPOWERS_ATTR_NOT_IMPLEMENTED __attribute__((error("Not implemented")))
Expand Down

0 comments on commit 21eddf2

Please sign in to comment.