Skip to content

Add: make digitalRead() for RGB_BUILTIN work #9418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions cores/esp32/esp32-hal-gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ extern void ARDUINO_ISR_ATTR __pinMode(uint8_t pin, uint8_t mode)
#endif

if (pin >= SOC_GPIO_PIN_COUNT) {
log_e("Invalid IO %i selected", pin);
log_e("Invalid pin selected");
return;
}

if(perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) == NULL){
perimanSetBusDeinit(ESP32_BUS_TYPE_GPIO, gpioDetachBus);
if(!perimanClearPinBus(pin)){
log_e("Deinit of previous bus from IO %i failed", pin);
log_e("Deinit of previous bus failed");
return;
}
}
Expand Down Expand Up @@ -140,7 +140,7 @@ extern void ARDUINO_ISR_ATTR __pinMode(uint8_t pin, uint8_t mode)
}
if(gpio_config(&conf) != ESP_OK)
{
log_e("IO %i config failed", pin);
log_e("GPIO config failed");
return;
}
if(perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) == NULL){
Expand All @@ -151,11 +151,16 @@ extern void ARDUINO_ISR_ATTR __pinMode(uint8_t pin, uint8_t mode)
}
}

#ifdef RGB_BUILTIN
uint8_t RGB_BUILTIN_storage = 0;
#endif

extern void ARDUINO_ISR_ATTR __digitalWrite(uint8_t pin, uint8_t val)
{
#ifdef RGB_BUILTIN
if(pin == RGB_BUILTIN){
//use RMT to set all channels on/off
RGB_BUILTIN_storage=val;
const uint8_t comm_val = val != 0 ? RGB_BRIGHTNESS : 0;
neopixelWrite(RGB_BUILTIN, comm_val, comm_val, comm_val);
return;
Expand All @@ -164,17 +169,23 @@ extern void ARDUINO_ISR_ATTR __digitalWrite(uint8_t pin, uint8_t val)
if(perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) != NULL){
gpio_set_level((gpio_num_t)pin, val);
} else {
log_e("IO %i is not set as GPIO.", pin);
log_e("Pin is not set as GPIO.");
}
}

extern int ARDUINO_ISR_ATTR __digitalRead(uint8_t pin)
{
#ifdef RGB_BUILTIN
if(pin == RGB_BUILTIN){
return RGB_BUILTIN_storage;
}
#endif

if(perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) != NULL){
return gpio_get_level((gpio_num_t)pin);
}
else {
log_e("IO %i is not set as GPIO.", pin);
log_e("Pin is not set as GPIO.");
return 0;
}
}
Expand Down Expand Up @@ -204,7 +215,7 @@ extern void __attachInterruptFunctionalArg(uint8_t pin, voidFuncPtrArg userFunc,
interrupt_initialized = (err == ESP_OK) || (err == ESP_ERR_INVALID_STATE);
}
if(!interrupt_initialized) {
log_e("IO %i ISR Service Failed To Start", pin);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't simplify the error messages. This will make it more difficult to debug.

log_e("GPIO ISR Service Failed To Start");
return;
}

Expand Down Expand Up @@ -256,14 +267,6 @@ extern void __detachInterrupt(uint8_t pin)
gpio_set_intr_type((gpio_num_t)pin, GPIO_INTR_DISABLE);
}

extern void enableInterrupt(uint8_t pin) {
gpio_intr_enable((gpio_num_t)pin);
}

extern void disableInterrupt(uint8_t pin) {
gpio_intr_disable((gpio_num_t)pin);
}

Comment on lines -259 to -266
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't delete the ISR enabler/disabler


extern void pinMode(uint8_t pin, uint8_t mode) __attribute__ ((weak, alias("__pinMode")));
extern void digitalWrite(uint8_t pin, uint8_t val) __attribute__ ((weak, alias("__digitalWrite")));
Expand Down