Skip to content
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

GPIO - Peripheral manager implementation #8179

Merged
merged 2 commits into from
May 11, 2023
Merged
Changes from 1 commit
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
50 changes: 40 additions & 10 deletions cores/esp32/esp32-hal-gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#include "esp32-hal-gpio.h"
#include "esp32-hal-periman.h"
#include "hal/gpio_hal.h"
#include "soc/soc_caps.h"

Expand Down Expand Up @@ -89,6 +90,10 @@ static InterruptHandle_t __pinInterruptHandlers[SOC_GPIO_PIN_COUNT] = {0,};

#include "driver/rtc_io.h"

static bool gpioDetachBus(void * bus){
return true;
}

extern void ARDUINO_ISR_ATTR __pinMode(uint8_t pin, uint8_t mode)
{
#ifdef RGB_BUILTIN
Expand All @@ -102,6 +107,14 @@ extern void ARDUINO_ISR_ATTR __pinMode(uint8_t pin, uint8_t mode)
log_e("Invalid pin selected");
return;
}

if(perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) == NULL){
perimanSetBusDeinit(ESP32_BUS_TYPE_GPIO, gpioDetachBus);
if(!perimanSetPinBus(pin, ESP32_BUS_TYPE_INIT, NULL)){
log_e("Deinit of previous bus failed");
return;
}
}

gpio_hal_context_t gpiohal;
gpiohal.dev = GPIO_LL_GET_HW(GPIO_PORT_0);
Expand Down Expand Up @@ -130,24 +143,41 @@ extern void ARDUINO_ISR_ATTR __pinMode(uint8_t pin, uint8_t mode)
log_e("GPIO config failed");
return;
}
if(perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) == NULL){
if(!perimanSetPinBus(pin, ESP32_BUS_TYPE_GPIO, (void *)(pin+1))){
//gpioDetachBus((void *)(pin+1));
return;
}
}
}

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
const uint8_t comm_val = val != 0 ? RGB_BRIGHTNESS : 0;
neopixelWrite(RGB_BUILTIN, comm_val, comm_val, comm_val);
return;
}
#endif
gpio_set_level((gpio_num_t)pin, val);
if(perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) != NULL){
#ifdef RGB_BUILTIN
if(pin == RGB_BUILTIN){
//use RMT to set all channels on/off
const uint8_t comm_val = val != 0 ? RGB_BRIGHTNESS : 0;
neopixelWrite(RGB_BUILTIN, comm_val, comm_val, comm_val);
return;
}
#endif
gpio_set_level((gpio_num_t)pin, val);
}
else {
log_e("Pin is not set as GPIO.");
}
P-R-O-C-H-Y marked this conversation as resolved.
Show resolved Hide resolved
}

extern int ARDUINO_ISR_ATTR __digitalRead(uint8_t pin)
{
return gpio_get_level((gpio_num_t)pin);
if(perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) != NULL){
return gpio_get_level((gpio_num_t)pin);
P-R-O-C-H-Y marked this conversation as resolved.
Show resolved Hide resolved
}
else {
log_e("Pin is not set as GPIO.");
return 0;
}
}

static void ARDUINO_ISR_ATTR __onPinInterrupt(void * arg) {
Expand Down