Skip to content

Minor changes, fixes #22

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

Merged
merged 4 commits into from
Oct 24, 2021
Merged
Show file tree
Hide file tree
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
27 changes: 19 additions & 8 deletions cores/esp32/esp32-hal-adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,23 @@ static uint8_t __analogVRefPin = 0;
#endif

static uint8_t __analogAttenuation = 3;//11db
#if CONFIG_IDF_TARGET_ESP32S2
static uint8_t __analogWidth = 4; // 13 bits
#else
static uint8_t __analogWidth = 3; // 12 bits
#endif
static uint8_t __analogWidth = ADC_WIDTH_MAX - 1; //3 for ESP32/ESP32C3; 4 for ESP32S2
static uint8_t __analogReturnedWidth = SOC_ADC_MAX_BITWIDTH; //12 for ESP32/ESP32C3; 13 for ESP32S2
static uint8_t __analogClockDiv = 1;
static adc_attenuation_t __pin_attenuation[SOC_GPIO_PIN_COUNT];

static inline uint16_t mapResolution(uint16_t value)
{
uint8_t from = __analogWidth + 9;
if (from == __analogReturnedWidth) {
return value;
}
if (from > __analogReturnedWidth) {
return value >> (from - __analogReturnedWidth);
}
return value << (__analogReturnedWidth - from);
}

void __analogSetClockDiv(uint8_t clockDiv){
if(!clockDiv){
clockDiv = 1;
Expand Down Expand Up @@ -150,6 +159,7 @@ void __analogReadResolution(uint8_t bits)
if(!bits || bits > 16){
return;
}
__analogReturnedWidth = bits;
#if CONFIG_IDF_TARGET_ESP32
__analogSetWidth(bits); // hadware from 9 to 12
#endif
Expand All @@ -169,7 +179,7 @@ uint16_t __analogRead(uint8_t pin)
channel -= 10;
r = adc2_get_raw( channel, __analogWidth, &value);
if ( r == ESP_OK ) {
return value;
return mapResolution(value);
} else if ( r == ESP_ERR_INVALID_STATE ) {
log_e("GPIO%u: %s: ADC2 not initialized yet.", pin, esp_err_to_name(r));
} else if ( r == ESP_ERR_TIMEOUT ) {
Expand All @@ -178,9 +188,10 @@ uint16_t __analogRead(uint8_t pin)
log_e("GPIO%u: %s", pin, esp_err_to_name(r));
}
} else {
return adc1_get_raw(channel);
value = adc1_get_raw(channel);
return mapResolution(value);
}
return value;
return mapResolution(value);
}

uint32_t __analogReadMilliVolts(uint8_t pin){
Expand Down
2 changes: 1 addition & 1 deletion libraries/EEPROM/src/EEPROM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ bool EEPROMClass::begin(size_t size) {

_data = (uint8_t*) malloc(size);
if(!_data) {
log_e("Not enough memory for %d bytes in EEPROM");
log_e("Not enough memory for %d bytes in EEPROM", size);
return false;
}
_size = size;
Expand Down
6 changes: 0 additions & 6 deletions libraries/WiFi/src/ETH.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,6 @@ bool ETHClass::begin(uint8_t phy_addr, int power, int mdc, int mdio, eth_phy_typ
esp_netif_config_t cfg = ESP_NETIF_DEFAULT_ETH();
esp_netif_t *eth_netif = esp_netif_new(&cfg);

if(esp_eth_set_default_handlers(eth_netif) != ESP_OK){
log_e("esp_eth_set_default_handlers failed");
return false;
}


esp_eth_mac_t *eth_mac = NULL;
#if CONFIG_ETH_SPI_ETHERNET_DM9051
if(type == ETH_PHY_DM9051){
Expand Down