Skip to content

Commit f56dbf8

Browse files
authored
Merge branch 'master' into master
2 parents 0ce9074 + 097ff8b commit f56dbf8

22 files changed

+339
-317
lines changed

Diff for: CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ set(CORE_SRCS
3636
cores/esp32/esp32-hal-matrix.c
3737
cores/esp32/esp32-hal-misc.c
3838
cores/esp32/esp32-hal-psram.c
39+
cores/esp32/esp32-hal-rgb-led.c
3940
cores/esp32/esp32-hal-sigmadelta.c
4041
cores/esp32/esp32-hal-spi.c
4142
cores/esp32/esp32-hal-time.c

Diff for: cores/esp32/Tone.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,8 @@ static void tone_task(void*){
3131
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);
3232

3333
log_d("Setup LED controll on channel %d", _channel);
34-
// ledcSetup(_channel, tone_msg.frequency, 11);
35-
// ledcAttachPin(tone_msg.pin, _channel);
36-
// ledcWrite(_channel, 1024);
37-
ledcWriteTone(_channel, tone_msg.frequency);
3834
ledcAttachPin(tone_msg.pin, _channel);
35+
ledcWriteTone(_channel, tone_msg.frequency);
3936

4037
if(tone_msg.duration){
4138
delay(tone_msg.duration);

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

+15
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ static InterruptHandle_t __pinInterruptHandlers[SOC_GPIO_PIN_COUNT] = {0,};
9191

9292
extern void ARDUINO_ISR_ATTR __pinMode(uint8_t pin, uint8_t mode)
9393
{
94+
#ifdef BOARD_HAS_NEOPIXEL
95+
if (pin == LED_BUILTIN){
96+
__pinMode(LED_BUILTIN-SOC_GPIO_PIN_COUNT, mode);
97+
return;
98+
}
99+
#endif
100+
94101
if (!GPIO_IS_VALID_GPIO(pin)) {
95102
log_e("Invalid pin selected");
96103
return;
@@ -127,6 +134,14 @@ extern void ARDUINO_ISR_ATTR __pinMode(uint8_t pin, uint8_t mode)
127134

128135
extern void ARDUINO_ISR_ATTR __digitalWrite(uint8_t pin, uint8_t val)
129136
{
137+
#ifdef BOARD_HAS_NEOPIXEL
138+
if(pin == LED_BUILTIN){
139+
//use RMT to set all channels on/off
140+
const uint8_t comm_val = val != 0 ? LED_BRIGHTNESS : 0;
141+
neopixelWrite(LED_BUILTIN, comm_val, comm_val, comm_val);
142+
return;
143+
}
144+
#endif
130145
gpio_set_level((gpio_num_t)pin, val);
131146
}
132147

Diff for: cores/esp32/esp32-hal-gpio.h

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ extern "C" {
2626

2727
#include "esp32-hal.h"
2828
#include "soc/soc_caps.h"
29+
#include "pins_arduino.h"
2930

3031
#if (CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3)
3132
#define NUM_OUPUT_PINS 46
@@ -63,6 +64,7 @@ extern "C" {
6364
#define ONLOW_WE 0x0C
6465
#define ONHIGH_WE 0x0D
6566

67+
6668
#define digitalPinIsValid(pin) GPIO_IS_VALID_GPIO(pin)
6769
#define digitalPinCanOutput(pin) GPIO_IS_VALID_OUTPUT_GPIO(pin)
6870

Diff for: cores/esp32/esp32-hal-rgb-led.c

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include "esp32-hal-rgb-led.h"
2+
3+
4+
void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val){
5+
rmt_data_t led_data[24];
6+
static rmt_obj_t* rmt_send = NULL;
7+
static bool initialized = false;
8+
9+
uint8_t _pin = pin;
10+
#ifdef BOARD_HAS_NEOPIXEL
11+
if(pin == LED_BUILTIN){
12+
_pin = LED_BUILTIN-SOC_GPIO_PIN_COUNT;
13+
}
14+
#endif
15+
16+
if(!initialized){
17+
if((rmt_send = rmtInit(_pin, RMT_TX_MODE, RMT_MEM_64)) == NULL){
18+
log_e("RGB LED driver initialization failed!");
19+
rmt_send = NULL;
20+
return;
21+
}
22+
rmtSetTick(rmt_send, 100);
23+
initialized = true;
24+
}
25+
26+
int color[] = {green_val, red_val, blue_val}; // Color coding is in order GREEN, RED, BLUE
27+
int i = 0;
28+
for(int col=0; col<3; col++ ){
29+
for(int bit=0; bit<8; bit++){
30+
if((color[col] & (1<<(7-bit)))){
31+
// HIGH bit
32+
led_data[i].level0 = 1; // T1H
33+
led_data[i].duration0 = 8; // 0.8us
34+
led_data[i].level1 = 0; // T1L
35+
led_data[i].duration1 = 4; // 0.4us
36+
}else{
37+
// LOW bit
38+
led_data[i].level0 = 1; // T0H
39+
led_data[i].duration0 = 4; // 0.4us
40+
led_data[i].level1 = 0; // T0L
41+
led_data[i].duration1 = 8; // 0.8us
42+
}
43+
i++;
44+
}
45+
}
46+
rmtWrite(rmt_send, led_data, 24);
47+
}

Diff for: cores/esp32/esp32-hal-rgb-led.h

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef MAIN_ESP32_HAL_RGB_LED_H_
2+
#define MAIN_ESP32_HAL_RGB_LED_H_
3+
4+
#ifdef __cplusplus
5+
extern "C" {
6+
#endif
7+
8+
#include "esp32-hal.h"
9+
10+
#ifndef LED_BRIGHTNESS
11+
#define LED_BRIGHTNESS 64
12+
#endif
13+
14+
void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val);
15+
16+
#ifdef __cplusplus
17+
}
18+
#endif
19+
20+
#endif /* MAIN_ESP32_HAL_RGB_LED_H_ */

Diff for: cores/esp32/esp32-hal.h

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ void yield(void);
8888
#include "esp32-hal-timer.h"
8989
#include "esp32-hal-bt.h"
9090
#include "esp32-hal-psram.h"
91+
#include "esp32-hal-rgb-led.h"
9192
#include "esp32-hal-cpu.h"
9293

9394
void analogWrite(uint8_t pin, int value);

Diff for: libraries/BLE/src/BLERemoteDescriptor.cpp

+19-2
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,26 @@ BLEUUID BLERemoteDescriptor::getUUID() {
5151

5252
void BLERemoteDescriptor::gattClientEventHandler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t* evtParam) {
5353
switch(event) {
54+
// ESP_GATTC_READ_DESCR_EVT
55+
// This event indicates that the server has responded to the read request.
56+
//
57+
// read:
58+
// - esp_gatt_status_t status
59+
// - uint16_t conn_id
60+
// - uint16_t handle
61+
// - uint8_t* value
62+
// - uint16_t value_len
5463
case ESP_GATTC_READ_DESCR_EVT:
55-
if (evtParam->read.handle != getHandle())
56-
break;
64+
// If this event is not for us, then nothing further to do.
65+
if (evtParam->read.handle != getHandle()) break;
66+
// At this point, we have determined that the event is for us, so now we save the value
67+
if (evtParam->read.status == ESP_GATT_OK) {
68+
// it will read the cached value of the descriptor
69+
m_value = std::string((char*) evtParam->read.value, evtParam->read.value_len);
70+
} else {
71+
m_value = "";
72+
}
73+
// Unlock the semaphore to ensure that the requestor of the data can continue.
5774
m_semaphoreReadDescrEvt.give();
5875
break;
5976

Diff for: libraries/BLE/src/BLEUtils.cpp

+17-17
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ typedef struct {
3636
} member_t;
3737

3838
static const member_t members_ids[] = {
39-
#if CONFIG_LOG_DEFAULT_LEVEL > 4
39+
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
4040
{0xFE08, "Microsoft"},
4141
{0xFE09, "Pillsy, Inc."},
4242
{0xFE0A, "ruwido austria gmbh"},
@@ -296,7 +296,7 @@ typedef struct {
296296
} gattdescriptor_t;
297297

298298
static const gattdescriptor_t g_descriptor_ids[] = {
299-
#if CONFIG_LOG_DEFAULT_LEVEL > 4
299+
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
300300
{0x2905,"Characteristic Aggregate Format"},
301301
{0x2900,"Characteristic Extended Properties"},
302302
{0x2904,"Characteristic Presentation Format"},
@@ -322,7 +322,7 @@ typedef struct {
322322
} characteristicMap_t;
323323

324324
static const characteristicMap_t g_characteristicsMappings[] = {
325-
#if CONFIG_LOG_DEFAULT_LEVEL > 4
325+
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
326326
{0x2A7E,"Aerobic Heart Rate Lower Limit"},
327327
{0x2A84,"Aerobic Heart Rate Upper Limit"},
328328
{0x2A7F,"Aerobic Threshold"},
@@ -557,7 +557,7 @@ typedef struct {
557557
* Definition of the service ids to names that we know about.
558558
*/
559559
static const gattService_t g_gattServices[] = {
560-
#if CONFIG_LOG_DEFAULT_LEVEL > 4
560+
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
561561
{"Alert Notification Service", "org.bluetooth.service.alert_notification", 0x1811},
562562
{"Automation IO", "org.bluetooth.service.automation_io", 0x1815 },
563563
{"Battery Service","org.bluetooth.service.battery_service", 0x180F},
@@ -638,7 +638,7 @@ static std::string gattIdToString(esp_gatt_id_t gattId) {
638638
*/
639639
const char* BLEUtils::addressTypeToString(esp_ble_addr_type_t type) {
640640
switch (type) {
641-
#if CONFIG_LOG_DEFAULT_LEVEL > 4
641+
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
642642
case BLE_ADDR_TYPE_PUBLIC:
643643
return "BLE_ADDR_TYPE_PUBLIC";
644644
case BLE_ADDR_TYPE_RANDOM:
@@ -690,7 +690,7 @@ std::string BLEUtils::adFlagsToString(uint8_t adFlags) {
690690
*/
691691
const char* BLEUtils::advTypeToString(uint8_t advType) {
692692
switch (advType) {
693-
#if CONFIG_LOG_DEFAULT_LEVEL > 4
693+
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
694694
case ESP_BLE_AD_TYPE_FLAG: // 0x01
695695
return "ESP_BLE_AD_TYPE_FLAG";
696696
case ESP_BLE_AD_TYPE_16SRV_PART: // 0x02
@@ -825,7 +825,7 @@ std::string BLEUtils::buildPrintData(uint8_t* source, size_t length) {
825825
*/
826826
std::string BLEUtils::gattCloseReasonToString(esp_gatt_conn_reason_t reason) {
827827
switch (reason) {
828-
#if CONFIG_LOG_DEFAULT_LEVEL > 4
828+
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
829829
case ESP_GATT_CONN_UNKNOWN: {
830830
return "ESP_GATT_CONN_UNKNOWN";
831831
}
@@ -863,7 +863,7 @@ std::string BLEUtils::gattCloseReasonToString(esp_gatt_conn_reason_t reason) {
863863

864864
std::string BLEUtils::gattClientEventTypeToString(esp_gattc_cb_event_t eventType) {
865865
switch (eventType) {
866-
#if CONFIG_LOG_DEFAULT_LEVEL > 4
866+
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
867867
case ESP_GATTC_ACL_EVT:
868868
return "ESP_GATTC_ACL_EVT";
869869
case ESP_GATTC_ADV_DATA_EVT:
@@ -961,7 +961,7 @@ std::string BLEUtils::gattClientEventTypeToString(esp_gattc_cb_event_t eventType
961961
*/
962962
std::string BLEUtils::gattServerEventTypeToString(esp_gatts_cb_event_t eventType) {
963963
switch (eventType) {
964-
#if CONFIG_LOG_DEFAULT_LEVEL > 4
964+
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
965965
case ESP_GATTS_REG_EVT:
966966
return "ESP_GATTS_REG_EVT";
967967
case ESP_GATTS_READ_EVT:
@@ -1026,7 +1026,7 @@ std::string BLEUtils::gattServerEventTypeToString(esp_gatts_cb_event_t eventType
10261026
*/
10271027
const char* BLEUtils::devTypeToString(esp_bt_dev_type_t type) {
10281028
switch (type) {
1029-
#if CONFIG_LOG_DEFAULT_LEVEL > 4
1029+
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
10301030
case ESP_BT_DEVICE_TYPE_BREDR:
10311031
return "ESP_BT_DEVICE_TYPE_BREDR";
10321032
case ESP_BT_DEVICE_TYPE_BLE:
@@ -1048,7 +1048,7 @@ void BLEUtils::dumpGapEvent(
10481048
esp_ble_gap_cb_param_t* param) {
10491049
log_v("Received a GAP event: %s", gapEventToString(event));
10501050
switch (event) {
1051-
#if CONFIG_LOG_DEFAULT_LEVEL > 4
1051+
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
10521052
// ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT
10531053
// adv_data_cmpl
10541054
// - esp_bt_status_t
@@ -1282,7 +1282,7 @@ void BLEUtils::dumpGattClientEvent(
12821282
//esp_ble_gattc_cb_param_t* evtParam = (esp_ble_gattc_cb_param_t*) param;
12831283
log_v("GATT Event: %s", BLEUtils::gattClientEventTypeToString(event).c_str());
12841284
switch (event) {
1285-
#if CONFIG_LOG_DEFAULT_LEVEL > 4
1285+
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
12861286
// ESP_GATTC_CLOSE_EVT
12871287
//
12881288
// close:
@@ -1529,7 +1529,7 @@ void BLEUtils::dumpGattServerEvent(
15291529
esp_ble_gatts_cb_param_t* evtParam) {
15301530
log_v("GATT ServerEvent: %s", BLEUtils::gattServerEventTypeToString(event).c_str());
15311531
switch (event) {
1532-
#if CONFIG_LOG_DEFAULT_LEVEL > 4
1532+
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
15331533

15341534
case ESP_GATTS_ADD_CHAR_DESCR_EVT: {
15351535
log_v("[status: %s, attr_handle: %d 0x%.2x, service_handle: %d 0x%.2x, char_uuid: %s]",
@@ -1730,7 +1730,7 @@ void BLEUtils::dumpGattServerEvent(
17301730
*/
17311731
const char* BLEUtils::eventTypeToString(esp_ble_evt_type_t eventType) {
17321732
switch (eventType) {
1733-
#if CONFIG_LOG_DEFAULT_LEVEL > 4
1733+
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
17341734
case ESP_BLE_EVT_CONN_ADV:
17351735
return "ESP_BLE_EVT_CONN_ADV";
17361736
case ESP_BLE_EVT_CONN_DIR_ADV:
@@ -1757,7 +1757,7 @@ const char* BLEUtils::eventTypeToString(esp_ble_evt_type_t eventType) {
17571757
*/
17581758
const char* BLEUtils::gapEventToString(uint32_t eventType) {
17591759
switch (eventType) {
1760-
#if CONFIG_LOG_DEFAULT_LEVEL > 4
1760+
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
17611761
case ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT:
17621762
return "ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT";
17631763
case ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT:
@@ -1901,7 +1901,7 @@ std::string BLEUtils::gattServiceToString(uint32_t serviceId) {
19011901
*/
19021902
std::string BLEUtils::gattStatusToString(esp_gatt_status_t status) {
19031903
switch (status) {
1904-
#if CONFIG_LOG_DEFAULT_LEVEL > 4
1904+
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
19051905
case ESP_GATT_OK:
19061906
return "ESP_GATT_OK";
19071907
case ESP_GATT_INVALID_HANDLE:
@@ -2015,7 +2015,7 @@ std::string BLEUtils::getMember(uint32_t memberId) {
20152015
*/
20162016
const char* BLEUtils::searchEventTypeToString(esp_gap_search_evt_t searchEvt) {
20172017
switch (searchEvt) {
2018-
#if CONFIG_LOG_DEFAULT_LEVEL > 4
2018+
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
20192019
case ESP_GAP_SEARCH_INQ_RES_EVT:
20202020
return "ESP_GAP_SEARCH_INQ_RES_EVT";
20212021
case ESP_GAP_SEARCH_INQ_CMPL_EVT:

Diff for: libraries/BLE/src/GeneralUtils.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ std::vector<std::string> GeneralUtils::split(std::string source, char delimiter)
368368
*/
369369
const char* GeneralUtils::errorToString(esp_err_t errCode) {
370370
switch (errCode) {
371-
#if CONFIG_LOG_DEFAULT_LEVEL > 4
371+
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
372372
case ESP_OK:
373373
return "ESP_OK";
374374
case ESP_FAIL:
@@ -453,7 +453,7 @@ const char* GeneralUtils::wifiErrorToString(uint8_t errCode) {
453453
if (errCode == UINT8_MAX) return "Not Connected (default value)";
454454

455455
switch ((wifi_err_reason_t) errCode) {
456-
#if CONFIG_LOG_DEFAULT_LEVEL > 4
456+
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
457457
case WIFI_REASON_UNSPECIFIED:
458458
return "WIFI_REASON_UNSPECIFIED";
459459
case WIFI_REASON_AUTH_EXPIRE:

Diff for: libraries/ESP32/examples/GPIO/BlinkRGB/BlinkRGB.ino

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
BlinkRGB
3+
4+
Demonstrates usage of onboard RGB LED on some ESP dev boards.
5+
6+
Calling digitalWrite(LED_BUILTIN, HIGH) will use hidden RGB driver.
7+
8+
RGBLedWrite demonstrates controll of each channel:
9+
void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val)
10+
11+
WARNING: After using digitalWrite to drive RGB LED it will be impossible to drive the same pin
12+
with normal HIGH/LOW level
13+
*/
14+
//#define LED_BRIGHTNESS 64 // Change white brightness (max 255)
15+
16+
// the setup function runs once when you press reset or power the board
17+
18+
void setup() {
19+
// No need to initialize the RGB LED
20+
}
21+
22+
// the loop function runs over and over again forever
23+
void loop() {
24+
#ifdef BOARD_HAS_NEOPIXEL
25+
digitalWrite(LED_BUILTIN, HIGH); // Turn the RGB LED white
26+
delay(1000);
27+
digitalWrite(LED_BUILTIN, LOW); // Turn the RGB LED off
28+
delay(1000);
29+
30+
neopixelWrite(LED_BUILTIN,LED_BRIGHTNESS,0,0); // Red
31+
delay(1000);
32+
neopixelWrite(LED_BUILTIN,0,LED_BRIGHTNESS,0); // Green
33+
delay(1000);
34+
neopixelWrite(LED_BUILTIN,0,0,LED_BRIGHTNESS); // Blue
35+
delay(1000);
36+
neopixelWrite(LED_BUILTIN,0,0,0); // Off / black
37+
delay(1000);
38+
#endif
39+
}

Diff for: libraries/WiFi/examples/SimpleWiFiServer/SimpleWiFiServer.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
http://yourAddress/H turns the LED on
1111
http://yourAddress/L turns it off
1212
13-
This example is written for a network using WPA encryption. For
14-
WEP or WPA, change the Wifi.begin() call accordingly.
13+
This example is written for a network using WPA2 encryption. For insecure
14+
WEP or WPA, change the Wifi.begin() call and use Wifi.setMinSecurity() accordingly.
1515
1616
Circuit:
1717
* WiFi shield attached

0 commit comments

Comments
 (0)