Chapter 2. API Reference
One can enable and register interrupt callback by calling dedic_gpio_bundle_set_interrupt_and_callback().
The prototype of the callback function is defined in dedic_gpio_isr_callback_t. Keep in mind, the
callback should return true if there’s some high priority task woken up.
// user defined ISR callback
IRAM_ATTR bool dedic_gpio_isr_callback(dedic_gpio_bundle_handle_t bundle, uint32_t␣
,→index, void *args)
{
SemaphoreHandle_t sem = (SemaphoreHandle_t)args;
BaseType_t high_task_wakeup = pdFALSE;
xSemaphoreGiveFromISR(sem, &high_task_wakeup);
return high_task_wakeup == pdTRUE;
}
// enable positive edge interrupt on the second GPIO in the bundle (i.e. index 1)
ESP_ERROR_CHECK(dedic_gpio_bundle_set_interrupt_and_callback(bundle, BIT(1), DEDIC_
,→GPIO_INTR_POS_EDGE, dedic_gpio_isr_callback, sem));
// wait for done semaphore
xSemaphoreTake(sem, portMAX_DELAY);
Manipulate GPIOs by Writing Assembly Code
For advanced users, they can always manipulate the GPIOs by writing assembly code or invoking CPU Low Level
APIs. The usual procedure could be:
1. Allocate a GPIO bundle: dedic_gpio_new_bundle()
2. Query the mask occupied by that bundle: dedic_gpio_get_out_mask() or/and
dedic_gpio_get_in_mask()
3. Call CPU LL apis (e.g. cpu_ll_write_dedic_gpio_mask) or write assembly code with that mask
4. The fasted way of toggling IO is to use the dedicated “set/clear”instructions:
CPU
Arch
Set bits of GPIO Clear bits of
GPIO
Remarks
Xtensa set_bit_gpio_out
imm[7:0]
clr_bit_gpio_out
imm[7:0]
immediate value width depends on the number of dedi-
cated GPIO channels
RISC-
V
csrrsi rd, csr,
imm[4:0]
csrrci rd, csr,
imm[4:0]
can only control the lowest 4 GPIO channels
For details of supported dedicated GPIO instructions, please refer to ESP32-S2 Technical Reference Manual > IO
MUX and GPIO Matrix (GPIO, IO_MUX) [PDF]. The supported dedicated CPU instructions are also wrapped inside
soc/cpu_ll.h as helper inline functions.
Note: Writing assembly code in application could make your code hard to port between targets, because those
customized instructions are not guaranteed to remain the same format on different targets.
Application Example
Matrix keyboard example based on dedicated GPIO: peripherals/gpio/matrix_keyboard.
API Reference
Header File
• components/driver/include/driver/dedic_gpio.h
Espressif Systems 269
Submit Document Feedback
Release v4.4