Skip to content

Commit

Permalink
added asserts for allowable pins
Browse files Browse the repository at this point in the history
  • Loading branch information
pljakobs committed Nov 2, 2024
1 parent ef5f105 commit 91602b3
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Sming/Arch/Esp32/Core/HardwarePWM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,19 @@ HardwarePWM::HardwarePWM(uint8_t* pins, uint8_t no_of_pins) : channel_count(no_o
{
assert(no_of_pins > 0 && no_of_pins <= SOC_LEDC_CHANNEL_NUM);
no_of_pins = std::min(uint8_t(SOC_LEDC_CHANNEL_NUM), no_of_pins);

debug_i("initializing PERIPH_LEDC_MODULE");
periph_module_enable(PERIPH_LEDC_MODULE);

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

/*
Expand Down

0 comments on commit 91602b3

Please sign in to comment.