Extend bus types and structure for Peripheral Manager (#8888)
* Extended bus types for peripheral manager * add extra_type to peripheral manager * Fix function call * Fix check for no extra_type * Add extra_type for SD and ETH CS pin * added bus_num and bus_channel to pin structure * update printPerimanInfo with new fields * replaced setting bus to INIT with DetachPin call * add defines for extra attributes * use new required parameters in perimanSetPinBus * function rename * removed duplicate define * Update print format --------- Co-authored-by: Rodrigo Garcia <rodrigo.garcia@espressif.com>
This commit is contained in:
parent
600f35916b
commit
0d0d27fba8
22 changed files with 404 additions and 217 deletions
|
|
@ -39,6 +39,7 @@
|
||||||
|
|
||||||
#include "stdlib_noniso.h"
|
#include "stdlib_noniso.h"
|
||||||
#include "binary.h"
|
#include "binary.h"
|
||||||
|
#include "extra_attr.h"
|
||||||
|
|
||||||
#define PI 3.1415926535897932384626433832795
|
#define PI 3.1415926535897932384626433832795
|
||||||
#define HALF_PI 1.5707963267948966192313216916398
|
#define HALF_PI 1.5707963267948966192313216916398
|
||||||
|
|
|
||||||
|
|
@ -181,8 +181,8 @@ bool HWCDC::deinit(void * busptr)
|
||||||
running = true;
|
running = true;
|
||||||
// Setting USB D+ D- pins
|
// Setting USB D+ D- pins
|
||||||
bool retCode = true;
|
bool retCode = true;
|
||||||
retCode &= perimanSetPinBus(USB_DM_GPIO_NUM, ESP32_BUS_TYPE_INIT, NULL);
|
retCode &= perimanClearPinBus(USB_DM_GPIO_NUM);
|
||||||
retCode &= perimanSetPinBus(USB_DP_GPIO_NUM, ESP32_BUS_TYPE_INIT, NULL);
|
retCode &= perimanClearPinBus(USB_DP_GPIO_NUM);
|
||||||
if (retCode) {
|
if (retCode) {
|
||||||
// Force the host to re-enumerate (BUS_RESET)
|
// Force the host to re-enumerate (BUS_RESET)
|
||||||
pinMode(USB_DM_GPIO_NUM, OUTPUT_OPEN_DRAIN);
|
pinMode(USB_DM_GPIO_NUM, OUTPUT_OPEN_DRAIN);
|
||||||
|
|
@ -220,10 +220,10 @@ void HWCDC::begin(unsigned long baud)
|
||||||
end();
|
end();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (perimanSetBusDeinit(ESP32_BUS_TYPE_USB, HWCDC::deinit)) {
|
if (perimanSetBusDeinit(ESP32_BUS_TYPE_USB_DM, HWCDC::deinit) && perimanSetBusDeinit(ESP32_BUS_TYPE_USB_DP, HWCDC::deinit)) {
|
||||||
// Setting USB D+ D- pins
|
// Setting USB D+ D- pins
|
||||||
perimanSetPinBus(USB_DM_GPIO_NUM, ESP32_BUS_TYPE_USB, (void *) this);
|
perimanSetPinBus(USB_DM_GPIO_NUM, ESP32_BUS_TYPE_USB_DM, (void *) this, -1, -1);
|
||||||
perimanSetPinBus(USB_DP_GPIO_NUM, ESP32_BUS_TYPE_USB, (void *) this);
|
perimanSetPinBus(USB_DP_GPIO_NUM, ESP32_BUS_TYPE_USB_DP, (void *) this, -1, -1);
|
||||||
} else {
|
} else {
|
||||||
log_e("Serial JTAG Pins can't be set into Peripheral Manager.");
|
log_e("Serial JTAG Pins can't be set into Peripheral Manager.");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -242,6 +242,8 @@ static void printBoardInfo(void){
|
||||||
static void printPerimanInfo(void){
|
static void printPerimanInfo(void){
|
||||||
chip_report_printf("GPIO Info:\n");
|
chip_report_printf("GPIO Info:\n");
|
||||||
chip_report_printf("------------------------------------------\n");
|
chip_report_printf("------------------------------------------\n");
|
||||||
|
chip_report_printf(" GPIO : BUS_TYPE[bus/unit][chan]\n");
|
||||||
|
chip_report_printf(" -------------------------------------- \n");
|
||||||
for(uint8_t i = 0; i < SOC_GPIO_PIN_COUNT; i++){
|
for(uint8_t i = 0; i < SOC_GPIO_PIN_COUNT; i++){
|
||||||
if(!perimanPinIsValid(i)){
|
if(!perimanPinIsValid(i)){
|
||||||
continue;//invalid pin
|
continue;//invalid pin
|
||||||
|
|
@ -250,8 +252,23 @@ static void printPerimanInfo(void){
|
||||||
if(type == ESP32_BUS_TYPE_INIT){
|
if(type == ESP32_BUS_TYPE_INIT){
|
||||||
continue;//unused pin
|
continue;//unused pin
|
||||||
}
|
}
|
||||||
chip_report_printf(" %17u : ", i);
|
const char* extra_type = perimanGetPinBusExtraType(i);
|
||||||
chip_report_printf("%s\n", perimanGetTypeName(type));
|
chip_report_printf(" %4u : ", i);
|
||||||
|
if(extra_type){
|
||||||
|
chip_report_printf("%s", extra_type);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
chip_report_printf("%s", perimanGetTypeName(type));
|
||||||
|
}
|
||||||
|
int8_t bus_number = perimanGetPinBusNum(i);
|
||||||
|
if (bus_number != -1){
|
||||||
|
chip_report_printf("[%u]", bus_number);
|
||||||
|
}
|
||||||
|
int8_t bus_channel = perimanGetPinBusChannel(i);
|
||||||
|
if (bus_channel != -1){
|
||||||
|
chip_report_printf("[%u]", bus_channel);
|
||||||
|
}
|
||||||
|
chip_report_printf("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -221,7 +221,7 @@ esp_err_t __analogInit(uint8_t pin, adc_channel_t channel, adc_unit_t adc_unit){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!perimanSetPinBus(pin, ESP32_BUS_TYPE_ADC_ONESHOT, (void *)(pin+1))){
|
if(!perimanSetPinBus(pin, ESP32_BUS_TYPE_ADC_ONESHOT, (void *)(pin+1), adc_unit, channel)){
|
||||||
adcDetachBus((void *)(pin+1));
|
adcDetachBus((void *)(pin+1));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
@ -396,7 +396,7 @@ static bool adcContinuousDetachBus(void * adc_unit_number){
|
||||||
int io_pin;
|
int io_pin;
|
||||||
adc_oneshot_channel_to_io(adc_unit, channel, &io_pin);
|
adc_oneshot_channel_to_io(adc_unit, channel, &io_pin);
|
||||||
if(perimanGetPinBusType(io_pin) == ESP32_BUS_TYPE_ADC_CONT){
|
if(perimanGetPinBusType(io_pin) == ESP32_BUS_TYPE_ADC_CONT){
|
||||||
if(!perimanSetPinBus(io_pin, ESP32_BUS_TYPE_INIT, NULL)){
|
if(!perimanClearPinBus(io_pin)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -497,7 +497,7 @@ bool analogContinuous(uint8_t pins[], size_t pins_count, uint32_t conversions_pe
|
||||||
//Set periman deinit function and reset all pins to init state.
|
//Set periman deinit function and reset all pins to init state.
|
||||||
perimanSetBusDeinit(ESP32_BUS_TYPE_ADC_CONT, adcContinuousDetachBus);
|
perimanSetBusDeinit(ESP32_BUS_TYPE_ADC_CONT, adcContinuousDetachBus);
|
||||||
for(int j = 0; j < pins_count; j++){
|
for(int j = 0; j < pins_count; j++){
|
||||||
if(!perimanSetPinBus(pins[j], ESP32_BUS_TYPE_INIT, NULL)){
|
if(!perimanClearPinBus(pins[j])){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -571,7 +571,7 @@ bool analogContinuous(uint8_t pins[], size_t pins_count, uint32_t conversions_pe
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int k = 0; k < pins_count; k++){
|
for(int k = 0; k < pins_count; k++){
|
||||||
if(!perimanSetPinBus(pins[k], ESP32_BUS_TYPE_ADC_CONT, (void *)(adc_unit+1))){
|
if(!perimanSetPinBus(pins[k], ESP32_BUS_TYPE_ADC_CONT, (void *)(adc_unit+1), adc_unit, channel[k])){
|
||||||
log_e("perimanSetPinBus to ADC Continuous failed!");
|
log_e("perimanSetPinBus to ADC Continuous failed!");
|
||||||
adcContinuousDetachBus((void *)(adc_unit+1));
|
adcContinuousDetachBus((void *)(adc_unit+1));
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ bool __dacWrite(uint8_t pin, uint8_t value)
|
||||||
dac_oneshot_handle_t bus = (dac_oneshot_handle_t)perimanGetPinBus(pin, ESP32_BUS_TYPE_DAC_ONESHOT);
|
dac_oneshot_handle_t bus = (dac_oneshot_handle_t)perimanGetPinBus(pin, ESP32_BUS_TYPE_DAC_ONESHOT);
|
||||||
if(bus == NULL){
|
if(bus == NULL){
|
||||||
perimanSetBusDeinit(ESP32_BUS_TYPE_DAC_ONESHOT, dacDetachBus);
|
perimanSetBusDeinit(ESP32_BUS_TYPE_DAC_ONESHOT, dacDetachBus);
|
||||||
if(!perimanSetPinBus(pin, ESP32_BUS_TYPE_INIT, NULL)){
|
if(!perimanClearPinBus(pin)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
dac_channel_t channel = (pin == DAC_CHAN0_GPIO_NUM)?DAC_CHAN_0:DAC_CHAN_1;
|
dac_channel_t channel = (pin == DAC_CHAN0_GPIO_NUM)?DAC_CHAN_0:DAC_CHAN_1;
|
||||||
|
|
@ -44,7 +44,7 @@ bool __dacWrite(uint8_t pin, uint8_t value)
|
||||||
log_e("dac_oneshot_new_channel failed with error: %d", err);
|
log_e("dac_oneshot_new_channel failed with error: %d", err);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(!perimanSetPinBus(pin, ESP32_BUS_TYPE_DAC_ONESHOT, (void *)bus)){
|
if(!perimanSetPinBus(pin, ESP32_BUS_TYPE_DAC_ONESHOT, (void *)bus, -1, channel)){
|
||||||
dacDetachBus((void *)bus);
|
dacDetachBus((void *)bus);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -67,7 +67,7 @@ bool __dacDisable(uint8_t pin)
|
||||||
void * bus = perimanGetPinBus(pin, ESP32_BUS_TYPE_DAC_ONESHOT);
|
void * bus = perimanGetPinBus(pin, ESP32_BUS_TYPE_DAC_ONESHOT);
|
||||||
if(bus != NULL){
|
if(bus != NULL){
|
||||||
// will call dacDetachBus
|
// will call dacDetachBus
|
||||||
return perimanSetPinBus(pin, ESP32_BUS_TYPE_INIT, NULL);
|
return perimanClearPinBus(pin);
|
||||||
} else {
|
} else {
|
||||||
log_e("pin %u is not attached to DAC", pin);
|
log_e("pin %u is not attached to DAC", pin);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@ extern void ARDUINO_ISR_ATTR __pinMode(uint8_t pin, uint8_t mode)
|
||||||
|
|
||||||
if(perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) == NULL){
|
if(perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) == NULL){
|
||||||
perimanSetBusDeinit(ESP32_BUS_TYPE_GPIO, gpioDetachBus);
|
perimanSetBusDeinit(ESP32_BUS_TYPE_GPIO, gpioDetachBus);
|
||||||
if(!perimanSetPinBus(pin, ESP32_BUS_TYPE_INIT, NULL)){
|
if(!perimanClearPinBus(pin)){
|
||||||
log_e("Deinit of previous bus failed");
|
log_e("Deinit of previous bus failed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -144,7 +144,7 @@ extern void ARDUINO_ISR_ATTR __pinMode(uint8_t pin, uint8_t mode)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) == NULL){
|
if(perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) == NULL){
|
||||||
if(!perimanSetPinBus(pin, ESP32_BUS_TYPE_GPIO, (void *)(pin+1))){
|
if(!perimanSetPinBus(pin, ESP32_BUS_TYPE_GPIO, (void *)(pin+1), -1, -1)){
|
||||||
//gpioDetachBus((void *)(pin+1));
|
//gpioDetachBus((void *)(pin+1));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -235,8 +235,10 @@ esp_err_t i2cSlaveInit(uint8_t num, int sda, int scl, uint16_t slaveID, uint32_t
|
||||||
frequency = 1000000;
|
frequency = 1000000;
|
||||||
}
|
}
|
||||||
|
|
||||||
perimanSetBusDeinit(ESP32_BUS_TYPE_I2C_SLAVE, i2cSlaveDetachBus);
|
perimanSetBusDeinit(ESP32_BUS_TYPE_I2C_SLAVE_SDA, i2cSlaveDetachBus);
|
||||||
if(!perimanSetPinBus(sda, ESP32_BUS_TYPE_INIT, NULL) || !perimanSetPinBus(scl, ESP32_BUS_TYPE_INIT, NULL)){
|
perimanSetBusDeinit(ESP32_BUS_TYPE_I2C_SLAVE_SCL, i2cSlaveDetachBus);
|
||||||
|
|
||||||
|
if(!perimanClearPinBus(sda) || !perimanClearPinBus(scl)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -353,7 +355,7 @@ esp_err_t i2cSlaveInit(uint8_t num, int sda, int scl, uint16_t slaveID, uint32_t
|
||||||
i2c_ll_slave_enable_rx_it(i2c->dev);
|
i2c_ll_slave_enable_rx_it(i2c->dev);
|
||||||
i2c_ll_set_stretch(i2c->dev, 0x3FF);
|
i2c_ll_set_stretch(i2c->dev, 0x3FF);
|
||||||
i2c_ll_update(i2c->dev);
|
i2c_ll_update(i2c->dev);
|
||||||
if(!perimanSetPinBus(sda, ESP32_BUS_TYPE_I2C_SLAVE, (void *)(i2c->num+1)) || !perimanSetPinBus(scl, ESP32_BUS_TYPE_I2C_SLAVE, (void *)(i2c->num+1))){
|
if(!perimanSetPinBus(sda, ESP32_BUS_TYPE_I2C_SLAVE_SDA, (void *)(i2c->num+1), i2c->num, -1) || !perimanSetPinBus(scl, ESP32_BUS_TYPE_I2C_SLAVE_SCL, (void *)(i2c->num+1), i2c->num, -1)){
|
||||||
i2cSlaveDetachBus((void *)(i2c->num+1));
|
i2cSlaveDetachBus((void *)(i2c->num+1));
|
||||||
ret = ESP_FAIL;
|
ret = ESP_FAIL;
|
||||||
}
|
}
|
||||||
|
|
@ -383,8 +385,8 @@ esp_err_t i2cSlaveDeinit(uint8_t num){
|
||||||
int scl = i2c->scl;
|
int scl = i2c->scl;
|
||||||
int sda = i2c->sda;
|
int sda = i2c->sda;
|
||||||
i2c_slave_free_resources(i2c);
|
i2c_slave_free_resources(i2c);
|
||||||
perimanSetPinBus(scl, ESP32_BUS_TYPE_INIT, NULL);
|
perimanClearPinBus(scl);
|
||||||
perimanSetPinBus(sda, ESP32_BUS_TYPE_INIT, NULL);
|
perimanClearPinBus(sda);
|
||||||
I2C_SLAVE_MUTEX_UNLOCK();
|
I2C_SLAVE_MUTEX_UNLOCK();
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -98,8 +98,10 @@ esp_err_t i2cInit(uint8_t i2c_num, int8_t sda, int8_t scl, uint32_t frequency){
|
||||||
frequency = 1000000UL;
|
frequency = 1000000UL;
|
||||||
}
|
}
|
||||||
|
|
||||||
perimanSetBusDeinit(ESP32_BUS_TYPE_I2C_MASTER, i2cDetachBus);
|
perimanSetBusDeinit(ESP32_BUS_TYPE_I2C_MASTER_SDA, i2cDetachBus);
|
||||||
if(!perimanSetPinBus(sda, ESP32_BUS_TYPE_INIT, NULL) || !perimanSetPinBus(scl, ESP32_BUS_TYPE_INIT, NULL)){
|
perimanSetBusDeinit(ESP32_BUS_TYPE_I2C_MASTER_SCL, i2cDetachBus);
|
||||||
|
|
||||||
|
if(!perimanClearPinBus(sda) || !perimanClearPinBus(scl)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -128,7 +130,7 @@ esp_err_t i2cInit(uint8_t i2c_num, int8_t sda, int8_t scl, uint32_t frequency){
|
||||||
bus[i2c_num].sda = sda;
|
bus[i2c_num].sda = sda;
|
||||||
//Clock Stretching Timeout: 20b:esp32, 5b:esp32-c3, 24b:esp32-s2
|
//Clock Stretching Timeout: 20b:esp32, 5b:esp32-c3, 24b:esp32-s2
|
||||||
i2c_set_timeout((i2c_port_t)i2c_num, I2C_LL_MAX_TIMEOUT);
|
i2c_set_timeout((i2c_port_t)i2c_num, I2C_LL_MAX_TIMEOUT);
|
||||||
if(!perimanSetPinBus(sda, ESP32_BUS_TYPE_I2C_MASTER, (void *)(i2c_num+1)) || !perimanSetPinBus(scl, ESP32_BUS_TYPE_I2C_MASTER, (void *)(i2c_num+1))){
|
if(!perimanSetPinBus(sda, ESP32_BUS_TYPE_I2C_MASTER_SDA, (void *)(i2c_num+1), i2c_num, -1) || !perimanSetPinBus(scl, ESP32_BUS_TYPE_I2C_MASTER_SCL, (void *)(i2c_num+1), i2c_num, -1)){
|
||||||
i2cDetachBus((void *)(i2c_num+1));
|
i2cDetachBus((void *)(i2c_num+1));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -159,8 +161,8 @@ esp_err_t i2cDeinit(uint8_t i2c_num){
|
||||||
err = i2c_driver_delete((i2c_port_t)i2c_num);
|
err = i2c_driver_delete((i2c_port_t)i2c_num);
|
||||||
if(err == ESP_OK){
|
if(err == ESP_OK){
|
||||||
bus[i2c_num].initialized = false;
|
bus[i2c_num].initialized = false;
|
||||||
perimanSetPinBus(bus[i2c_num].scl, ESP32_BUS_TYPE_INIT, NULL);
|
perimanClearPinBus(bus[i2c_num].scl);
|
||||||
perimanSetPinBus(bus[i2c_num].sda, ESP32_BUS_TYPE_INIT, NULL);
|
perimanClearPinBus(bus[i2c_num].sda);
|
||||||
bus[i2c_num].scl = -1;
|
bus[i2c_num].scl = -1;
|
||||||
bus[i2c_num].sda = -1;
|
bus[i2c_num].sda = -1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ bool ledcAttach(uint8_t pin, uint32_t freq, uint8_t resolution)
|
||||||
|
|
||||||
perimanSetBusDeinit(ESP32_BUS_TYPE_LEDC, ledcDetachBus);
|
perimanSetBusDeinit(ESP32_BUS_TYPE_LEDC, ledcDetachBus);
|
||||||
ledc_channel_handle_t *bus = (ledc_channel_handle_t*)perimanGetPinBus(pin, ESP32_BUS_TYPE_LEDC);
|
ledc_channel_handle_t *bus = (ledc_channel_handle_t*)perimanGetPinBus(pin, ESP32_BUS_TYPE_LEDC);
|
||||||
if(bus != NULL && !perimanSetPinBus(pin, ESP32_BUS_TYPE_INIT, NULL)){
|
if(bus != NULL && !perimanClearPinBus(pin)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -110,7 +110,7 @@ bool ledcAttach(uint8_t pin, uint32_t freq, uint8_t resolution)
|
||||||
#endif
|
#endif
|
||||||
ledc_handle.used_channels |= 1UL << channel;
|
ledc_handle.used_channels |= 1UL << channel;
|
||||||
|
|
||||||
if(!perimanSetPinBus(pin, ESP32_BUS_TYPE_LEDC, (void *)handle)){
|
if(!perimanSetPinBus(pin, ESP32_BUS_TYPE_LEDC, (void *)handle, group, channel)){
|
||||||
ledcDetachBus((void *)handle);
|
ledcDetachBus((void *)handle);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -216,7 +216,7 @@ bool ledcDetach(uint8_t pin)
|
||||||
ledc_channel_handle_t *bus = (ledc_channel_handle_t*)perimanGetPinBus(pin, ESP32_BUS_TYPE_LEDC);
|
ledc_channel_handle_t *bus = (ledc_channel_handle_t*)perimanGetPinBus(pin, ESP32_BUS_TYPE_LEDC);
|
||||||
if(bus != NULL){
|
if(bus != NULL){
|
||||||
// will call ledcDetachBus
|
// will call ledcDetachBus
|
||||||
return perimanSetPinBus(pin, ESP32_BUS_TYPE_INIT, NULL);
|
return perimanClearPinBus(pin);
|
||||||
} else {
|
} else {
|
||||||
log_e("pin %u is not attached to LEDC", pin);
|
log_e("pin %u is not attached to LEDC", pin);
|
||||||
}
|
}
|
||||||
|
|
@ -360,7 +360,7 @@ void analogWrite(uint8_t pin, int value) {
|
||||||
// Use ledc hardware for internal pins
|
// Use ledc hardware for internal pins
|
||||||
if (pin < SOC_GPIO_PIN_COUNT) {
|
if (pin < SOC_GPIO_PIN_COUNT) {
|
||||||
ledc_channel_handle_t *bus = (ledc_channel_handle_t*)perimanGetPinBus(pin, ESP32_BUS_TYPE_LEDC);
|
ledc_channel_handle_t *bus = (ledc_channel_handle_t*)perimanGetPinBus(pin, ESP32_BUS_TYPE_LEDC);
|
||||||
if(bus == NULL && perimanSetPinBus(pin, ESP32_BUS_TYPE_INIT, NULL)){
|
if(bus == NULL && perimanClearPinBus(pin)){
|
||||||
if(ledcAttach(pin, analog_frequency, analog_resolution) == 0){
|
if(ledcAttach(pin, analog_frequency, analog_resolution) == 0){
|
||||||
log_e("analogWrite setup failed (freq = %u, resolution = %u). Try setting different resolution or frequency");
|
log_e("analogWrite setup failed (freq = %u, resolution = %u). Try setting different resolution or frequency");
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,12 @@
|
||||||
#include "esp32-hal-periman.h"
|
#include "esp32-hal-periman.h"
|
||||||
#include "esp_bit_defs.h"
|
#include "esp_bit_defs.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct ATTR_PACKED {
|
||||||
peripheral_bus_type_t type;
|
peripheral_bus_type_t type;
|
||||||
|
const char* extra_type;
|
||||||
void * bus;
|
void * bus;
|
||||||
|
int8_t bus_num;
|
||||||
|
int8_t bus_channel;
|
||||||
} peripheral_pin_item_t;
|
} peripheral_pin_item_t;
|
||||||
|
|
||||||
static peripheral_bus_deinit_cb_t deinit_functions[ESP32_BUS_TYPE_MAX];
|
static peripheral_bus_deinit_cb_t deinit_functions[ESP32_BUS_TYPE_MAX];
|
||||||
|
|
@ -46,32 +49,67 @@ const char* perimanGetTypeName(peripheral_bus_type_t type) {
|
||||||
case ESP32_BUS_TYPE_RMT_RX: return "RMT_RX";
|
case ESP32_BUS_TYPE_RMT_RX: return "RMT_RX";
|
||||||
#endif
|
#endif
|
||||||
#if SOC_I2S_SUPPORTED
|
#if SOC_I2S_SUPPORTED
|
||||||
case ESP32_BUS_TYPE_I2S_STD: return "I2S_STD";
|
case ESP32_BUS_TYPE_I2S_STD_MCLK: return "I2S_STD_MCLK";
|
||||||
case ESP32_BUS_TYPE_I2S_TDM: return "I2S_TDM";
|
case ESP32_BUS_TYPE_I2S_STD_BCLK: return "I2S_STD_BCLK";
|
||||||
case ESP32_BUS_TYPE_I2S_PDM_TX: return "I2S_PDM_TX";
|
case ESP32_BUS_TYPE_I2S_STD_WS: return "I2S_STD_WS";
|
||||||
case ESP32_BUS_TYPE_I2S_PDM_RX: return "I2S_PDM_RX";
|
case ESP32_BUS_TYPE_I2S_STD_DOUT: return "I2S_STD_DOUT";
|
||||||
|
case ESP32_BUS_TYPE_I2S_STD_DIN: return "I2S_STD_DIN";
|
||||||
|
case ESP32_BUS_TYPE_I2S_TDM_MCLK: return "I2S_TDM_MCLK";
|
||||||
|
case ESP32_BUS_TYPE_I2S_TDM_BCLK: return "I2S_TDM_BCLK";
|
||||||
|
case ESP32_BUS_TYPE_I2S_TDM_WS: return "I2S_TDM_WS";
|
||||||
|
case ESP32_BUS_TYPE_I2S_TDM_DOUT: return "I2S_TDM_DOUT";
|
||||||
|
case ESP32_BUS_TYPE_I2S_TDM_DIN: return "I2S_TDM_DIN";
|
||||||
|
case ESP32_BUS_TYPE_I2S_PDM_TX_CLK: return "I2S_PDM_TX_CLK";
|
||||||
|
case ESP32_BUS_TYPE_I2S_PDM_TX_DOUT0: return "I2S_PDM_TX_DOUT0";
|
||||||
|
case ESP32_BUS_TYPE_I2S_PDM_TX_DOUT1: return "I2S_PDM_TX_DOUT1";
|
||||||
|
case ESP32_BUS_TYPE_I2S_PDM_RX_CLK: return "I2S_PDM_RX_CLK";
|
||||||
|
case ESP32_BUS_TYPE_I2S_PDM_RX_DIN0: return "I2S_PDM_RX_DIN0";
|
||||||
|
case ESP32_BUS_TYPE_I2S_PDM_RX_DIN1: return "I2S_PDM_RX_DIN1";
|
||||||
|
case ESP32_BUS_TYPE_I2S_PDM_RX_DIN2: return "I2S_PDM_RX_DIN2";
|
||||||
|
case ESP32_BUS_TYPE_I2S_PDM_RX_DIN3: return "I2S_PDM_RX_DIN3";
|
||||||
#endif
|
#endif
|
||||||
#if SOC_I2C_SUPPORTED
|
#if SOC_I2C_SUPPORTED
|
||||||
case ESP32_BUS_TYPE_I2C_MASTER: return "I2C_MASTER";
|
case ESP32_BUS_TYPE_I2C_MASTER_SDA: return "I2C_MASTER_SDA";
|
||||||
case ESP32_BUS_TYPE_I2C_SLAVE: return "I2C_SLAVE";
|
case ESP32_BUS_TYPE_I2C_MASTER_SCL: return "I2C_MASTER_SCL";
|
||||||
|
case ESP32_BUS_TYPE_I2C_SLAVE_SDA: return "I2C_SLAVE_SDA";
|
||||||
|
case ESP32_BUS_TYPE_I2C_SLAVE_SCL: return "I2C_SLAVE_SCL";
|
||||||
#endif
|
#endif
|
||||||
#if SOC_GPSPI_SUPPORTED
|
#if SOC_GPSPI_SUPPORTED
|
||||||
case ESP32_BUS_TYPE_SPI_MASTER: return "SPI_MASTER";
|
case ESP32_BUS_TYPE_SPI_MASTER_SCK: return "SPI_MASTER_SCK";
|
||||||
|
case ESP32_BUS_TYPE_SPI_MASTER_MISO: return "SPI_MASTER_MISO";
|
||||||
|
case ESP32_BUS_TYPE_SPI_MASTER_MOSI: return "SPI_MASTER_MOSI";
|
||||||
|
case ESP32_BUS_TYPE_SPI_MASTER_CS: return "SPI_MASTER_CS";
|
||||||
#endif
|
#endif
|
||||||
#if SOC_SDMMC_HOST_SUPPORTED
|
#if SOC_SDMMC_HOST_SUPPORTED
|
||||||
case ESP32_BUS_TYPE_SDMMC: return "SDMMC";
|
case ESP32_BUS_TYPE_SDMMC_CLK: return "SDMMC_CLK";
|
||||||
|
case ESP32_BUS_TYPE_SDMMC_CMD: return "SDMMC_CMD";
|
||||||
|
case ESP32_BUS_TYPE_SDMMC_D0: return "SDMMC_D0";
|
||||||
|
case ESP32_BUS_TYPE_SDMMC_D1: return "SDMMC_D1";
|
||||||
|
case ESP32_BUS_TYPE_SDMMC_D2: return "SDMMC_D2";
|
||||||
|
case ESP32_BUS_TYPE_SDMMC_D3: return "SDMMC_D3";
|
||||||
#endif
|
#endif
|
||||||
#if SOC_TOUCH_SENSOR_SUPPORTED
|
#if SOC_TOUCH_SENSOR_SUPPORTED
|
||||||
case ESP32_BUS_TYPE_TOUCH: return "TOUCH";
|
case ESP32_BUS_TYPE_TOUCH: return "TOUCH";
|
||||||
#endif
|
#endif
|
||||||
#if SOC_USB_SERIAL_JTAG_SUPPORTED || SOC_USB_OTG_SUPPORTED
|
#if SOC_USB_SERIAL_JTAG_SUPPORTED || SOC_USB_OTG_SUPPORTED
|
||||||
case ESP32_BUS_TYPE_USB: return "USB";
|
case ESP32_BUS_TYPE_USB_DM: return "USB_DM";
|
||||||
|
case ESP32_BUS_TYPE_USB_DP: return "USB_DP";
|
||||||
|
#endif
|
||||||
|
#if SOC_GPSPI_SUPPORTED
|
||||||
|
case ESP32_BUS_TYPE_ETHERNET_SPI: return "ETHERNET_SPI";
|
||||||
|
#endif
|
||||||
|
#if CONFIG_ETH_USE_ESP32_EMAC
|
||||||
|
case ESP32_BUS_TYPE_ETHERNET_RMII: return "ETHERNET_RMII";
|
||||||
|
case ESP32_BUS_TYPE_ETHERNET_CLK: return "ETHERNET_CLK";
|
||||||
|
case ESP32_BUS_TYPE_ETHERNET_MCD: return "ETHERNET_MCD";
|
||||||
|
case ESP32_BUS_TYPE_ETHERNET_MDIO: return "ETHERNET_MDIO";
|
||||||
|
case ESP32_BUS_TYPE_ETHERNET_PWR: return "ETHERNET_PWR";
|
||||||
#endif
|
#endif
|
||||||
default: return "UNKNOWN";
|
default: return "UNKNOWN";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool perimanSetPinBus(uint8_t pin, peripheral_bus_type_t type, void * bus){
|
bool perimanSetPinBus(uint8_t pin, peripheral_bus_type_t type, void * bus, int8_t bus_num, int8_t bus_channel){
|
||||||
peripheral_bus_type_t otype = ESP32_BUS_TYPE_INIT;
|
peripheral_bus_type_t otype = ESP32_BUS_TYPE_INIT;
|
||||||
void * obus = NULL;
|
void * obus = NULL;
|
||||||
if(GPIO_NOT_VALID(pin)){
|
if(GPIO_NOT_VALID(pin)){
|
||||||
|
|
@ -110,10 +148,27 @@ bool perimanSetPinBus(uint8_t pin, peripheral_bus_type_t type, void * bus){
|
||||||
}
|
}
|
||||||
pins[pin].type = type;
|
pins[pin].type = type;
|
||||||
pins[pin].bus = bus;
|
pins[pin].bus = bus;
|
||||||
|
pins[pin].bus_num = bus_num;
|
||||||
|
pins[pin].bus_channel = bus_channel;
|
||||||
|
pins[pin].extra_type = NULL;
|
||||||
log_v("Pin %u successfully set to type %s (%u) with bus %p", pin, perimanGetTypeName(type), (unsigned int)type, bus);
|
log_v("Pin %u successfully set to type %s (%u) with bus %p", pin, perimanGetTypeName(type), (unsigned int)type, bus);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool perimanSetPinBusExtraType(uint8_t pin, const char* extra_type){
|
||||||
|
if(GPIO_NOT_VALID(pin)){
|
||||||
|
log_e("Invalid pin: %u", pin);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (pins[pin].type == ESP32_BUS_TYPE_INIT) {
|
||||||
|
log_e("Can't set extra type for Bus INIT Type (pin %u)", pin);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
pins[pin].extra_type = extra_type;
|
||||||
|
log_v("Successfully set extra_type %s for pin %u", extra_type, pin);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void * perimanGetPinBus(uint8_t pin, peripheral_bus_type_t type){
|
void * perimanGetPinBus(uint8_t pin, peripheral_bus_type_t type){
|
||||||
if(GPIO_NOT_VALID(pin)){
|
if(GPIO_NOT_VALID(pin)){
|
||||||
log_e("Invalid pin: %u", pin);
|
log_e("Invalid pin: %u", pin);
|
||||||
|
|
@ -137,6 +192,30 @@ peripheral_bus_type_t perimanGetPinBusType(uint8_t pin){
|
||||||
return pins[pin].type;
|
return pins[pin].type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* perimanGetPinBusExtraType(uint8_t pin){
|
||||||
|
if(GPIO_NOT_VALID(pin)){
|
||||||
|
log_e("Invalid pin: %u", pin);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return pins[pin].extra_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
int8_t perimanGetPinBusNum(uint8_t pin){
|
||||||
|
if(GPIO_NOT_VALID(pin)){
|
||||||
|
log_e("Invalid pin: %u", pin);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return pins[pin].bus_num;
|
||||||
|
}
|
||||||
|
|
||||||
|
int8_t perimanGetPinBusChannel(uint8_t pin){
|
||||||
|
if(GPIO_NOT_VALID(pin)){
|
||||||
|
log_e("Invalid pin: %u", pin);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return pins[pin].bus_channel;
|
||||||
|
}
|
||||||
|
|
||||||
bool perimanSetBusDeinit(peripheral_bus_type_t type, peripheral_bus_deinit_cb_t cb){
|
bool perimanSetBusDeinit(peripheral_bus_type_t type, peripheral_bus_deinit_cb_t cb){
|
||||||
if(type >= ESP32_BUS_TYPE_MAX || type == ESP32_BUS_TYPE_INIT){
|
if(type >= ESP32_BUS_TYPE_MAX || type == ESP32_BUS_TYPE_INIT){
|
||||||
log_e("Invalid type: %s (%u)", perimanGetTypeName(type), (unsigned int)type);
|
log_e("Invalid type: %s (%u)", perimanGetTypeName(type), (unsigned int)type);
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@ extern "C"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#define perimanClearPinBus(p) perimanSetPinBus(p, ESP32_BUS_TYPE_INIT, NULL, -1, -1)
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ESP32_BUS_TYPE_INIT, // IO has not been attached to a bus yet
|
ESP32_BUS_TYPE_INIT, // IO has not been attached to a bus yet
|
||||||
ESP32_BUS_TYPE_GPIO, // IO is used as GPIO
|
ESP32_BUS_TYPE_GPIO, // IO is used as GPIO
|
||||||
|
|
@ -41,29 +43,64 @@ typedef enum {
|
||||||
ESP32_BUS_TYPE_RMT_RX, // IO is used as RMT input
|
ESP32_BUS_TYPE_RMT_RX, // IO is used as RMT input
|
||||||
#endif
|
#endif
|
||||||
#if SOC_I2S_SUPPORTED
|
#if SOC_I2S_SUPPORTED
|
||||||
ESP32_BUS_TYPE_I2S_STD, // IO is used as I2S STD pin
|
ESP32_BUS_TYPE_I2S_STD_MCLK, // IO is used as I2S STD MCLK pin
|
||||||
ESP32_BUS_TYPE_I2S_TDM, // IO is used as I2S TDM pin
|
ESP32_BUS_TYPE_I2S_STD_BCLK, // IO is used as I2S STD BCLK pin
|
||||||
ESP32_BUS_TYPE_I2S_PDM_TX, // IO is used as I2S PDM pin
|
ESP32_BUS_TYPE_I2S_STD_WS, // IO is used as I2S STD WS pin
|
||||||
ESP32_BUS_TYPE_I2S_PDM_RX, // IO is used as I2S PDM pin
|
ESP32_BUS_TYPE_I2S_STD_DOUT, // IO is used as I2S STD DOUT pin
|
||||||
|
ESP32_BUS_TYPE_I2S_STD_DIN, // IO is used as I2S STD DIN pin
|
||||||
|
|
||||||
|
ESP32_BUS_TYPE_I2S_TDM_MCLK, // IO is used as I2S TDM MCLK pin
|
||||||
|
ESP32_BUS_TYPE_I2S_TDM_BCLK, // IO is used as I2S TDM BCLK pin
|
||||||
|
ESP32_BUS_TYPE_I2S_TDM_WS, // IO is used as I2S TDM WS pin
|
||||||
|
ESP32_BUS_TYPE_I2S_TDM_DOUT, // IO is used as I2S TDM DOUT pin
|
||||||
|
ESP32_BUS_TYPE_I2S_TDM_DIN, // IO is used as I2S TDM DIN pin
|
||||||
|
|
||||||
|
ESP32_BUS_TYPE_I2S_PDM_TX_CLK, // IO is used as I2S PDM CLK pin
|
||||||
|
ESP32_BUS_TYPE_I2S_PDM_TX_DOUT0,// IO is used as I2S PDM DOUT0 pin
|
||||||
|
ESP32_BUS_TYPE_I2S_PDM_TX_DOUT1,// IO is used as I2S PDM DOUT1 pin
|
||||||
|
|
||||||
|
ESP32_BUS_TYPE_I2S_PDM_RX_CLK, // IO is used as I2S PDM CLK pin
|
||||||
|
ESP32_BUS_TYPE_I2S_PDM_RX_DIN0, // IO is used as I2S PDM DIN0 pin
|
||||||
|
ESP32_BUS_TYPE_I2S_PDM_RX_DIN1, // IO is used as I2S PDM DIN1 pin
|
||||||
|
ESP32_BUS_TYPE_I2S_PDM_RX_DIN2, // IO is used as I2S PDM DIN2 pin
|
||||||
|
ESP32_BUS_TYPE_I2S_PDM_RX_DIN3, // IO is used as I2S PDM DIN3 pin
|
||||||
#endif
|
#endif
|
||||||
#if SOC_I2C_SUPPORTED
|
#if SOC_I2C_SUPPORTED
|
||||||
ESP32_BUS_TYPE_I2C_MASTER, // IO is used as I2C master pin
|
ESP32_BUS_TYPE_I2C_MASTER_SDA, // IO is used as I2C master SDA pin
|
||||||
ESP32_BUS_TYPE_I2C_SLAVE, // IO is used as I2C slave pin
|
ESP32_BUS_TYPE_I2C_MASTER_SCL, // IO is used as I2C master SCL pin
|
||||||
|
ESP32_BUS_TYPE_I2C_SLAVE_SDA, // IO is used as I2C slave SDA pin
|
||||||
|
ESP32_BUS_TYPE_I2C_SLAVE_SCL, // IO is used as I2C slave SCL pin
|
||||||
#endif
|
#endif
|
||||||
#if SOC_GPSPI_SUPPORTED
|
#if SOC_GPSPI_SUPPORTED
|
||||||
ESP32_BUS_TYPE_SPI_MASTER, // IO is used as SPI master pin
|
ESP32_BUS_TYPE_SPI_MASTER_SCK, // IO is used as SPI master SCK pin
|
||||||
|
ESP32_BUS_TYPE_SPI_MASTER_MISO, // IO is used as SPI master MISO pin
|
||||||
|
ESP32_BUS_TYPE_SPI_MASTER_MOSI, // IO is used as SPI master MOSI pin
|
||||||
|
ESP32_BUS_TYPE_SPI_MASTER_CS, // IO is used as SPI master CS pin
|
||||||
#endif
|
#endif
|
||||||
#if SOC_SDMMC_HOST_SUPPORTED
|
#if SOC_SDMMC_HOST_SUPPORTED
|
||||||
ESP32_BUS_TYPE_SDMMC, // IO is used as SDMMC pin
|
ESP32_BUS_TYPE_SDMMC_CLK, // IO is used as SDMMC CLK pin
|
||||||
|
ESP32_BUS_TYPE_SDMMC_CMD, // IO is used as SDMMC CMD pin
|
||||||
|
ESP32_BUS_TYPE_SDMMC_D0, // IO is used as SDMMC D0 pin
|
||||||
|
ESP32_BUS_TYPE_SDMMC_D1, // IO is used as SDMMC D1 pin
|
||||||
|
ESP32_BUS_TYPE_SDMMC_D2, // IO is used as SDMMC D2 pin
|
||||||
|
ESP32_BUS_TYPE_SDMMC_D3, // IO is used as SDMMC D3 pin
|
||||||
#endif
|
#endif
|
||||||
#if SOC_TOUCH_SENSOR_SUPPORTED
|
#if SOC_TOUCH_SENSOR_SUPPORTED
|
||||||
ESP32_BUS_TYPE_TOUCH, // IO is used as TOUCH pin
|
ESP32_BUS_TYPE_TOUCH, // IO is used as TOUCH pin
|
||||||
#endif
|
#endif
|
||||||
#if SOC_USB_SERIAL_JTAG_SUPPORTED || SOC_USB_OTG_SUPPORTED
|
#if SOC_USB_SERIAL_JTAG_SUPPORTED || SOC_USB_OTG_SUPPORTED
|
||||||
ESP32_BUS_TYPE_USB, // IO is used as USB pin
|
ESP32_BUS_TYPE_USB_DM, // IO is used as USB DM (+) pin
|
||||||
|
ESP32_BUS_TYPE_USB_DP, // IO is used as USB DP (-) pin
|
||||||
#endif
|
#endif
|
||||||
#if SOC_GPSPI_SUPPORTED
|
#if SOC_GPSPI_SUPPORTED
|
||||||
ESP32_BUS_TYPE_ETHERNET, // IO is used as ETHERNET-RMII pin
|
ESP32_BUS_TYPE_ETHERNET_SPI, // IO is used as ETHERNET SPI pin
|
||||||
|
#endif
|
||||||
|
#if CONFIG_ETH_USE_ESP32_EMAC
|
||||||
|
ESP32_BUS_TYPE_ETHERNET_RMII, // IO is used as ETHERNET RMII pin
|
||||||
|
ESP32_BUS_TYPE_ETHERNET_CLK, // IO is used as ETHERNET CLK pin
|
||||||
|
ESP32_BUS_TYPE_ETHERNET_MCD, // IO is used as ETHERNET MCD pin
|
||||||
|
ESP32_BUS_TYPE_ETHERNET_MDIO, // IO is used as ETHERNET MDIO pin
|
||||||
|
ESP32_BUS_TYPE_ETHERNET_PWR, // IO is used as ETHERNET PWR pin
|
||||||
#endif
|
#endif
|
||||||
ESP32_BUS_TYPE_MAX
|
ESP32_BUS_TYPE_MAX
|
||||||
} peripheral_bus_type_t;
|
} peripheral_bus_type_t;
|
||||||
|
|
@ -72,8 +109,8 @@ typedef bool (*peripheral_bus_deinit_cb_t)(void * bus);
|
||||||
|
|
||||||
const char* perimanGetTypeName(peripheral_bus_type_t type);
|
const char* perimanGetTypeName(peripheral_bus_type_t type);
|
||||||
|
|
||||||
// Sets the bus type and bus handle for given pin.
|
// Sets the bus type, bus handle, bus number and bus channel for given pin.
|
||||||
bool perimanSetPinBus(uint8_t pin, peripheral_bus_type_t type, void * bus);
|
bool perimanSetPinBus(uint8_t pin, peripheral_bus_type_t type, void * bus, int8_t bus_num, int8_t bus_channel);
|
||||||
|
|
||||||
// Returns handle of the bus for the given pin if type of bus matches. NULL otherwise
|
// Returns handle of the bus for the given pin if type of bus matches. NULL otherwise
|
||||||
void * perimanGetPinBus(uint8_t pin, peripheral_bus_type_t type);
|
void * perimanGetPinBus(uint8_t pin, peripheral_bus_type_t type);
|
||||||
|
|
@ -81,12 +118,24 @@ void * perimanGetPinBus(uint8_t pin, peripheral_bus_type_t type);
|
||||||
// Returns the type of the bus for the given pin if attached. ESP32_BUS_TYPE_MAX otherwise
|
// Returns the type of the bus for the given pin if attached. ESP32_BUS_TYPE_MAX otherwise
|
||||||
peripheral_bus_type_t perimanGetPinBusType(uint8_t pin);
|
peripheral_bus_type_t perimanGetPinBusType(uint8_t pin);
|
||||||
|
|
||||||
|
// Returns the bus number or unit of the bus for the given pin if set. -1 otherwise
|
||||||
|
int8_t perimanGetPinBusNum(uint8_t pin);
|
||||||
|
|
||||||
|
// Returns the bus channel of the bus for the given pin if set. -1 otherwise
|
||||||
|
int8_t perimanGetPinBusChannel(uint8_t pin);
|
||||||
|
|
||||||
// Sets the peripheral destructor callback. Used to destroy bus when pin is assigned another function
|
// Sets the peripheral destructor callback. Used to destroy bus when pin is assigned another function
|
||||||
bool perimanSetBusDeinit(peripheral_bus_type_t type, peripheral_bus_deinit_cb_t cb);
|
bool perimanSetBusDeinit(peripheral_bus_type_t type, peripheral_bus_deinit_cb_t cb);
|
||||||
|
|
||||||
// Check if given pin is a valid GPIO number
|
// Check if given pin is a valid GPIO number
|
||||||
bool perimanPinIsValid(uint8_t pin);
|
bool perimanPinIsValid(uint8_t pin);
|
||||||
|
|
||||||
|
// Sets the extra type for non Init bus. Used to customise pin bus name which can be printed by printPerimanInfo().
|
||||||
|
bool perimanSetPinBusExtraType(uint8_t pin, const char* extra_type);
|
||||||
|
|
||||||
|
// Returns the extra type of the bus for given pin if set. NULL otherwise
|
||||||
|
const char* perimanGetPinBusExtraType(uint8_t pin);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -270,7 +270,7 @@ bool rmtDeinit(int pin)
|
||||||
log_v("Deiniting RMT GPIO %d", pin);
|
log_v("Deiniting RMT GPIO %d", pin);
|
||||||
if (_rmtGetBus(pin, __FUNCTION__) != NULL) {
|
if (_rmtGetBus(pin, __FUNCTION__) != NULL) {
|
||||||
// release all allocated data
|
// release all allocated data
|
||||||
return perimanSetPinBus(pin, ESP32_BUS_TYPE_INIT, NULL);
|
return perimanClearPinBus(pin);
|
||||||
}
|
}
|
||||||
log_e("GPIO %d - No RMT channel associated.", pin);
|
log_e("GPIO %d - No RMT channel associated.", pin);
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -468,7 +468,7 @@ bool rmtInit(int pin, rmt_ch_dir_t channel_direction, rmt_reserve_memsize_t mem_
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to dettach any (Tx|Rx|Whatever) previous bus or just keep it as not attached
|
// Try to dettach any (Tx|Rx|Whatever) previous bus or just keep it as not attached
|
||||||
if (!perimanSetPinBus(pin, ESP32_BUS_TYPE_INIT, NULL)) {
|
if (!perimanClearPinBus(pin)) {
|
||||||
log_w("GPIO %d - Can't detach previous peripheral.", pin);
|
log_w("GPIO %d - Can't detach previous peripheral.", pin);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -574,7 +574,7 @@ bool rmtInit(int pin, rmt_ch_dir_t channel_direction, rmt_reserve_memsize_t mem_
|
||||||
// Finally, allocate Peripheral Manager RMT bus and associate it to its GPIO
|
// Finally, allocate Peripheral Manager RMT bus and associate it to its GPIO
|
||||||
peripheral_bus_type_t pinBusType =
|
peripheral_bus_type_t pinBusType =
|
||||||
channel_direction == RMT_TX_MODE ? ESP32_BUS_TYPE_RMT_TX : ESP32_BUS_TYPE_RMT_RX;
|
channel_direction == RMT_TX_MODE ? ESP32_BUS_TYPE_RMT_TX : ESP32_BUS_TYPE_RMT_RX;
|
||||||
if (!perimanSetPinBus(pin, pinBusType, (void *) bus)) {
|
if (!perimanSetPinBus(pin, pinBusType, (void *) bus, -1, -1)) {
|
||||||
log_e("Can't allocate the GPIO %d in the Peripheral Manager.", pin);
|
log_e("Can't allocate the GPIO %d in the Peripheral Manager.", pin);
|
||||||
goto Err;
|
goto Err;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ bool sigmaDeltaAttach(uint8_t pin, uint32_t freq) //freq 1220-312500
|
||||||
{
|
{
|
||||||
perimanSetBusDeinit(ESP32_BUS_TYPE_SIGMADELTA, sigmaDeltaDetachBus);
|
perimanSetBusDeinit(ESP32_BUS_TYPE_SIGMADELTA, sigmaDeltaDetachBus);
|
||||||
sdm_channel_handle_t bus = (sdm_channel_handle_t)perimanGetPinBus(pin, ESP32_BUS_TYPE_SIGMADELTA);
|
sdm_channel_handle_t bus = (sdm_channel_handle_t)perimanGetPinBus(pin, ESP32_BUS_TYPE_SIGMADELTA);
|
||||||
if(bus != NULL && !perimanSetPinBus(pin, ESP32_BUS_TYPE_INIT, NULL)){
|
if(bus != NULL && !perimanClearPinBus(pin)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bus = NULL;
|
bus = NULL;
|
||||||
|
|
@ -52,7 +52,7 @@ bool sigmaDeltaAttach(uint8_t pin, uint32_t freq) //freq 1220-312500
|
||||||
log_e("sdm_channel_enable failed with error: %d", err);
|
log_e("sdm_channel_enable failed with error: %d", err);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(!perimanSetPinBus(pin, ESP32_BUS_TYPE_SIGMADELTA, (void *)bus)){
|
if(!perimanSetPinBus(pin, ESP32_BUS_TYPE_SIGMADELTA, (void *)bus, -1, -1)){
|
||||||
sigmaDeltaDetachBus((void *)bus);
|
sigmaDeltaDetachBus((void *)bus);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -81,7 +81,7 @@ bool sigmaDeltaDetach(uint8_t pin)
|
||||||
void * bus = perimanGetPinBus(pin, ESP32_BUS_TYPE_SIGMADELTA);
|
void * bus = perimanGetPinBus(pin, ESP32_BUS_TYPE_SIGMADELTA);
|
||||||
if(bus != NULL){
|
if(bus != NULL){
|
||||||
// will call sigmaDeltaDetachBus
|
// will call sigmaDeltaDetachBus
|
||||||
return perimanSetPinBus(pin, ESP32_BUS_TYPE_INIT, NULL);
|
return perimanClearPinBus(pin);
|
||||||
} else {
|
} else {
|
||||||
log_e("pin %u is not attached to SigmaDelta", pin);
|
log_e("pin %u is not attached to SigmaDelta", pin);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -212,14 +212,14 @@ bool spiAttachSCK(spi_t * spi, int8_t sck)
|
||||||
if(!spi || sck < 0) {
|
if(!spi || sck < 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
void * bus = perimanGetPinBus(sck, ESP32_BUS_TYPE_SPI_MASTER);
|
void * bus = perimanGetPinBus(sck, ESP32_BUS_TYPE_SPI_MASTER_SCK);
|
||||||
if(bus != NULL && !perimanSetPinBus(sck, ESP32_BUS_TYPE_INIT, NULL)){
|
if(bus != NULL && !perimanClearPinBus(sck)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
pinMode(sck, OUTPUT);
|
pinMode(sck, OUTPUT);
|
||||||
pinMatrixOutAttach(sck, SPI_CLK_IDX(spi->num), false, false);
|
pinMatrixOutAttach(sck, SPI_CLK_IDX(spi->num), false, false);
|
||||||
spi->sck = sck;
|
spi->sck = sck;
|
||||||
if(!perimanSetPinBus(sck, ESP32_BUS_TYPE_SPI_MASTER, (void *)(spi->num+1))){
|
if(!perimanSetPinBus(sck, ESP32_BUS_TYPE_SPI_MASTER_SCK, (void *)(spi->num+1), spi->num, -1)){
|
||||||
spiDetachBus((void *)(spi->num+1));
|
spiDetachBus((void *)(spi->num+1));
|
||||||
log_e("Failed to set pin bus to SPI for pin %d", sck);
|
log_e("Failed to set pin bus to SPI for pin %d", sck);
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -232,8 +232,8 @@ bool spiAttachMISO(spi_t * spi, int8_t miso)
|
||||||
if(!spi || miso < 0) {
|
if(!spi || miso < 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
void * bus = perimanGetPinBus(miso, ESP32_BUS_TYPE_SPI_MASTER);
|
void * bus = perimanGetPinBus(miso, ESP32_BUS_TYPE_SPI_MASTER_MISO);
|
||||||
if(bus != NULL && !perimanSetPinBus(miso, ESP32_BUS_TYPE_INIT, NULL)){
|
if(bus != NULL && !perimanClearPinBus(miso)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
SPI_MUTEX_LOCK();
|
SPI_MUTEX_LOCK();
|
||||||
|
|
@ -241,7 +241,7 @@ bool spiAttachMISO(spi_t * spi, int8_t miso)
|
||||||
pinMatrixInAttach(miso, SPI_MISO_IDX(spi->num), false);
|
pinMatrixInAttach(miso, SPI_MISO_IDX(spi->num), false);
|
||||||
spi->miso = miso;
|
spi->miso = miso;
|
||||||
SPI_MUTEX_UNLOCK();
|
SPI_MUTEX_UNLOCK();
|
||||||
if(!perimanSetPinBus(miso, ESP32_BUS_TYPE_SPI_MASTER, (void *)(spi->num+1))){
|
if(!perimanSetPinBus(miso, ESP32_BUS_TYPE_SPI_MASTER_MISO, (void *)(spi->num+1), spi->num, -1)){
|
||||||
spiDetachBus((void *)(spi->num+1));
|
spiDetachBus((void *)(spi->num+1));
|
||||||
log_e("Failed to set pin bus to SPI for pin %d", miso);
|
log_e("Failed to set pin bus to SPI for pin %d", miso);
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -254,14 +254,14 @@ bool spiAttachMOSI(spi_t * spi, int8_t mosi)
|
||||||
if(!spi || mosi < 0) {
|
if(!spi || mosi < 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
void * bus = perimanGetPinBus(mosi, ESP32_BUS_TYPE_SPI_MASTER);
|
void * bus = perimanGetPinBus(mosi, ESP32_BUS_TYPE_SPI_MASTER_MOSI);
|
||||||
if(bus != NULL && !perimanSetPinBus(mosi, ESP32_BUS_TYPE_INIT, NULL)){
|
if(bus != NULL && !perimanClearPinBus(mosi)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
pinMode(mosi, OUTPUT);
|
pinMode(mosi, OUTPUT);
|
||||||
pinMatrixOutAttach(mosi, SPI_MOSI_IDX(spi->num), false, false);
|
pinMatrixOutAttach(mosi, SPI_MOSI_IDX(spi->num), false, false);
|
||||||
spi->mosi = mosi;
|
spi->mosi = mosi;
|
||||||
if(!perimanSetPinBus(mosi, ESP32_BUS_TYPE_SPI_MASTER, (void *)(spi->num+1))){
|
if(!perimanSetPinBus(mosi, ESP32_BUS_TYPE_SPI_MASTER_MOSI, (void *)(spi->num+1), spi->num, -1)){
|
||||||
spiDetachBus((void *)(spi->num+1));
|
spiDetachBus((void *)(spi->num+1));
|
||||||
log_e("Failed to set pin bus to SPI for pin %d", mosi);
|
log_e("Failed to set pin bus to SPI for pin %d", mosi);
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -276,7 +276,7 @@ bool spiDetachSCK(spi_t * spi, int8_t sck)
|
||||||
}
|
}
|
||||||
pinMatrixOutDetach(sck, false, false);
|
pinMatrixOutDetach(sck, false, false);
|
||||||
spi->sck = -1;
|
spi->sck = -1;
|
||||||
perimanSetPinBus(sck, ESP32_BUS_TYPE_INIT, NULL);
|
perimanClearPinBus(sck);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -287,7 +287,7 @@ bool spiDetachMISO(spi_t * spi, int8_t miso)
|
||||||
}
|
}
|
||||||
pinMatrixInDetach(SPI_MISO_IDX(spi->num), false, false);
|
pinMatrixInDetach(SPI_MISO_IDX(spi->num), false, false);
|
||||||
spi->miso = -1;
|
spi->miso = -1;
|
||||||
perimanSetPinBus(miso, ESP32_BUS_TYPE_INIT, NULL);
|
perimanClearPinBus(miso);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -298,7 +298,7 @@ bool spiDetachMOSI(spi_t * spi, int8_t mosi)
|
||||||
}
|
}
|
||||||
pinMatrixOutDetach(mosi, false, false);
|
pinMatrixOutDetach(mosi, false, false);
|
||||||
spi->mosi = -1;
|
spi->mosi = -1;
|
||||||
perimanSetPinBus(mosi, ESP32_BUS_TYPE_INIT, NULL);
|
perimanClearPinBus(mosi);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -307,15 +307,15 @@ bool spiAttachSS(spi_t * spi, uint8_t cs_num, int8_t ss)
|
||||||
if(!spi || ss < 0 || cs_num > 2) {
|
if(!spi || ss < 0 || cs_num > 2) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
void * bus = perimanGetPinBus(ss, ESP32_BUS_TYPE_SPI_MASTER);
|
void * bus = perimanGetPinBus(ss, ESP32_BUS_TYPE_SPI_MASTER_CS);
|
||||||
if(bus != NULL && !perimanSetPinBus(ss, ESP32_BUS_TYPE_INIT, NULL)){
|
if(bus != NULL && !perimanClearPinBus(ss)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
pinMode(ss, OUTPUT);
|
pinMode(ss, OUTPUT);
|
||||||
pinMatrixOutAttach(ss, SPI_SS_IDX(spi->num, cs_num), false, false);
|
pinMatrixOutAttach(ss, SPI_SS_IDX(spi->num, cs_num), false, false);
|
||||||
spiEnableSSPins(spi, (1 << cs_num));
|
spiEnableSSPins(spi, (1 << cs_num));
|
||||||
spi->ss = ss;
|
spi->ss = ss;
|
||||||
if(!perimanSetPinBus(ss, ESP32_BUS_TYPE_SPI_MASTER, (void *)(spi->num+1))){
|
if(!perimanSetPinBus(ss, ESP32_BUS_TYPE_SPI_MASTER_CS, (void *)(spi->num+1), spi->num, -1)){
|
||||||
spiDetachBus((void *)(spi->num+1));
|
spiDetachBus((void *)(spi->num+1));
|
||||||
log_e("Failed to set pin bus to SPI for pin %d", ss);
|
log_e("Failed to set pin bus to SPI for pin %d", ss);
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -330,7 +330,7 @@ bool spiDetachSS(spi_t * spi, int8_t ss)
|
||||||
}
|
}
|
||||||
pinMatrixOutDetach(ss, false, false);
|
pinMatrixOutDetach(ss, false, false);
|
||||||
spi->ss = -1;
|
spi->ss = -1;
|
||||||
perimanSetPinBus(ss, ESP32_BUS_TYPE_INIT, NULL);
|
perimanClearPinBus(ss);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -578,7 +578,11 @@ spi_t * spiStartBus(uint8_t spi_num, uint32_t clockDiv, uint8_t dataMode, uint8_
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
perimanSetBusDeinit(ESP32_BUS_TYPE_SPI_MASTER, spiDetachBus);
|
perimanSetBusDeinit(ESP32_BUS_TYPE_SPI_MASTER_SCK, spiDetachBus);
|
||||||
|
perimanSetBusDeinit(ESP32_BUS_TYPE_SPI_MASTER_MISO, spiDetachBus);
|
||||||
|
perimanSetBusDeinit(ESP32_BUS_TYPE_SPI_MASTER_MOSI, spiDetachBus);
|
||||||
|
perimanSetBusDeinit(ESP32_BUS_TYPE_SPI_MASTER_CS, spiDetachBus);
|
||||||
|
|
||||||
spi_t * spi = &_spi_bus_array[spi_num];
|
spi_t * spi = &_spi_bus_array[spi_num];
|
||||||
|
|
||||||
#if !CONFIG_DISABLE_HAL_LOCKS
|
#if !CONFIG_DISABLE_HAL_LOCKS
|
||||||
|
|
|
||||||
|
|
@ -88,10 +88,10 @@ static void configure_pins(usb_hal_context_t *usb)
|
||||||
if (!usb->use_external_phy) {
|
if (!usb->use_external_phy) {
|
||||||
gpio_set_drive_capability(USBPHY_DM_NUM, GPIO_DRIVE_CAP_3);
|
gpio_set_drive_capability(USBPHY_DM_NUM, GPIO_DRIVE_CAP_3);
|
||||||
gpio_set_drive_capability(USBPHY_DP_NUM, GPIO_DRIVE_CAP_3);
|
gpio_set_drive_capability(USBPHY_DP_NUM, GPIO_DRIVE_CAP_3);
|
||||||
if (perimanSetBusDeinit(ESP32_BUS_TYPE_USB, usb_otg_deinit)) {
|
if (perimanSetBusDeinit(ESP32_BUS_TYPE_USB_DM, usb_otg_deinit) && perimanSetBusDeinit(ESP32_BUS_TYPE_USB_DP, usb_otg_deinit)){
|
||||||
// Bus Pointer is not used anyway - once the USB GPIOs are assigned, they can't be detached
|
// Bus Pointer is not used anyway - once the USB GPIOs are assigned, they can't be detached
|
||||||
perimanSetPinBus(USBPHY_DM_NUM, ESP32_BUS_TYPE_USB, (void *) usb);
|
perimanSetPinBus(USBPHY_DM_NUM, ESP32_BUS_TYPE_USB_DM, (void *) usb, -1, -1);
|
||||||
perimanSetPinBus(USBPHY_DP_NUM, ESP32_BUS_TYPE_USB, (void *) usb);
|
perimanSetPinBus(USBPHY_DP_NUM, ESP32_BUS_TYPE_USB_DP, (void *) usb, -1, -1);
|
||||||
} else {
|
} else {
|
||||||
log_e("USB OTG Pins can't be set into Peripheral Manager.");
|
log_e("USB OTG Pins can't be set into Peripheral Manager.");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -215,13 +215,13 @@ static touch_value_t __touchRead(uint8_t pin)
|
||||||
|
|
||||||
if(perimanGetPinBus(pin, ESP32_BUS_TYPE_TOUCH) == NULL){
|
if(perimanGetPinBus(pin, ESP32_BUS_TYPE_TOUCH) == NULL){
|
||||||
perimanSetBusDeinit(ESP32_BUS_TYPE_TOUCH, touchDetachBus);
|
perimanSetBusDeinit(ESP32_BUS_TYPE_TOUCH, touchDetachBus);
|
||||||
if(!perimanSetPinBus(pin, ESP32_BUS_TYPE_INIT, NULL)){
|
if(!perimanClearPinBus(pin)){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
__touchInit();
|
__touchInit();
|
||||||
__touchChannelInit(pad);
|
__touchChannelInit(pad);
|
||||||
|
|
||||||
if(!perimanSetPinBus(pin, ESP32_BUS_TYPE_TOUCH, (void *)(pin+1))){
|
if(!perimanSetPinBus(pin, ESP32_BUS_TYPE_TOUCH, (void *)(pin+1), -1, pad)){
|
||||||
touchDetachBus((void *)(pin+1));
|
touchDetachBus((void *)(pin+1));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -312,7 +312,7 @@ void touchSleepWakeUpEnable(uint8_t pin, touch_value_t threshold)
|
||||||
perimanSetBusDeinit(ESP32_BUS_TYPE_TOUCH, touchDetachBus);
|
perimanSetBusDeinit(ESP32_BUS_TYPE_TOUCH, touchDetachBus);
|
||||||
__touchInit();
|
__touchInit();
|
||||||
__touchChannelInit(pad);
|
__touchChannelInit(pad);
|
||||||
if(!perimanSetPinBus(pin, ESP32_BUS_TYPE_TOUCH, (void *)(pin+1))){
|
if(!perimanSetPinBus(pin, ESP32_BUS_TYPE_TOUCH, (void *)(pin+1), -1, pad)){
|
||||||
log_e("Failed to set bus to Peripheral manager");
|
log_e("Failed to set bus to Peripheral manager");
|
||||||
touchDetachBus((void *)(pin+1));
|
touchDetachBus((void *)(pin+1));
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,7 @@ static bool _uartDetachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t
|
||||||
gpio_hal_iomux_func_sel(GPIO_PIN_MUX_REG[rxPin], PIN_FUNC_GPIO);
|
gpio_hal_iomux_func_sel(GPIO_PIN_MUX_REG[rxPin], PIN_FUNC_GPIO);
|
||||||
esp_rom_gpio_connect_in_signal(GPIO_FUNC_IN_LOW, UART_PERIPH_SIGNAL(uart_num, SOC_UART_RX_PIN_IDX), false);
|
esp_rom_gpio_connect_in_signal(GPIO_FUNC_IN_LOW, UART_PERIPH_SIGNAL(uart_num, SOC_UART_RX_PIN_IDX), false);
|
||||||
uart->_rxPin = -1; // -1 means unassigned/detached
|
uart->_rxPin = -1; // -1 means unassigned/detached
|
||||||
if (!perimanSetPinBus(rxPin, ESP32_BUS_TYPE_INIT, NULL)) {
|
if (!perimanClearPinBus(rxPin)) {
|
||||||
retCode = false;
|
retCode = false;
|
||||||
log_e("UART%d failed to detach RX pin %d", uart_num, rxPin);
|
log_e("UART%d failed to detach RX pin %d", uart_num, rxPin);
|
||||||
}
|
}
|
||||||
|
|
@ -108,7 +108,7 @@ static bool _uartDetachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t
|
||||||
gpio_hal_iomux_func_sel(GPIO_PIN_MUX_REG[txPin], PIN_FUNC_GPIO);
|
gpio_hal_iomux_func_sel(GPIO_PIN_MUX_REG[txPin], PIN_FUNC_GPIO);
|
||||||
esp_rom_gpio_connect_out_signal(txPin, SIG_GPIO_OUT_IDX, false, false);
|
esp_rom_gpio_connect_out_signal(txPin, SIG_GPIO_OUT_IDX, false, false);
|
||||||
uart->_txPin = -1; // -1 means unassigned/detached
|
uart->_txPin = -1; // -1 means unassigned/detached
|
||||||
if (!perimanSetPinBus(txPin, ESP32_BUS_TYPE_INIT, NULL)) {
|
if (!perimanClearPinBus(txPin)) {
|
||||||
retCode = false;
|
retCode = false;
|
||||||
log_e("UART%d failed to detach TX pin %d", uart_num, txPin);
|
log_e("UART%d failed to detach TX pin %d", uart_num, txPin);
|
||||||
}
|
}
|
||||||
|
|
@ -117,7 +117,7 @@ static bool _uartDetachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t
|
||||||
gpio_hal_iomux_func_sel(GPIO_PIN_MUX_REG[ctsPin], PIN_FUNC_GPIO);
|
gpio_hal_iomux_func_sel(GPIO_PIN_MUX_REG[ctsPin], PIN_FUNC_GPIO);
|
||||||
esp_rom_gpio_connect_in_signal(GPIO_FUNC_IN_LOW, UART_PERIPH_SIGNAL(uart_num, SOC_UART_CTS_PIN_IDX), false);
|
esp_rom_gpio_connect_in_signal(GPIO_FUNC_IN_LOW, UART_PERIPH_SIGNAL(uart_num, SOC_UART_CTS_PIN_IDX), false);
|
||||||
uart->_ctsPin = -1; // -1 means unassigned/detached
|
uart->_ctsPin = -1; // -1 means unassigned/detached
|
||||||
if (!perimanSetPinBus(ctsPin, ESP32_BUS_TYPE_INIT, NULL)) {
|
if (!perimanClearPinBus(ctsPin)) {
|
||||||
retCode = false;
|
retCode = false;
|
||||||
log_e("UART%d failed to detach CTS pin %d", uart_num, ctsPin);
|
log_e("UART%d failed to detach CTS pin %d", uart_num, ctsPin);
|
||||||
}
|
}
|
||||||
|
|
@ -126,7 +126,7 @@ static bool _uartDetachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t
|
||||||
gpio_hal_iomux_func_sel(GPIO_PIN_MUX_REG[rtsPin], PIN_FUNC_GPIO);
|
gpio_hal_iomux_func_sel(GPIO_PIN_MUX_REG[rtsPin], PIN_FUNC_GPIO);
|
||||||
esp_rom_gpio_connect_out_signal(rtsPin, SIG_GPIO_OUT_IDX, false, false);
|
esp_rom_gpio_connect_out_signal(rtsPin, SIG_GPIO_OUT_IDX, false, false);
|
||||||
uart->_rtsPin = -1; // -1 means unassigned/detached
|
uart->_rtsPin = -1; // -1 means unassigned/detached
|
||||||
if (!perimanSetPinBus(rtsPin, ESP32_BUS_TYPE_INIT, NULL)) {
|
if (!perimanClearPinBus(rtsPin)) {
|
||||||
retCode = false;
|
retCode = false;
|
||||||
log_e("UART%d failed to detach RTS pin %d", uart_num, rtsPin);
|
log_e("UART%d failed to detach RTS pin %d", uart_num, rtsPin);
|
||||||
}
|
}
|
||||||
|
|
@ -185,11 +185,11 @@ static bool _uartAttachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t
|
||||||
bool retCode = true;
|
bool retCode = true;
|
||||||
if (rxPin >= 0) {
|
if (rxPin >= 0) {
|
||||||
// forces a clean detaching from a previous peripheral
|
// forces a clean detaching from a previous peripheral
|
||||||
if (perimanGetPinBusType(rxPin) != ESP32_BUS_TYPE_INIT) perimanSetPinBus(rxPin, ESP32_BUS_TYPE_INIT, NULL);
|
if (perimanGetPinBusType(rxPin) != ESP32_BUS_TYPE_INIT) perimanClearPinBus(rxPin);
|
||||||
// connect RX Pad
|
// connect RX Pad
|
||||||
bool ret = ESP_OK == uart_set_pin(uart->num, UART_PIN_NO_CHANGE, rxPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
|
bool ret = ESP_OK == uart_set_pin(uart->num, UART_PIN_NO_CHANGE, rxPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
ret &= perimanSetPinBus(rxPin, ESP32_BUS_TYPE_UART_RX, (void *)uart);
|
ret &= perimanSetPinBus(rxPin, ESP32_BUS_TYPE_UART_RX, (void *)uart, uart_num, -1);
|
||||||
if (ret) uart->_rxPin = rxPin;
|
if (ret) uart->_rxPin = rxPin;
|
||||||
}
|
}
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
|
|
@ -199,11 +199,11 @@ static bool _uartAttachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t
|
||||||
}
|
}
|
||||||
if (txPin >= 0) {
|
if (txPin >= 0) {
|
||||||
// forces a clean detaching from a previous peripheral
|
// forces a clean detaching from a previous peripheral
|
||||||
if (perimanGetPinBusType(txPin) != ESP32_BUS_TYPE_INIT) perimanSetPinBus(txPin, ESP32_BUS_TYPE_INIT, NULL);
|
if (perimanGetPinBusType(txPin) != ESP32_BUS_TYPE_INIT) perimanClearPinBus(txPin);
|
||||||
// connect TX Pad
|
// connect TX Pad
|
||||||
bool ret = ESP_OK == uart_set_pin(uart->num, txPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
|
bool ret = ESP_OK == uart_set_pin(uart->num, txPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
ret &= perimanSetPinBus(txPin, ESP32_BUS_TYPE_UART_TX, (void *)uart);
|
ret &= perimanSetPinBus(txPin, ESP32_BUS_TYPE_UART_TX, (void *)uart, uart_num, -1);
|
||||||
if (ret) uart->_txPin = txPin;
|
if (ret) uart->_txPin = txPin;
|
||||||
}
|
}
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
|
|
@ -213,11 +213,11 @@ static bool _uartAttachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t
|
||||||
}
|
}
|
||||||
if (ctsPin >= 0) {
|
if (ctsPin >= 0) {
|
||||||
// forces a clean detaching from a previous peripheral
|
// forces a clean detaching from a previous peripheral
|
||||||
if (perimanGetPinBusType(ctsPin) != ESP32_BUS_TYPE_INIT) perimanSetPinBus(ctsPin, ESP32_BUS_TYPE_INIT, NULL);
|
if (perimanGetPinBusType(ctsPin) != ESP32_BUS_TYPE_INIT) perimanClearPinBus(ctsPin);
|
||||||
// connect CTS Pad
|
// connect CTS Pad
|
||||||
bool ret = ESP_OK == uart_set_pin(uart->num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, ctsPin);
|
bool ret = ESP_OK == uart_set_pin(uart->num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, ctsPin);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
ret &= perimanSetPinBus(ctsPin, ESP32_BUS_TYPE_UART_CTS, (void *)uart);
|
ret &= perimanSetPinBus(ctsPin, ESP32_BUS_TYPE_UART_CTS, (void *)uart, uart_num, -1);
|
||||||
if (ret) uart->_ctsPin = ctsPin;
|
if (ret) uart->_ctsPin = ctsPin;
|
||||||
}
|
}
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
|
|
@ -227,11 +227,11 @@ static bool _uartAttachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t
|
||||||
}
|
}
|
||||||
if (rtsPin >= 0) {
|
if (rtsPin >= 0) {
|
||||||
// forces a clean detaching from a previous peripheral
|
// forces a clean detaching from a previous peripheral
|
||||||
if (perimanGetPinBusType(rtsPin) != ESP32_BUS_TYPE_INIT) perimanSetPinBus(rtsPin, ESP32_BUS_TYPE_INIT, NULL);
|
if (perimanGetPinBusType(rtsPin) != ESP32_BUS_TYPE_INIT) perimanClearPinBus(rtsPin);
|
||||||
// connect RTS Pad
|
// connect RTS Pad
|
||||||
bool ret = ESP_OK == uart_set_pin(uart->num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, rtsPin, UART_PIN_NO_CHANGE);
|
bool ret = ESP_OK == uart_set_pin(uart->num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, rtsPin, UART_PIN_NO_CHANGE);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
ret &= perimanSetPinBus(rtsPin, ESP32_BUS_TYPE_UART_RTS, (void *)uart);
|
ret &= perimanSetPinBus(rtsPin, ESP32_BUS_TYPE_UART_RTS, (void *)uart, uart_num, -1);
|
||||||
if (ret) uart->_rtsPin = rtsPin;
|
if (ret) uart->_rtsPin = rtsPin;
|
||||||
}
|
}
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
|
|
|
||||||
3
cores/esp32/extra_attr.h
Normal file
3
cores/esp32/extra_attr.h
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
#define ATTR_PACKED __attribute__((__packed__))
|
||||||
|
#define ATTR_ALIGNED(x) __attribute__((__aligned__(x)))
|
||||||
|
#define ATTR_SECTION(x) __attribute__((__section__(x)))
|
||||||
|
|
@ -280,14 +280,18 @@ void I2SClass::setInvertedPdm(bool clk){
|
||||||
|
|
||||||
bool I2SClass::initSTD(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch){
|
bool I2SClass::initSTD(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch){
|
||||||
// Peripheral manager deinit previous peripheral if pin was used
|
// Peripheral manager deinit previous peripheral if pin was used
|
||||||
if (_mclk >= 0) if (!perimanSetPinBus(_mclk, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if (_mclk >= 0) if (!perimanClearPinBus(_mclk)){ return false; }
|
||||||
if (_bclk >= 0) if (!perimanSetPinBus(_bclk, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if (_bclk >= 0) if (!perimanClearPinBus(_bclk)){ return false; }
|
||||||
if (_ws >= 0) if (!perimanSetPinBus(_ws, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if (_ws >= 0) if (!perimanClearPinBus(_ws)) { return false; }
|
||||||
if (_dout >= 0) if (!perimanSetPinBus(_dout, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if (_dout >= 0) if (!perimanClearPinBus(_dout)){ return false; }
|
||||||
if (_din >= 0) if (!perimanSetPinBus(_din, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if (_din >= 0) if (!perimanClearPinBus(_din)) { return false; }
|
||||||
|
|
||||||
// Set peripheral manager detach function for I2S
|
// Set peripheral manager detach function for I2S
|
||||||
perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_STD, I2SClass::i2sDetachBus);
|
if (_mclk >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_STD_MCLK, I2SClass::i2sDetachBus); }
|
||||||
|
if (_bclk >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_STD_BCLK, I2SClass::i2sDetachBus); }
|
||||||
|
if (_ws >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_STD_WS, I2SClass::i2sDetachBus); }
|
||||||
|
if (_dout >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_STD_DOUT, I2SClass::i2sDetachBus); }
|
||||||
|
if (_din >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_STD_DIN, I2SClass::i2sDetachBus); }
|
||||||
|
|
||||||
// I2S configuration
|
// I2S configuration
|
||||||
i2s_chan_config_t chan_cfg = I2S_DEFAULT_CFG();
|
i2s_chan_config_t chan_cfg = I2S_DEFAULT_CFG();
|
||||||
|
|
@ -316,11 +320,11 @@ bool I2SClass::initSTD(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mo
|
||||||
}
|
}
|
||||||
|
|
||||||
// Peripheral manager set bus type to I2S
|
// Peripheral manager set bus type to I2S
|
||||||
if (_mclk >= 0) if (!perimanSetPinBus(_mclk, ESP32_BUS_TYPE_I2S_STD, (void *)(this))){ goto err; }
|
if (_mclk >= 0) if (!perimanSetPinBus(_mclk, ESP32_BUS_TYPE_I2S_STD_MCLK, (void *)(this), -1, -1)){ goto err; }
|
||||||
if (_bclk >= 0) if (!perimanSetPinBus(_bclk, ESP32_BUS_TYPE_I2S_STD, (void *)(this))){ goto err; }
|
if (_bclk >= 0) if (!perimanSetPinBus(_bclk, ESP32_BUS_TYPE_I2S_STD_BCLK, (void *)(this), -1, -1)){ goto err; }
|
||||||
if (_ws >= 0) if (!perimanSetPinBus(_ws, ESP32_BUS_TYPE_I2S_STD, (void *)(this))){ goto err; }
|
if (_ws >= 0) if (!perimanSetPinBus(_ws, ESP32_BUS_TYPE_I2S_STD_WS, (void *)(this), -1, -1)){ goto err; }
|
||||||
if (_dout >= 0) if (!perimanSetPinBus(_dout, ESP32_BUS_TYPE_I2S_STD, (void *)(this))){ goto err; }
|
if (_dout >= 0) if (!perimanSetPinBus(_dout, ESP32_BUS_TYPE_I2S_STD_DOUT, (void *)(this), -1, -1)){ goto err; }
|
||||||
if (_din >= 0) if (!perimanSetPinBus(_din, ESP32_BUS_TYPE_I2S_STD, (void *)(this))){ goto err; }
|
if (_din >= 0) if (!perimanSetPinBus(_din, ESP32_BUS_TYPE_I2S_STD_DIN, (void *)(this), -1, -1)){ goto err; }
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
err:
|
err:
|
||||||
|
|
@ -332,14 +336,18 @@ err:
|
||||||
#if SOC_I2S_SUPPORTS_TDM
|
#if SOC_I2S_SUPPORTS_TDM
|
||||||
bool I2SClass::initTDM(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch, int8_t slot_mask){
|
bool I2SClass::initTDM(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch, int8_t slot_mask){
|
||||||
// Peripheral manager deinit previous peripheral if pin was used
|
// Peripheral manager deinit previous peripheral if pin was used
|
||||||
if (_mclk >= 0) if (!perimanSetPinBus(_mclk, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if (_mclk >= 0) if (!perimanClearPinBus(_mclk)){ return false; }
|
||||||
if (_bclk >= 0) if (!perimanSetPinBus(_bclk, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if (_bclk >= 0) if (!perimanClearPinBus(_bclk)){ return false; }
|
||||||
if (_ws >= 0) if (!perimanSetPinBus(_ws, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if (_ws >= 0) if (!perimanClearPinBus(_ws)) { return false; }
|
||||||
if (_dout >= 0) if (!perimanSetPinBus(_dout, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if (_dout >= 0) if (!perimanClearPinBus(_dout)){ return false; }
|
||||||
if (_din >= 0) if (!perimanSetPinBus(_din, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if (_din >= 0) if (!perimanClearPinBus(_din)) { return false; }
|
||||||
|
|
||||||
// Set peripheral manager detach function for I2S
|
// Set peripheral manager detach function for I2S
|
||||||
perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_TDM, I2SClass::i2sDetachBus);
|
if (_mclk >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_TDM_MCLK, I2SClass::i2sDetachBus); }
|
||||||
|
if (_bclk >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_TDM_BCLK, I2SClass::i2sDetachBus); }
|
||||||
|
if (_ws >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_TDM_WS, I2SClass::i2sDetachBus); }
|
||||||
|
if (_dout >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_TDM_DOUT, I2SClass::i2sDetachBus); }
|
||||||
|
if (_din >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_TDM_DIN, I2SClass::i2sDetachBus); }
|
||||||
|
|
||||||
// I2S configuration
|
// I2S configuration
|
||||||
i2s_chan_config_t chan_cfg = I2S_DEFAULT_CFG();
|
i2s_chan_config_t chan_cfg = I2S_DEFAULT_CFG();
|
||||||
|
|
@ -368,11 +376,11 @@ bool I2SClass::initTDM(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mo
|
||||||
}
|
}
|
||||||
|
|
||||||
// Peripheral manager set bus type to I2S
|
// Peripheral manager set bus type to I2S
|
||||||
if (_mclk >= 0) if (!perimanSetPinBus(_mclk, ESP32_BUS_TYPE_I2S_TDM, (void *)(this))){ goto err; }
|
if (_mclk >= 0) if (!perimanSetPinBus(_mclk, ESP32_BUS_TYPE_I2S_TDM_MCLK, (void *)(this), -1, -1)){ goto err; }
|
||||||
if (_bclk >= 0) if (!perimanSetPinBus(_bclk, ESP32_BUS_TYPE_I2S_TDM, (void *)(this))){ goto err; }
|
if (_bclk >= 0) if (!perimanSetPinBus(_bclk, ESP32_BUS_TYPE_I2S_TDM_BCLK, (void *)(this), -1, -1)){ goto err; }
|
||||||
if (_ws >= 0) if (!perimanSetPinBus(_ws, ESP32_BUS_TYPE_I2S_TDM, (void *)(this))){ goto err; }
|
if (_ws >= 0) if (!perimanSetPinBus(_ws, ESP32_BUS_TYPE_I2S_TDM_WS, (void *)(this), -1, -1)){ goto err; }
|
||||||
if (_dout >= 0) if (!perimanSetPinBus(_dout, ESP32_BUS_TYPE_I2S_TDM, (void *)(this))){ goto err; }
|
if (_dout >= 0) if (!perimanSetPinBus(_dout, ESP32_BUS_TYPE_I2S_TDM_DOUT, (void *)(this), -1, -1)){ goto err; }
|
||||||
if (_din >= 0) if (!perimanSetPinBus(_din, ESP32_BUS_TYPE_I2S_TDM, (void *)(this))){ goto err; }
|
if (_din >= 0) if (!perimanSetPinBus(_din, ESP32_BUS_TYPE_I2S_TDM_DIN, (void *)(this), -1, -1)){ goto err; }
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
err:
|
err:
|
||||||
|
|
@ -385,12 +393,14 @@ err:
|
||||||
#if SOC_I2S_SUPPORTS_PDM_TX
|
#if SOC_I2S_SUPPORTS_PDM_TX
|
||||||
bool I2SClass::initPDMtx(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch){
|
bool I2SClass::initPDMtx(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch){
|
||||||
// Peripheral manager deinit previous peripheral if pin was used
|
// Peripheral manager deinit previous peripheral if pin was used
|
||||||
if (_tx_clk >= 0) if (!perimanSetPinBus(_tx_clk, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if (_tx_clk >= 0) if (!perimanClearPinBus(_tx_clk)) { return false; }
|
||||||
if (_tx_dout0 >= 0) if (!perimanSetPinBus(_tx_dout0, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if (_tx_dout0 >= 0) if (!perimanClearPinBus(_tx_dout0)){ return false; }
|
||||||
if (_tx_dout1 >= 0) if (!perimanSetPinBus(_tx_dout1, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if (_tx_dout1 >= 0) if (!perimanClearPinBus(_tx_dout1)){ return false; }
|
||||||
|
|
||||||
// Set peripheral manager detach function for I2S
|
// Set peripheral manager detach function for I2S
|
||||||
perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_PDM_TX, I2SClass::i2sDetachBus);
|
if (_tx_clk >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_PDM_TX_CLK, I2SClass::i2sDetachBus); }
|
||||||
|
if (_tx_dout0 >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_PDM_TX_DOUT0, I2SClass::i2sDetachBus); }
|
||||||
|
if (_tx_dout1 >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_PDM_TX_DOUT1, I2SClass::i2sDetachBus); }
|
||||||
|
|
||||||
// I2S configuration
|
// I2S configuration
|
||||||
i2s_chan_config_t chan_cfg = I2S_DEFAULT_CFG();
|
i2s_chan_config_t chan_cfg = I2S_DEFAULT_CFG();
|
||||||
|
|
@ -406,9 +416,9 @@ bool I2SClass::initPDMtx(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_
|
||||||
}
|
}
|
||||||
|
|
||||||
// Peripheral manager set bus type to I2S
|
// Peripheral manager set bus type to I2S
|
||||||
if (_tx_clk >= 0) if (!perimanSetPinBus(_tx_clk, ESP32_BUS_TYPE_I2S_PDM_TX, (void *)(this))){ goto err; }
|
if (_tx_clk >= 0) if (!perimanSetPinBus(_tx_clk, ESP32_BUS_TYPE_I2S_PDM_TX_CLK, (void *)(this), -1, -1)){ goto err; }
|
||||||
if (_tx_dout0 >= 0) if (!perimanSetPinBus(_tx_dout0, ESP32_BUS_TYPE_I2S_PDM_TX, (void *)(this))){ goto err; }
|
if (_tx_dout0 >= 0) if (!perimanSetPinBus(_tx_dout0, ESP32_BUS_TYPE_I2S_PDM_TX_DOUT0, (void *)(this), -1, -1)){ goto err; }
|
||||||
if (_tx_dout1 >= 0) if (!perimanSetPinBus(_tx_dout1, ESP32_BUS_TYPE_I2S_PDM_TX, (void *)(this))){ goto err; }
|
if (_tx_dout1 >= 0) if (!perimanSetPinBus(_tx_dout1, ESP32_BUS_TYPE_I2S_PDM_TX_DOUT1, (void *)(this), -1, -1)){ goto err; }
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
err:
|
err:
|
||||||
|
|
@ -421,14 +431,18 @@ err:
|
||||||
#if SOC_I2S_SUPPORTS_PDM_RX
|
#if SOC_I2S_SUPPORTS_PDM_RX
|
||||||
bool I2SClass::initPDMrx(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch){
|
bool I2SClass::initPDMrx(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch){
|
||||||
// Peripheral manager deinit previous peripheral if pin was used
|
// Peripheral manager deinit previous peripheral if pin was used
|
||||||
if (_rx_clk >= 0) if (!perimanSetPinBus(_rx_clk, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if (_rx_clk >= 0) if (!perimanClearPinBus(_rx_clk)) { return false; }
|
||||||
if (_rx_din0 >= 0) if (!perimanSetPinBus(_rx_din0, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if (_rx_din0 >= 0) if (!perimanClearPinBus(_rx_din0)){ return false; }
|
||||||
if (_rx_din1 >= 0) if (!perimanSetPinBus(_rx_din1, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if (_rx_din1 >= 0) if (!perimanClearPinBus(_rx_din1)){ return false; }
|
||||||
if (_rx_din2 >= 0) if (!perimanSetPinBus(_rx_din2, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if (_rx_din2 >= 0) if (!perimanClearPinBus(_rx_din2)){ return false; }
|
||||||
if (_rx_din3 >= 0) if (!perimanSetPinBus(_rx_din3, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if (_rx_din3 >= 0) if (!perimanClearPinBus(_rx_din3)){ return false; }
|
||||||
|
|
||||||
// Set peripheral manager detach function for I2S
|
// Set peripheral manager detach function for I2S
|
||||||
perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_PDM_RX, I2SClass::i2sDetachBus);
|
if (_rx_clk >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_PDM_RX_CLK, I2SClass::i2sDetachBus); }
|
||||||
|
if (_rx_din0 >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_PDM_RX_DIN0, I2SClass::i2sDetachBus); }
|
||||||
|
if (_rx_din1 >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_PDM_RX_DIN1, I2SClass::i2sDetachBus); }
|
||||||
|
if (_rx_din2 >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_PDM_RX_DIN2, I2SClass::i2sDetachBus); }
|
||||||
|
if (_rx_din3 >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_PDM_RX_DIN3, I2SClass::i2sDetachBus); }
|
||||||
|
|
||||||
// I2S configuration
|
// I2S configuration
|
||||||
i2s_chan_config_t chan_cfg = I2S_DEFAULT_CFG();
|
i2s_chan_config_t chan_cfg = I2S_DEFAULT_CFG();
|
||||||
|
|
@ -444,11 +458,11 @@ bool I2SClass::initPDMrx(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_
|
||||||
}
|
}
|
||||||
|
|
||||||
// Peripheral manager set bus type to I2S
|
// Peripheral manager set bus type to I2S
|
||||||
if (_rx_clk >= 0) if (!perimanSetPinBus(_rx_clk, ESP32_BUS_TYPE_I2S_PDM_RX, (void *)(this))){ goto err; }
|
if (_rx_clk >= 0) if (!perimanSetPinBus(_rx_clk, ESP32_BUS_TYPE_I2S_PDM_RX_CLK, (void *)(this), -1, -1)){ goto err; }
|
||||||
if (_rx_din0 >= 0) if (!perimanSetPinBus(_rx_din0, ESP32_BUS_TYPE_I2S_PDM_RX, (void *)(this))){ goto err; }
|
if (_rx_din0 >= 0) if (!perimanSetPinBus(_rx_din0, ESP32_BUS_TYPE_I2S_PDM_RX_DIN0, (void *)(this), -1, -1)){ goto err; }
|
||||||
if (_rx_din1 >= 0) if (!perimanSetPinBus(_rx_din1, ESP32_BUS_TYPE_I2S_PDM_RX, (void *)(this))){ goto err; }
|
if (_rx_din1 >= 0) if (!perimanSetPinBus(_rx_din1, ESP32_BUS_TYPE_I2S_PDM_RX_DIN1, (void *)(this), -1, -1)){ goto err; }
|
||||||
if (_rx_din2 >= 0) if (!perimanSetPinBus(_rx_din2, ESP32_BUS_TYPE_I2S_PDM_RX, (void *)(this))){ goto err; }
|
if (_rx_din2 >= 0) if (!perimanSetPinBus(_rx_din2, ESP32_BUS_TYPE_I2S_PDM_RX_DIN2, (void *)(this), -1, -1)){ goto err; }
|
||||||
if (_rx_din3 >= 0) if (!perimanSetPinBus(_rx_din3, ESP32_BUS_TYPE_I2S_PDM_RX, (void *)(this))){ goto err; }
|
if (_rx_din3 >= 0) if (!perimanSetPinBus(_rx_din3, ESP32_BUS_TYPE_I2S_PDM_RX_DIN3, (void *)(this), -1, -1)){ goto err; }
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
err:
|
err:
|
||||||
|
|
@ -524,26 +538,26 @@ bool I2SClass::end(){
|
||||||
#if SOC_I2S_SUPPORTS_TDM
|
#if SOC_I2S_SUPPORTS_TDM
|
||||||
case I2S_MODE_TDM:
|
case I2S_MODE_TDM:
|
||||||
#endif
|
#endif
|
||||||
perimanSetPinBus(_mclk, ESP32_BUS_TYPE_INIT, NULL);
|
perimanClearPinBus(_mclk);
|
||||||
perimanSetPinBus(_bclk, ESP32_BUS_TYPE_INIT, NULL);
|
perimanClearPinBus(_bclk);
|
||||||
perimanSetPinBus(_ws, ESP32_BUS_TYPE_INIT, NULL);
|
perimanClearPinBus(_ws);
|
||||||
if (_dout >= 0) perimanSetPinBus(_dout, ESP32_BUS_TYPE_INIT, NULL);
|
if (_dout >= 0) perimanClearPinBus(_dout);
|
||||||
if (_din >= 0) perimanSetPinBus(_din, ESP32_BUS_TYPE_INIT, NULL);
|
if (_din >= 0) perimanClearPinBus(_din);
|
||||||
break;
|
break;
|
||||||
#if SOC_I2S_SUPPORTS_PDM_TX
|
#if SOC_I2S_SUPPORTS_PDM_TX
|
||||||
case I2S_MODE_PDM_TX:
|
case I2S_MODE_PDM_TX:
|
||||||
perimanSetPinBus(_tx_clk, ESP32_BUS_TYPE_INIT, NULL);
|
perimanClearPinBus(_tx_clk);
|
||||||
if (_tx_dout0 >= 0) perimanSetPinBus(_tx_dout0, ESP32_BUS_TYPE_INIT, NULL);
|
if (_tx_dout0 >= 0) perimanClearPinBus(_tx_dout0);
|
||||||
if (_tx_dout1 >= 0) perimanSetPinBus(_tx_dout1, ESP32_BUS_TYPE_INIT, NULL);
|
if (_tx_dout1 >= 0) perimanClearPinBus(_tx_dout1);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if SOC_I2S_SUPPORTS_PDM_RX
|
#if SOC_I2S_SUPPORTS_PDM_RX
|
||||||
case I2S_MODE_PDM_RX:
|
case I2S_MODE_PDM_RX:
|
||||||
perimanSetPinBus(_rx_clk, ESP32_BUS_TYPE_INIT, NULL);
|
perimanClearPinBus(_rx_clk);
|
||||||
if (_rx_din0 >= 0) perimanSetPinBus(_rx_din0, ESP32_BUS_TYPE_INIT, NULL);
|
if (_rx_din0 >= 0) perimanClearPinBus(_rx_din0);
|
||||||
if (_rx_din1 >= 0) perimanSetPinBus(_rx_din1, ESP32_BUS_TYPE_INIT, NULL);
|
if (_rx_din1 >= 0) perimanClearPinBus(_rx_din1);
|
||||||
if (_rx_din2 >= 0) perimanSetPinBus(_rx_din2, ESP32_BUS_TYPE_INIT, NULL);
|
if (_rx_din2 >= 0) perimanClearPinBus(_rx_din2);
|
||||||
if (_rx_din3 >= 0) perimanSetPinBus(_rx_din3, ESP32_BUS_TYPE_INIT, NULL);
|
if (_rx_din3 >= 0) perimanClearPinBus(_rx_din3);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,13 @@ bool ETHClass::begin(eth_phy_type_t type, uint8_t phy_addr, int mdc, int mdio, i
|
||||||
if(_esp_netif != NULL){
|
if(_esp_netif != NULL){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
perimanSetBusDeinit(ESP32_BUS_TYPE_ETHERNET, ETHClass::ethDetachBus);
|
perimanSetBusDeinit(ESP32_BUS_TYPE_ETHERNET_RMII, ETHClass::ethDetachBus);
|
||||||
|
perimanSetBusDeinit(ESP32_BUS_TYPE_ETHERNET_CLK, ETHClass::ethDetachBus);
|
||||||
|
perimanSetBusDeinit(ESP32_BUS_TYPE_ETHERNET_MCD, ETHClass::ethDetachBus);
|
||||||
|
perimanSetBusDeinit(ESP32_BUS_TYPE_ETHERNET_MDIO, ETHClass::ethDetachBus);
|
||||||
|
if(power != -1){
|
||||||
|
perimanSetBusDeinit(ESP32_BUS_TYPE_ETHERNET_PWR, ETHClass::ethDetachBus);
|
||||||
|
}
|
||||||
|
|
||||||
tcpipInit();
|
tcpipInit();
|
||||||
|
|
||||||
|
|
@ -100,17 +106,17 @@ bool ETHClass::begin(eth_phy_type_t type, uint8_t phy_addr, int mdc, int mdio, i
|
||||||
_pin_rmii_clock = mac_config.clock_config.rmii.clock_gpio;
|
_pin_rmii_clock = mac_config.clock_config.rmii.clock_gpio;
|
||||||
_pin_power = power;
|
_pin_power = power;
|
||||||
|
|
||||||
if(!perimanSetPinBus(_pin_rmii_clock, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if(!perimanClearPinBus(_pin_rmii_clock)){ return false; }
|
||||||
if(!perimanSetPinBus(_pin_mcd, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if(!perimanClearPinBus(_pin_mcd)){ return false; }
|
||||||
if(!perimanSetPinBus(_pin_mdio, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if(!perimanClearPinBus(_pin_mdio)){ return false; }
|
||||||
if(!perimanSetPinBus(ETH_RMII_TX_EN, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if(!perimanClearPinBus(ETH_RMII_TX_EN)){ return false; }
|
||||||
if(!perimanSetPinBus(ETH_RMII_TX0, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if(!perimanClearPinBus(ETH_RMII_TX0)){ return false; }
|
||||||
if(!perimanSetPinBus(ETH_RMII_TX1, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if(!perimanClearPinBus(ETH_RMII_TX1)){ return false; }
|
||||||
if(!perimanSetPinBus(ETH_RMII_RX0, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if(!perimanClearPinBus(ETH_RMII_RX0)){ return false; }
|
||||||
if(!perimanSetPinBus(ETH_RMII_RX1_EN, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if(!perimanClearPinBus(ETH_RMII_RX1_EN)){ return false; }
|
||||||
if(!perimanSetPinBus(ETH_RMII_CRS_DV, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if(!perimanClearPinBus(ETH_RMII_CRS_DV)){ return false; }
|
||||||
if(_pin_power != -1){
|
if(_pin_power != -1){
|
||||||
if(!perimanSetPinBus(_pin_power, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if(!perimanClearPinBus(_pin_power)){ return false; }
|
||||||
}
|
}
|
||||||
|
|
||||||
eth_mac_config_t eth_mac_config = ETH_MAC_DEFAULT_CONFIG();
|
eth_mac_config_t eth_mac_config = ETH_MAC_DEFAULT_CONFIG();
|
||||||
|
|
@ -204,19 +210,19 @@ bool ETHClass::begin(eth_phy_type_t type, uint8_t phy_addr, int mdc, int mdio, i
|
||||||
}
|
}
|
||||||
_eth_started = true;
|
_eth_started = true;
|
||||||
|
|
||||||
if(!perimanSetPinBus(_pin_rmii_clock, ESP32_BUS_TYPE_ETHERNET, (void *)(this))){ goto err; }
|
if(!perimanSetPinBus(_pin_rmii_clock, ESP32_BUS_TYPE_ETHERNET_CLK, (void *)(this), -1, -1)){ goto err; }
|
||||||
if(!perimanSetPinBus(_pin_mcd, ESP32_BUS_TYPE_ETHERNET, (void *)(this))){ goto err; }
|
if(!perimanSetPinBus(_pin_mcd, ESP32_BUS_TYPE_ETHERNET_MCD, (void *)(this), -1, -1)){ goto err; }
|
||||||
if(!perimanSetPinBus(_pin_mdio, ESP32_BUS_TYPE_ETHERNET, (void *)(this))){ goto err; }
|
if(!perimanSetPinBus(_pin_mdio, ESP32_BUS_TYPE_ETHERNET_MDIO, (void *)(this), -1, -1)){ goto err; }
|
||||||
|
|
||||||
if(!perimanSetPinBus(ETH_RMII_TX_EN, ESP32_BUS_TYPE_ETHERNET, (void *)(this))){ goto err; }
|
if(!perimanSetPinBus(ETH_RMII_TX_EN, ESP32_BUS_TYPE_ETHERNET_RMII, (void *)(this), -1, -1)){ goto err; }
|
||||||
if(!perimanSetPinBus(ETH_RMII_TX0, ESP32_BUS_TYPE_ETHERNET, (void *)(this))){ goto err; }
|
if(!perimanSetPinBus(ETH_RMII_TX0, ESP32_BUS_TYPE_ETHERNET_RMII, (void *)(this), -1, -1)){ goto err; }
|
||||||
if(!perimanSetPinBus(ETH_RMII_TX1, ESP32_BUS_TYPE_ETHERNET, (void *)(this))){ goto err; }
|
if(!perimanSetPinBus(ETH_RMII_TX1, ESP32_BUS_TYPE_ETHERNET_RMII, (void *)(this), -1, -1)){ goto err; }
|
||||||
if(!perimanSetPinBus(ETH_RMII_RX0, ESP32_BUS_TYPE_ETHERNET, (void *)(this))){ goto err; }
|
if(!perimanSetPinBus(ETH_RMII_RX0, ESP32_BUS_TYPE_ETHERNET_RMII, (void *)(this), -1, -1)){ goto err; }
|
||||||
if(!perimanSetPinBus(ETH_RMII_RX1_EN, ESP32_BUS_TYPE_ETHERNET, (void *)(this))){ goto err; }
|
if(!perimanSetPinBus(ETH_RMII_RX1_EN, ESP32_BUS_TYPE_ETHERNET_RMII, (void *)(this), -1, -1)){ goto err; }
|
||||||
if(!perimanSetPinBus(ETH_RMII_CRS_DV, ESP32_BUS_TYPE_ETHERNET, (void *)(this))){ goto err; }
|
if(!perimanSetPinBus(ETH_RMII_CRS_DV, ESP32_BUS_TYPE_ETHERNET_RMII, (void *)(this), -1, -1)){ goto err; }
|
||||||
|
|
||||||
if(_pin_power != -1){
|
if(_pin_power != -1){
|
||||||
if(!perimanSetPinBus(_pin_power, ESP32_BUS_TYPE_ETHERNET, (void *)(this))){ goto err; }
|
if(!perimanSetPinBus(_pin_power, ESP32_BUS_TYPE_ETHERNET_PWR, (void *)(this), -1, -1)){ goto err; }
|
||||||
}
|
}
|
||||||
// holds a few milliseconds to let DHCP start and enter into a good state
|
// holds a few milliseconds to let DHCP start and enter into a good state
|
||||||
// FIX ME -- adresses issue https://github.com/espressif/arduino-esp32/issues/5733
|
// FIX ME -- adresses issue https://github.com/espressif/arduino-esp32/issues/5733
|
||||||
|
|
@ -347,25 +353,25 @@ bool ETHClass::beginSPI(eth_phy_type_t type, uint8_t phy_addr, int cs, int irq,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
perimanSetBusDeinit(ESP32_BUS_TYPE_ETHERNET, ETHClass::ethDetachBus);
|
perimanSetBusDeinit(ESP32_BUS_TYPE_ETHERNET_SPI, ETHClass::ethDetachBus);
|
||||||
|
|
||||||
if(_pin_cs != -1){
|
if(_pin_cs != -1){
|
||||||
if(!perimanSetPinBus(_pin_cs, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if(!perimanClearPinBus(_pin_cs)){ return false; }
|
||||||
}
|
}
|
||||||
if(_pin_rst != -1){
|
if(_pin_rst != -1){
|
||||||
if(!perimanSetPinBus(_pin_rst, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if(!perimanClearPinBus(_pin_rst)){ return false; }
|
||||||
}
|
}
|
||||||
if(_pin_irq != -1){
|
if(_pin_irq != -1){
|
||||||
if(!perimanSetPinBus(_pin_irq, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if(!perimanClearPinBus(_pin_irq)){ return false; }
|
||||||
}
|
}
|
||||||
if(_pin_sck != -1){
|
if(_pin_sck != -1){
|
||||||
if(!perimanSetPinBus(_pin_sck, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if(!perimanClearPinBus(_pin_sck)){ return false; }
|
||||||
}
|
}
|
||||||
if(_pin_miso != -1){
|
if(_pin_miso != -1){
|
||||||
if(!perimanSetPinBus(_pin_miso, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if(!perimanClearPinBus(_pin_miso)){ return false; }
|
||||||
}
|
}
|
||||||
if(_pin_mosi != -1){
|
if(_pin_mosi != -1){
|
||||||
if(!perimanSetPinBus(_pin_mosi, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if(!perimanClearPinBus(_pin_mosi)){ return false; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ETH_SPI_SUPPORTS_CUSTOM
|
#if ETH_SPI_SUPPORTS_CUSTOM
|
||||||
|
|
@ -386,6 +392,7 @@ bool ETHClass::beginSPI(eth_phy_type_t type, uint8_t phy_addr, int cs, int irq,
|
||||||
if(_spi != NULL){
|
if(_spi != NULL){
|
||||||
pinMode(_pin_cs, OUTPUT);
|
pinMode(_pin_cs, OUTPUT);
|
||||||
digitalWrite(_pin_cs, HIGH);
|
digitalWrite(_pin_cs, HIGH);
|
||||||
|
perimanSetPinBusExtraType(_pin_cs, "ETH_CS");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -572,23 +579,23 @@ bool ETHClass::beginSPI(eth_phy_type_t type, uint8_t phy_addr, int cs, int irq,
|
||||||
#if ETH_SPI_SUPPORTS_CUSTOM
|
#if ETH_SPI_SUPPORTS_CUSTOM
|
||||||
if(_spi == NULL){
|
if(_spi == NULL){
|
||||||
#endif
|
#endif
|
||||||
if(!perimanSetPinBus(_pin_cs, ESP32_BUS_TYPE_ETHERNET, (void *)(this))){ goto err; }
|
if(!perimanSetPinBus(_pin_cs, ESP32_BUS_TYPE_ETHERNET_SPI, (void *)(this), -1, -1)){ goto err; }
|
||||||
#if ETH_SPI_SUPPORTS_CUSTOM
|
#if ETH_SPI_SUPPORTS_CUSTOM
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if(!perimanSetPinBus(_pin_irq, ESP32_BUS_TYPE_ETHERNET, (void *)(this))){ goto err; }
|
if(!perimanSetPinBus(_pin_irq, ESP32_BUS_TYPE_ETHERNET_SPI, (void *)(this), -1, -1)){ goto err; }
|
||||||
|
|
||||||
if(_pin_sck != -1){
|
if(_pin_sck != -1){
|
||||||
if(!perimanSetPinBus(_pin_sck, ESP32_BUS_TYPE_ETHERNET, (void *)(this))){ goto err; }
|
if(!perimanSetPinBus(_pin_sck, ESP32_BUS_TYPE_ETHERNET_SPI, (void *)(this), -1, -1)){ goto err; }
|
||||||
}
|
}
|
||||||
if(_pin_miso != -1){
|
if(_pin_miso != -1){
|
||||||
if(!perimanSetPinBus(_pin_miso, ESP32_BUS_TYPE_ETHERNET, (void *)(this))){ goto err; }
|
if(!perimanSetPinBus(_pin_miso, ESP32_BUS_TYPE_ETHERNET_SPI, (void *)(this), -1, -1)){ goto err; }
|
||||||
}
|
}
|
||||||
if(_pin_mosi != -1){
|
if(_pin_mosi != -1){
|
||||||
if(!perimanSetPinBus(_pin_mosi, ESP32_BUS_TYPE_ETHERNET, (void *)(this))){ goto err; }
|
if(!perimanSetPinBus(_pin_mosi, ESP32_BUS_TYPE_ETHERNET_SPI, (void *)(this), -1, -1)){ goto err; }
|
||||||
}
|
}
|
||||||
if(_pin_rst != -1){
|
if(_pin_rst != -1){
|
||||||
if(!perimanSetPinBus(_pin_rst, ESP32_BUS_TYPE_ETHERNET, (void *)(this))){ goto err; }
|
if(!perimanSetPinBus(_pin_rst, ESP32_BUS_TYPE_ETHERNET_SPI, (void *)(this), -1, -1)){ goto err; }
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -642,16 +649,16 @@ void ETHClass::end(void)
|
||||||
|
|
||||||
#if CONFIG_ETH_USE_ESP32_EMAC
|
#if CONFIG_ETH_USE_ESP32_EMAC
|
||||||
if(_pin_rmii_clock != -1 && _pin_mcd != -1 && _pin_mdio != -1){
|
if(_pin_rmii_clock != -1 && _pin_mcd != -1 && _pin_mdio != -1){
|
||||||
perimanSetPinBus(_pin_rmii_clock, ESP32_BUS_TYPE_INIT, NULL);
|
perimanClearPinBus(_pin_rmii_clock);
|
||||||
perimanSetPinBus(_pin_mcd, ESP32_BUS_TYPE_INIT, NULL);
|
perimanClearPinBus(_pin_mcd);
|
||||||
perimanSetPinBus(_pin_mdio, ESP32_BUS_TYPE_INIT, NULL);
|
perimanClearPinBus(_pin_mdio);
|
||||||
|
|
||||||
perimanSetPinBus(ETH_RMII_TX_EN, ESP32_BUS_TYPE_INIT, NULL);
|
perimanClearPinBus(ETH_RMII_TX_EN);
|
||||||
perimanSetPinBus(ETH_RMII_TX0, ESP32_BUS_TYPE_INIT, NULL);
|
perimanClearPinBus(ETH_RMII_TX0);
|
||||||
perimanSetPinBus(ETH_RMII_TX1, ESP32_BUS_TYPE_INIT, NULL);
|
perimanClearPinBus(ETH_RMII_TX1);
|
||||||
perimanSetPinBus(ETH_RMII_RX0, ESP32_BUS_TYPE_INIT, NULL);
|
perimanClearPinBus(ETH_RMII_RX0);
|
||||||
perimanSetPinBus(ETH_RMII_RX1_EN, ESP32_BUS_TYPE_INIT, NULL);
|
perimanClearPinBus(ETH_RMII_RX1_EN);
|
||||||
perimanSetPinBus(ETH_RMII_CRS_DV, ESP32_BUS_TYPE_INIT, NULL);
|
perimanClearPinBus(ETH_RMII_CRS_DV);
|
||||||
|
|
||||||
_pin_rmii_clock = -1;
|
_pin_rmii_clock = -1;
|
||||||
_pin_mcd = -1;
|
_pin_mcd = -1;
|
||||||
|
|
@ -659,32 +666,32 @@ void ETHClass::end(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(_pin_power != -1){
|
if(_pin_power != -1){
|
||||||
perimanSetPinBus(_pin_power, ESP32_BUS_TYPE_INIT, NULL);
|
perimanClearPinBus(_pin_power);
|
||||||
_pin_power = -1;
|
_pin_power = -1;
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_ETH_USE_ESP32_EMAC */
|
#endif /* CONFIG_ETH_USE_ESP32_EMAC */
|
||||||
if(_pin_cs != -1){
|
if(_pin_cs != -1){
|
||||||
perimanSetPinBus(_pin_cs, ESP32_BUS_TYPE_INIT, NULL);
|
perimanClearPinBus(_pin_cs);
|
||||||
_pin_cs = -1;
|
_pin_cs = -1;
|
||||||
}
|
}
|
||||||
if(_pin_irq != -1){
|
if(_pin_irq != -1){
|
||||||
perimanSetPinBus(_pin_irq, ESP32_BUS_TYPE_INIT, NULL);
|
perimanClearPinBus(_pin_irq);
|
||||||
_pin_irq = -1;
|
_pin_irq = -1;
|
||||||
}
|
}
|
||||||
if(_pin_sck != -1){
|
if(_pin_sck != -1){
|
||||||
perimanSetPinBus(_pin_sck, ESP32_BUS_TYPE_INIT, NULL);
|
perimanClearPinBus(_pin_sck);
|
||||||
_pin_sck = -1;
|
_pin_sck = -1;
|
||||||
}
|
}
|
||||||
if(_pin_miso != -1){
|
if(_pin_miso != -1){
|
||||||
perimanSetPinBus(_pin_miso, ESP32_BUS_TYPE_INIT, NULL);
|
perimanClearPinBus(_pin_miso);
|
||||||
_pin_miso = -1;
|
_pin_miso = -1;
|
||||||
}
|
}
|
||||||
if(_pin_mosi != -1){
|
if(_pin_mosi != -1){
|
||||||
perimanSetPinBus(_pin_mosi, ESP32_BUS_TYPE_INIT, NULL);
|
perimanClearPinBus(_pin_mosi);
|
||||||
_pin_mosi = -1;
|
_pin_mosi = -1;
|
||||||
}
|
}
|
||||||
if(_pin_rst != -1){
|
if(_pin_rst != -1){
|
||||||
perimanSetPinBus(_pin_rst, ESP32_BUS_TYPE_INIT, NULL);
|
perimanClearPinBus(_pin_rst);
|
||||||
_pin_rst = -1;
|
_pin_rst = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
#include "sd_diskio.h"
|
#include "sd_diskio.h"
|
||||||
#include "esp_system.h"
|
#include "esp_system.h"
|
||||||
|
#include "esp32-hal-periman.h"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "ff.h"
|
#include "ff.h"
|
||||||
#include "diskio.h"
|
#include "diskio.h"
|
||||||
|
|
@ -748,6 +750,7 @@ uint8_t sdcard_init(uint8_t cs, SPIClass * spi, int hz)
|
||||||
|
|
||||||
pinMode(card->ssPin, OUTPUT);
|
pinMode(card->ssPin, OUTPUT);
|
||||||
digitalWrite(card->ssPin, HIGH);
|
digitalWrite(card->ssPin, HIGH);
|
||||||
|
perimanSetPinBusExtraType(card->ssPin, "SD_SS");
|
||||||
|
|
||||||
s_cards[pdrv] = card;
|
s_cards[pdrv] = card;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -107,8 +107,14 @@ bool SDMMCFS::begin(const char * mountpoint, bool mode1bit, bool format_if_mount
|
||||||
if(_card) {
|
if(_card) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
perimanSetBusDeinit(ESP32_BUS_TYPE_SDMMC, SDMMCFS::sdmmcDetachBus);
|
perimanSetBusDeinit(ESP32_BUS_TYPE_SDMMC_CLK, SDMMCFS::sdmmcDetachBus);
|
||||||
|
perimanSetBusDeinit(ESP32_BUS_TYPE_SDMMC_CMD, SDMMCFS::sdmmcDetachBus);
|
||||||
|
perimanSetBusDeinit(ESP32_BUS_TYPE_SDMMC_D0, SDMMCFS::sdmmcDetachBus);
|
||||||
|
if(!mode1bit) {
|
||||||
|
perimanSetBusDeinit(ESP32_BUS_TYPE_SDMMC_D1, SDMMCFS::sdmmcDetachBus);
|
||||||
|
perimanSetBusDeinit(ESP32_BUS_TYPE_SDMMC_D2, SDMMCFS::sdmmcDetachBus);
|
||||||
|
perimanSetBusDeinit(ESP32_BUS_TYPE_SDMMC_D3, SDMMCFS::sdmmcDetachBus);
|
||||||
|
}
|
||||||
//mount
|
//mount
|
||||||
sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
|
sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
|
||||||
#ifdef SOC_SDMMC_USE_GPIO_MATRIX
|
#ifdef SOC_SDMMC_USE_GPIO_MATRIX
|
||||||
|
|
@ -129,13 +135,13 @@ bool SDMMCFS::begin(const char * mountpoint, bool mode1bit, bool format_if_mount
|
||||||
slot_config.width = 4;
|
slot_config.width = 4;
|
||||||
#endif // SOC_SDMMC_USE_GPIO_MATRIX
|
#endif // SOC_SDMMC_USE_GPIO_MATRIX
|
||||||
|
|
||||||
if(!perimanSetPinBus(_pin_cmd, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if(!perimanClearPinBus(_pin_cmd)){ return false; }
|
||||||
if(!perimanSetPinBus(_pin_clk, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if(!perimanClearPinBus(_pin_clk)){ return false; }
|
||||||
if(!perimanSetPinBus(_pin_d0, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if(!perimanClearPinBus(_pin_d0)){ return false; }
|
||||||
if(!mode1bit) {
|
if(!mode1bit) {
|
||||||
if(!perimanSetPinBus(_pin_d1, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if(!perimanClearPinBus(_pin_d1)){ return false; }
|
||||||
if(!perimanSetPinBus(_pin_d2, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if(!perimanClearPinBus(_pin_d2)){ return false; }
|
||||||
if(!perimanSetPinBus(_pin_d3, ESP32_BUS_TYPE_INIT, NULL)){ return false; }
|
if(!perimanClearPinBus(_pin_d3)){ return false; }
|
||||||
}
|
}
|
||||||
|
|
||||||
sdmmc_host_t host = SDMMC_HOST_DEFAULT();
|
sdmmc_host_t host = SDMMC_HOST_DEFAULT();
|
||||||
|
|
@ -174,13 +180,13 @@ bool SDMMCFS::begin(const char * mountpoint, bool mode1bit, bool format_if_mount
|
||||||
}
|
}
|
||||||
_impl->mountpoint(mountpoint);
|
_impl->mountpoint(mountpoint);
|
||||||
|
|
||||||
if(!perimanSetPinBus(_pin_cmd, ESP32_BUS_TYPE_SDMMC, (void *)(this))){ goto err; }
|
if(!perimanSetPinBus(_pin_cmd, ESP32_BUS_TYPE_SDMMC_CMD, (void *)(this), -1, -1)){ goto err; }
|
||||||
if(!perimanSetPinBus(_pin_clk, ESP32_BUS_TYPE_SDMMC, (void *)(this))){ goto err; }
|
if(!perimanSetPinBus(_pin_clk, ESP32_BUS_TYPE_SDMMC_CLK, (void *)(this), -1, -1)){ goto err; }
|
||||||
if(!perimanSetPinBus(_pin_d0, ESP32_BUS_TYPE_SDMMC, (void *)(this))){ goto err; }
|
if(!perimanSetPinBus(_pin_d0, ESP32_BUS_TYPE_SDMMC_D0, (void *)(this), -1, -1)){ goto err; }
|
||||||
if(!mode1bit) {
|
if(!mode1bit) {
|
||||||
if(!perimanSetPinBus(_pin_d1, ESP32_BUS_TYPE_SDMMC, (void *)(this))){ goto err; }
|
if(!perimanSetPinBus(_pin_d1, ESP32_BUS_TYPE_SDMMC_D1, (void *)(this), -1, -1)){ goto err; }
|
||||||
if(!perimanSetPinBus(_pin_d2, ESP32_BUS_TYPE_SDMMC, (void *)(this))){ goto err; }
|
if(!perimanSetPinBus(_pin_d2, ESP32_BUS_TYPE_SDMMC_D2, (void *)(this), -1, -1)){ goto err; }
|
||||||
if(!perimanSetPinBus(_pin_d3, ESP32_BUS_TYPE_SDMMC, (void *)(this))){ goto err; }
|
if(!perimanSetPinBus(_pin_d3, ESP32_BUS_TYPE_SDMMC_D3, (void *)(this), -1, -1)){ goto err; }
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
@ -196,13 +202,13 @@ void SDMMCFS::end()
|
||||||
esp_vfs_fat_sdcard_unmount(_impl->mountpoint(), _card);
|
esp_vfs_fat_sdcard_unmount(_impl->mountpoint(), _card);
|
||||||
_impl->mountpoint(NULL);
|
_impl->mountpoint(NULL);
|
||||||
_card = NULL;
|
_card = NULL;
|
||||||
perimanSetPinBus(_pin_cmd, ESP32_BUS_TYPE_INIT, NULL);
|
perimanClearPinBus(_pin_cmd);
|
||||||
perimanSetPinBus(_pin_clk, ESP32_BUS_TYPE_INIT, NULL);
|
perimanClearPinBus(_pin_clk);
|
||||||
perimanSetPinBus(_pin_d0, ESP32_BUS_TYPE_INIT, NULL);
|
perimanClearPinBus(_pin_d0);
|
||||||
if(!_mode1bit) {
|
if(!_mode1bit) {
|
||||||
perimanSetPinBus(_pin_d1, ESP32_BUS_TYPE_INIT, NULL);
|
perimanClearPinBus(_pin_d1);
|
||||||
perimanSetPinBus(_pin_d2, ESP32_BUS_TYPE_INIT, NULL);
|
perimanClearPinBus(_pin_d2);
|
||||||
perimanSetPinBus(_pin_d3, ESP32_BUS_TYPE_INIT, NULL);
|
perimanClearPinBus(_pin_d3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue