Skip to content

Commit f2a5041

Browse files
authored
Fix(sigmaDelta): fixes sigmaDeltaAttach() when another peripheral is already attached (#9268)
1 parent 72f9fe3 commit f2a5041

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Diff for: cores/esp32/esp32-hal-sigmadelta.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ static bool sigmaDeltaDetachBus(void * bus){
2727
bool sigmaDeltaAttach(uint8_t pin, uint32_t freq) //freq 1220-312500
2828
{
2929
perimanSetBusDeinit(ESP32_BUS_TYPE_SIGMADELTA, sigmaDeltaDetachBus);
30-
sdm_channel_handle_t bus = (sdm_channel_handle_t)perimanGetPinBus(pin, ESP32_BUS_TYPE_SIGMADELTA);
31-
if(bus != NULL && !perimanClearPinBus(pin)){
30+
sdm_channel_handle_t bus = NULL;
31+
// pin may be previously attached to other peripheral -> detach it.
32+
// if attached to sigmaDelta, detach it and set the new frequency
33+
if(perimanGetPinBusType(pin) != ESP32_BUS_TYPE_INIT && !perimanClearPinBus(pin)){
34+
log_e("Pin %u could not be detached.", pin);
3235
return false;
3336
}
34-
bus = NULL;
3537
sdm_config_t config = {
3638
.gpio_num = (int)pin,
3739
.clk_src = SDM_CLK_SRC_DEFAULT,

0 commit comments

Comments
 (0)