Skip to content

Commit 640c9a1

Browse files
committed
core: Limit the value of analog(Read|Write)Resolution
If the value of analogWriteResolution is 0, there is a risk of division by zero in max64 processing, so the value is limited. Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
1 parent 00c4d67 commit 640c9a1

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

cores/arduino/zephyrCommon.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ unsigned long millis(void) {
461461
static int _analog_write_resolution = 8;
462462

463463
void analogWriteResolution(int bits) {
464-
_analog_write_resolution = bits;
464+
_analog_write_resolution = CLAMP(bits, 1, 31);
465465
}
466466

467467
int analogWriteResolution() {
@@ -561,7 +561,7 @@ void __attribute__((weak)) analogReference(uint8_t mode) {
561561
static int read_resolution = 10;
562562

563563
void analogReadResolution(int bits) {
564-
read_resolution = bits;
564+
read_resolution = CLAMP(bits, 1, 31);
565565
}
566566

567567
int analogReadResolution() {

0 commit comments

Comments
 (0)