88#define DT_DRV_COMPAT espressif_esp32_gpio
99
1010/* Include esp-idf headers first to avoid redefining BIT() macro */
11+ #ifndef CONFIG_SOC_ESP32C3
1112#include <soc/dport_reg.h>
13+ #endif
1214#include <soc/gpio_reg.h>
1315#include <soc/io_mux_reg.h>
1416#include <soc/soc.h>
1820#include <errno.h>
1921#include <device.h>
2022#include <drivers/gpio.h>
23+ #ifdef CONFIG_SOC_ESP32C3
24+ #include <drivers/interrupt_controller/intc_esp32c3.h>
25+ #else
2126#include <drivers/interrupt_controller/intc_esp32.h>
27+ #endif
2228#include <kernel.h>
2329#include <sys/util.h>
2430#include <drivers/pinmux.h>
@@ -30,6 +36,20 @@ LOG_MODULE_REGISTER(gpio_esp32, CONFIG_LOG_DEFAULT_LEVEL);
3036
3137#define DEV_CFG (_dev ) ((struct gpio_esp32_config *const)(_dev)->config)
3238
39+ #ifdef CONFIG_SOC_ESP32C3
40+ /* gpio structs in esp32c3 series are diferent from xtensa ones */
41+ #define out out.data
42+ #define in in.data
43+ #define out_w1ts out_w1ts.val
44+ #define out_w1tc out_w1tc.val
45+ /* arch_curr_cpu() is not available for riscv based chips */
46+ #define CPU_ID () 0
47+ #define ISR_HANDLER isr_handler_t
48+ #else
49+ #define CPU_ID () arch_curr_cpu()->id
50+ #define ISR_HANDLER intr_handler_t
51+ #endif
52+
3353struct gpio_esp32_config {
3454 /* gpio_driver_config needs to be first */
3555 struct gpio_driver_config drv_cfg ;
@@ -144,8 +164,10 @@ static int gpio_esp32_port_get_raw(const struct device *port, uint32_t *value)
144164
145165 if (cfg -> gpio_port0 ) {
146166 * value = cfg -> gpio_dev -> in ;
167+ #if defined(CONFIG_GPIO_ESP32_1 )
147168 } else {
148169 * value = cfg -> gpio_dev -> in1 .data ;
170+ #endif
149171 }
150172
151173 return 0 ;
@@ -160,8 +182,10 @@ static int gpio_esp32_port_set_masked_raw(const struct device *port,
160182
161183 if (cfg -> gpio_port0 ) {
162184 cfg -> gpio_dev -> out = (cfg -> gpio_dev -> out & ~mask ) | (mask & value );
185+ #if defined(CONFIG_GPIO_ESP32_1 )
163186 } else {
164187 cfg -> gpio_dev -> out1 .data = (cfg -> gpio_dev -> out1 .data & ~mask ) | (mask & value );
188+ #endif
165189 }
166190
167191 irq_unlock (key );
@@ -176,8 +200,10 @@ static int gpio_esp32_port_set_bits_raw(const struct device *port,
176200
177201 if (cfg -> gpio_port0 ) {
178202 cfg -> gpio_dev -> out_w1ts = pins ;
203+ #if defined(CONFIG_GPIO_ESP32_1 )
179204 } else {
180205 cfg -> gpio_dev -> out1_w1ts .data = pins ;
206+ #endif
181207 }
182208
183209 return 0 ;
@@ -190,8 +216,10 @@ static int gpio_esp32_port_clear_bits_raw(const struct device *port,
190216
191217 if (cfg -> gpio_port0 ) {
192218 cfg -> gpio_dev -> out_w1tc = pins ;
219+ #if defined(CONFIG_GPIO_ESP32_1 )
193220 } else {
194221 cfg -> gpio_dev -> out1_w1tc .data = pins ;
222+ #endif
195223 }
196224
197225 return 0 ;
@@ -205,8 +233,10 @@ static int gpio_esp32_port_toggle_bits(const struct device *port,
205233
206234 if (cfg -> gpio_port0 ) {
207235 cfg -> gpio_dev -> out ^= pins ;
236+ #if defined(CONFIG_GPIO_ESP32_1 )
208237 } else {
209238 cfg -> gpio_dev -> out1 .data ^= pins ;
239+ #endif
210240 }
211241
212242 irq_unlock (key );
@@ -281,7 +311,7 @@ static uint32_t gpio_esp32_get_pending_int(const struct device *dev)
281311{
282312 struct gpio_esp32_config * const cfg = DEV_CFG (dev );
283313 uint32_t irq_status ;
284- uint32_t const core_id = arch_curr_cpu () -> id ;
314+ uint32_t const core_id = CPU_ID () ;
285315
286316#if defined(CONFIG_GPIO_ESP32_1 )
287317 gpio_ll_get_intr_status_high (cfg -> gpio_base , core_id , & irq_status );
@@ -296,7 +326,7 @@ static void IRAM_ATTR gpio_esp32_fire_callbacks(const struct device *dev)
296326 struct gpio_esp32_config * const cfg = DEV_CFG (dev );
297327 struct gpio_esp32_data * data = dev -> data ;
298328 uint32_t irq_status ;
299- uint32_t const core_id = arch_curr_cpu () -> id ;
329+ uint32_t const core_id = CPU_ID () ;
300330
301331#if defined(CONFIG_GPIO_ESP32_1 )
302332 gpio_ll_get_intr_status_high (cfg -> gpio_base , core_id , & irq_status );
@@ -327,7 +357,7 @@ static int gpio_esp32_init(const struct device *dev)
327357 }
328358
329359 if (!isr_connected ) {
330- esp_intr_alloc (DT_IRQN (DT_NODELABEL (gpio0 )), 0 , gpio_esp32_isr , (void * )dev , NULL );
360+ esp_intr_alloc (DT_IRQN (DT_NODELABEL (gpio0 )), 0 , ( ISR_HANDLER ) gpio_esp32_isr , (void * )dev , NULL );
331361 isr_connected = true;
332362 }
333363
0 commit comments