Unverified Commit 447f6db6 authored by Me No Dev's avatar Me No Dev Committed by GitHub

Merge branch 'master' into release/v2.x

parents 3670e2bf 72c41d09
...@@ -41,6 +41,7 @@ body: ...@@ -41,6 +41,7 @@ body:
options: options:
- latest master (checkout manually) - latest master (checkout manually)
- latest development Release Candidate (RC-X) - latest development Release Candidate (RC-X)
- v2.0.9
- v2.0.8 - v2.0.8
- v2.0.7 - v2.0.7
- v2.0.6 - v2.0.6
......
This diff is collapsed.
...@@ -28,7 +28,7 @@ ESP_EVENT_DEFINE_BASE(ARDUINO_HW_CDC_EVENTS); ...@@ -28,7 +28,7 @@ ESP_EVENT_DEFINE_BASE(ARDUINO_HW_CDC_EVENTS);
static RingbufHandle_t tx_ring_buf = NULL; static RingbufHandle_t tx_ring_buf = NULL;
static xQueueHandle rx_queue = NULL; static xQueueHandle rx_queue = NULL;
static uint8_t rx_data_buf[64]; static uint8_t rx_data_buf[64] = {0};
static intr_handle_t intr_handle = NULL; static intr_handle_t intr_handle = NULL;
static volatile bool initial_empty = false; static volatile bool initial_empty = false;
static xSemaphoreHandle tx_lock = NULL; static xSemaphoreHandle tx_lock = NULL;
...@@ -195,6 +195,7 @@ void HWCDC::end() ...@@ -195,6 +195,7 @@ void HWCDC::end()
intr_handle = NULL; intr_handle = NULL;
if(tx_lock != NULL) { if(tx_lock != NULL) {
vSemaphoreDelete(tx_lock); vSemaphoreDelete(tx_lock);
tx_lock = NULL;
} }
setRxBufferSize(0); setRxBufferSize(0);
setTxBufferSize(0); setTxBufferSize(0);
......
...@@ -367,9 +367,6 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in ...@@ -367,9 +367,6 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
} }
break; break;
#endif #endif
default:
log_e("Bad UART Number");
return;
} }
} }
......
...@@ -16,7 +16,8 @@ ...@@ -16,7 +16,8 @@
#ifdef CONFIG_BT_ENABLED #ifdef CONFIG_BT_ENABLED
bool btInUse(){ return true; } // user may want to change it to free resources
__attribute__((weak)) bool btInUse(){ return true; }
#include "esp_bt.h" #include "esp_bt.h"
......
...@@ -209,9 +209,8 @@ bool verifyRollbackLater() { return false; } ...@@ -209,9 +209,8 @@ bool verifyRollbackLater() { return false; }
#endif #endif
#ifdef CONFIG_BT_ENABLED #ifdef CONFIG_BT_ENABLED
//overwritten in esp32-hal-bt.c //from esp32-hal-bt.c
bool btInUse() __attribute__((weak)); extern bool btInUse();
bool btInUse(){ return false; }
#endif #endif
void initArduino() void initArduino()
......
...@@ -90,7 +90,7 @@ This function is used to setup the LEDC channel to 50 % PWM tone on selected fre ...@@ -90,7 +90,7 @@ This function is used to setup the LEDC channel to 50 % PWM tone on selected fre
* ``freq`` select frequency of pwm signal. * ``freq`` select frequency of pwm signal.
This function will return ``frequency`` set for channel. This function will return ``frequency`` set for channel.
If ``0`` is returned, error occurs and ledc cahnnel was not configured. If ``0`` is returned, error occurs and ledc channel was not configured.
ledcWriteNote ledcWriteNote
************* *************
......
...@@ -15,3 +15,20 @@ How to compile libs with different debug level? ...@@ -15,3 +15,20 @@ How to compile libs with different debug level?
----------------------------------------------- -----------------------------------------------
The short answer is ``esp32-arduino-lib-builder/configs/defconfig.common:44``. A guide explaining the process can be found here <guides/core_debug> The short answer is ``esp32-arduino-lib-builder/configs/defconfig.common:44``. A guide explaining the process can be found here <guides/core_debug>
SPIFFS mount failed
-------------------
When you come across and error like this:
.. code-block:: shell
E (588) SPIFFS: mount failed, -10025
[E][SPIFFS.cpp:47] begin(): Mounting SPIFFS failed! Error: -1
Try enforcing format on fail in your code by adding ``true`` in the ``begin`` method such as this:
.. code-block:: c++
SPIFFS.begin(true);
See the method prototype for reference: ``bool begin(bool formatOnFail=false, const char * basePath="/spiffs", uint8_t maxOpenFiles=10, const char * partitionLabel=NULL);``
\ No newline at end of file
...@@ -233,9 +233,9 @@ Like so: ...@@ -233,9 +233,9 @@ Like so:
.. code-block:: arduino .. code-block:: arduino
String myString = myPreferences.getString("myStringKey"); float myFloat = myPreferences.getFloat("pi");
This will retrieve the String value from the namespace key ``"myStringKey"`` and assign it to the String type variable ``myString``. This will retrieve the float value from the namespace key ``"pi"`` and assign it to the float type variable ``myFloat``.
Summary Summary
...@@ -277,9 +277,10 @@ When started, the system has no way of knowing which of the above conditions is ...@@ -277,9 +277,10 @@ When started, the system has no way of knowing which of the above conditions is
// not the complete setup(), but in setup(), include this... // not the complete setup(), but in setup(), include this...
stcPrefs.begin("STCPrefs", RO_MODE); // Open our namespace (or create it stcPrefs.begin("STCPrefs", RO_MODE); // Open our namespace (or create it
// if it doesn't exist) in in RO mode. // if it doesn't exist) in RO mode.
bool tpInit = stcPrefs.isKey("nvsInit"); // Test for the existence of the "already initialized" key. bool tpInit = stcPrefs.isKey("nvsInit"); // Test for the existence
// of the "already initialized" key.
if (tpInit == false) { if (tpInit == false) {
// If tpInit is 'false', the key "nvsInit" does not yet exist therefore this // If tpInit is 'false', the key "nvsInit" does not yet exist therefore this
...@@ -289,13 +290,15 @@ When started, the system has no way of knowing which of the above conditions is ...@@ -289,13 +290,15 @@ When started, the system has no way of knowing which of the above conditions is
// The .begin() method created the "STCPrefs" namespace and since this is our // The .begin() method created the "STCPrefs" namespace and since this is our
// first-time run we will create our keys and store the initial "factory default" values. // first-time run we will create
// our keys and store the initial "factory default" values.
stcPrefs.putUChar("curBright", 10); stcPrefs.putUChar("curBright", 10);
stcPrefs.putString("talChan", "one"); stcPrefs.putString("talChan", "one");
stcPrefs.putLong("talMax", -220226); stcPrefs.putLong("talMax", -220226);
stcPrefs.putBool("ctMde", true); stcPrefs.putBool("ctMde", true);
stcPrefs.putBool("nvsInit", true); // Create the "already initialized" key and store a value. stcPrefs.putBool("nvsInit", true); // Create the "already initialized"
// key and store a value.
// The "factory defaults" are created and stored so... // The "factory defaults" are created and stored so...
stcPrefs.end(); // Close the namespace in RW mode and... stcPrefs.end(); // Close the namespace in RW mode and...
...@@ -456,10 +459,12 @@ This is best explained with an example. Here the ``Bytes`` methods are used to s ...@@ -456,10 +459,12 @@ This is best explained with an example. Here the ``Bytes`` methods are used to s
Serial.begin(115200); Serial.begin(115200);
delay(250); delay(250);
mySketchPrefs.begin("myPrefs", RW_MODE); // open (or create) the namespace "myPrefs" in RW mode mySketchPrefs.begin("myPrefs", RW_MODE); // open (or create) the namespace
// "myPrefs" in RW mode
mySketchPrefs.clear(); // delete any previous keys in this namespace mySketchPrefs.clear(); // delete any previous keys in this namespace
// Create an array of test values. We're using hex numbers throughout to better show how the bytes move around. // Create an array of test values. We're using hex numbers
// throughout to better show how the bytes move around.
int16_t myArray[] = { 0x1112, 0x2122, 0x3132, 0x4142, 0x5152, 0x6162, 0x7172 }; int16_t myArray[] = { 0x1112, 0x2122, 0x3132, 0x4142, 0x5152, 0x6162, 0x7172 };
Serial.println("Printing myArray..."); Serial.println("Printing myArray...");
...@@ -468,22 +473,28 @@ This is best explained with an example. Here the ``Bytes`` methods are used to s ...@@ -468,22 +473,28 @@ This is best explained with an example. Here the ``Bytes`` methods are used to s
} }
Serial.println("\r\n"); Serial.println("\r\n");
// In the next statement, the second sizeof() needs to match the data type of the elements of myArray // In the next statement, the second sizeof() needs
Serial.print("The number of elements in myArray is: "); Serial.println( sizeof(myArray) / sizeof(int16_t) ); // to match the data type of the elements of myArray
Serial.print("But the size of myArray in bytes is: "); Serial.println( sizeof(myArray) ); Serial.print("The number of elements in myArray is: ");
Serial.println( sizeof(myArray) / sizeof(int16_t) );
Serial.print("But the size of myArray in bytes is: ");
Serial.println( sizeof(myArray) );
Serial.println(""); Serial.println("");
Serial.println("Storing myArray into the Preferences namespace \"myPrefs\" against the key \"myPrefsBytes\"."); Serial.println(
"Storing myArray into the Preferences namespace \"myPrefs\" against the key \"myPrefsBytes\".");
// Note: in the next statement, to store the entire array, we must use the // Note: in the next statement, to store the entire array, we must use the
// size of the arrray in bytes, not the number of elements in the array. // size of the arrray in bytes, not the number of elements in the array.
mySketchPrefs.putBytes( "myPrefsBytes", myArray, sizeof(myArray) ); mySketchPrefs.putBytes( "myPrefsBytes", myArray, sizeof(myArray) );
Serial.print("The size of \"myPrefsBytes\" is (in bytes): "); Serial.println( mySketchPrefs.getBytesLength("myPrefsBytes") ); Serial.print("The size of \"myPrefsBytes\" is (in bytes): ");
Serial.println( mySketchPrefs.getBytesLength("myPrefsBytes") );
Serial.println(""); Serial.println("");
int16_t myIntBuffer[20] = {}; // No magic about 20. Just making a buffer (array) big enough. int16_t myIntBuffer[20] = {}; // No magic about 20. Just making a buffer (array) big enough.
Serial.println("Retrieving the value of myPrefsBytes into myIntBuffer."); Serial.println("Retrieving the value of myPrefsBytes into myIntBuffer.");
Serial.println(" - Note the data type of myIntBuffer matches that of myArray"); Serial.println(" - Note the data type of myIntBuffer matches that of myArray");
mySketchPrefs.getBytes( "myPrefsBytes", myIntBuffer, mySketchPrefs.getBytesLength("myPrefsBytes") ); mySketchPrefs.getBytes("myPrefsBytes", myIntBuffer,
mySketchPrefs.getBytesLength("myPrefsBytes"));
Serial.println("Printing myIntBuffer..."); Serial.println("Printing myIntBuffer...");
// In the next statement, sizeof() needs to match the data type of the elements of myArray // In the next statement, sizeof() needs to match the data type of the elements of myArray
...@@ -492,9 +503,11 @@ This is best explained with an example. Here the ``Bytes`` methods are used to s ...@@ -492,9 +503,11 @@ This is best explained with an example. Here the ``Bytes`` methods are used to s
} }
Serial.println("\r\n"); Serial.println("\r\n");
Serial.println("We can see how the data from myArray is actually stored in the namespace as follows."); Serial.println(
uint8_t myByteBuffer[40] = {}; // No magic about 40. Just making a buffer (array) big enough. "We can see how the data from myArray is actually stored in the namespace as follows.");
mySketchPrefs.getBytes( "myPrefsBytes", myByteBuffer, mySketchPrefs.getBytesLength("myPrefsBytes") ); uint8_t myByteBuffer[40] = {}; // No magic about 40. Just making a buffer (array) big enough.
mySketchPrefs.getBytes("myPrefsBytes", myByteBuffer,
mySketchPrefs.getBytesLength("myPrefsBytes"));
Serial.println("Printing myByteBuffer..."); Serial.println("Printing myByteBuffer...");
for (int i = 0; i < mySketchPrefs.getBytesLength("myPrefsBytes"); i++) { for (int i = 0; i < mySketchPrefs.getBytesLength("myPrefsBytes"); i++) {
......
...@@ -28,7 +28,8 @@ ...@@ -28,7 +28,8 @@
//#define CAMERA_MODEL_ESP32_CAM_BOARD //#define CAMERA_MODEL_ESP32_CAM_BOARD
//#define CAMERA_MODEL_ESP32S2_CAM_BOARD //#define CAMERA_MODEL_ESP32S2_CAM_BOARD
//#define CAMERA_MODEL_ESP32S3_CAM_LCD //#define CAMERA_MODEL_ESP32S3_CAM_LCD
//#define CAMERA_MODEL_DFRobot_FireBeetle2_ESP32S3 // Has PSRAM
//#define CAMERA_MODEL_DFRobot_Romeo_ESP32S3 // Has PSRAM
#include "camera_pins.h" #include "camera_pins.h"
// =========================== // ===========================
......
...@@ -293,6 +293,25 @@ ...@@ -293,6 +293,25 @@
#define HREF_GPIO_NUM 7 #define HREF_GPIO_NUM 7
#define PCLK_GPIO_NUM 13 #define PCLK_GPIO_NUM 13
#elif defined(CAMERA_MODEL_DFRobot_FireBeetle2_ESP32S3) || defined(CAMERA_MODEL_DFRobot_Romeo_ESP32S3)
#define PWDN_GPIO_NUM -1
#define RESET_GPIO_NUM -1
#define XCLK_GPIO_NUM 45
#define SIOD_GPIO_NUM 1
#define SIOC_GPIO_NUM 2
#define Y9_GPIO_NUM 48
#define Y8_GPIO_NUM 46
#define Y7_GPIO_NUM 8
#define Y6_GPIO_NUM 7
#define Y5_GPIO_NUM 4
#define Y4_GPIO_NUM 41
#define Y3_GPIO_NUM 40
#define Y2_GPIO_NUM 39
#define VSYNC_GPIO_NUM 6
#define HREF_GPIO_NUM 42
#define PCLK_GPIO_NUM 5
#else #else
#error "Camera model not selected" #error "Camera model not selected"
#endif #endif
/*
* This example demonstrates usage of interrupt by detecting a button press.
*
* Setup: Connect first button between pin defined in BUTTON1 and GND
* Similarly connect second button between pin defined in BUTTON2 and GND.
* If you do not have a button simply connect a wire to those buttons
* - touching GND pin with other end of the wire will behave same as pressing the connected button.
* Wen using the bare wire be careful not to touch any other pin by accident.
*
* Note: There is no de-bounce implemented and the physical connection will normally
* trigger many more button presses than actually happened.
* This is completely normal and is not to be considered a fault.
*/
#include <Arduino.h> #include <Arduino.h>
#include <FunctionalInterrupt.h> #include <FunctionalInterrupt.h>
#define BUTTON1 16 #define BUTTON1 16
#define BUTTON2 17 #define BUTTON2 17
class Button class Button{
{
public: public:
Button(uint8_t reqPin) : PIN(reqPin){ Button(uint8_t reqPin) : PIN(reqPin){
pinMode(PIN, INPUT_PULLUP); pinMode(PIN, INPUT_PULLUP);
attachInterrupt(PIN, std::bind(&Button::isr,this), FALLING);
}; };
~Button() {
void begin(){
attachInterrupt(PIN, std::bind(&Button::isr,this), FALLING);
Serial.printf("Started button interrupt on pin %d\n", PIN);
}
~Button(){
detachInterrupt(PIN); detachInterrupt(PIN);
} }
void ARDUINO_ISR_ATTR isr() { void ARDUINO_ISR_ATTR isr(){
numberKeyPresses += 1; numberKeyPresses += 1;
pressed = true; pressed = true;
} }
void checkPressed() { void checkPressed(){
if (pressed) { if (pressed) {
Serial.printf("Button on pin %u has been pressed %u times\n", PIN, numberKeyPresses); Serial.printf("Button on pin %u has been pressed %u times\n", PIN, numberKeyPresses);
pressed = false; pressed = false;
...@@ -28,7 +47,7 @@ public: ...@@ -28,7 +47,7 @@ public:
} }
private: private:
const uint8_t PIN; const uint8_t PIN;
volatile uint32_t numberKeyPresses; volatile uint32_t numberKeyPresses;
volatile bool pressed; volatile bool pressed;
}; };
...@@ -36,9 +55,13 @@ private: ...@@ -36,9 +55,13 @@ private:
Button button1(BUTTON1); Button button1(BUTTON1);
Button button2(BUTTON2); Button button2(BUTTON2);
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
while(!Serial) delay(10);
Serial.println("Starting Functional Interrupt example.");
button1.begin();
button2.begin();
Serial.println("Setup done.");
} }
void loop() { void loop() {
......
...@@ -5,27 +5,31 @@ ...@@ -5,27 +5,31 @@
static esp_err_t err; static esp_err_t err;
typedef void (*deviceWriteCb)(Device*, Param*, const param_val_t val, void *priv_data, write_ctx_t *ctx); typedef void (*deviceWriteCb)(Device*, Param*, const param_val_t val, void *priv_data, write_ctx_t *ctx);
typedef void (*deviceReadCb)(Device*, Param*, void *priv_data, read_ctx_t *ctx); typedef void (*deviceReadCb)(Device*, Param*, void *priv_data, read_ctx_t *ctx);
typedef struct {
void (*write_cb)(Device*, Param*, param_val_t, void*, write_ctx_t*); void *priv_data;
void (*read_cb)(Device*, Param*, void*, read_ctx_t*); deviceWriteCb write_cb;
Device device; deviceReadCb read_cb;
Param param; } RMakerDevicePrivT;
static esp_err_t write_callback(const device_handle_t *dev_handle, const param_handle_t *par_handle, const param_val_t val, void *priv_data, write_ctx_t *ctx) static esp_err_t write_callback(const device_handle_t *dev_handle, const param_handle_t *par_handle, const param_val_t val, void *priv_data, write_ctx_t *ctx)
{ {
Device device;
Param param;
device.setDeviceHandle(dev_handle); device.setDeviceHandle(dev_handle);
param.setParamHandle(par_handle); param.setParamHandle(par_handle);
deviceWriteCb cb = ((RMakerDevicePrivT *)priv_data)->write_cb;
write_cb(&device, &param, val, priv_data, ctx); cb(&device, &param, val, ((RMakerDevicePrivT *)priv_data)->priv_data, ctx);
return ESP_OK; return ESP_OK;
} }
static esp_err_t read_callback(const device_handle_t *dev_handle, const param_handle_t *par_handle, void *priv_data, read_ctx_t *ctx) static esp_err_t read_callback(const device_handle_t *dev_handle, const param_handle_t *par_handle, void *priv_data, read_ctx_t *ctx)
{ {
Device device;
Param param;
device.setDeviceHandle(dev_handle); device.setDeviceHandle(dev_handle);
param.setParamHandle(par_handle); param.setParamHandle(par_handle);
deviceReadCb cb = ((RMakerDevicePrivT *)priv_data)->read_cb;
read_cb(&device, &param, priv_data, ctx); cb(&device, &param, ((RMakerDevicePrivT *)priv_data)->priv_data, ctx);
return ESP_OK; return ESP_OK;
} }
...@@ -41,8 +45,8 @@ esp_err_t Device::deleteDevice() ...@@ -41,8 +45,8 @@ esp_err_t Device::deleteDevice()
void Device::addCb(deviceWriteCb writeCb, deviceReadCb readCb) void Device::addCb(deviceWriteCb writeCb, deviceReadCb readCb)
{ {
write_cb = writeCb; this->private_data.write_cb = writeCb;
read_cb = readCb; this->private_data.read_cb = readCb;
err = esp_rmaker_device_add_cb(getDeviceHandle(), write_callback, read_callback); err = esp_rmaker_device_add_cb(getDeviceHandle(), write_callback, read_callback);
if(err != ESP_OK) { if(err != ESP_OK) {
log_e("Failed to register callback"); log_e("Failed to register callback");
......
...@@ -21,17 +21,42 @@ ...@@ -21,17 +21,42 @@
class Device class Device
{ {
public:
typedef void (*deviceWriteCb)(Device*, Param*, const param_val_t val, void *priv_data, write_ctx_t *ctx);
typedef void (*deviceReadCb)(Device*, Param*, void *priv_data, read_ctx_t *ctx);
typedef struct {
void *priv_data;
deviceWriteCb write_cb;
deviceReadCb read_cb;
} RMakerDevicePrivT;
private: private:
const device_handle_t *device_handle; const device_handle_t *device_handle;
RMakerDevicePrivT private_data;
protected:
void setPrivateData(void *priv_data) {
this->private_data.priv_data = priv_data;
}
const RMakerDevicePrivT* getDevicePrivateData()
{
return &this->private_data;
}
public: public:
Device() Device()
{ {
device_handle = NULL; device_handle = NULL;
} this->private_data.priv_data = NULL;
this->private_data.write_cb = NULL;
this->private_data.read_cb = NULL;
}
Device(const char *dev_name, const char *dev_type = NULL, void *priv_data = NULL) Device(const char *dev_name, const char *dev_type = NULL, void *priv_data = NULL)
{ {
device_handle = esp_rmaker_device_create(dev_name, dev_type, priv_data); this->private_data.priv_data = priv_data;
this->private_data.write_cb = NULL;
this->private_data.read_cb = NULL;
device_handle = esp_rmaker_device_create(dev_name, dev_type, &this->private_data);
if(device_handle == NULL){ if(device_handle == NULL){
log_e("Device create error"); log_e("Device create error");
} }
...@@ -48,9 +73,6 @@ class Device ...@@ -48,9 +73,6 @@ class Device
{ {
return device_handle; return device_handle;
} }
typedef void (*deviceWriteCb)(Device*, Param*, const param_val_t val, void *priv_data, write_ctx_t *ctx);
typedef void (*deviceReadCb)(Device*, Param*, void *priv_data, read_ctx_t *ctx);
esp_err_t deleteDevice(); esp_err_t deleteDevice();
void addCb(deviceWriteCb write_cb, deviceReadCb read_cb = NULL); void addCb(deviceWriteCb write_cb, deviceReadCb read_cb = NULL);
...@@ -94,7 +116,8 @@ class Switch : public Device ...@@ -94,7 +116,8 @@ class Switch : public Device
} }
void standardSwitchDevice(const char *dev_name, void *priv_data, bool power) void standardSwitchDevice(const char *dev_name, void *priv_data, bool power)
{ {
esp_rmaker_device_t *dev_handle = esp_rmaker_switch_device_create(dev_name, priv_data, power); this->setPrivateData(priv_data);
esp_rmaker_device_t *dev_handle = esp_rmaker_switch_device_create(dev_name, (void *)this->getDevicePrivateData(), power);
setDeviceHandle(dev_handle); setDeviceHandle(dev_handle);
if(dev_handle == NULL){ if(dev_handle == NULL){
log_e("Switch device not created"); log_e("Switch device not created");
...@@ -115,7 +138,8 @@ class LightBulb : public Device ...@@ -115,7 +138,8 @@ class LightBulb : public Device
} }
void standardLightBulbDevice(const char *dev_name, void *priv_data, bool power) void standardLightBulbDevice(const char *dev_name, void *priv_data, bool power)
{ {
esp_rmaker_device_t *dev_handle = esp_rmaker_lightbulb_device_create(dev_name, priv_data, power); this->setPrivateData(priv_data);
esp_rmaker_device_t *dev_handle = esp_rmaker_lightbulb_device_create(dev_name, (void *)this->getDevicePrivateData(), power);
setDeviceHandle(dev_handle); setDeviceHandle(dev_handle);
if(dev_handle == NULL){ if(dev_handle == NULL){
log_e("Light device not created"); log_e("Light device not created");
...@@ -157,7 +181,8 @@ class TemperatureSensor : public Device ...@@ -157,7 +181,8 @@ class TemperatureSensor : public Device
} }
void standardTemperatureSensorDevice(const char *dev_name, void *priv_data, float temp) void standardTemperatureSensorDevice(const char *dev_name, void *priv_data, float temp)
{ {
esp_rmaker_device_t *dev_handle = esp_rmaker_temp_sensor_device_create(dev_name, priv_data, temp); this->setPrivateData(priv_data);
esp_rmaker_device_t *dev_handle = esp_rmaker_temp_sensor_device_create(dev_name, (void *)this->getDevicePrivateData(), temp);
setDeviceHandle(dev_handle); setDeviceHandle(dev_handle);
if(dev_handle == NULL){ if(dev_handle == NULL){
log_e("Temperature Sensor device not created"); log_e("Temperature Sensor device not created");
......
# Provisioning for Arduino # Provisioning for Arduino
This sketch implements provisioning using various IDF components This sketch implements provisioning using various IDF components.
# Description ## Description
This example allows Arduino user to choose either BLE or SOFTAP as a mode of transport, over which the provisioning related communication is to take place, between the device (to be provisioned) and the client (owner of the device). This example allows Arduino users to choose either BLE or SOFTAP as the mode of transport for provisioning-related communication between the device (to be provisioned) and the client (owner of the device).
# APIs introduced for provisioning ## APIs introduced for provisioning
## WiFi.onEvent() ### WiFi.onEvent()
Using this API user can register to receive WiFi Events and Provisioning Events Using this API, users can register to receive WiFi Events and Provisioning Events.
## WiFi.beginProvision() ### WiFi.beginProvision()
WiFi.beginProvision(void ( * scheme_cb)(), wifi_prov_scheme_event_handler_t scheme_event_handler, wifi_prov_security_t security, char * pop, char * service_name, char * service_key, uint8_t * uuid); ```
WiFi.beginProvision(void (*scheme_cb)(), wifi_prov_scheme_event_handler_t scheme_event_handler, wifi_prov_security_t security, char *pop, char *service_name, char *service_key, uint8_t *uuid);
```
#### Parameters passed #### Parameters passed
* function pointer : choose the mode of transfer - Function pointer: Choose the mode of transfer
* provSchemeBLE - Using BLE - `provSchemeBLE` - Using BLE
* provSchemeSoftAP - Using SoftAP - `provSchemeSoftAP` - Using SoftAP
* security : choose security type - `security`: Choose the security type
* WIFI_PROV_SECURITY_1 - It allows secure communication which consists of secure handshake using key exchange and proof of possession (pop) and encryption/decryption of messages. - `WIFI_PROV_SECURITY_1` - Enables secure communication with a secure handshake using key exchange and proof of possession (pop), and encryption/decryption of messages.
- `WIFI_PROV_SECURITY_0` - Does not provide application-level security, allowing plain text communication.
* WIFI_PROV_SECURITY_0 - It do not provide application level security, it involve simply plain text communication. - `scheme_event_handler`: Specify the handlers according to the chosen mode
- BLE:
- `WIFI_PROV_SCHEME_BLE_EVENT_HANDLER_FREE_BTDM` - Used when the application doesn't need BT and BLE after provisioning is finished.
- `WIFI_PROV_SCHEME_BLE_EVENT_HANDLER_FREE_BLE` - Used when the application doesn't need BLE to be active after provisioning is finished.
- `WIFI_PROV_SCHEME_BLE_EVENT_HANDLER_FREE_BT` - Used when the application doesn't need BT to be active after provisioning is finished.
* scheme_event_handler : specify the handlers according to the mode chosen - SoftAP:
* BLE : - `WIFI_PROV_EVENT_HANDLER_NONE`
- WIFI_PROV_SCHEME_BLE_EVENT_HANDLER_FREE_BTDM - This scheme event handler is used when application doesn't need BT and BLE after provisioning is finised
- WIFI_PROV_SCHEME_BLE_EVENT_HANDLER_FREE_BLE - This scheme event handler is used when application doesn't need BLE to be active after provisioning is finised
- WIFI_PROV_SCHEME_BLE_EVENT_HANDLER_FREE_BT - This scheme event handler is used when application doesn't need BT to be active after provisioning is finised
* SoftAp : - `pop`: String used for authentication.
- WIFI_PROV_EVENT_HANDLER_NONE
* pop : It is the string that is used to provide the authentication. - `service_name`: Specify the service name for the device. If not specified, the default chosen name is `PROV_XXX`, where XXX represents the last 3 bytes of the MAC address.
* service_name : Specify service name for the device, if it is not specified then default chosen name is PROV_XXX where XXX are the last 3 bytes of the MAC address. - `service_key`: Specify the service key. If the chosen mode of provisioning is BLE, the `service_key` is always NULL.
* service_key : Specify service key, if chosen mode of provisioning is BLE then service_key is always NULL - `uuid`: Users can specify their own 128-bit UUID while provisioning using BLE. If not specified, the default value is:
* uuid : user can specify there own 128 bit UUID while provisioning using BLE, if not specified then default value taken is ```
- { 0xb4, 0xdf, 0x5a, 0x1c, 0x3f, 0x6b, 0xf4, 0xbf, { 0xb4, 0xdf, 0x5a, 0x1c, 0x3f, 0x6b, 0xf4, 0xbf, 0xea, 0x4a, 0x82, 0x03, 0x04, 0x90, 0x1a, 0x02 }
0xea, 0x4a, 0x82, 0x03, 0x04, 0x90, 0x1a, 0x02, } ```
# NOTE - `reset_provisioned`: Resets previously provisioned data before initializing. Using this prevents problem when the device automatically connects to previously connected WiFi and therefore cannot be found.
* If none of the parameters are specified in beginProvision then default provisioning takes place using SoftAP with **NOTE:** If none of the parameters are specified in `beginProvision`, default provisioning takes place using SoftAP with the following settings:
* scheme = WIFI_PROV_SCHEME_SOFTAP - `scheme = WIFI_PROV_SCHEME_SOFTAP`
* scheme_event_handler = WIFI_PROV_EVENT_HANDLER_NONE - `scheme_event_handler = WIFI_PROV_EVENT_HANDLER_NONE`
* security = WIFI_PROV_SECURITY_1 - `security = WIFI_PROV_SECURITY_1`
* pop = "abcd1234" - `pop = "abcd1234"`
* service_name = "PROV_XXX" - `service_name = "PROV_XXX"`
* service_key = NULL - `service_key = NULL`
* uuid = NULL - `uuid = NULL`
- `reset_provisioned = false`
# Log Output ## Flashing
* Enable debuger : [ Tools -> Core Debug Level -> Info ] This sketch takes up a lot of space for the app and may not be able to flash with default setting on some chips.
If you see Error like this: "Sketch too big"
In Arduino IDE go to: Tools > Partition scheme > chose anything that has more than 1.4MB APP for example `No OTA (2MB APP/2MB SPIFFS)`
# Provisioning Tools ## Log Output
https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/provisioning/wifi_provisioning.html#provisioning-tools - To enable debugging: Go to Tools -> Core Debug Level -> Info.
# Example output ## Provisioning Tools
[Provisioning Tools](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/provisioning/wifi_provisioning.html#provisioning-tools)
## Provisioning using SoftAP ## Example Output
### Provisioning using SoftAP
``` ```
[I][WiFiProv.cpp:117] beginProvision(): Starting AP using SOFTAP [I][WiFiProv.cpp:117] beginProvision(): Starting AP using SOFTAP
service_name : PROV_XXX service_name: PROV_XXX
password : 123456789 password: 123456789
pop : abcd1234 pop: abcd1234
Provisioning started Provisioning started
Give Credentials of your access point using " Android app " Give Credentials of your access point using "Android app"
Received Wi-Fi credentials Received Wi-Fi credentials
SSID : GIONEE M2 SSID: GIONEE M2
Password : 123456789 Password: 123456789
Connected IP address : 192.168.43.120 Connected IP address: 192.168.43.120
Provisioning Successful Provisioning Successful
Provisioning Ends Provisioning Ends
``` ```
## Provisioning using BLE ### Provisioning using BLE
``` ```
[I][WiFiProv.cpp:115] beginProvision(): Starting AP using BLE [I][WiFiProv.cpp:115] beginProvision(): Starting AP using BLE
service_name : PROV_XXX service_name: PROV_XXX
pop : abcd1234 pop: abcd1234
Provisioning started Provisioning started
Give Credentials of your access point using " Android app " Give Credentials of your access point using "Android app"
Received Wi-Fi credentials Received Wi-Fi credentials
SSID : GIONEE M2 SSID: GIONEE M2
Password : 123456789 Password: 123456789
Connected IP address : 192.168.43.120 Connected IP address: 192.168.43.120
Provisioning Successful Provisioning Successful
Provisioning Ends Provisioning Ends
``` ```
## Credentials are available on device ### Credentials are available on the device
```
[I][WiFiProv.cpp:146] beginProvision(): Aleardy Provisioned, starting Wi-Fi STA
[I][WiFiProv.cpp:150] beginProvision(): SSID : Wce*****
[I][WiFiProv.cpp:152] beginProvision(): CONNECTING TO THE ACCESS POINT :
Connected IP address : 192.168.43.120
``` ```
[I][WiFiProv.cpp:146] beginProvision(): Already Provisioned, starting Wi-Fi STA
[I][WiFiProv.cpp:150] beginProvision(): SSID: Wce*****
[I][WiFiProv.cpp:152] beginProvision(): CONNECTING TO THE ACCESS POINT:
Connected IP address: 192.168.43.120
```
\ No newline at end of file
/*
Please read README.md file in this folder, or on the web:
https://github.com/espressif/arduino-esp32/tree/master/libraries/WiFiProv/examples/WiFiProv
Note: This sketch takes up a lot of space for the app and may not be able to flash with default setting on some chips.
If you see Error like this: "Sketch too big"
In Arduino IDE go to: Tools > Partition scheme > chose anything that has more than 1.4MB APP
- for example "No OTA (2MB APP/2MB SPIFFS)"
*/
#include "WiFiProv.h" #include "WiFiProv.h"
#include "WiFi.h" #include "WiFi.h"
// #define USE_SOFT_AP // Uncomment if you want to enforce using Soft AP method instead of BLE
const char * pop = "abcd1234"; // Proof of possession - otherwise called a PIN - string provided by the device, entered by user in the phone app
const char * service_name = "PROV_123"; // Name of your device (the Espressif apps expects by default device name starting with "Prov_")
const char * service_key = NULL; // Password used for SofAP method (NULL = no password needed)
bool reset_provisioned = true; // When true the library will automatically delete previously provisioned data.
void SysProvEvent(arduino_event_t *sys_event) void SysProvEvent(arduino_event_t *sys_event)
{ {
switch (sys_event->event_id) { switch (sys_event->event_id) {
...@@ -11,9 +29,9 @@ void SysProvEvent(arduino_event_t *sys_event) ...@@ -11,9 +29,9 @@ void SysProvEvent(arduino_event_t *sys_event)
Serial.println("\nDisconnected. Connecting to the AP again... "); Serial.println("\nDisconnected. Connecting to the AP again... ");
break; break;
case ARDUINO_EVENT_PROV_START: case ARDUINO_EVENT_PROV_START:
Serial.println("\nProvisioning started\nGive Credentials of your access point using \" Android app \""); Serial.println("\nProvisioning started\nGive Credentials of your access point using smartphone app");
break; break;
case ARDUINO_EVENT_PROV_CRED_RECV: { case ARDUINO_EVENT_PROV_CRED_RECV: {
Serial.println("\nReceived Wi-Fi credentials"); Serial.println("\nReceived Wi-Fi credentials");
Serial.print("\tSSID : "); Serial.print("\tSSID : ");
Serial.println((const char *) sys_event->event_info.prov_cred_recv.ssid); Serial.println((const char *) sys_event->event_info.prov_cred_recv.ssid);
...@@ -21,12 +39,12 @@ void SysProvEvent(arduino_event_t *sys_event) ...@@ -21,12 +39,12 @@ void SysProvEvent(arduino_event_t *sys_event)
Serial.println((char const *) sys_event->event_info.prov_cred_recv.password); Serial.println((char const *) sys_event->event_info.prov_cred_recv.password);
break; break;
} }
case ARDUINO_EVENT_PROV_CRED_FAIL: { case ARDUINO_EVENT_PROV_CRED_FAIL: {
Serial.println("\nProvisioning failed!\nPlease reset to factory and retry provisioning\n"); Serial.println("\nProvisioning failed!\nPlease reset to factory and retry provisioning\n");
if(sys_event->event_info.prov_fail_reason == WIFI_PROV_STA_AUTH_ERROR) if(sys_event->event_info.prov_fail_reason == WIFI_PROV_STA_AUTH_ERROR)
Serial.println("\nWi-Fi AP password incorrect"); Serial.println("\nWi-Fi AP password incorrect");
else else
Serial.println("\nWi-Fi AP not found....Add API \" nvs_flash_erase() \" before beginProvision()"); Serial.println("\nWi-Fi AP not found....Add API \" nvs_flash_erase() \" before beginProvision()");
break; break;
} }
case ARDUINO_EVENT_PROV_CRED_SUCCESS: case ARDUINO_EVENT_PROV_CRED_SUCCESS:
...@@ -42,15 +60,26 @@ void SysProvEvent(arduino_event_t *sys_event) ...@@ -42,15 +60,26 @@ void SysProvEvent(arduino_event_t *sys_event)
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
//Sample uuid that user can pass during provisioning using BLE
/* uint8_t uuid[16] = {0xb4, 0xdf, 0x5a, 0x1c, 0x3f, 0x6b, 0xf4, 0xbf,
0xea, 0x4a, 0x82, 0x03, 0x04, 0x90, 0x1a, 0x02 };*/
WiFi.onEvent(SysProvEvent); WiFi.onEvent(SysProvEvent);
#if CONFIG_IDF_TARGET_ESP32 && CONFIG_BLUEDROID_ENABLED
WiFiProv.beginProvision(WIFI_PROV_SCHEME_BLE, WIFI_PROV_SCHEME_HANDLER_FREE_BTDM, WIFI_PROV_SECURITY_1, "abcd1234", "Prov_123"); #if CONFIG_IDF_TARGET_ESP32 && CONFIG_BLUEDROID_ENABLED && not USE_SOFT_AP
Serial.println("Begin Provisioning using BLE");
// Sample uuid that user can pass during provisioning using BLE
uint8_t uuid[16] = {0xb4, 0xdf, 0x5a, 0x1c, 0x3f, 0x6b, 0xf4, 0xbf,
0xea, 0x4a, 0x82, 0x03, 0x04, 0x90, 0x1a, 0x02 };
WiFiProv.beginProvision(WIFI_PROV_SCHEME_BLE, WIFI_PROV_SCHEME_HANDLER_FREE_BTDM, WIFI_PROV_SECURITY_1, pop, service_name, service_key, uuid, reset_provisioned);
#else #else
WiFiProv.beginProvision(WIFI_PROV_SCHEME_SOFTAP, WIFI_PROV_SCHEME_HANDLER_NONE, WIFI_PROV_SECURITY_1, "abcd1234", "Prov_123"); Serial.println("Begin Provisioning using Soft AP");
WiFiProv.beginProvision(WIFI_PROV_SCHEME_SOFTAP, WIFI_PROV_SCHEME_HANDLER_NONE, WIFI_PROV_SECURITY_1, pop, service_name, service_key);
#endif #endif
#if CONFIG_BLUEDROID_ENABLED && not USE_SOFT_AP
log_d("ble qr");
WiFiProv.printQR(service_name, pop, "ble");
#else
log_d("wifi qr");
WiFiProv.printQR(service_name, pop, "softap");
#endif
} }
void loop() { void loop() {
......
...@@ -26,6 +26,9 @@ ...@@ -26,6 +26,9 @@
#include <esp_wifi.h> #include <esp_wifi.h>
#include <esp_event.h> #include <esp_event.h>
#include <esp32-hal.h> #include <esp32-hal.h>
#if __has_include("qrcode.h")
#include "qrcode.h"
#endif
#include <nvs_flash.h> #include <nvs_flash.h>
#if CONFIG_BLUEDROID_ENABLED #if CONFIG_BLUEDROID_ENABLED
...@@ -66,7 +69,7 @@ static void get_device_service_name(prov_scheme_t prov_scheme, char *service_nam ...@@ -66,7 +69,7 @@ static void get_device_service_name(prov_scheme_t prov_scheme, char *service_nam
#endif #endif
} }
void WiFiProvClass :: beginProvision(prov_scheme_t prov_scheme, scheme_handler_t scheme_handler, wifi_prov_security_t security, const char * pop, const char *service_name, const char *service_key, uint8_t * uuid) void WiFiProvClass :: beginProvision(prov_scheme_t prov_scheme, scheme_handler_t scheme_handler, wifi_prov_security_t security, const char * pop, const char *service_name, const char *service_key, uint8_t * uuid, bool reset_provisioned)
{ {
bool provisioned = false; bool provisioned = false;
static char service_name_temp[32]; static char service_name_temp[32];
...@@ -107,10 +110,13 @@ void WiFiProvClass :: beginProvision(prov_scheme_t prov_scheme, scheme_handler_t ...@@ -107,10 +110,13 @@ void WiFiProvClass :: beginProvision(prov_scheme_t prov_scheme, scheme_handler_t
log_e("wifi_prov_mgr_init failed!"); log_e("wifi_prov_mgr_init failed!");
return; return;
} }
if(wifi_prov_mgr_is_provisioned(&provisioned) != ESP_OK){ if(reset_provisioned){
log_e("wifi_prov_mgr_is_provisioned failed!"); log_i("Resetting provisioned data.");
wifi_prov_mgr_deinit(); wifi_prov_mgr_reset_provisioning();
return; }else if(wifi_prov_mgr_is_provisioned(&provisioned) != ESP_OK){
log_e("wifi_prov_mgr_is_provisioned failed!");
wifi_prov_mgr_deinit();
return;
} }
if(provisioned == false) { if(provisioned == false) {
#if CONFIG_BLUEDROID_ENABLED #if CONFIG_BLUEDROID_ENABLED
...@@ -158,4 +164,30 @@ void WiFiProvClass :: beginProvision(prov_scheme_t prov_scheme, scheme_handler_t ...@@ -158,4 +164,30 @@ void WiFiProvClass :: beginProvision(prov_scheme_t prov_scheme, scheme_handler_t
} }
} }
// Copied from IDF example
void WiFiProvClass :: printQR(const char *name, const char *pop, const char *transport){
if (!name || !transport) {
log_w("Cannot generate QR code payload. Data missing.");
return;
}
char payload[150] = {0};
if (pop) {
snprintf(payload, sizeof(payload), "{\"ver\":\"%s\",\"name\":\"%s\"" \
",\"pop\":\"%s\",\"transport\":\"%s\"}",
"v1", name, pop, transport);
} else {
snprintf(payload, sizeof(payload), "{\"ver\":\"%s\",\"name\":\"%s\"" \
",\"transport\":\"%s\"}",
"v1", name, transport);
}
#if __has_include("qrcode.h")
log_i("Scan this QR code from the provisioning application for Provisioning.");
esp_qrcode_config_t cfg = ESP_QRCODE_CONFIG_DEFAULT();
esp_qrcode_generate(&cfg, payload);
#else
log_i("If QR code is not visible, copy paste the below URL in a browser.\n%s?data=%s", "https://espressif.github.io/esp-jumpstart/qrcode.html", payload);
log_i("If you are using Arduino as IDF component, install ESP Rainmaker:\nhttps://github.com/espressif/esp-rainmaker");
#endif
}
WiFiProvClass WiFiProv; WiFiProvClass WiFiProv;
...@@ -47,7 +47,9 @@ class WiFiProvClass ...@@ -47,7 +47,9 @@ class WiFiProvClass
public: public:
void beginProvision(prov_scheme_t prov_scheme = WIFI_PROV_SCHEME_SOFTAP, scheme_handler_t scheme_handler = WIFI_PROV_SCHEME_HANDLER_NONE, void beginProvision(prov_scheme_t prov_scheme = WIFI_PROV_SCHEME_SOFTAP, scheme_handler_t scheme_handler = WIFI_PROV_SCHEME_HANDLER_NONE,
wifi_prov_security_t security = WIFI_PROV_SECURITY_1, const char * pop = "abcd1234", const char * service_name = NULL, const char * service_key = NULL, uint8_t *uuid = NULL); wifi_prov_security_t security = WIFI_PROV_SECURITY_1, const char * pop = "abcd1234", const char * service_name = NULL,
const char * service_key = NULL, uint8_t *uuid = NULL, bool reset_provisioned = false);
void printQR(const char *name, const char *pop, const char *transport);
}; };
extern WiFiProvClass WiFiProv; extern WiFiProvClass WiFiProv;
......
#ifndef Pins_Arduino_h
#define Pins_Arduino_h
#include <stdint.h>
#define USB_VID 0x303a
#define USB_PID 0x1001
#define EXTERNAL_NUM_INTERRUPTS 20
#define NUM_DIGITAL_PINS 20
#define NUM_ANALOG_INPUTS 6
#define analogInputToDigitalPin(p) (((p)<6)?(analogChannelToDigitalPin(p)):-1)
#define digitalPinToInterrupt(p) (((p)<20)?(p):-1)
#define digitalPinHasPWM(p) (p < 20)
static const uint8_t LED_BUILTIN = 45;
#define BUILTIN_LED LED_BUILTIN // backward compatibility
#define LED_BUILTIN LED_BUILTIN
#define RGB_BUILTIN LED_BUILTIN
#define RGB_BRIGHTNESS 64
static const uint8_t TX = 43;
static const uint8_t RX = 44;
static const uint8_t SDA = 12;
static const uint8_t SCL = 13;
static const uint8_t SDA1 = 2;
static const uint8_t SCL1 = 1;
static const uint8_t SS = 41;
static const uint8_t MOSI = 40;
static const uint8_t MISO = 39;
static const uint8_t SCK = 38;
static const uint8_t D0 = 1;
static const uint8_t D1 = 2;
static const uint8_t D2 = 44;
static const uint8_t D3 = 43;
static const uint8_t D4 = 42;
static const uint8_t D5 = 41;
static const uint8_t D6 = 40;
static const uint8_t D7 = 39;
static const uint8_t D8 = 38;
static const uint8_t D9 = 27;
static const uint8_t D10 = 45;
static const uint8_t D11 = 4;
static const uint8_t D12 = 5;
static const uint8_t D13 = 6;
static const uint8_t D14 = 7;
static const uint8_t D15 = 15;
static const uint8_t D16 = 16;
static const uint8_t D17 = 17;
static const uint8_t D18 = 18;
static const uint8_t A0 = 4;
static const uint8_t A1 = 5;
static const uint8_t A2 = 6;
static const uint8_t A3 = 7;
static const uint8_t A4 = 1;
static const uint8_t A5 = 2;
#endif /* Pins_Arduino_h */
# ESP-IDF Partition Table
# Name, Type, SubType, Offset, Size, Flags
# bootloader.bin,, 0x1000, 32K
# partition table,, 0x8000, 4K
nvs, data, nvs, 0x9000, 20K,
otadata, data, ota, 0xe000, 8K,
ota_0, app, ota_0, 0x10000, 2048K,
ota_1, app, ota_1, 0x210000, 2048K,
uf2, app, factory,0x410000, 256K,
ffat, data, fat, 0x450000, 3776K,
#ifndef Pins_Arduino_h
#define Pins_Arduino_h
#include <stdint.h>
#define USB_VID 0x239A
#define USB_PID 0x8125
#define USB_MANUFACTURER "Adafruit"
#define USB_PRODUCT "MatrixPortal ESP32-S3"
#define USB_SERIAL "" // Empty string for MAC adddress
#define EXTERNAL_NUM_INTERRUPTS 46
#define NUM_DIGITAL_PINS 48
#define NUM_ANALOG_INPUTS 6
#define analogInputToDigitalPin(p) (((p)<NUM_ANALOG_INPUTS)?(analogChannelToDigitalPin(p)):-1)
#define digitalPinToInterrupt(p) (((p)<EXTERNAL_NUM_INTERRUPTS)?(p):-1)
#define digitalPinHasPWM(p) (p < 46)
#define LED_BUILTIN 13
#define PIN_NEOPIXEL 33
#define NEOPIXEL_NUM 1
static const uint8_t TX = 18;
static const uint8_t RX = 8;
#define TX1 TX
#define RX1 RX
static const uint8_t SDA = 16;
static const uint8_t SCL = 17;
static const uint8_t SS = -1;
static const uint8_t MOSI = -1;
static const uint8_t SCK = -1;
static const uint8_t MISO = -1;
static const uint8_t A0 = 12;
static const uint8_t A1 = 3;
static const uint8_t A2 = 9;
static const uint8_t A3 = 10;
static const uint8_t A4 = 11;
static const uint8_t A5 = 5; // Light
static const uint8_t T3 = 3; // Touch pin IDs map directly
static const uint8_t T8 = 8; // to underlying GPIO numbers NOT
static const uint8_t T9 = 9; // the analog numbers on board silk
static const uint8_t T10 = 10;
static const uint8_t T11 = 11;
static const uint8_t T12 = 12;
#endif /* Pins_Arduino_h */
#ifndef Pins_Arduino_h
#define Pins_Arduino_h
#include <stdint.h>
#define EXTERNAL_NUM_INTERRUPTS 46
#define NUM_DIGITAL_PINS 48
#define NUM_ANALOG_INPUTS 20
#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1)
#define digitalPinToInterrupt(p) (((p)<48)?(p):-1)
#define digitalPinHasPWM(p) (p < 46)
static const uint8_t TX = 43;
static const uint8_t RX = 44;
static const uint8_t SDA = 1;
static const uint8_t SCL = 2;
static const uint8_t MOSI = 15;
static const uint8_t MISO = 16;
static const uint8_t SCK = 17;
static const uint8_t SS = 18;
#define GDI_DISPLAY_FPC_INTERFACE
#ifdef GDI_DISPLAY_FPC_INTERFACE
#define GDI_BLK 21
#define GDI_SPI_SCLK SCK
#define GDI_SPI_MOSI MOSI
#define GDI_SPI_MISO MISO
#define GDI_DC 3
#define GDI_RES 38
#define GDI_CS 18
#define GDI_SDCS 0
#define GDI_FCS 7
#define GDI_TCS 12
#define GDI_SCL SCL
#define GDI_SDA SDA
#define GDI_INT 13
#define GDI_BUSY_TE 14
#endif /* GDI_DISPLAY_FPC_INTERFACE */
// CAM
#define CAM_DVP_INTERFACE
#ifdef CAM_DVP_INTERFACE
#define CAM_D5 4
#define CAM_PCLK 5
#define CAM_VSYNC 6
#define CAM_D6 7
#define CAM_D7 8
#define CAM_D8 46
#define CAM_D9 48
#define CAM_XMCLK 45
#define CAM_D2 39
#define CAM_D3 40
#define CAM_D4 41
#define CAM_HREF 42
#define CAM_SCL SCL
#define CAM_SDA SDA
#endif /* CAM_DVP_INTERFACE */
// Motor
#define MOTOR_INTERFACE
#ifdef MOTOR_INTERFACE
#define M1_EN 12
#define M1_PH 13
#define M2_EN 14
#define M2_PH 21
#define M3_EN 9
#define M3_PH 10
#define M4_EN 47
#define M4_PH 11
#endif
#endif /* Pins_Arduino_h */
#ifndef Pins_Arduino_h
#define Pins_Arduino_h
#include <stdint.h>
#include "soc/soc_caps.h"
#define USB_VID 0x303a
#define USB_PID 0x1001
#define EXTERNAL_NUM_INTERRUPTS 46
#define NUM_DIGITAL_PINS 48
#define NUM_ANALOG_INPUTS 20
// Some boards have too low voltage on this pin (board design bug)
// Use different pin with 3V and connect with 48
// and change this setup for the chosen pin (for example 38)
static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + 48;
#define BUILTIN_LED LED_BUILTIN // backward compatibility
#define LED_BUILTIN LED_BUILTIN
#define RGB_BUILTIN LED_BUILTIN
#define RGB_BRIGHTNESS 64
#define analogInputToDigitalPin(p) \
(((p) < 20) ? (analogChannelToDigitalPin(p)) : -1)
#define digitalPinToInterrupt(p) (((p) < 48) ? (p) : -1)
#define digitalPinHasPWM(p) (p < 46)
static const uint8_t TX = 43;
static const uint8_t RX = 44;
static const uint8_t TXD2 = 17;
static const uint8_t RXD2 = 18;
static const uint8_t SDA = 12;
static const uint8_t SCL = 11;
static const uint8_t SS = 15;
static const uint8_t MOSI = 37;
static const uint8_t MISO = 35;
static const uint8_t SCK = 36;
static const uint8_t G0 = 0;
static const uint8_t G1 = 1;
static const uint8_t G2 = 2;
static const uint8_t G3 = 3;
static const uint8_t G4 = 4;
static const uint8_t G5 = 5;
static const uint8_t G6 = 6;
static const uint8_t G7 = 7;
static const uint8_t G8 = 8;
static const uint8_t G9 = 9;
static const uint8_t G11 = 11;
static const uint8_t G12 = 12;
static const uint8_t G13 = 13;
static const uint8_t G14 = 14;
static const uint8_t G17 = 17;
static const uint8_t G18 = 18;
static const uint8_t G19 = 19;
static const uint8_t G20 = 20;
static const uint8_t G21 = 21;
static const uint8_t G33 = 33;
static const uint8_t G34 = 34;
static const uint8_t G35 = 35;
static const uint8_t G36 = 36;
static const uint8_t G37 = 37;
static const uint8_t G38 = 38;
static const uint8_t G45 = 45;
static const uint8_t G46 = 46;
static const uint8_t ADC = 10;
#endif /* Pins_Arduino_h */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment