Skip to content

Commit 5364216

Browse files
authored
Add checks for SOC defines (#8351)
* Add checks for SOC defines * Add SoC checks to BLE library * fix i2c compilation error * fix wrong placement of include * add check to SPI library * add check to USB library * add checks to Wire library
1 parent 42f216f commit 5364216

File tree

99 files changed

+444
-66
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+444
-66
lines changed

cores/esp32/USB.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14+
1415
#include "USB.h"
1516

17+
#if SOC_USB_OTG_SUPPORTED
1618
#if CONFIG_TINYUSB_ENABLED
1719

1820
#include "pins_arduino.h"
@@ -357,3 +359,4 @@ const char * ESPUSB::webUSBURL(void){
357359
ESPUSB USB;
358360

359361
#endif /* CONFIG_TINYUSB_ENABLED */
362+
#endif /* SOC_USB_OTG_SUPPORTED */

cores/esp32/USB.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
#pragma once
1515

1616
#include "soc/soc_caps.h"
17-
1817
#if SOC_USB_OTG_SUPPORTED
1918

19+
#include "sdkconfig.h"
20+
#if CONFIG_TINYUSB_ENABLED
21+
2022
#include "esp_event.h"
2123
#include "USBCDC.h"
2224

@@ -116,4 +118,6 @@ class ESPUSB {
116118

117119
extern ESPUSB USB;
118120

121+
122+
#endif /* CONFIG_TINYUSB_ENABLED */
119123
#endif /* SOC_USB_OTG_SUPPORTED */

cores/esp32/USBCDC.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14+
15+
#include "USBCDC.h"
16+
17+
#if SOC_USB_OTG_SUPPORTED
1418
#include "USB.h"
1519
#if CONFIG_TINYUSB_CDC_ENABLED
1620

17-
#include "USBCDC.h"
21+
1822
#include "esp32-hal-tinyusb.h"
1923
#include "rom/ets_sys.h"
2024

@@ -456,3 +460,4 @@ USBCDC Serial(0);
456460
#endif
457461

458462
#endif /* CONFIG_TINYUSB_CDC_ENABLED */
463+
#endif /* SOC_USB_OTG_SUPPORTED */

cores/esp32/USBCDC.h

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
// limitations under the License.
1414
#pragma once
1515

16+
#include "soc/soc_caps.h"
17+
#if SOC_USB_OTG_SUPPORTED
18+
1619
#include "sdkconfig.h"
1720
#if CONFIG_TINYUSB_CDC_ENABLED
1821

@@ -143,3 +146,4 @@ extern USBCDC Serial;
143146
#endif
144147

145148
#endif /* CONFIG_TINYUSB_CDC_ENABLED */
149+
#endif /* SOC_USB_OTG_SUPPORTED */

cores/esp32/USBMSC.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14+
1415
#include "USBMSC.h"
1516

17+
#if SOC_USB_OTG_SUPPORTED
1618
#if CONFIG_TINYUSB_MSC_ENABLED
1719

1820
#include "esp32-hal-tinyusb.h"
@@ -258,3 +260,4 @@ void USBMSC::mediaPresent(bool media_present){
258260
}
259261

260262
#endif /* CONFIG_TINYUSB_MSC_ENABLED */
263+
#endif /* SOC_USB_OTG_SUPPORTED */

cores/esp32/USBMSC.h

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
// limitations under the License.
1414

1515
#pragma once
16+
17+
#include "soc/soc_caps.h"
18+
#if SOC_USB_OTG_SUPPORTED
19+
1620
#include <stdint.h>
1721
#include <stdbool.h>
1822
#include "sdkconfig.h"
@@ -49,3 +53,4 @@ class USBMSC
4953
};
5054

5155
#endif /* CONFIG_TINYUSB_MSC_ENABLED */
56+
#endif /* SOC_USB_OTG_SUPPORTED */

cores/esp32/esp32-hal-bt.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "esp32-hal-bt.h"
1616

17+
#if SOC_BT_SUPPORTED
1718
#ifdef CONFIG_BT_ENABLED
1819

1920
// user may want to change it to free resources
@@ -97,5 +98,6 @@ bool btStop()
9798
return false;
9899
}
99100

100-
#endif // CONFIG_BT_ENABLED
101+
#endif /* CONFIG_BT_ENABLED */
101102

103+
#endif /* SOC_BT_SUPPORTED */

cores/esp32/esp32-hal-bt.h

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
#ifndef _ESP32_ESP32_HAL_BT_H_
1616
#define _ESP32_ESP32_HAL_BT_H_
1717

18+
#include "soc/soc_caps.h"
19+
#if SOC_BT_SUPPORTED
20+
1821
#include "esp32-hal.h"
1922

2023
#ifdef __cplusplus
@@ -29,4 +32,6 @@ bool btStop();
2932
}
3033
#endif
3134

