Skip to content

Commit 4110000

Browse files
committed
added asserts for allowable pins
1 parent 99d0970 commit 4110000

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Sming/Arch/Esp32/Core/HardwarePWM.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,19 @@ HardwarePWM::HardwarePWM(uint8_t* pins, uint8_t no_of_pins) : channel_count(no_o
142142
{
143143
assert(no_of_pins > 0 && no_of_pins <= SOC_LEDC_CHANNEL_NUM);
144144
no_of_pins = std::min(uint8_t(SOC_LEDC_CHANNEL_NUM), no_of_pins);
145-
145+
debug_i("initializing PERIPH_LEDC_MODULE");
146146
periph_module_enable(PERIPH_LEDC_MODULE);
147147

148148
for(uint8_t i = 0; i < no_of_pins; i++) {
149+
//make sure we don't try to use pins unavailable for the SoC
150+
#if defined(__riscv)
151+
//esp32c3
152+
assert((pins[i] >= 0 && pins[i] <= 9) || (pins[i] >= 18 && pins[i] <= 21));
153+
#elif
154+
//esp32
155+
if((pins[i] >= 0 && pins[i] <= 19) || (pins[i] >= 22 && pins[i] <= 28) || (pins[i] >= 32 && pins[i] <= 39))
156+
;
157+
#endif
149158
channels[i] = pins[i];
150159

151160
/*

0 commit comments

Comments
 (0)