arduino-audio-driver
Loading...
Searching...
No Matches
GPIO_EspressifIDF.h
Go to the documentation of this file.
1#if defined(ESP32_CMAKE)
2#include <driver/gpio.h>
3#include <esp_err.h>
6
7namespace audio_driver {
8
13class GPIO : public API_GPIO {
14public:
15 GPIO() = default;
16
17 bool begin(IDriverDeviceInfo &pins) {
18 // No global init required in ESP-IDF for GPIO
19 return true;
20 }
21
22 void end() {
23 // Optional: reset GPIOs if needed
24 }
25
26 void pinMode(GpioPin pin, int mode) {
27 gpio_config_t io_conf = {};
28 io_conf.pin_bit_mask = (1ULL << pin);
29
30 switch (mode) {
31 case INPUT:
32 io_conf.mode = GPIO_MODE_INPUT;
33 io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
34 io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
35 io_conf.intr_type = GPIO_INTR_DISABLE;
36 break;
37
38 case INPUT_PULLUP:
39 io_conf.mode = GPIO_MODE_INPUT;
40 io_conf.pull_up_en = GPIO_PULLUP_ENABLE;
41 io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
42 io_conf.intr_type = GPIO_INTR_DISABLE;
43 break;
44
45 case INPUT_PULLDOWN:
46 io_conf.mode = GPIO_MODE_INPUT;
47 io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
48 io_conf.pull_down_en = GPIO_PULLDOWN_ENABLE;
49 io_conf.intr_type = GPIO_INTR_DISABLE;
50 break;
51
52 case OUTPUT:
53 default:
54 io_conf.mode = GPIO_MODE_OUTPUT;
55 io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
56 io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
57 io_conf.intr_type = GPIO_INTR_DISABLE;
58 break;
59 }
60
61 gpio_config(&io_conf);
62 }
63
64 bool digitalWrite(GpioPin pin, bool value) {
65 esp_err_t err = gpio_set_level((gpio_num_t)pin, value ? 1 : 0);
66 return err == ESP_OK;
67 }
68
69 bool digitalRead(GpioPin pin) { return gpio_get_level((gpio_num_t)pin); }
71 int analogRead(ADCPin pin) { return -1; }
72};
73
74} // namespace audio_driver
75
76#endif
#define INPUT
Definition DriverCommon.h:41
#define OUTPUT
Definition DriverCommon.h:44
#define INPUT_PULLUP
Definition DriverCommon.h:47
#define INPUT_PULLDOWN
Definition DriverCommon.h:50
Abstraction for digital GPIO pin operations.
Namespace for audio driver components.
Definition AudioBoard.h:5
int16_t GpioPin
Definition DriverCommon.h:153
int16_t ADCPin
Definition DriverCommon.h:154
GPIOZephyr GPIO
Definition GPIO_Zephyr.h:109