mirror of
https://github.com/0xFEEDC0DE64/arduino-esp32.git
synced 2025-06-26 18:31:35 +02:00
When building the core with `-Wextra` a few locations have `case:` fall throughs or skipped field initializers. Add proper comments for B64 cases to avoid GCC warnings Initialized unused fields in Tone and WiFiGeneric to avoid missing field initializer warnings. ```` 2022-05-19T17:40:42.2280300Z /home/runner/arduino_ide/hardware/espressif/esp32/cores/esp32/libb64/cdecode.c: In function 'base64_decode_block_signed': 2022-05-19T17:40:42.2282122Z /home/runner/arduino_ide/hardware/espressif/esp32/cores/esp32/libb64/cdecode.c:42:23: warning: this statement may fall through [-Wimplicit-fallthrough=] 2022-05-19T17:40:42.2283247Z *plainchar = (fragment & 0x03f) << 2; 2022-05-19T17:40:42.2284240Z ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~ 2022-05-19T17:40:42.2285087Z /home/runner/arduino_ide/hardware/espressif/esp32/cores/esp32/libb64/cdecode.c:43:7: note: here 2022-05-19T17:40:42.2285435Z case step_b: 2022-05-19T17:40:42.2285691Z ^~~~ 2022-05-19T17:40:42.2286515Z /home/runner/arduino_ide/hardware/espressif/esp32/cores/esp32/libb64/cdecode.c:53:23: warning: this statement may fall through [-Wimplicit-fallthrough=] 2022-05-19T17:40:42.2286932Z *plainchar = (fragment & 0x00f) << 4; 2022-05-19T17:40:42.2287219Z ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~ 2022-05-19T17:40:42.2287609Z /home/runner/arduino_ide/hardware/espressif/esp32/cores/esp32/libb64/cdecode.c:54:7: note: here 2022-05-19T17:40:42.2287909Z case step_c: 2022-05-19T17:40:42.2288200Z ^~~~ 2022-05-19T17:40:42.2288972Z /home/runner/arduino_ide/hardware/espressif/esp32/cores/esp32/libb64/cdecode.c:64:23: warning: this statement may fall through [-Wimplicit-fallthrough=] 2022-05-19T17:40:42.2289491Z *plainchar = (fragment & 0x003) << 6; 2022-05-19T17:40:42.2289745Z ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~ 2022-05-19T17:40:42.2290162Z /home/runner/arduino_ide/hardware/espressif/esp32/cores/esp32/libb64/cdecode.c:65:7: note: here 2022-05-19T17:40:42.2290509Z case step_d: 2022-05-19T17:40:42.2290714Z ^~~~ 2022-05-19T17:40:42.2482744Z /home/runner/arduino_ide/hardware/espressif/esp32/cores/esp32/libb64/cencode.c: In function 'base64_encode_block': 2022-05-19T17:40:42.2484713Z /home/runner/arduino_ide/hardware/espressif/esp32/cores/esp32/libb64/cencode.c:46:20: warning: this statement may fall through [-Wimplicit-fallthrough=] 2022-05-19T17:40:42.2485415Z result = (fragment & 0x003) << 4; 2022-05-19T17:40:42.2486713Z ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~ 2022-05-19T17:40:42.2487696Z /home/runner/arduino_ide/hardware/espressif/esp32/cores/esp32/libb64/cencode.c:47:9: note: here 2022-05-19T17:40:42.2488519Z case step_B: 2022-05-19T17:40:42.2489175Z ^~~~ 2022-05-19T17:40:42.2492458Z /home/runner/arduino_ide/hardware/espressif/esp32/cores/esp32/libb64/cencode.c:56:20: warning: this statement may fall through [-Wimplicit-fallthrough=] 2022-05-19T17:40:42.2493351Z result = (fragment & 0x00f) << 2; 2022-05-19T17:40:42.2494227Z ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~ 2022-05-19T17:40:42.2496324Z /home/runner/arduino_ide/hardware/espressif/esp32/cores/esp32/libb64/cencode.c:57:9: note: here 2022-05-19T17:40:42.2496937Z case step_C: 2022-05-19T17:40:42.2497261Z ^~~~ 2022-05-19T17:40:44.6354962Z /home/runner/arduino_ide/hardware/espressif/esp32/cores/esp32/Tone.cpp: In function 'void setToneChannel(uint8_t)': 2022-05-19T17:40:44.6356417Z /home/runner/arduino_ide/hardware/espressif/esp32/cores/esp32/Tone.cpp:99:5: warning: missing initializer for member 'tone_msg_t::pin' [-Wmissing-field-initializers] 2022-05-19T17:40:44.6357120Z }; 2022-05-19T17:40:44.6358732Z ^ 2022-05-19T17:40:44.6364470Z /home/runner/arduino_ide/hardware/espressif/esp32/cores/esp32/Tone.cpp:99:5: warning: missing initializer for member 'tone_msg_t::frequency' [-Wmissing-field-initializers] 2022-05-19T17:40:44.6367914Z /home/runner/arduino_ide/hardware/espressif/esp32/cores/esp32/Tone.cpp:99:5: warning: missing initializer for member 'tone_msg_t::duration' [-Wmissing-field-initializers] 2022-05-19T17:40:44.6372875Z /home/runner/arduino_ide/hardware/espressif/esp32/cores/esp32/Tone.cpp: In function 'void noTone(uint8_t)': 2022-05-19T17:40:44.6373943Z /home/runner/arduino_ide/hardware/espressif/esp32/cores/esp32/Tone.cpp:110:5: warning: missing initializer for member 'tone_msg_t::frequency' [-Wmissing-field-initializers] 2022-05-19T17:40:44.6375154Z }; 2022-05-19T17:40:44.6375825Z ^ 2022-05-19T17:40:44.6379852Z /home/runner/arduino_ide/hardware/espressif/esp32/cores/esp32/Tone.cpp:110:5: warning: missing initializer for member 'tone_msg_t::duration' [-Wmissing-field-initializers] 2022-05-19T17:40:44.6383291Z /home/runner/arduino_ide/hardware/espressif/esp32/cores/esp32/Tone.cpp:110:5: warning: missing initializer for member 'tone_msg_t::channel' [-Wmissing-field-initializers] 2022-05-19T17:40:44.6388688Z /home/runner/arduino_ide/hardware/espressif/esp32/cores/esp32/Tone.cpp: In function 'void tone(uint8_t, unsigned int, long unsigned int)': 2022-05-19T17:40:44.6389829Z /home/runner/arduino_ide/hardware/espressif/esp32/cores/esp32/Tone.cpp:128:5: warning: missing initializer for member 'tone_msg_t::channel' [-Wmissing-field-initializers] 2022-05-19T17:40:44.6390677Z }; 2022-05-19T17:40:44.6391420Z ^ 2022-05-19T17:42:00.6768353Z /home/runner/arduino_ide/hardware/espressif/esp32/libraries/WiFi/src/WiFiGeneric.cpp: In static member function 'static bool WiFiGenericClass::setDualAntennaConfig(uint8_t, uint8_t, wifi_rx_ant_t, wifi_tx_ant_t)': 2022-05-19T17:42:00.6769293Z /home/runner/arduino_ide/hardware/espressif/esp32/libraries/WiFi/src/WiFiGeneric.cpp:1333:5: warning: missing initializer for member 'wifi_ant_config_t::rx_ant_default' [-Wmissing-field-initializers] 2022-05-19T17:42:00.6769658Z }; 2022-05-19T17:42:00.6769824Z ^ ````
139 lines
3.7 KiB
C++
139 lines
3.7 KiB
C++
#include <Arduino.h>
|
|
#include "esp32-hal-ledc.h"
|
|
#include "freertos/task.h"
|
|
#include "freertos/queue.h"
|
|
#include "freertos/semphr.h"
|
|
|
|
static TaskHandle_t _tone_task = NULL;
|
|
static QueueHandle_t _tone_queue = NULL;
|
|
static uint8_t _channel = 0;
|
|
|
|
typedef enum{
|
|
TONE_START,
|
|
TONE_END,
|
|
TONE_SET_CHANNEL
|
|
} tone_cmd_t;
|
|
|
|
typedef struct{
|
|
tone_cmd_t tone_cmd;
|
|
uint8_t pin;
|
|
unsigned int frequency;
|
|
unsigned long duration;
|
|
uint8_t channel;
|
|
} tone_msg_t;
|
|
|
|
static void tone_task(void*){
|
|
tone_msg_t tone_msg;
|
|
while(1){
|
|
xQueueReceive(_tone_queue, &tone_msg, portMAX_DELAY);
|
|
switch(tone_msg.tone_cmd){
|
|
case TONE_START:
|
|
log_d("Task received from queue TONE_START: _pin=%d, frequency=%u Hz, duration=%lu ms", tone_msg.pin, tone_msg.frequency, tone_msg.duration);
|
|
|
|
log_d("Setup LED controll on channel %d", _channel);
|
|
// ledcSetup(_channel, tone_msg.frequency, 11);
|
|
// ledcAttachPin(tone_msg.pin, _channel);
|
|
// ledcWrite(_channel, 1024);
|
|
ledcWriteTone(_channel, tone_msg.frequency);
|
|
ledcAttachPin(tone_msg.pin, _channel);
|
|
|
|
if(tone_msg.duration){
|
|
delay(tone_msg.duration);
|
|
ledcDetachPin(tone_msg.pin);
|
|
ledcWriteTone(_channel, 0);
|
|
}
|
|
break;
|
|
|
|
case TONE_END:
|
|
log_d("Task received from queue TONE_END: pin=%d", tone_msg.pin);
|
|
ledcDetachPin(tone_msg.pin);
|
|
ledcWriteTone(_channel, 0);
|
|
break;
|
|
|
|
case TONE_SET_CHANNEL:
|
|
log_d("Task received from queue TONE_SET_CHANNEL: channel=%d", tone_msg.channel);
|
|
_channel = tone_msg.channel;
|
|
break;
|
|
|
|
default: ; // do nothing
|
|
} // switch
|
|
} // infinite loop
|
|
}
|
|
|
|
static int tone_init(){
|
|
if(_tone_queue == NULL){
|
|
log_v("Creating tone queue");
|
|
_tone_queue = xQueueCreate(128, sizeof(tone_msg_t));
|
|
if(_tone_queue == NULL){
|
|
log_e("Could not create tone queue");
|
|
return 0; // ERR
|
|
}
|
|
log_v("Tone queue created");
|
|
}
|
|
|
|
if(_tone_task == NULL){
|
|
log_v("Creating tone task");
|
|
xTaskCreate(
|
|
tone_task, // Function to implement the task
|
|
"toneTask", // Name of the task
|
|
3500, // Stack size in words
|
|
NULL, // Task input parameter
|
|
1, // Priority of the task
|
|
&_tone_task // Task handle.
|
|
);
|
|
if(_tone_task == NULL){
|
|
log_e("Could not create tone task");
|
|
return 0; // ERR
|
|
}
|
|
log_v("Tone task created");
|
|
}
|
|
return 1; // OK
|
|
}
|
|
|
|
void setToneChannel(uint8_t channel){
|
|
log_d("channel=%d", channel);
|
|
if(tone_init()){
|
|
tone_msg_t tone_msg = {
|
|
.tone_cmd = TONE_SET_CHANNEL,
|
|
.pin = 0, // Ignored
|
|
.frequency = 0, // Ignored
|
|
.duration = 0, // Ignored
|
|
.channel = channel
|
|
};
|
|
xQueueSend(_tone_queue, &tone_msg, portMAX_DELAY);
|
|
}
|
|
}
|
|
|
|
void noTone(uint8_t _pin){
|
|
log_d("noTone was called");
|
|
if(tone_init()){
|
|
tone_msg_t tone_msg = {
|
|
.tone_cmd = TONE_END,
|
|
.pin = _pin,
|
|
.frequency = 0, // Ignored
|
|
.duration = 0, // Ignored
|
|
.channel = 0 // Ignored
|
|
};
|
|
xQueueSend(_tone_queue, &tone_msg, portMAX_DELAY);
|
|
}
|
|
}
|
|
|
|
// parameters:
|
|
// _pin - pin number which will output the signal
|
|
// frequency - PWM frequency in Hz
|
|
// duration - time in ms - how long will the signal be outputted.
|
|
// If not provided, or 0 you must manually call noTone to end output
|
|
void tone(uint8_t _pin, unsigned int frequency, unsigned long duration){
|
|
log_d("_pin=%d, frequency=%u Hz, duration=%lu ms", _pin, frequency, duration);
|
|
if(tone_init()){
|
|
tone_msg_t tone_msg = {
|
|
.tone_cmd = TONE_START,
|
|
.pin = _pin,
|
|
.frequency = frequency,
|
|
.duration = duration,
|
|
.channel = 0 // Ignored
|
|
};
|
|
xQueueSend(_tone_queue, &tone_msg, portMAX_DELAY);
|
|
}
|
|
}
|