Skip to content

Commit 0baeb19

Browse files
authored
Merge pull request #141 from espressif/master
Update 27052022
2 parents d4b230d + 3e8f7fe commit 0baeb19

File tree

15 files changed

+116
-111
lines changed

15 files changed

+116
-111
lines changed

.github/workflows/upload-idf-component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Push components to https://components.espressif.com
22
on:
33
push:
44
tags:
5-
- *
5+
- '*'
66
jobs:
77
upload_components:
88
runs-on: ubuntu-latest

cores/esp32/Tone.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ void setToneChannel(uint8_t channel){
9595
if(tone_init()){
9696
tone_msg_t tone_msg = {
9797
.tone_cmd = TONE_SET_CHANNEL,
98+
.pin = 0, // Ignored
99+
.frequency = 0, // Ignored
100+
.duration = 0, // Ignored
98101
.channel = channel
99102
};
100103
xQueueSend(_tone_queue, &tone_msg, portMAX_DELAY);
@@ -106,7 +109,10 @@ void noTone(uint8_t _pin){
106109
if(tone_init()){
107110
tone_msg_t tone_msg = {
108111
.tone_cmd = TONE_END,
109-
.pin = _pin
112+
.pin = _pin,
113+
.frequency = 0, // Ignored
114+
.duration = 0, // Ignored
115+
.channel = 0 // Ignored
110116
};
111117
xQueueSend(_tone_queue, &tone_msg, portMAX_DELAY);
112118
}
@@ -124,7 +130,8 @@ void tone(uint8_t _pin, unsigned int frequency, unsigned long duration){
124130
.tone_cmd = TONE_START,
125131
.pin = _pin,
126132
.frequency = frequency,
127-
.duration = duration
133+
.duration = duration,
134+
.channel = 0 // Ignored
128135
};
129136
xQueueSend(_tone_queue, &tone_msg, portMAX_DELAY);
130137
}

cores/esp32/esp32-hal-adc.c

Lines changed: 45 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -13,50 +13,28 @@
1313
// limitations under the License.
1414

1515
#include "esp32-hal-adc.h"
16-
#include "freertos/FreeRTOS.h"
17-
#include "freertos/task.h"
18-
#include "esp_attr.h"
19-
#include "soc/rtc_cntl_reg.h"
2016
#include "driver/adc.h"
21-
22-
#include "esp_system.h"
23-
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
24-
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
2517
#include "esp_adc_cal.h"
26-
#include "soc/sens_reg.h"
27-
#include "soc/rtc_io_reg.h"
28-
#include "esp32/rom/ets_sys.h"
29-
#include "esp_intr_alloc.h"
30-
#include "soc/dac_channel.h"
31-
#define DEFAULT_VREF 1100
32-
static esp_adc_cal_characteristics_t *__analogCharacteristics[2] = {NULL, NULL};
33-
static uint16_t __analogVRef = 0;
34-
static uint8_t __analogVRefPin = 0;
35-
#elif CONFIG_IDF_TARGET_ESP32S2
36-
#include "esp32s2/rom/ets_sys.h"
37-
#include "soc/sens_reg.h"
38-
#include "soc/rtc_io_reg.h"
18+
19+
#if SOC_DAC_SUPPORTED //ESP32, ESP32S2
3920
#include "soc/dac_channel.h"
40-
#elif CONFIG_IDF_TARGET_ESP32S3
41-
#include "esp32s3/rom/ets_sys.h"
4221
#include "soc/sens_reg.h"
4322
#include "soc/rtc_io_reg.h"
44-
#elif CONFIG_IDF_TARGET_ESP32C3
45-
#include "esp32c3/rom/ets_sys.h"
46-
#else
47-
#error Target CONFIG_IDF_TARGET is not supported
48-
#endif
49-
#else // ESP32 Before IDF 4.0
50-
#include "rom/ets_sys.h"
51-
#include "esp_intr.h"
5223
#endif
5324

25+
#define DEFAULT_VREF 1100
26+
5427
static uint8_t __analogAttenuation = 3;//11db
5528
static uint8_t __analogWidth = ADC_WIDTH_MAX - 1; //3 for ESP32/ESP32C3; 4 for ESP32S2
5629
static uint8_t __analogReturnedWidth = SOC_ADC_MAX_BITWIDTH; //12 for ESP32/ESP32C3; 13 for ESP32S2
5730
static uint8_t __analogClockDiv = 1;
5831
static adc_attenuation_t __pin_attenuation[SOC_GPIO_PIN_COUNT];
5932

33+
static uint16_t __analogVRef = 0;
34+
#if CONFIG_IDF_TARGET_ESP32
35+
static uint8_t __analogVRefPin = 0;
36+
#endif
37+
6038
static inline uint16_t mapResolution(uint16_t value)
6139
{
6240
uint8_t from = __analogWidth + 9;
@@ -117,8 +95,8 @@ void __analogSetPinAttenuation(uint8_t pin, adc_attenuation_t attenuation)
11795
if(channel < 0 || attenuation > 3){
11896
return ;
11997
}
120-
if(channel > 9){
121-
adc2_config_channel_atten(channel - 10, attenuation);
98+
if(channel > (SOC_ADC_MAX_CHANNEL_NUM - 1)){
99+
adc2_config_channel_atten(channel - SOC_ADC_MAX_CHANNEL_NUM, attenuation);
122100
} else {
123101
adc1_config_channel_atten(channel, attenuation);
124102
}
@@ -181,8 +159,8 @@ uint16_t __analogRead(uint8_t pin)
181159
return value;
182160
}
183161
__adcAttachPin(pin);
184-
if(channel > 9){
185-
channel -= 10;
162+
if(channel > (SOC_ADC_MAX_CHANNEL_NUM - 1)){
163+
channel -= SOC_ADC_MAX_CHANNEL_NUM;
186164
r = adc2_get_raw( channel, __analogWidth, &value);
187165
if ( r == ESP_OK ) {
188166
return mapResolution(value);
@@ -206,7 +184,7 @@ uint32_t __analogReadMilliVolts(uint8_t pin){
206184
log_e("Pin %u is not ADC pin!", pin);
207185
return 0;
208186
}
209-
#if CONFIG_IDF_TARGET_ESP32
187+
210188
if(!__analogVRef){
211189
if (esp_adc_cal_check_efuse(ESP_ADC_CAL_VAL_EFUSE_TP) == ESP_OK) {
212190
log_d("eFuse Two Point: Supported");
@@ -218,6 +196,8 @@ uint32_t __analogReadMilliVolts(uint8_t pin){
218196
}
219197
if(!__analogVRef){
220198
__analogVRef = DEFAULT_VREF;
199+
200+
#if CONFIG_IDF_TARGET_ESP32
221201
if(__analogVRefPin){
222202
esp_adc_cal_characteristics_t chars;
223203
if(adc_vref_to_gpio(ADC_UNIT_2, __analogVRefPin) == ESP_OK){
@@ -227,42 +207,44 @@ uint32_t __analogReadMilliVolts(uint8_t pin){
227207
log_d("Vref to GPIO%u: %u", __analogVRefPin, __analogVRef);
228208
}
229209
}
210+
#endif
230211
}
231212
}
232213
uint8_t unit = 1;
233-
if(channel > 9){
214+
if(channel > (SOC_ADC_MAX_CHANNEL_NUM - 1)){
234215
unit = 2;
235216
}
217+
236218
uint16_t adc_reading = __analogRead(pin);
237-
if(__analogCharacteristics[unit - 1] == NULL){
238-
__analogCharacteristics[unit - 1] = calloc(1, sizeof(esp_adc_cal_characteristics_t));
239-
if(__analogCharacteristics[unit - 1] == NULL){
240-
return 0;
241-
}
242-
esp_adc_cal_value_t val_type = esp_adc_cal_characterize(unit, __analogAttenuation, __analogWidth, __analogVRef, __analogCharacteristics[unit - 1]);
219+
220+
uint8_t atten = __analogAttenuation;
221+
if (__pin_attenuation[pin] != ADC_ATTENDB_MAX){
222+
atten = __pin_attenuation[pin];
223+
}
224+
225+
esp_adc_cal_characteristics_t chars = {};
226+
esp_adc_cal_value_t val_type = esp_adc_cal_characterize(unit, atten, __analogWidth, __analogVRef, &chars);
227+
228+
static bool print_chars_info = true;
229+
if(print_chars_info)
230+
{
243231
if (val_type == ESP_ADC_CAL_VAL_EFUSE_TP) {
244-
log_i("ADC%u: Characterized using Two Point Value: %u\n", unit, __analogCharacteristics[unit - 1]->vref);
245-
} else if (val_type == ESP_ADC_CAL_VAL_EFUSE_VREF) {
246-
log_i("ADC%u: Characterized using eFuse Vref: %u\n", unit, __analogCharacteristics[unit - 1]->vref);
247-
} else if(__analogVRef != DEFAULT_VREF){
248-
log_i("ADC%u: Characterized using Vref to GPIO%u: %u\n", unit, __analogVRefPin, __analogCharacteristics[unit - 1]->vref);
249-
} else {
250-
log_i("ADC%u: Characterized using Default Vref: %u\n", unit, __analogCharacteristics[unit - 1]->vref);
232+
log_i("ADC%u: Characterized using Two Point Value: %u\n", unit, chars.vref);
233+
}
234+
else if (val_type == ESP_ADC_CAL_VAL_EFUSE_VREF) {
235+
log_i("ADC%u: Characterized using eFuse Vref: %u\n", unit, chars.vref);
236+
}
237+
#if CONFIG_IDF_TARGET_ESP32
238+
else if(__analogVRef != DEFAULT_VREF){
239+
log_i("ADC%u: Characterized using Vref to GPIO%u: %u\n", unit, __analogVRefPin, chars.vref);
251240
}
241+
#endif
242+
else {
243+
log_i("ADC%u: Characterized using Default Vref: %u\n", unit, chars.vref);
244+
}
245+
print_chars_info = false;
252246
}
253-
return esp_adc_cal_raw_to_voltage(adc_reading, __analogCharacteristics[unit - 1]);
254-
#else
255-
uint16_t adc_reading = __analogRead(pin);
256-
uint16_t max_reading = 8191;
257-
uint16_t max_mv = 1100;
258-
switch(__analogAttenuation){
259-
case 3: max_mv = 3900; break;
260-
case 2: max_mv = 2200; break;
261-
case 1: max_mv = 1500; break;
262-
default: break;
263-
}
264-
return (adc_reading * max_mv) / max_reading;
265-
#endif
247+
return esp_adc_cal_raw_to_voltage((uint32_t)adc_reading, &chars);
266248
}
267249

268250
#if CONFIG_IDF_TARGET_ESP32
@@ -297,4 +279,3 @@ extern void analogSetVRefPin(uint8_t pin) __attribute__ ((weak, alias("__analogS
297279
extern void analogSetWidth(uint8_t bits) __attribute__ ((weak, alias("__analogSetWidth")));
298280
extern int hallRead() __attribute__ ((weak, alias("__hallRead")));
299281
#endif
300-

cores/esp32/esp32-hal-timer.c

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@ typedef union {
3232

3333
#define NUM_OF_TIMERS SOC_TIMER_GROUP_TOTAL_TIMERS
3434

35-
typedef struct {
36-
int timer_group;
37-
int timer_idx;
38-
int alarm_interval;
39-
bool auto_reload;
40-
} timer_info_t;
41-
4235
typedef struct hw_timer_s
4336
{
4437
uint8_t group;
@@ -194,7 +187,7 @@ static void _on_apb_change(void * arg, apb_change_ev_t ev_type, uint32_t old_apb
194187
hw_timer_t * timerBegin(uint8_t num, uint16_t divider, bool countUp){
195188
if(num >= NUM_OF_TIMERS)
196189
{
197-
log_e("Timer dont have that timer number.");
190+
log_e("Timer number %u exceeds available number of Timers.", num);
198191
return NULL;
199192
}
200193

@@ -220,24 +213,23 @@ void timerEnd(hw_timer_t *timer){
220213
timer_deinit(timer->group, timer->num);
221214
}
222215

216+
bool IRAM_ATTR timerFnWrapper(void *arg){
217+
void (*fn)(void) = arg;
218+
fn();
219+
220+
// some additional logic or handling may be required here to approriately yield or not
221+
return false;
222+
}
223+
223224
void timerAttachInterrupt(hw_timer_t *timer, void (*fn)(void), bool edge){
224225
if(edge){
225226
log_w("EDGE timer interrupt is not supported! Setting to LEVEL...");
226-
edge = false;
227227
}
228-
timer_enable_intr(timer->group, timer->num);
229-
230-
timer_info_t *timer_info = calloc(1, sizeof(timer_info_t));
231-
timer_info->timer_group = timer->group;
232-
timer_info->timer_idx = timer->num;
233-
timer_info->auto_reload = timerGetAutoReload(timer);
234-
timer_info->alarm_interval = timerAlarmRead(timer);
235-
236-
timer_isr_callback_add(timer->group, timer->num, (timer_isr_t)fn, timer_info, 0);
228+
timer_isr_callback_add(timer->group, timer->num, timerFnWrapper, fn, 0);
237229
}
238230

239231
void timerDetachInterrupt(hw_timer_t *timer){
240-
timerAttachInterrupt(timer, NULL, false);
232+
timer_isr_callback_remove(timer->group, timer->num);
241233
}
242234

243235
uint64_t timerReadMicros(hw_timer_t *timer){

cores/esp32/libb64/cdecode.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ static int base64_decode_block_signed(const int8_t* code_in, const int length_in
4040
fragment = (int8_t)base64_decode_value_signed(*codechar++);
4141
} while (fragment < 0);
4242
*plainchar = (fragment & 0x03f) << 2;
43+
// fall through
4344
case step_b:
4445
do {
4546
if (codechar == code_in+length_in){
@@ -51,6 +52,7 @@ static int base64_decode_block_signed(const int8_t* code_in, const int length_in
5152
} while (fragment < 0);
5253
*plainchar++ |= (fragment & 0x030) >> 4;
5354
*plainchar = (fragment & 0x00f) << 4;
55+
// fall through
5456
case step_c:
5557
do {
5658
if (codechar == code_in+length_in){
@@ -62,6 +64,7 @@ static int base64_decode_block_signed(const int8_t* code_in, const int length_in
6264
} while (fragment < 0);
6365
*plainchar++ |= (fragment & 0x03c) >> 2;
6466
*plainchar = (fragment & 0x003) << 6;
67+
// fall through
6568
case step_d:
6669
do {
6770
if (codechar == code_in+length_in){

cores/esp32/libb64/cencode.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ int base64_encode_block(const char* plaintext_in, int length_in, char* code_out,
4444
result = (fragment & 0x0fc) >> 2;
4545
*codechar++ = base64_encode_value(result);
4646
result = (fragment & 0x003) << 4;
47+
// fall through
4748
case step_B:
4849
if (plainchar == plaintextend) {
4950
state_in->result = result;
@@ -54,6 +55,7 @@ int base64_encode_block(const char* plaintext_in, int length_in, char* code_out,
5455
result |= (fragment & 0x0f0) >> 4;
5556
*codechar++ = base64_encode_value(result);
5657
result = (fragment & 0x00f) << 2;
58+
// fall through
5759
case step_C:
5860
if (plainchar == plaintextend) {
5961
state_in->result = result;

libraries/BluetoothSerial/src/BluetoothSerial.cpp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,8 @@ bool BluetoothSerial::setPin(const char *pin) {
921921

922922
bool BluetoothSerial::connect(String remoteName)
923923
{
924+
bool retval = false;
925+
924926
if (!isReady(true, READY_TIMEOUT)) return false;
925927
if (remoteName && remoteName.length() < 1) {
926928
log_e("No remote name is provided");
@@ -942,9 +944,12 @@ bool BluetoothSerial::connect(String remoteName)
942944
#endif
943945
xEventGroupClearBits(_spp_event_group, SPP_CLOSED);
944946
if (esp_bt_gap_start_discovery(ESP_BT_INQ_MODE_GENERAL_INQUIRY, INQ_LEN, INQ_NUM_RSPS) == ESP_OK) {
945-
return waitForConnect(SCAN_TIMEOUT);
947+
retval = waitForConnect(SCAN_TIMEOUT);
946948
}
947-
return false;
949+
if (retval == false) {
950+
_isRemoteAddressSet = false;
951+
}
952+
return retval;
948953
}
949954

950955
/**
@@ -958,6 +963,7 @@ bool BluetoothSerial::connect(String remoteName)
958963
*/
959964
bool BluetoothSerial::connect(uint8_t remoteAddress[], int channel, esp_spp_sec_t sec_mask, esp_spp_role_t role)
960965
{
966+
bool retval = false;
961967
if (!isReady(true, READY_TIMEOUT)) return false;
962968
if (!remoteAddress) {
963969
log_e("No remote address is provided");
@@ -981,10 +987,10 @@ bool BluetoothSerial::connect(uint8_t remoteAddress[], int channel, esp_spp_sec_
981987
#endif
982988
if(esp_spp_connect(sec_mask, role, channel, _peer_bd_addr) != ESP_OK ) {
983989
log_e("spp connect failed");
984-
return false;
985-
}
986-
bool rc=waitForConnect(READY_TIMEOUT);
987-
if(rc) {
990+
retval = false;
991+
} else {
992+
retval = waitForConnect(READY_TIMEOUT);
993+
if(retval) {
988994
log_i("connected");
989995
} else {
990996
if(this->isClosed()) {
@@ -993,12 +999,15 @@ bool BluetoothSerial::connect(uint8_t remoteAddress[], int channel, esp_spp_sec_
993999
log_e("connect timed out after %dms", READY_TIMEOUT);
9941000
}
9951001
}
996-
return rc;
9971002
}
998-
if (esp_spp_start_discovery(_peer_bd_addr) == ESP_OK) {
999-
return waitForConnect(READY_TIMEOUT);
1003+
} else if (esp_spp_start_discovery(_peer_bd_addr) == ESP_OK) {
1004+
retval = waitForConnect(READY_TIMEOUT);
1005+
}
1006+
1007+
if (!retval) {
1008+
_isRemoteAddressSet = false;
10001009
}
1001-
return false;
1010+
return retval;
10021011
}
10031012

10041013
bool BluetoothSerial::connect()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Import("env")
2-
env.Replace( MKSPIFFSTOOL=env.get("PROJECT_DIR") + '/mklittlefs' )
2+
env.Replace( MKSPIFFSTOOL=env.get("PROJECT_DIR") + '/mklittlefs' ) # PlatformIO now believes it has actually created a SPIFFS

0 commit comments

Comments
 (0)