Fix(sigmaDelta): fixes sigmaDeltaAttach() when another peripheral is already attached (#9268)

This commit is contained in:
Rodrigo Garcia 2024-02-21 11:24:59 -03:00 committed by GitHub
parent 72f9fe3b8b
commit f2a5041c9c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -27,11 +27,13 @@ static bool sigmaDeltaDetachBus(void * bus){
bool sigmaDeltaAttach(uint8_t pin, uint32_t freq) //freq 1220-312500 bool sigmaDeltaAttach(uint8_t pin, uint32_t freq) //freq 1220-312500
{ {
perimanSetBusDeinit(ESP32_BUS_TYPE_SIGMADELTA, sigmaDeltaDetachBus); perimanSetBusDeinit(ESP32_BUS_TYPE_SIGMADELTA, sigmaDeltaDetachBus);
sdm_channel_handle_t bus = (sdm_channel_handle_t)perimanGetPinBus(pin, ESP32_BUS_TYPE_SIGMADELTA); sdm_channel_handle_t bus = NULL;
if(bus != NULL && !perimanClearPinBus(pin)){ // pin may be previously attached to other peripheral -> detach it.
// if attached to sigmaDelta, detach it and set the new frequency
if(perimanGetPinBusType(pin) != ESP32_BUS_TYPE_INIT && !perimanClearPinBus(pin)){
log_e("Pin %u could not be detached.", pin);
return false; return false;
} }
bus = NULL;
sdm_config_t config = { sdm_config_t config = {
.gpio_num = (int)pin, .gpio_num = (int)pin,
.clk_src = SDM_CLK_SRC_DEFAULT, .clk_src = SDM_CLK_SRC_DEFAULT,