35+
#endif /* SOC_BT_SUPPORTED */
36+
3237
#endif /* _ESP32_ESP32_HAL_BT_H_ */

cores/esp32/esp32-hal-i2c-slave.c

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#include "soc/soc_caps.h"
16+
17+
#if SOC_I2C_SUPPORT_SLAVE
1518
#include <stdint.h>
1619
#include <stdbool.h>
1720
#include <stdio.h>
@@ -874,3 +877,5 @@ static bool i2cSlaveDetachBus(void * bus_i2c_num){
874877
}
875878
return true;
876879
}
880+
881+
#endif /* SOC_I2C_SUPPORT_SLAVE */

cores/esp32/esp32-hal-i2c-slave.h

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
#pragma once
1616

17+
#include "soc/soc_caps.h"
18+
#if SOC_I2C_SUPPORT_SLAVE
19+
1720
#ifdef __cplusplus
1821
extern "C" {
1922
#endif
@@ -33,3 +36,5 @@ size_t i2cSlaveWrite(uint8_t num, const uint8_t *buf, uint32_t len, uint32_t tim
3336
#ifdef __cplusplus
3437
}
3538
#endif
39+
40+
#endif /* SOC_I2C_SUPPORT_SLAVE */

cores/esp32/esp32-hal-i2c.c

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
// limitations under the License.
1414

1515
#include "esp32-hal-i2c.h"
16+
17+
#if SOC_I2C_SUPPORTED
1618
#include "esp32-hal.h"
1719
#if !CONFIG_DISABLE_HAL_LOCKS
1820
#include "freertos/FreeRTOS.h"
@@ -390,3 +392,5 @@ esp_err_t i2cGetClock(uint8_t i2c_num, uint32_t * frequency){
390392
*frequency = bus[i2c_num].frequency;
391393
return ESP_OK;
392394
}
395+
396+
#endif /* SOC_I2C_SUPPORTED */

cores/esp32/esp32-hal-i2c.h

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#ifndef _ESP32_HAL_I2C_H_
1818
#define _ESP32_HAL_I2C_H_
1919

20+
#include "soc/soc_caps.h"
21+
#if SOC_I2C_SUPPORTED
22+
2023
#ifdef __cplusplus
2124
extern "C" {
2225
#endif
@@ -38,4 +41,5 @@ bool i2cIsInit(uint8_t i2c_num);
3841
}
3942
#endif
4043

44+
#endif /* SOC_I2C_SUPPORTED */
4145
#endif /* _ESP32_HAL_I2C_H_ */

cores/esp32/esp32-hal-ledc.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include "esp32-hal.h"
1615
#include "soc/soc_caps.h"
16+
17+
#if SOC_LEDC_SUPPORTED
18+
#include "esp32-hal.h"
19+
#include "esp32-hal-ledc.h"
1720
#include "driver/ledc.h"
1821
#include "esp32-hal-periman.h"
1922

@@ -382,3 +385,5 @@ void analogWriteResolution(uint8_t pin, uint8_t resolution) {
382385
}
383386
analog_resolution = resolution;
384387
}
388+
389+
#endif /* SOC_LEDC_SUPPORTED */

cores/esp32/esp32-hal-ledc.h

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
#ifndef _ESP32_HAL_LEDC_H_
1616
#define _ESP32_HAL_LEDC_H_
1717

