Skip to content

Commit 344573d

Browse files
authored
Merge pull request #11700 from espressif/feature/periman_get_detach_cb
feat(perimgr): add function to retrieve detaching CB
2 parents 0dbaa3f + f8e90a5 commit 344573d

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

cores/esp32/esp32-hal-periman.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ typedef struct ATTR_PACKED {
1616
int8_t bus_channel;
1717
} peripheral_pin_item_t;
1818

19-
static peripheral_bus_deinit_cb_t deinit_functions[ESP32_BUS_TYPE_MAX];
19+
static peripheral_bus_deinit_cb_t deinit_functions[ESP32_BUS_TYPE_MAX] = {NULL};
2020
static peripheral_pin_item_t pins[SOC_GPIO_PIN_COUNT];
2121

2222
#define GPIO_NOT_VALID(p) ((p >= SOC_GPIO_PIN_COUNT) || ((SOC_GPIO_VALID_GPIO_MASK & (1ULL << p)) == 0))
@@ -236,6 +236,14 @@ bool perimanSetBusDeinit(peripheral_bus_type_t type, peripheral_bus_deinit_cb_t
236236
return true;
237237
}
238238

239+
peripheral_bus_deinit_cb_t perimanGetBusDeinit(peripheral_bus_type_t type) {
240+
if (type >= ESP32_BUS_TYPE_MAX || type == ESP32_BUS_TYPE_INIT) {
241+
log_e("Invalid type: %s (%u)", perimanGetTypeName(type), (unsigned int)type);
242+
return NULL;
243+
}
244+
return deinit_functions[type];
245+
}
246+
239247
bool perimanPinIsValid(uint8_t pin) {
240248
return !(GPIO_NOT_VALID(pin));
241249
}

cores/esp32/esp32-hal-periman.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ int8_t perimanGetPinBusChannel(uint8_t pin);
134134
// Sets the peripheral destructor callback. Used to destroy bus when pin is assigned another function
135135
bool perimanSetBusDeinit(peripheral_bus_type_t type, peripheral_bus_deinit_cb_t cb);
136136

137+
// Get the peripheral destructor callback. It allows changing/restoring the peripheral pin function detaching, if necessary
138+
// returns NULL if none is set
139+
peripheral_bus_deinit_cb_t perimanGetBusDeinit(peripheral_bus_type_t type);
140+
137141
// Check if given pin is a valid GPIO number
138142
bool perimanPinIsValid(uint8_t pin);
139143

0 commit comments

Comments
 (0)