Skip to content

Commit 8a179e6

Browse files
authored
Enforces more consistency into Peripheral Manager (#8188)
* Avoid log_i() message the first time a bus is assigned * Prevent operation with ESP32_BUS_TYPE_INIT * keeps coding style * do not print messages on INIT bus type
1 parent 68c678e commit 8a179e6

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

Diff for: cores/esp32/esp32-hal-periman.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,16 @@ bool perimanSetPinBus(uint8_t pin, peripheral_bus_type_t type, void * bus){
3333
log_e("Bus is NULL");
3434
return false;
3535
}
36+
if (type == ESP32_BUS_TYPE_INIT && bus != NULL){
37+
log_e("Can't set a Bus to INIT Type");
38+
return false;
39+
}
3640
otype = pins[pin].type;
3741
obus = pins[pin].bus;
3842
if(type == otype && bus == obus){
39-
log_i("Bus already set");
43+
if (type != ESP32_BUS_TYPE_INIT) {
44+
log_i("Bus already set");
45+
}
4046
return true;
4147
}
4248
if(obus != NULL){
@@ -59,7 +65,7 @@ void * perimanGetPinBus(uint8_t pin, peripheral_bus_type_t type){
5965
log_e("Invalid pin: %u", pin);
6066
return NULL;
6167
}
62-
if(type >= ESP32_BUS_TYPE_MAX){
68+
if(type >= ESP32_BUS_TYPE_MAX || type == ESP32_BUS_TYPE_INIT){
6369
log_e("Invalid type: %u", (unsigned int)type);
6470
return NULL;
6571
}
@@ -78,7 +84,7 @@ peripheral_bus_type_t perimanGetPinBusType(uint8_t pin){
7884
}
7985

8086
bool perimanSetBusDeinit(peripheral_bus_type_t type, peripheral_bus_deinit_cb_t cb){
81-
if(type >= ESP32_BUS_TYPE_MAX){
87+
if(type >= ESP32_BUS_TYPE_MAX || type == ESP32_BUS_TYPE_INIT){
8288
log_e("Invalid type: %u", (unsigned int)type);
8389
return false;
8490
}

0 commit comments

Comments
 (0)