Skip to content

Commit f0db73b

Browse files
authored
Merge pull request #22 from espressif/master
Minor changes, fixes
2 parents a443b81 + aabbed0 commit f0db73b

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

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

+19-8
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,23 @@ static uint8_t __analogVRefPin = 0;
4646
#endif
4747

4848
static uint8_t __analogAttenuation = 3;//11db
49-
#if CONFIG_IDF_TARGET_ESP32S2
50-
static uint8_t __analogWidth = 4; // 13 bits
51-
#else
52-
static uint8_t __analogWidth = 3; // 12 bits
53-
#endif
49+
static uint8_t __analogWidth = ADC_WIDTH_MAX - 1; //3 for ESP32/ESP32C3; 4 for ESP32S2
50+
static uint8_t __analogReturnedWidth = SOC_ADC_MAX_BITWIDTH; //12 for ESP32/ESP32C3; 13 for ESP32S2
5451
static uint8_t __analogClockDiv = 1;
5552
static adc_attenuation_t __pin_attenuation[SOC_GPIO_PIN_COUNT];
5653

54+
static inline uint16_t mapResolution(uint16_t value)
55+
{
56+
uint8_t from = __analogWidth + 9;
57+
if (from == __analogReturnedWidth) {
58+
return value;
59+
}
60+
if (from > __analogReturnedWidth) {
61+
return value >> (from - __analogReturnedWidth);
62+
}
63+
return value << (__analogReturnedWidth - from);
64+
}
65+
5766
void __analogSetClockDiv(uint8_t clockDiv){
5867
if(!clockDiv){
5968
clockDiv = 1;
@@ -150,6 +159,7 @@ void __analogReadResolution(uint8_t bits)
150159
if(!bits || bits > 16){
151160
return;
152161
}
162+
__analogReturnedWidth = bits;
153163
#if CONFIG_IDF_TARGET_ESP32
154164
__analogSetWidth(bits); // hadware from 9 to 12
155165
#endif
@@ -169,7 +179,7 @@ uint16_t __analogRead(uint8_t pin)
169179
channel -= 10;
170180
r = adc2_get_raw( channel, __analogWidth, &value);
171181
if ( r == ESP_OK ) {
172-
return value;
182+
return mapResolution(value);
173183
} else if ( r == ESP_ERR_INVALID_STATE ) {
174184
log_e("GPIO%u: %s: ADC2 not initialized yet.", pin, esp_err_to_name(r));
175185
} else if ( r == ESP_ERR_TIMEOUT ) {
@@ -178,9 +188,10 @@ uint16_t __analogRead(uint8_t pin)
178188
log_e("GPIO%u: %s", pin, esp_err_to_name(r));
179189
}
180190
} else {
181-
return adc1_get_raw(channel);
191+
value = adc1_get_raw(channel);
192+
return mapResolution(value);
182193
}
183-
return value;
194+
return mapResolution(value);
184195
}
185196

186197
uint32_t __analogReadMilliVolts(uint8_t pin){

Diff for: libraries/EEPROM/src/EEPROM.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ bool EEPROMClass::begin(size_t size) {
133133

134134
_data = (uint8_t*) malloc(size);
135135
if(!_data) {
136-
log_e("Not enough memory for %d bytes in EEPROM");
136+
log_e("Not enough memory for %d bytes in EEPROM", size);
137137
return false;
138138
}
139139
_size = size;

Diff for: libraries/WiFi/src/ETH.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,6 @@ bool ETHClass::begin(uint8_t phy_addr, int power, int mdc, int mdio, eth_phy_typ
237237
esp_netif_config_t cfg = ESP_NETIF_DEFAULT_ETH();
238238
esp_netif_t *eth_netif = esp_netif_new(&cfg);
239239

240-
if(esp_eth_set_default_handlers(eth_netif) != ESP_OK){
241-
log_e("esp_eth_set_default_handlers failed");
242-
return false;
243-
}
244-
245-
246240
esp_eth_mac_t *eth_mac = NULL;
247241
#if CONFIG_ETH_SPI_ETHERNET_DM9051
248242
if(type == ETH_PHY_DM9051){

0 commit comments

Comments
 (0)