@@ -18,6 +18,59 @@ static peripheral_pin_item_t pins[SOC_GPIO_PIN_COUNT];
18
18
19
19
#define GPIO_NOT_VALID (p ) ((p >= SOC_GPIO_PIN_COUNT) || ((SOC_GPIO_VALID_GPIO_MASK & (1ULL << p)) == 0))
20
20
21
+ const char * perimanGetTypeName (peripheral_bus_type_t type ) {
22
+ switch (type ) {
23
+ case ESP32_BUS_TYPE_INIT : return "INIT" ;
24
+ case ESP32_BUS_TYPE_GPIO : return "GPIO" ;
25
+ case ESP32_BUS_TYPE_UART_RX : return "UART_RX" ;
26
+ case ESP32_BUS_TYPE_UART_TX : return "UART_TX" ;
27
+ case ESP32_BUS_TYPE_UART_CTS : return "UART_CTS" ;
28
+ case ESP32_BUS_TYPE_UART_RTS : return "UART_RTS" ;
29
+ #if SOC_SDM_SUPPORTED
30
+ case ESP32_BUS_TYPE_SIGMADELTA : return "SIGMADELTA" ;
31
+ #endif
32
+ #if SOC_ADC_SUPPORTED
33
+ case ESP32_BUS_TYPE_ADC_ONESHOT : return "ADC_ONESHOT" ;
34
+ case ESP32_BUS_TYPE_ADC_CONT : return "ADC_CONT" ;
35
+ #endif
36
+ #if SOC_DAC_SUPPORTED
37
+ case ESP32_BUS_TYPE_DAC_ONESHOT : return "DAC_ONESHOT" ;
38
+ case ESP32_BUS_TYPE_DAC_CONT : return "DAC_CONT" ;
39
+ case ESP32_BUS_TYPE_DAC_COSINE : return "DAC_COSINE" ;
40
+ #endif
41
+ #if SOC_LEDC_SUPPORTED
42
+ case ESP32_BUS_TYPE_LEDC : return "LEDC" ;
43
+ #endif
44
+ #if SOC_RMT_SUPPORTED
45
+ case ESP32_BUS_TYPE_RMT_TX : return "RMT_TX" ;
46
+ case ESP32_BUS_TYPE_RMT_RX : return "RMT_RX" ;
47
+ #endif
48
+ #if SOC_I2S_SUPPORTED
49
+ case ESP32_BUS_TYPE_I2S_STD : return "I2S_STD" ;
50
+ case ESP32_BUS_TYPE_I2S_TDM : return "I2S_TDM" ;
51
+ case ESP32_BUS_TYPE_I2S_PDM_TX : return "I2S_PDM_TX" ;
52
+ case ESP32_BUS_TYPE_I2S_PDM_RX : return "I2S_PDM_RX" ;
53
+ #endif
54
+ #if SOC_I2C_SUPPORTED
55
+ case ESP32_BUS_TYPE_I2C_MASTER : return "I2C_MASTER" ;
56
+ case ESP32_BUS_TYPE_I2C_SLAVE : return "I2C_SLAVE" ;
57
+ #endif
58
+ #if SOC_GPSPI_SUPPORTED
59
+ case ESP32_BUS_TYPE_SPI_MASTER : return "SPI_MASTER" ;
60
+ #endif
61
+ #if SOC_SDMMC_HOST_SUPPORTED
62
+ case ESP32_BUS_TYPE_SDMMC : return "SDMMC" ;
63
+ #endif
64
+ #if SOC_TOUCH_SENSOR_SUPPORTED
65
+ case ESP32_BUS_TYPE_TOUCH : return "TOUCH" ;
66
+ #endif
67
+ #if SOC_USB_SERIAL_JTAG_SUPPORTED || SOC_USB_OTG_SUPPORTED
68
+ case ESP32_BUS_TYPE_USB : return "USB" ;
69
+ #endif
70
+ default : return "UNKNOWN" ;
71
+ }
72
+ }
73
+
21
74
bool perimanSetPinBus (uint8_t pin , peripheral_bus_type_t type , void * bus ){
22
75
peripheral_bus_type_t otype = ESP32_BUS_TYPE_INIT ;
23
76
void * obus = NULL ;
@@ -26,37 +79,38 @@ bool perimanSetPinBus(uint8_t pin, peripheral_bus_type_t type, void * bus){
26
79
return false;
27
80
}
28
81
if (type >= ESP32_BUS_TYPE_MAX ){
29
- log_e ("Invalid type: %u " , ( unsigned int )type );
82
+ log_e ("Invalid type: %s (%u) when setting pin %u " , perimanGetTypeName ( type ), ( unsigned int )type , pin );
30
83
return false;
31
84
}
32
85
if (type > ESP32_BUS_TYPE_GPIO && bus == NULL ){
33
- log_e ("Bus is NULL" );
86
+ log_e ("Bus is NULL for pin %u with type %s (%u)" , pin , perimanGetTypeName ( type ), ( unsigned int ) type );
34
87
return false;
35
88
}
36
89
if (type == ESP32_BUS_TYPE_INIT && bus != NULL ){
37
- log_e ("Can't set a Bus to INIT Type" );
90
+ log_e ("Can't set a Bus to INIT Type (pin %u)" , pin );
38
91
return false;
39
- }
92
+ }
40
93
otype = pins [pin ].type ;
41
94
obus = pins [pin ].bus ;
42
95
if (type == otype && bus == obus ){
43
96
if (type != ESP32_BUS_TYPE_INIT ) {
44
- log_i ( "Bus already set" );
97
+ log_i ( "Pin %u already has type %s (%u) with bus %p" , pin , perimanGetTypeName ( type ), ( unsigned int ) type , bus );
45
98
}
46
99
return true;
47
100
}
48
101
if (obus != NULL ){
49
102
if (deinit_functions [otype ] == NULL ){
50
- log_e ("Bus does not have deinit function set" );
103
+ log_e ("No deinit function for type %s (%u) (pin %u)" , perimanGetTypeName ( otype ), ( unsigned int ) otype , pin );
51
104
return false;
52
105
}
53
106
if (!deinit_functions [otype ](obus )){
54
- log_e ("Previous bus failed to deinit" );
107
+ log_e ("Deinit function for previous bus type %s (%u) failed (pin %u)" , perimanGetTypeName ( otype ), ( unsigned int ) otype , pin );
55
108
return false;
56
109
}
57
110
}
58
111
pins [pin ].type = type ;
59
112
pins [pin ].bus = bus ;
113
+ log_v ("Pin %u successfully set to type %s (%u) with bus %p" , pin , perimanGetTypeName (type ), (unsigned int )type , bus );
60
114
return true;
61
115
}
62
116
@@ -66,7 +120,7 @@ void * perimanGetPinBus(uint8_t pin, peripheral_bus_type_t type){
66
120
return NULL ;
67
121
}
68
122
if (type >= ESP32_BUS_TYPE_MAX || type == ESP32_BUS_TYPE_INIT ){
69
- log_e ("Invalid type: %u " , ( unsigned int )type );
123
+ log_e ("Invalid type %s (%u) for pin %u " , perimanGetTypeName ( type ), ( unsigned int )type , pin );
70
124
return NULL ;
71
125
}
72
126
if (pins [pin ].type == type ){
@@ -85,14 +139,15 @@ peripheral_bus_type_t perimanGetPinBusType(uint8_t pin){
85
139
86
140
bool perimanSetBusDeinit (peripheral_bus_type_t type , peripheral_bus_deinit_cb_t cb ){
87
141
if (type >= ESP32_BUS_TYPE_MAX || type == ESP32_BUS_TYPE_INIT ){
88
- log_e ("Invalid type: %u" , (unsigned int )type );
142
+ log_e ("Invalid type: %s (%u)" , perimanGetTypeName ( type ) , (unsigned int )type );
89
143
return false;
90
144
}
91
145
if (cb == NULL ){
92
- log_e ("Callback is NULL" );
146
+ log_e ("Callback is NULL when setting deinit function for type %s (%u)" , perimanGetTypeName ( type ), ( unsigned int ) type );
93
147
return false;
94
148
}
95
149
deinit_functions [type ] = cb ;
150
+ log_v ("Deinit function for type %s (%u) successfully set to %p" , perimanGetTypeName (type ), (unsigned int )type , cb );
96
151
return true;
97
152
}
98
153
0 commit comments