18+
#include "soc/soc_caps.h"
19+
#if SOC_LEDC_SUPPORTED
20+
1821
#ifdef __cplusplus
1922
extern "C" {
2023
#endif
@@ -59,4 +62,5 @@ bool ledcFadeWithInterruptArg(uint8_t pin, uint32_t start_duty, uint32_t target_
5962
}
6063
#endif
6164

65+
#endif /* SOC_LEDC_SUPPORTED */
6266
#endif /* _ESP32_HAL_LEDC_H_ */

cores/esp32/esp32-hal-misc.c

+8-5
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,26 @@
3838

3939
#include "esp_system.h"
4040
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
41+
4142
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
4243
#include "esp32/rom/rtc.h"
4344
#elif CONFIG_IDF_TARGET_ESP32S2
4445
#include "esp32s2/rom/rtc.h"
45-
#include "driver/temperature_sensor.h"
4646
#elif CONFIG_IDF_TARGET_ESP32S3
4747
#include "esp32s3/rom/rtc.h"
48-
#include "driver/temperature_sensor.h"
4948
#elif CONFIG_IDF_TARGET_ESP32C3
5049
#include "esp32c3/rom/rtc.h"
51-
#include "driver/temperature_sensor.h"
5250
#elif CONFIG_IDF_TARGET_ESP32C6
5351
#include "esp32c6/rom/rtc.h"
54-
#include "driver/temperature_sensor.h"
52+
5553
#else
5654
#error Target CONFIG_IDF_TARGET is not supported
5755
#endif
56+
57+
#if SOC_TEMP_SENSOR_SUPPORTED
58+
#include "driver/temperature_sensor.h"
59+
#endif
60+
5861
#else // ESP32 Before IDF 4.0
5962
#include "rom/rtc.h"
6063
#endif
@@ -68,7 +71,7 @@ float temperatureRead()
6871
{
6972
return (temprature_sens_read() - 32) / 1.8;
7073
}
71-
#else
74+
#elif SOC_TEMP_SENSOR_SUPPORTED
7275
static temperature_sensor_handle_t temp_sensor = NULL;
7376

7477
static bool temperatureReadInit()

cores/esp32/esp32-hal-rmt.c

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#include "soc/soc_caps.h"
16+
17+
#if SOC_RMT_SUPPORTED
1518
#include "esp32-hal.h"
1619
#include "driver/gpio.h"
1720
#include "driver/rmt_tx.h"
@@ -568,3 +571,5 @@ bool rmtInit(int pin, rmt_ch_dir_t channel_direction, rmt_reserve_memsize_t mem_
568571
_rmtDetachBus((void *)bus);
569572
return false;
570573
}
574+
575+
#endif /* SOC_RMT_SUPPORTED */

cores/esp32/esp32-hal-rmt.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
#ifndef MAIN_ESP32_HAL_RMT_H_
1616
#define MAIN_ESP32_HAL_RMT_H_
1717

18+
#include "soc/soc_caps.h"
19+
#if SOC_RMT_SUPPORTED
20+
1821
#ifdef __cplusplus
1922
extern "C" {
2023
#endif
@@ -214,4 +217,5 @@ bool rmtDeinit(int pin);
214217
}
215218
#endif
216219

217-
#endif /* MAIN_ESP32_HAL_RMT_H_ */
220+
#endif /* SOC_RMT_SUPPORTED */
221+
#endif /* MAIN_ESP32_HAL_RMT_H_ */

cores/esp32/esp32-hal-spi.c

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
// limitations under the License.
1414

1515
#include "esp32-hal-spi.h"
16+
17+
#if SOC_GPSPI_SUPPORTED
1618
#include "esp32-hal.h"
1719
#include "freertos/FreeRTOS.h"
1820
#include "freertos/task.h"
@@ -1577,3 +1579,5 @@ uint32_t spiFrequencyToClockDiv(uint32_t freq)
15771579
}
15781580
return bestReg.value;
15791581
}
1582+
1583+
#endif /* SOC_GPSPI_SUPPORTED */

cores/esp32/esp32-hal-spi.h

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
#ifndef MAIN_ESP32_HAL_SPI_H_
1616
#define MAIN_ESP32_HAL_SPI_H_
1717

18+
#include "soc/soc_caps.h"
19+
#if SOC_GPSPI_SUPPORTED
20+
1821
#ifdef __cplusplus
1922
extern "C" {
2023
#endif
@@ -146,4 +149,5 @@ uint32_t spiClockDivToFrequency(uint32_t freq);
146149
}
147150
#endif
148151

152+
#endif /* SOC_GPSPI_SUPPORTED */
149153
#endif /* MAIN_ESP32_HAL_SPI_H_ */

cores/esp32/esp32-hal-timer.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
// limitations under the License.
1414

1515
#include "esp32-hal-timer.h"
16+
17+
#if SOC_GPTIMER_SUPPORTED
1618
#include "driver/gptimer.h"
17-
#include "soc/soc_caps.h"
1819
#if defined __has_include && __has_include ("clk_tree.h")
1920
#include "clk_tree.h"
2021
#else
@@ -212,3 +213,5 @@ double timerReadSeconds(hw_timer_t * timer){
212213
uint32_t frequency = timerGetFrequency(timer);
213214
return (double)timer_val / frequency;
214215
}
216+
217+
#endif /* SOC_GPTIMER_SUPPORTED */

cores/esp32/esp32-hal-timer.h

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
#pragma once
2121

22+
#include "soc/soc_caps.h"
23+
#if SOC_GPTIMER_SUPPORTED
24+
2225
#include "esp32-hal.h"
2326
#include "driver/gptimer_types.h"
2427

@@ -53,3 +56,5 @@ void timerAlarm(hw_timer_t * timer, uint64_t alarm_value, bool autoreload, uint6
5356
#ifdef __cplusplus
5457
}
5558
#endif
59+
60+
#endif /* SOC_GPTIMER_SUPPORTED */

cores/esp32/esp32-hal-tinyusb.c

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
#include "soc/soc_caps.h"
12

3+
#if SOC_USB_OTG_SUPPORTED
24
#include "sdkconfig.h"
35
#if CONFIG_TINYUSB_ENABLED
46
#include <stdlib.h>
@@ -794,3 +796,4 @@ uint8_t tinyusb_get_free_out_endpoint(void){
794796
}
795797

796798
#endif /* CONFIG_TINYUSB_ENABLED */
799+
#endif /* SOC_USB_OTG_SUPPORTED */

0 commit comments

Comments
 (0)