From b90bbd6349bd08e9bf3bf065d22948f597fe8f0f Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Sun, 13 Oct 2019 14:13:15 -0500 Subject: [PATCH 1/7] Add setDigitalRead command handler type and command handler. --- main/CommandHandler.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/main/CommandHandler.cpp b/main/CommandHandler.cpp index 9190e28..d4359cd 100644 --- a/main/CommandHandler.cpp +++ b/main/CommandHandler.cpp @@ -994,6 +994,19 @@ int setAnalogWrite(const uint8_t command[], uint8_t response[]) return 6; } +int setDigitalRead(const uint8_t command[], uint8_t response[]) +{ + uint8_t pin = command[4]; + + int8_t value = digitalRead(pin); + + response[2] = 1; // number of parameters + response[3] = 1; // parameter 1 length + response[4] = value; + + return 6; +} + int wpa2EntSetIdentity(const uint8_t command[], uint8_t response[]) { char identity[32 + 1]; @@ -1112,7 +1125,7 @@ const CommandHandlerType commandHandlers[] = { setClientCert, setCertKey, NULL, NULL, sendDataTcp, getDataBufTcp, insertDataBuf, NULL, NULL, NULL, wpa2EntSetIdentity, wpa2EntSetUsername, wpa2EntSetPassword, wpa2EntSetCACert, wpa2EntSetCertKey, wpa2EntEnable, // 0x50 -> 0x5f - setPinMode, setDigitalWrite, setAnalogWrite, + setPinMode, setDigitalWrite, setAnalogWrite, setDigitalRead, }; #define NUM_COMMAND_HANDLERS (sizeof(commandHandlers) / sizeof(commandHandlers[0])) From 5687201ec9b9a5fe886cdbaac94207c4d466176d Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Sun, 13 Oct 2019 21:32:06 -0500 Subject: [PATCH 2/7] Add setAnalogRead type & command handler. Add core analogRead function. --- arduino/cores/esp32/wiring_analog.c | 9 +++++++++ arduino/cores/esp32/wiring_analog.h | 2 ++ main/CommandHandler.cpp | 15 ++++++++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/arduino/cores/esp32/wiring_analog.c b/arduino/cores/esp32/wiring_analog.c index f81a1b9..b265c7b 100644 --- a/arduino/cores/esp32/wiring_analog.c +++ b/arduino/cores/esp32/wiring_analog.c @@ -18,6 +18,7 @@ */ #include +#include #include "wiring_analog.h" @@ -43,3 +44,11 @@ void analogWrite(uint32_t pin, uint32_t value) }; ledc_channel_config(&ledc_conf); } + +int analogRead(uint32_t pin) +{ + adc1_config_width(ADC_WIDTH_BIT_12); + adc1_config_channel_atten(pin,ADC_ATTEN_DB_11); + int val = adc1_get_raw(pin); + return val; +} diff --git a/arduino/cores/esp32/wiring_analog.h b/arduino/cores/esp32/wiring_analog.h index 39a734b..0902ac0 100644 --- a/arduino/cores/esp32/wiring_analog.h +++ b/arduino/cores/esp32/wiring_analog.h @@ -28,6 +28,8 @@ extern "C" { extern void analogWrite(uint32_t pin, uint32_t value); +extern int analogRead(uint32_t pin); + #ifdef __cplusplus } #endif diff --git a/main/CommandHandler.cpp b/main/CommandHandler.cpp index d4359cd..db81052 100644 --- a/main/CommandHandler.cpp +++ b/main/CommandHandler.cpp @@ -1007,6 +1007,19 @@ int setDigitalRead(const uint8_t command[], uint8_t response[]) return 6; } +int setAnalogRead(const uint8_t command[], uint8_t response[]) +{ + uint8_t pin = command[4]; + + int value = digitalRead(pin); + + response[2] = 1; // number of parameters + response[3] = sizeof(value); // parameter 1 length + memcpy(&response[4], &value, sizeof(value)); + + return 5 + sizeof(value); +} + int wpa2EntSetIdentity(const uint8_t command[], uint8_t response[]) { char identity[32 + 1]; @@ -1125,7 +1138,7 @@ const CommandHandlerType commandHandlers[] = { setClientCert, setCertKey, NULL, NULL, sendDataTcp, getDataBufTcp, insertDataBuf, NULL, NULL, NULL, wpa2EntSetIdentity, wpa2EntSetUsername, wpa2EntSetPassword, wpa2EntSetCACert, wpa2EntSetCertKey, wpa2EntEnable, // 0x50 -> 0x5f - setPinMode, setDigitalWrite, setAnalogWrite, setDigitalRead, + setPinMode, setDigitalWrite, setAnalogWrite, setDigitalRead, setAnalogRead, }; #define NUM_COMMAND_HANDLERS (sizeof(commandHandlers) / sizeof(commandHandlers[0])) From b9c66fa1b1f6a4b91d5c12dd937e82b88eb0dd71 Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Mon, 14 Oct 2019 00:32:48 -0500 Subject: [PATCH 3/7] Convert pin to ADC1 channel. --- arduino/cores/esp32/wiring_analog.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/arduino/cores/esp32/wiring_analog.c b/arduino/cores/esp32/wiring_analog.c index b265c7b..e72650d 100644 --- a/arduino/cores/esp32/wiring_analog.c +++ b/arduino/cores/esp32/wiring_analog.c @@ -19,6 +19,7 @@ #include #include +#include #include "wiring_analog.h" @@ -47,8 +48,31 @@ void analogWrite(uint32_t pin, uint32_t value) int analogRead(uint32_t pin) { + int channel; + switch(pin) + { + case ADC1_CHANNEL_0_GPIO_NUM: + channel = ADC1_GPIO36_CHANNEL; + case ADC1_CHANNEL_1_GPIO_NUM: + channel = ADC1_GPIO37_CHANNEL; + case ADC1_CHANNEL_2_GPIO_NUM: + channel = ADC1_GPIO38_CHANNEL; + case ADC1_CHANNEL_3_GPIO_NUM: + channel = ADC1_GPIO39_CHANNEL; + case ADC1_CHANNEL_4_GPIO_NUM: + channel = ADC1_GPIO32_CHANNEL; + case ADC1_CHANNEL_5_GPIO_NUM: + channel = ADC1_GPIO33_CHANNEL; + case ADC1_CHANNEL_6_GPIO_NUM: + channel = ADC1_GPIO34_CHANNEL; + case ADC1_CHANNEL_7_GPIO_NUM: + channel = ADC1_GPIO35_CHANNEL; + default: + return -1; + } + adc1_config_width(ADC_WIDTH_BIT_12); - adc1_config_channel_atten(pin,ADC_ATTEN_DB_11); - int val = adc1_get_raw(pin); + adc1_config_channel_atten(channel, ADC_ATTEN_DB_11); + int val = adc1_get_raw(channel); return val; } From 6bb17bb1794a5348799a1cdfae70d3b93795abbc Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Thu, 17 Oct 2019 00:12:35 -0500 Subject: [PATCH 4/7] Add basic ADC calibration. --- arduino/cores/esp32/wiring_analog.c | 22 +++++++++++++++++++--- arduino/cores/esp32/wiring_analog.h | 2 +- main/CommandHandler.cpp | 4 +++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/arduino/cores/esp32/wiring_analog.c b/arduino/cores/esp32/wiring_analog.c index e72650d..9b80a0c 100644 --- a/arduino/cores/esp32/wiring_analog.c +++ b/arduino/cores/esp32/wiring_analog.c @@ -19,6 +19,7 @@ #include #include +#include #include #include "wiring_analog.h" @@ -46,33 +47,48 @@ void analogWrite(uint32_t pin, uint32_t value) ledc_channel_config(&ledc_conf); } -int analogRead(uint32_t pin) +int analogRead(uint32_t pin, uint32_t atten) { - int channel; + #define DEFAULT_VREF 1100 + static esp_adc_cal_characteristics_t *adc_chars; + adc_channel_t channel; + switch(pin) { case ADC1_CHANNEL_0_GPIO_NUM: channel = ADC1_GPIO36_CHANNEL; + break; case ADC1_CHANNEL_1_GPIO_NUM: channel = ADC1_GPIO37_CHANNEL; + break; case ADC1_CHANNEL_2_GPIO_NUM: channel = ADC1_GPIO38_CHANNEL; + break; case ADC1_CHANNEL_3_GPIO_NUM: channel = ADC1_GPIO39_CHANNEL; + break; case ADC1_CHANNEL_4_GPIO_NUM: channel = ADC1_GPIO32_CHANNEL; + break; case ADC1_CHANNEL_5_GPIO_NUM: channel = ADC1_GPIO33_CHANNEL; + break; case ADC1_CHANNEL_6_GPIO_NUM: channel = ADC1_GPIO34_CHANNEL; + break; case ADC1_CHANNEL_7_GPIO_NUM: channel = ADC1_GPIO35_CHANNEL; + break; default: return -1; } adc1_config_width(ADC_WIDTH_BIT_12); - adc1_config_channel_atten(channel, ADC_ATTEN_DB_11); + adc1_config_channel_atten(channel, atten); + + adc_chars = calloc(1, sizeof(esp_adc_cal_characteristics_t)); + esp_adc_cal_characterize(ADC_UNIT_1, atten, ADC_WIDTH_BIT_12, DEFAULT_VREF, adc_chars); + int val = adc1_get_raw(channel); return val; } diff --git a/arduino/cores/esp32/wiring_analog.h b/arduino/cores/esp32/wiring_analog.h index 0902ac0..2bc480d 100644 --- a/arduino/cores/esp32/wiring_analog.h +++ b/arduino/cores/esp32/wiring_analog.h @@ -28,7 +28,7 @@ extern "C" { extern void analogWrite(uint32_t pin, uint32_t value); -extern int analogRead(uint32_t pin); +extern int analogRead(uint32_t pin, uint32_t atten); #ifdef __cplusplus } diff --git a/main/CommandHandler.cpp b/main/CommandHandler.cpp index db81052..bca87bb 100644 --- a/main/CommandHandler.cpp +++ b/main/CommandHandler.cpp @@ -1010,11 +1010,13 @@ int setDigitalRead(const uint8_t command[], uint8_t response[]) int setAnalogRead(const uint8_t command[], uint8_t response[]) { uint8_t pin = command[4]; + uint8_t atten = command[6]; - int value = digitalRead(pin); + int value = analogRead(pin, atten); response[2] = 1; // number of parameters response[3] = sizeof(value); // parameter 1 length + memcpy(&response[4], &value, sizeof(value)); return 5 + sizeof(value); From 687498c981a4bcf5dda14b25cb03b2319c6111a6 Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Thu, 17 Oct 2019 10:17:38 -0500 Subject: [PATCH 5/7] Bumped version to 1.4.1 --- combine.py | 4 ++-- main/CommandHandler.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/combine.py b/combine.py index 5ce43e9..127d1c3 100644 --- a/combine.py +++ b/combine.py @@ -7,7 +7,7 @@ partitionData = open("build/partitions.bin", "rb").read() appData = open("build/nina-fw.bin", "rb").read() certsData = open("data/roots.pem", "rb").read() -# calculate the output binary size, app offset +# calculate the output binary size, app offset outputSize = 0x30000 + len(appData) if (outputSize % 1024): outputSize += 1024 - (outputSize % 1024) @@ -31,7 +31,7 @@ for i in range(0, len(certsData)): # zero terminate the pem file outputData[0x10000 + len(certsData)] = 0 -outputFilename = "NINA_W102-1.4.0.bin" +outputFilename = "NINA_W102-1.4.1.bin" if (len(sys.argv) > 1): outputFilename = sys.argv[1] diff --git a/main/CommandHandler.cpp b/main/CommandHandler.cpp index bca87bb..3cc6f15 100644 --- a/main/CommandHandler.cpp +++ b/main/CommandHandler.cpp @@ -28,7 +28,7 @@ #include "Arduino.h" -const char FIRMWARE_VERSION[6] = "1.4.0"; +const char FIRMWARE_VERSION[6] = "1.4.1"; // Optional, user-defined X.509 certificate char CERT_BUF[1300]; From fa5f7a54867d9734a84cd6643739396bce6a7df6 Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Thu, 17 Oct 2019 10:51:01 -0500 Subject: [PATCH 6/7] v1.5.0. --- Makefile | 4 ++-- combine.py | 2 +- main/CommandHandler.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 4ee9c75..b58702d 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ load-passthrough: cp passthrough.UF2 $(BOOT_VOLUME) load-nina: - esptool.py --port $(M4_PORT) --before no_reset --baud $(UPLOAD_BAUD) write_flash 0 NINA_W102-1.4.0.bin + esptool.py --port $(M4_PORT) --before no_reset --baud $(UPLOAD_BAUD) write_flash 0 NINA_W102-1.5.0.bin load-circuitpython: cp $(CIRCUITPYTHON_UF2) $(BOOT_VOLUME) @@ -47,4 +47,4 @@ firmware: all .PHONY: load-circuitpython -.PHONY: serial \ No newline at end of file +.PHONY: serial diff --git a/combine.py b/combine.py index 127d1c3..25951a4 100644 --- a/combine.py +++ b/combine.py @@ -31,7 +31,7 @@ for i in range(0, len(certsData)): # zero terminate the pem file outputData[0x10000 + len(certsData)] = 0 -outputFilename = "NINA_W102-1.4.1.bin" +outputFilename = "NINA_W102-1.5.0.bin" if (len(sys.argv) > 1): outputFilename = sys.argv[1] diff --git a/main/CommandHandler.cpp b/main/CommandHandler.cpp index 3cc6f15..ebf6dde 100644 --- a/main/CommandHandler.cpp +++ b/main/CommandHandler.cpp @@ -28,7 +28,7 @@ #include "Arduino.h" -const char FIRMWARE_VERSION[6] = "1.4.1"; +const char FIRMWARE_VERSION[6] = "1.5.0"; // Optional, user-defined X.509 certificate char CERT_BUF[1300]; From 8a15b9e195907ad0ab699633e42b759b94d58dc4 Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Mon, 21 Oct 2019 10:57:43 -0500 Subject: [PATCH 7/7] Metadata updates Pulled over a code-of-conduct.md from a random Arduino library (the CircuitPython one mentions a lot of CircuitPython specifics), and added **Contributing** section to README. Curious that there isn't a central place where a code of conduct can be stored, with a reference rather than a copy in each repo. Updated CHANGELOG for 1.3.1, 1.4.0, and 1.5.0. --- CHANGELOG | 11 ++++ README.md | 16 +++++- code-of-conduct.md | 127 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 code-of-conduct.md diff --git a/CHANGELOG b/CHANGELOG index aef0fb5..33cf3fc 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,16 @@ +Adafruit's Arduino NINA-W102 firmware 1.5.0 - 2019.10.21 + +* Added Digital Read and Analog Read + +Adafruit's Arduino NINA-W102 firmware 1.4.0 - 2019.10.09 + +* Updated to use ESP-IDF 3.3 (LTS) +* Updated WiFiSSLClient +* Workflow improvements in Makefile + Adafruit's Arduino NINA-W102 firmware 1.3.1 - 2019.04.24 +* Added WPA2 Enterprise * Updated README.md to indicate this is Adafruit's fork * Updated README.md with current, reproducible build instructions * Updated CHANGELOG with various Adafruit changes diff --git a/README.md b/README.md index a80ee4d..5a05d10 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,20 @@ repository is located at https://github.com/arduino/nina-fw This firmware uses [Espressif's IDF](https://github.com/espressif/esp-idf) +## Contributing to nina-fw + +Please be aware that by contributing to this project +you are agreeing to the [Code of Conduct](https://github.com/adafruit/nina-fw/code-of-conduct.md). +Contributors who follow the [Code of Conduct](https://github.com/adafruit/nina-fw/code-of-conduct.md) +are welcome to submit pull requests and they will be promptly +reviewed by project admins. Please join the [Discord](https://adafru.it/discord) too. + +The NINA firmware version needs to be updated in four places in this repo: +1. CommandHandler.cpp +1. combine.py +1. Makefile +1. CHANGELOG + ## Building The firmware shipped in Adafruit's products is compiled following these @@ -20,7 +34,7 @@ original Arduino firmware repository. 1. Use appropriate tools (esptool.py, appropriate pass-through firmware etc) to load this binary file onto your board. a. If you do not know how to do this, [we have an excellent guide on the Adafruit Learning System for upgrading your ESP32's firmware](https://learn.adafruit.com/upgrading-esp32-firmware) - + ## License diff --git a/code-of-conduct.md b/code-of-conduct.md new file mode 100644 index 0000000..50845e5 --- /dev/null +++ b/code-of-conduct.md @@ -0,0 +1,127 @@ +# Adafruit Community Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and leaders pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, gender identity and expression, level or type of +experience, education, socio-economic status, nationality, personal appearance, +race, religion, or sexual identity and orientation. + +## Our Standards + +We are committed to providing a friendly, safe and welcoming environment for +all. + +Examples of behavior that contributes to creating a positive environment +include: + +* Be kind and courteous to others +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Collaborating with other community members +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and sexual attention or advances +* The use of inappropriate images, including in a community member's avatar +* The use of inappropriate language, including in a community member's nickname +* Any spamming, flaming, baiting or other attention-stealing behavior +* Excessive or unwelcome helping; answering outside the scope of the question + asked +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate + +The goal of the standards and moderation guidelines outlined here is to build +and maintain a respectful community. We ask that you don’t just aim to be +"technically unimpeachable", but rather try to be your best self. + +We value many things beyond technical expertise, including collaboration and +supporting others within our community. Providing a positive experience for +other community members can have a much more significant impact than simply +providing the correct answer. + +## Our Responsibilities + +Project leaders are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project leaders have the right and responsibility to remove, edit, or +reject messages, comments, commits, code, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any community member for other behaviors that they deem +inappropriate, threatening, offensive, or harmful. + +## Moderation + +Instances of behaviors that violate the Adafruit Community Code of Conduct +may be reported by any member of the community. Community members are +encouraged to report these situations, including situations they witness +involving other community members. + +You may report in the following ways: + +In any situation, you may send an email to . + +On the Adafruit Discord, you may send an open message from any channel +to all Community Helpers by tagging @community helpers. You may also send an +open message from any channel, or a direct message to @kattni#1507, +@tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, or +@Andon#8175. + +Email and direct message reports will be kept confidential. + +In situations on Discord where the issue is particularly egregious, possibly +illegal, requires immediate action, or violates the Discord terms of service, +you should also report the message directly to Discord. + +These are the steps for upholding our community’s standards of conduct. + +1. Any member of the community may report any situation that violates the +Adafruit Community Code of Conduct. All reports will be reviewed and +investigated. +2. If the behavior is an egregious violation, the community member who +committed the violation may be banned immediately, without warning. +3. Otherwise, moderators will first respond to such behavior with a warning. +4. Moderators follow a soft "three strikes" policy - the community member may +be given another chance, if they are receptive to the warning and change their +behavior. +5. If the community member is unreceptive or unreasonable when warned by a +moderator, or the warning goes unheeded, they may be banned for a first or +second offense. Repeated offenses will result in the community member being +banned. + +## Scope + +This Code of Conduct and the enforcement policies listed above apply to all +Adafruit Community venues. This includes but is not limited to any community +spaces (both public and private), the entire Adafruit Discord server, and +Adafruit GitHub repositories. Examples of Adafruit Community spaces include +but are not limited to meet-ups, audio chats on the Adafruit Discord, or +interaction at a conference. + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. As a community +member, you are representing our community, and are expected to behave +accordingly. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 1.4, available at +, +and the [Rust Code of Conduct](https://www.rust-lang.org/en-US/conduct.html). + +For other projects adopting the Adafruit Community Code of +Conduct, please contact the maintainers of those projects for enforcement. +If you wish to use this code of conduct for your own project, consider +explicitly mentioning your moderation policy or making a copy with your +own moderation policy so as to avoid confusion.