Skip to content

Commit fc24e98

Browse files
authored
Merge branch 'master' into feature/ide_2_debug
2 parents e4f1a2b + fd72cf4 commit fc24e98

File tree

12 files changed

+105
-33
lines changed

12 files changed

+105
-33
lines changed

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

+28-3
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,15 @@ void ledcAttachPin(uint8_t pin, uint8_t chan)
166166
return;
167167
}
168168
uint8_t group=(chan/8), channel=(chan%8), timer=((chan/2)%4);
169-
169+
uint32_t duty = ledc_get_duty(group,channel);
170+
170171
ledc_channel_config_t ledc_channel = {
171172
.speed_mode = group,
172173
.channel = channel,
173174
.timer_sel = timer,
174175
.intr_type = LEDC_INTR_DISABLE,
175176
.gpio_num = pin,
176-
.duty = 0,
177+
.duty = duty,
177178
.hpoint = 0
178179
};
179180
ledc_channel_config(&ledc_channel);
@@ -211,6 +212,8 @@ uint32_t ledcChangeFrequency(uint8_t chan, uint32_t freq, uint8_t bit_num)
211212

212213
static int8_t pin_to_channel[SOC_GPIO_PIN_COUNT] = { 0 };
213214
static int cnt_channel = LEDC_CHANNELS;
215+
static uint8_t analog_resolution = 8;
216+
static int analog_frequency = 1000;
214217
void analogWrite(uint8_t pin, int value) {
215218
// Use ledc hardware for internal pins
216219
if (pin < SOC_GPIO_PIN_COUNT) {
@@ -220,8 +223,8 @@ void analogWrite(uint8_t pin, int value) {
220223
return;
221224
}
222225
pin_to_channel[pin] = cnt_channel--;
226+
ledcSetup(cnt_channel, analog_frequency, analog_resolution);
223227
ledcAttachPin(pin, cnt_channel);
224-
ledcSetup(cnt_channel, 1000, 8);
225228
}
226229
ledcWrite(pin_to_channel[pin] - 1, value);
227230
}
@@ -230,3 +233,25 @@ void analogWrite(uint8_t pin, int value) {
230233
int8_t analogGetChannel(uint8_t pin) {
231234
return pin_to_channel[pin] - 1;
232235
}
236+
237+
void analogWriteFrequency(uint32_t freq) {
238+
if (cnt_channel != LEDC_CHANNELS) {
239+
for (int channel = LEDC_CHANNELS - 1; channel >= cnt_channel; channel--) {
240+
ledcChangeFrequency(channel, freq, analog_resolution);
241+
}
242+
}
243+
analog_frequency = freq;
244+
}
245+
246+
void analogWriteResolution(uint8_t bits) {
247+
if(bits > LEDC_MAX_BIT_WIDTH) {
248+
log_w("analogWrite resolution width too big! Setting to maximum %u bits)", LEDC_MAX_BIT_WIDTH);
249+
bits = LEDC_MAX_BIT_WIDTH;
250+
}
251+
if (cnt_channel != LEDC_CHANNELS) {
252+
for (int channel = LEDC_CHANNELS - 1; channel >= cnt_channel; channel--) {
253+
ledcChangeFrequency(channel, analog_frequency, bits);
254+
}
255+
}
256+
analog_resolution = bits;
257+
}

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

+2
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ void yield(void);
9393

9494
void analogWrite(uint8_t pin, int value);
9595
int8_t analogGetChannel(uint8_t pin);
96+
void analogWriteFrequency(uint32_t freq);
97+
void analogWriteResolution(uint8_t bits);
9698

9799
//returns chip temperature in Celsius
98100
float temperatureRead();

Diff for: docs/source/api/rainmaker.rst

+15-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ The key features of ESP RainMaker are:
2222

2323
Additional information about ESP RainMaker can be found `here <https://rainmaker.espressif.com/>`__.
2424

25-
#########################
26-
Arduino ESP Rainmaker API
27-
#########################
2825

2926
ESP RainMaker Agent API
3027
-----------------------
@@ -127,6 +124,21 @@ This function will return
127124
1. `ESP_OK` : On success
128125
2. Error in case of failure
129126

127+
RMaker.enableScenes
128+
*******************
129+
130+
This API enables the Scenes service for the node. It should be called after `RMaker.initNode()` and before `RMaker.start()`.
131+
For more information, check `here <https://rainmaker.espressif.com/docs/scenes.html>`__.
132+
133+
.. code-block:: arduino
134+
135+
esp_err_t enableScenes()
136+
137+
This function will return
138+
139+
1. `ESP_OK` : On success
140+
2. Error in case of failure
141+
130142
RMaker.setTimeZone
131143
******************
132144

Diff for: docs/source/esp-idf_component.rst

+15
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,21 @@ Installation
3939
4040
.. note:: If you use Arduino with ESP-IDF often, you can place the arduino folder into global components folder.
4141

42+
If you're targeting the ESP32-S2 or ESP32-S3 and you want to use USBHID classes such as ``USBHID``, ``USBHIDConsumerControl``, ``USBHIDGamepad``, ``USBHIDKeyboard``, ``USBHIDMouse``, ``USBHIDSystemControl``, or ``USBHIDVendor``:
43+
44+
1. Clone these nested repos somewhere:
45+
46+
.. code-block:: bash
47+
48+
git clone https://github.com/espressif/esp32-arduino-lib-builder.git esp32-arduino-lib-builder && \
49+
git clone https://github.com/hathach/tinyusb.git esp32-arduino-lib-builder/components/arduino_tinyusb/tinyusb
50+
51+
2. In the project folder, edit ``CMakeLists.txt`` and add the following before the ``project()`` line:
52+
53+
.. code-block:: bash
54+
55+
set(EXTRA_COMPONENT_DIRS <path to esp32-arduino-lib-builder/components/arduino_tinyusb>)
56+
4257
Configuration
4358
-------------
4459

Diff for: libraries/RainMaker/examples/RMakerCustom/RMakerCustom.ino

+9-7
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ static Device my_device("Dimmer", "custom.device.dimmer", &gpio_dimmer);
2626

2727
void sysProvEvent(arduino_event_t *sys_event)
2828
{
29-
switch (sys_event->event_id) {
29+
switch (sys_event->event_id) {
3030
case ARDUINO_EVENT_PROV_START:
3131
#if CONFIG_IDF_TARGET_ESP32S2
3232
Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on SoftAP\n", service_name, pop);
3333
printQR(service_name, pop, "softap");
3434
#else
3535
Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n", service_name, pop);
3636
printQR(service_name, pop, "ble");
37-
#endif
37+
#endif
3838
break;
3939
default:;
4040
}
@@ -63,7 +63,7 @@ void setup()
6363
pinMode(gpio_dimmer, OUTPUT);
6464
digitalWrite(gpio_dimmer, DEFAULT_POWER_MODE);
6565

66-
Node my_node;
66+
Node my_node;
6767
my_node = RMaker.initNode("ESP RainMaker Node");
6868

6969
//Create custom dimmer device
@@ -78,20 +78,22 @@ void setup()
7878
my_device.addParam(level_param);
7979

8080
my_device.addCb(write_callback);
81-
82-
//Add custom dimmer device to the node
81+
82+
//Add custom dimmer device to the node
8383
my_node.addDevice(my_device);
8484

85-
//This is optional
85+
//This is optional
8686
RMaker.enableOTA(OTA_USING_PARAMS);
87-
//If you want to enable scheduling, set time zone for your region using setTimeZone().
87+
//If you want to enable scheduling, set time zone for your region using setTimeZone().
8888
//The list of available values are provided here https://rainmaker.espressif.com/docs/time-service.html
8989
// RMaker.setTimeZone("Asia/Shanghai");
9090
// Alternatively, enable the Timezone service and let the phone apps set the appropriate timezone
9191
RMaker.enableTZService();
9292

9393
RMaker.enableSchedule();
9494

95+
RMaker.enableScenes();
96+
9597
RMaker.start();
9698

9799
WiFi.onEvent(sysProvEvent);

Diff for: libraries/RainMaker/examples/RMakerCustomAirCooler/RMakerCustomAirCooler.ino

+9-7
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ static Device my_device("Air Cooler", "my.device.air-cooler", NULL);
4343

4444
void sysProvEvent(arduino_event_t *sys_event)
4545
{
46-
switch (sys_event->event_id) {
46+
switch (sys_event->event_id) {
4747
case ARDUINO_EVENT_PROV_START:
4848
#if CONFIG_IDF_TARGET_ESP32S2
4949
Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on SoftAP\n", service_name, pop);
5050
printQR(service_name, pop, "softap");
5151
#else
5252
Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n", service_name, pop);
5353
printQR(service_name, pop, "ble");
54-
#endif
54+
#endif
5555
break;
5656
default:;
5757
}
@@ -114,7 +114,7 @@ void setup()
114114
pinMode(gpio_speed, OUTPUT);
115115
analogWrite(gpio_speed, DEFAULT_SPEED);
116116

117-
Node my_node;
117+
Node my_node;
118118
my_node = RMaker.initNode("ESP RainMaker Node");
119119

120120
//Create custom air cooler device
@@ -138,20 +138,22 @@ void setup()
138138
my_device.addParam(mode_param);
139139

140140
my_device.addCb(write_callback);
141-
142-
//Add custom Air Cooler device to the node
141+
142+
//Add custom Air Cooler device to the node
143143
my_node.addDevice(my_device);
144144

145-
//This is optional
145+
//This is optional
146146
// RMaker.enableOTA(OTA_USING_PARAMS);
147-
//If you want to enable scheduling, set time zone for your region using setTimeZone().
147+
//If you want to enable scheduling, set time zone for your region using setTimeZone().
148148
//The list of available values are provided here https://rainmaker.espressif.com/docs/time-service.html
149149
// RMaker.setTimeZone("Asia/Shanghai");
150150
//Alternatively, enable the Timezone service and let the phone apps set the appropriate timezone
151151
// RMaker.enableTZService();
152152

153153
RMaker.enableSchedule();
154154

155+
RMaker.enableScenes();
156+
155157
RMaker.start();
156158

157159
WiFi.onEvent(sysProvEvent);

Diff for: libraries/RainMaker/examples/RMakerSonoffDualR3/RMakerSonoffDualR3.ino

+1
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ void setup()
136136
// Alternatively, enable the Timezone service and let the phone apps set the appropriate timezone
137137
RMaker.enableTZService();
138138
RMaker.enableSchedule();
139+
RMaker.enableScenes();
139140

140141
//Service Name
141142
for(int i=0; i<17; i=i+8) {

Diff for: libraries/RainMaker/examples/RMakerSwitch/RMakerSwitch.ino

+2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ void setup()
8181

8282
RMaker.enableSchedule();
8383

84+
RMaker.enableScenes();
85+
8486
RMaker.start();
8587

8688
WiFi.onEvent(sysProvEvent);

Diff for: libraries/RainMaker/src/RMaker.cpp

+11-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "RMaker.h"
44
#include <esp_rmaker_schedule.h>
55
#include <esp_rmaker_utils.h>
6+
#include <esp_rmaker_scenes.h>
67
bool wifiLowLevelInit(bool persistent);
78
static esp_err_t err;
89

@@ -28,12 +29,12 @@ static void event_handler(void *arg, esp_event_base_t event_base, int32_t event_
2829
log_i("Unhandled RainMaker Event:");
2930
}
3031
} else if (event_base == RMAKER_OTA_EVENT) {
31-
if(event_data == NULL){
32+
if (event_data == NULL) {
3233
event_data = (void*)"";
3334
}
3435
switch(event_id) {
3536
case RMAKER_OTA_EVENT_STARTING:
36-
log_i("Starting OTA : %s", (char*)event_data);
37+
log_i("Starting OTA");
3738
break;
3839
case RMAKER_OTA_EVENT_IN_PROGRESS:
3940
log_i("OTA in progress : %s", (char*)event_data);
@@ -146,5 +147,13 @@ esp_err_t RMakerClass::enableOTA(ota_type_t type, const char *cert)
146147
return err;
147148
}
148149

150+
esp_err_t RMakerClass::enableScenes()
151+
{
152+
err = esp_rmaker_scenes_enable();
153+
if (err != ESP_OK) {
154+
log_e("Scenes enable failed");
155+
}
156+
return err;
157+
}
149158
RMakerClass RMaker;
150159
#endif

Diff for: libraries/RainMaker/src/RMaker.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,17 @@ class RMakerClass
2525
{
2626
private:
2727
esp_rmaker_config_t rainmaker_cfg = {false};
28-
28+
2929
public:
30-
30+
3131
void setTimeSync(bool val);
3232
Node initNode(const char *name, const char *type = "ESP RainMaker with Arduino");
3333
esp_err_t deinitNode(Node node);
3434
esp_err_t setTimeZone(const char *tz = "Asia/Shanghai");
3535
esp_err_t enableSchedule();
3636
esp_err_t enableTZService();
3737
esp_err_t enableOTA(ota_type_t type, const char *cert = ESP_RMAKER_OTA_DEFAULT_SERVER_CERT);
38+
esp_err_t enableScenes();
3839
esp_err_t start();
3940
esp_err_t stop();
4041
};

Diff for: libraries/RainMaker/src/RMakerUtils.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#include "RMakerUtils.h"
22
#ifdef CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK
3-
void RMakerFactoryReset(int seconds)
3+
#define RESET_DELAY_SEC 2
4+
void RMakerFactoryReset(int reboot_seconds)
45
{
5-
esp_rmaker_factory_reset(0, seconds);
6+
esp_rmaker_factory_reset(RESET_DELAY_SEC, reboot_seconds);
67
}
78

8-
void RMakerWiFiReset(int seconds)
9+
void RMakerWiFiReset(int reboot_seconds)
910
{
10-
esp_rmaker_wifi_reset(0, seconds);
11+
esp_rmaker_wifi_reset(RESET_DELAY_SEC, reboot_seconds);
1112
}
1213
#endif

Diff for: variants/wt32-eth01/pins_arduino.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ static const uint8_t RX = 3;
5454

5555
//SPI VSPI default pins
5656
static const uint8_t SS = -1;
57-
static const uint8_t MOSI = 15;
58-
static const uint8_t MISO = 12;
59-
static const uint8_t SCK = 14;
57+
static const uint8_t MOSI = 14;
58+
static const uint8_t MISO = 15;
59+
static const uint8_t SCK = 12;
6060

6161
//I2C default pins
62-
static const uint8_t SDA = 2;
63-
static const uint8_t SCL = 4;
62+
static const uint8_t SDA = 33;
63+
static const uint8_t SCL = 32;
6464

6565
#endif /* Pins_Arduino_h */

0 commit comments

Comments
 (0)