Skip to content

Commit c09a895

Browse files
committed
Small improvements to peripheral manager and SigmaDelta
1 parent af9d6d2 commit c09a895

File tree

4 files changed

+37
-9
lines changed

4 files changed

+37
-9
lines changed

cores/esp32/esp32-hal-periman.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include "esp32-hal-log.h"
88
#include "esp32-hal-periman.h"
9-
#include "soc/soc_caps.h"
9+
#include "esp_bit_defs.h"
1010

1111
typedef struct {
1212
peripheral_bus_type_t type;
@@ -16,10 +16,12 @@ typedef struct {
1616
static peripheral_bus_deinit_cb_t deinit_functions[ESP32_BUS_TYPE_MAX];
1717
static peripheral_pin_item_t pins[SOC_GPIO_PIN_COUNT];
1818

19+
#define GPIO_NOT_VALID(p) ((p >= SOC_GPIO_PIN_COUNT) || ((SOC_GPIO_VALID_GPIO_MASK & (1ULL << p)) == 0))
20+
1921
bool perimanSetPinBus(uint8_t pin, peripheral_bus_type_t type, void * bus){
2022
peripheral_bus_type_t otype = ESP32_BUS_TYPE_INIT;
2123
void * obus = NULL;
22-
if(pin >= SOC_GPIO_PIN_COUNT){
24+
if(GPIO_NOT_VALID(pin)){
2325
log_e("Invalid pin: %u", pin);
2426
return false;
2527
}
@@ -53,7 +55,7 @@ bool perimanSetPinBus(uint8_t pin, peripheral_bus_type_t type, void * bus){
5355
}
5456

5557
void * perimanGetPinBus(uint8_t pin, peripheral_bus_type_t type){
56-
if(pin >= SOC_GPIO_PIN_COUNT){
58+
if(GPIO_NOT_VALID(pin)){
5759
log_e("Invalid pin: %u", pin);
5860
return NULL;
5961
}
@@ -68,7 +70,7 @@ void * perimanGetPinBus(uint8_t pin, peripheral_bus_type_t type){
6870
}
6971

7072
peripheral_bus_type_t perimanGetPinBusType(uint8_t pin){
71-
if(pin >= SOC_GPIO_PIN_COUNT){
73+
if(GPIO_NOT_VALID(pin)){
7274
log_e("Invalid pin: %u", pin);
7375
return ESP32_BUS_TYPE_MAX;
7476
}

cores/esp32/esp32-hal-periman.h

+22-1
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,49 @@ extern "C"
99
{
1010
#endif
1111

12+
#include "soc/soc_caps.h"
1213
#include <stdint.h>
1314
#include <stdbool.h>
1415
#include <stddef.h>
1516

1617
typedef enum {
1718
ESP32_BUS_TYPE_INIT, // IO has not been attached to a bus yet
1819
ESP32_BUS_TYPE_GPIO, // IO is used as GPIO
20+
ESP32_BUS_TYPE_UART, // IO is used as UART pin
21+
#if SOC_SDM_SUPPORTED
1922
ESP32_BUS_TYPE_SIGMADELTA, // IO is used as SigmeDelta output
23+
#endif
24+
#if SOC_ADC_SUPPORTED
2025
ESP32_BUS_TYPE_ADC_ONESHOT, // IO is used as ADC OneShot input
2126
ESP32_BUS_TYPE_ADC_CONT, // IO is used as ADC continuous input
27+
#endif
28+
#if SOC_DAC_SUPPORTED
2229
ESP32_BUS_TYPE_DAC_ONESHOT, // IO is used as DAC OneShot output
2330
ESP32_BUS_TYPE_DAC_CONT, // IO is used as DAC continuous output
2431
ESP32_BUS_TYPE_DAC_COSINE, // IO is used as DAC cosine output
32+
#endif
33+
#if SOC_LEDC_SUPPORTED
34+
ESP32_BUS_TYPE_LEDC, // IO is used as LEDC output
35+
#endif
36+
#if SOC_RMT_SUPPORTED
2537
ESP32_BUS_TYPE_RMT_TX, // IO is used as RMT output
2638
ESP32_BUS_TYPE_RMT_RX, // IO is used as RMT input
39+
#endif
40+
#if SOC_I2S_SUPPORTED
2741
ESP32_BUS_TYPE_I2S_STD, // IO is used as I2S STD pin
2842
ESP32_BUS_TYPE_I2S_PDM, // IO is used as I2S PDM pin
2943
ESP32_BUS_TYPE_I2S_TDM, // IO is used as I2S TDM pin
30-
ESP32_BUS_TYPE_UART, // IO is used as UART pin
44+
#endif
45+
#if SOC_I2C_SUPPORTED
3146
ESP32_BUS_TYPE_I2C_MASTER, // IO is used as I2C master pin
3247
ESP32_BUS_TYPE_I2C_SLAVE, // IO is used as I2C slave pin
48+
#endif
49+
#if SOC_GPSPI_SUPPORTED
3350
ESP32_BUS_TYPE_SPI_MASTER, // IO is used as SPI master pin
51+
#endif
52+
#if SOC_SDMMC_HOST_SUPPORTED
53+
ESP32_BUS_TYPE_SDMMC, // IO is used as SDMMC pin
54+
#endif
3455
ESP32_BUS_TYPE_MAX
3556
} peripheral_bus_type_t;
3657

cores/esp32/esp32-hal-sigmadelta.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
#include "esp32-hal.h"
88
#include "esp32-hal-periman.h"
9-
#include "soc/soc_caps.h"
9+
10+
#if SOC_SDM_SUPPORTED
1011
#include "driver/sdm.h"
1112

1213
static bool sigmaDeltaDetachBus(void * bus){
@@ -69,7 +70,7 @@ bool sigmaDeltaWrite(uint8_t pin, uint8_t duty) //chan 0-x according to SOC duty
6970
}
7071
return true;
7172
} else {
72-
log_e("pin %u is not attached to SigmaDelta");
73+
log_e("pin %u is not attached to SigmaDelta", pin);
7374
}
7475
return false;
7576
}
@@ -84,4 +85,5 @@ bool sigmaDeltaDetach(uint8_t pin)
8485
log_e("pin %u is not attached to SigmaDelta");
8586
}
8687
return false;
87-
}
88+
}
89+
#endif

cores/esp32/esp32-hal-sigmadelta.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
extern "C" {
1111
#endif
1212

13+
#include "soc/soc_caps.h"
14+
#if SOC_SDM_SUPPORTED
15+
1316
#include <stdint.h>
1417
#include <stdbool.h>
1518

@@ -19,7 +22,7 @@ bool sigmaDeltaWrite(uint8_t pin, uint8_t duty);
1922
uint8_t sigmaDeltaRead(uint8_t pin);
2023
bool sigmaDeltaDetach(uint8_t pin);
2124

22-
25+
#endif
2326
#ifdef __cplusplus
2427
}
2528
#endif

0 commit comments

Comments
 (0)