From b60b47ff518262aff94e24f57b625ee6676254d7 Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Thu, 23 Jun 2022 07:18:48 +0200 Subject: [PATCH] cpu/esp_common: inverse MCU_* conditionals to deal with ESP32 variants The MCU_* conditionals are inverted so that they can be tested for ESP8266. In all other cases the MCU is any ESP32x SoC --- cpu/esp_common/esp-wifi/esp_wifi_netdev.c | 4 +- cpu/esp_common/include/esp_common.h | 2 +- cpu/esp_common/include/gpio_arch_common.h | 4 +- cpu/esp_common/periph/i2c_sw.c | 48 +++++++++++------------ 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/cpu/esp_common/esp-wifi/esp_wifi_netdev.c b/cpu/esp_common/esp-wifi/esp_wifi_netdev.c index 81580a63e3..26b162317f 100644 --- a/cpu/esp_common/esp-wifi/esp_wifi_netdev.c +++ b/cpu/esp_common/esp-wifi/esp_wifi_netdev.c @@ -615,7 +615,7 @@ static int _esp_wifi_send(netdev_t *netdev, const iolist_t *iolist) /* send the the packet to the peer(s) mac address */ if (esp_wifi_internal_tx(ESP_IF_WIFI_STA, dev->tx_buf, dev->tx_len) == ESP_OK) { #endif -#ifdef MCU_ESP32 +#ifndef MCU_ESP8266 /* for ESP8266 it is done in _esp_wifi_tx_cb */ _esp_wifi_send_is_in = false; netdev->event_callback(netdev, NETDEV_EVENT_TX_COMPLETE); @@ -872,7 +872,7 @@ void esp_wifi_setup (esp_wifi_netdev_t* dev) #ifndef MODULE_ESP_NOW /* if module esp_now is used, the following part is already done */ -#ifdef MCU_ESP32 +#ifndef MCU_ESP8266 extern portMUX_TYPE g_intr_lock_mux; mutex_init(&g_intr_lock_mux); #endif diff --git a/cpu/esp_common/include/esp_common.h b/cpu/esp_common/include/esp_common.h index f3f848a0ca..5942e24c09 100644 --- a/cpu/esp_common/include/esp_common.h +++ b/cpu/esp_common/include/esp_common.h @@ -45,7 +45,7 @@ extern "C" { #define RTC_BSS_ATTR __attribute__((section(".rtc.bss"))) #endif -#ifndef MCU_ESP32 +#ifdef MCU_ESP8266 #ifndef RTC_DATA_ATTR #define RTC_DATA_ATTR __attribute__((section(".rtc.data"))) #endif diff --git a/cpu/esp_common/include/gpio_arch_common.h b/cpu/esp_common/include/gpio_arch_common.h index 8a0088b2f1..f4b1541880 100644 --- a/cpu/esp_common/include/gpio_arch_common.h +++ b/cpu/esp_common/include/gpio_arch_common.h @@ -39,12 +39,12 @@ extern "C" { typedef enum { _GPIO = 0, /**< pin used as standard GPIO */ -#ifdef MCU_ESP32 +#ifndef MCU_ESP8266 _ADC, /**< pin is used as ADC input */ _CAN, /**< pin is used as CAN signal */ _DAC, /**< pin is used as DAC output */ _EMAC, /**< pin is used as EMAC signal */ -#endif /* MCU_ESP32 */ +#endif /* !MCU_ESP8266 */ _I2C, /**< pin is used as I2C signal */ _PWM, /**< pin is used as PWM output */ _SPI, /**< pin is used as SPI interface */ diff --git a/cpu/esp_common/periph/i2c_sw.c b/cpu/esp_common/periph/i2c_sw.c index 940f616816..791c98b591 100644 --- a/cpu/esp_common/periph/i2c_sw.c +++ b/cpu/esp_common/periph/i2c_sw.c @@ -45,7 +45,7 @@ #include "gpio_arch.h" #include "rom/ets_sys.h" -#ifdef MCU_ESP32 +#ifndef MCU_ESP8266 #include "soc/gpio_reg.h" #include "soc/gpio_struct.h" @@ -57,7 +57,7 @@ #define GPIO_SET(l,h,b) if (b < 32) GPIO.l = BIT(b); else GPIO.h.val = BIT(b-32) #define GPIO_GET(l,h,b) ((b < 32) ? GPIO.l & BIT(b) : GPIO.h.val & BIT(b-32)) -#else /* MCU_ESP32 */ +#else /* MCU_ESP8266 */ #include "esp/gpio_regs.h" #include "sdk/ets.h" @@ -79,7 +79,7 @@ extern uint8_t system_get_cpu_freq(void); extern bool system_update_cpu_freq(uint8_t freq); -#endif /* MCU_ESP32 */ +#endif /* MCU_ESP8266 */ typedef struct { @@ -203,7 +203,7 @@ void i2c_init(i2c_t dev) } /* Configure and initialize SDA and SCL pin. */ -#ifdef MCU_ESP32 +#ifndef MCU_ESP8266 /* * ESP32 pins are used in input/output mode with open-drain output driver. * Signal levels are then realized as following: @@ -225,7 +225,7 @@ void i2c_init(i2c_t dev) } gpio_set(i2c_config[dev].sda); -#else /* MCU_ESP32 */ +#else /* !MCU_ESP8266 */ /* * Due to critical timing required by the I2C software implementation, * the ESP8266 GPIOs can not be used directly in GPIO_OD_PU mode. @@ -245,7 +245,7 @@ void i2c_init(i2c_t dev) gpio_init(_i2c_bus[dev].sda, GPIO_IN_PU)) { return; } -#endif /* MCU_ESP32 */ +#endif /* !MCU_ESP8266 */ /* store the usage type in GPIO table */ gpio_set_pin_usage(_i2c_bus[dev].scl, _I2C); @@ -438,29 +438,29 @@ static inline void _i2c_delay(_i2c_bus_t* bus) static inline bool _i2c_scl_read(_i2c_bus_t* bus) { /* read SCL status (pin is in open-drain mode and set) */ -#ifdef MCU_ESP32 +#ifndef MCU_ESP8266 return GPIO_GET(in, in1, bus->scl); -#else /* MCU_ESP32 */ +#else /* !MCU_ESP8266 */ return GPIO.IN & bus->scl_bit; -#endif /* MCU_ESP32 */ +#endif /* !MCU_ESP8266 */ } static inline bool _i2c_sda_read(_i2c_bus_t* bus) { /* read SDA status (pin is in open-drain mode and set) */ -#ifdef MCU_ESP32 +#ifndef MCU_ESP8266 return GPIO_GET(in, in1, bus->sda); -#else /* MCU_ESP32 */ +#else /* !MCU_ESP8266 */ return GPIO.IN & bus->sda_bit; -#endif /* MCU_ESP32 */ +#endif /* !MCU_ESP8266 */ } static inline void _i2c_scl_high(_i2c_bus_t* bus) { -#ifdef MCU_ESP32 +#ifndef MCU_ESP8266 /* set SCL signal high (pin is in open-drain mode and pulled-up) */ GPIO_SET(out_w1ts, out1_w1ts, bus->scl); -#else /* MCU_ESP32 */ +#else /* !MCU_ESP8266 */ #if I2C_CLOCK_STRETCH > 0 /* * set SCL signal high (switch back to GPIO_IN_PU mode, that is the pin is @@ -471,15 +471,15 @@ static inline void _i2c_scl_high(_i2c_bus_t* bus) /* No clock stretching supported, always drive the SCL pin. */ GPIO.OUT_SET = bus->scl_bit; #endif /* I2C_CLOCK_STRETCH > 0 */ -#endif /* MCU_ESP32 */ +#endif /* !MCU_ESP8266 */ } static inline void _i2c_scl_low(_i2c_bus_t* bus) { -#ifdef MCU_ESP32 +#ifndef MCU_ESP8266 /* set SCL signal low (actively driven to low) */ GPIO_SET(out_w1tc, out1_w1tc, bus->scl); -#else /* MCU_ESP32 */ +#else /* !MCU_ESP8266 */ #if I2C_CLOCK_STRETCH > 0 /* * set SCL signal low (switch temporarily to GPIO_OD_PU where the @@ -490,35 +490,35 @@ static inline void _i2c_scl_low(_i2c_bus_t* bus) /* No clock stretching supported, always drive the SCL pin. */ GPIO.OUT_CLEAR = bus->scl_bit; #endif /* I2C_CLOCK_STRETCH > 0 */ -#endif /* MCU_ESP32 */ +#endif /* !MCU_ESP8266 */ } static inline void _i2c_sda_high(_i2c_bus_t* bus) { -#ifdef MCU_ESP32 +#ifndef MCU_ESP8266 /* set SDA signal high (pin is in open-drain mode and pulled-up) */ GPIO_SET(out_w1ts, out1_w1ts, bus->sda); -#else /* MCU_ESP32 */ +#else /* !MCU_ESP8266 */ /* * set SDA signal high (switch back to GPIO_IN_PU mode, that is the pin is * in open-drain mode and pulled-up to high) */ GPIO.ENABLE_OUT_CLEAR = bus->sda_bit; -#endif /* MCU_ESP32 */ +#endif /* !MCU_ESP8266 */ } static inline void _i2c_sda_low(_i2c_bus_t* bus) { -#ifdef MCU_ESP32 +#ifndef MCU_ESP8266 /* set SDA signal low (actively driven to low) */ GPIO_SET(out_w1tc, out1_w1tc, bus->sda); -#else /* MCU_ESP32 */ +#else /* !MCU_ESP8266 */ /* * set SDA signal low (switch temporarily to GPIO_OD_PU where the * written output value 0 drives the pin actively to low) */ GPIO.ENABLE_OUT_SET = bus->sda_bit; -#endif /* MCU_ESP32 */ +#endif /* !MCU_ESP8266 */ } static void _i2c_clear(_i2c_bus_t* bus)