File tree 1 file changed +5
-3
lines changed
1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -27,11 +27,13 @@ static bool sigmaDeltaDetachBus(void * bus){
27
27
bool sigmaDeltaAttach (uint8_t pin , uint32_t freq ) //freq 1220-312500
28
28
{
29
29
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 );
32
35
return false;
33
36
}
34
- bus = NULL ;
35
37
sdm_config_t config = {
36
38
.gpio_num = (int )pin ,
37
39
.clk_src = SDM_CLK_SRC_DEFAULT ,
You can’t perform that action at this time.
0 commit comments