64 Commits

Author SHA1 Message Date
Kuba Szczodrzyński
dfde2d8a62 [release] v0.10.0
Some checks failed
Lint check / Lint with clang-format (push) Has been cancelled
Lint check / Lint with black (push) Has been cancelled
PlatformIO Publish / publish (push) Has been cancelled
2022-09-03 21:40:04 +02:00
Kuba Szczodrzyński
a3f57114da [core] Update ltchiptool to v1.5.2 2022-09-03 21:38:46 +02:00
Kuba Szczodrzyński
904af10914 [core] Implement POSIX gettimeofday() and settimeofday() 2022-09-03 21:26:07 +02:00
Kuba Szczodrzyński
9b5013a694 [beken-72xx] Move periodic heap logging to core 2022-09-03 21:25:39 +02:00
Kuba Szczodrzyński
922adfd3d4 [core] Print full error details in Update library 2022-09-03 21:24:46 +02:00
Kuba Szczodrzyński
362144033b [core] Move main.cpp to core directory 2022-09-03 20:01:24 +02:00
Kuba Szczodrzyński
caf9a579d3 [beken-72xx] Fix writing 0% and 100% with PWM 2022-09-03 19:01:17 +02:00
Kuba Szczodrzyński
cb40fdcdbe [beken-72xx] Unprotect flash before writing 2022-09-03 17:50:36 +02:00
Kuba Szczodrzyński
ef15e754c9 [core] Make LT API usable from C 2022-09-03 17:49:19 +02:00
Kuba Szczodrzyński
d55568c146 [beken-72xx] Fix PWM on BK7231N 2022-09-02 23:58:38 +02:00
Kuba Szczodrzyński
e134863db1 [realtek-ambz] Fix mDNS compilation problem on lwIP < 2.1.0 2022-09-02 21:11:12 +02:00
Kuba Szczodrzyński
c37ae51dd3 [core] Update default logging options, fix disabling logger 2022-09-02 14:35:21 +02:00
Kuba Szczodrzyński
4fc2ff43c1 [core] Make info, warning and error logging per-module configurable 2022-09-02 14:12:05 +02:00
Kuba Szczodrzyński
607f13d935 [core] Refactor per-module logger macros 2022-09-02 14:02:00 +02:00
Kuba Szczodrzyński
44c1a3f695 [beken-72xx] Fix digitalRead() setting wrong pin mode 2022-09-01 21:13:04 +02:00
Kuba Szczodrzyński
d30decfbc8 [core] Fix lwipopts.h invalid include 2022-09-01 19:09:19 +02:00
Kuba Szczodrzyński
705b2f794e [beken-72xx] Increase TCP/IP stack size to fix mDNS stack overflow 2022-08-31 22:39:49 +02:00
Kuba Szczodrzyński
4958690d9e [core] Make lwIP debugging configurable 2022-08-31 22:38:07 +02:00
Kuba Szczodrzyński
d7749d3a24 [core] Export Update combined error code 2022-08-31 22:28:47 +02:00
Kuba Szczodrzyński
73e07a594f [core] Add mDNS debug logging, start IGMP if not enabled 2022-08-31 22:28:13 +02:00
Kuba Szczodrzyński
755c2ef400 [core] Add periodical free heap logging 2022-08-31 22:26:12 +02:00
Kuba Szczodrzyński
3f588e970a [core] Rework mDNS responder to fix TXT records 2022-08-27 00:00:45 +02:00
Kuba Szczodrzyński
3264807e77 [core] Fix StreamString clearing data using println() 2022-08-26 20:03:01 +02:00
Kuba Szczodrzyński
01225d4648 [beken-72xx] Update to external lwIP v2.1.3 2022-08-26 20:02:57 +02:00
Kuba Szczodrzyński
48aa809c98 [beken-72xx] Move to external lwIP v2.0.2 2022-08-25 23:34:54 +02:00
Kuba Szczodrzyński
4a722d4069 [core] Add option to debug FlashDB 2022-08-25 13:45:01 +02:00
Kuba Szczodrzyński
07aca2a0e7 [beken-72xx] Unprotect flash after initializing 2022-08-25 13:44:24 +02:00
Kuba Szczodrzyński
10000d9b6c [beken-72xx] Fix enabling WiFi AP mode only 2022-08-18 14:15:41 +02:00
Kuba Szczodrzyński
f0e247f31e [core] Print error if WiFi mode changing failed 2022-08-18 14:15:05 +02:00
Kuba Szczodrzyński
593dec5e88 [beken-72xx] Update ltchiptool to fix corrupted output binaries 2022-08-17 22:40:56 +02:00
Kuba Szczodrzyński
c45b86c993 [beken-72xx] Fix enabling AP mode 2022-08-17 15:17:14 +02:00
Kuba Szczodrzyński
02f01f2199 [beken-72xx] Initialize WiFiData when needed, null-terminate SSIDs 2022-08-17 11:24:32 +02:00
Kuba Szczodrzyński
88b1adc2d6 [github] Fix docs custom domain deployment 2022-08-16 23:24:20 +02:00
Kuba Szczodrzyński
a0a0e6775b [beken-72xx] Improve WiFi status recognition, fix null pointer access 2022-08-16 22:52:05 +02:00
Kuba Szczodrzyński
4096253694 [github] Add custom domain for docs workflow 2022-08-16 18:22:29 +02:00
Kuba Szczodrzyński
33ba44ebda [core] Move running OTA detection to family code 2022-08-16 18:01:38 +02:00
Kuba Szczodrzyński
9b4cf2a92b [core] Pin GitHub packages to known-good versions 2022-08-07 19:48:54 +02:00
Kuba Szczodrzyński
e6b915d8e3 [tools] Move dumptool to ltchiptool 2022-08-06 19:33:21 +02:00
Kuba Szczodrzyński
bb73fb5f55 [core] Force updating ltchiptool to fix linking problems 2022-08-06 17:07:28 +02:00
Kuba Szczodrzyński
10c5945afb [core] Allow exporting UF2 under a custom filename 2022-08-06 17:06:08 +02:00
Kuba Szczodrzyński
0bd613d556 [core] Support upload_flags property 2022-08-06 16:50:12 +02:00
Kuba Szczodrzyński
aae2f65b9e [release] v0.9.0
Some checks failed
Lint check / Lint with clang-format (push) Has been cancelled
Lint check / Lint with black (push) Has been cancelled
PlatformIO Publish / publish (push) Has been cancelled
2022-08-06 13:42:37 +02:00
Kuba Szczodrzyński
d02197474e [docs] Update ESPHome docs, add cloudcutter guide 2022-08-06 13:37:47 +02:00
Kuba Szczodrzyński
41b37e9c24 [core] Update ltchiptool to v1.4.0 2022-08-06 13:06:44 +02:00
Kuba Szczodrzyński
b03400fac2 [beken-72xx] Implement OTA API, add Update debugging 2022-08-06 11:36:53 +02:00
Kuba Szczodrzyński
3e808f7b6b [beken-72xx] Write OTA package to UF2 image 2022-08-05 20:29:48 +02:00
Kuba Szczodrzyński
1e3a8971fb [core] Migrate tools to ltchiptool 2022-08-05 20:29:45 +02:00
Kuba Szczodrzyński
d8c0105b97 [examples] Fix PinScan compilation on realtek-ambz 2022-08-03 12:48:50 +02:00
Kuba Szczodrzyński
b3689cbac8 [beken-72xx] Specify keys for OTA packaging 2022-08-01 19:56:34 +02:00
Kuba Szczodrzyński
1b5d6472f7 [examples] Fix PinScan telnet functionality 2022-08-01 11:28:56 +02:00
Kuba Szczodrzyński
e9511c507a [core] Allow disabling LT logger programmatically 2022-08-01 11:28:16 +02:00
Kuba Szczodrzyński
365f64ded5 [beken-72xx] Make Serial.end() disable hardware UART 2022-08-01 11:27:57 +02:00
Kuba Szczodrzyński
3601fa63d8 [examples] Add PinScan example 2022-08-01 10:52:58 +02:00
Kuba Szczodrzyński
5d00ddf516 [beken-72xx] Fix detaching interrupt handler 2022-07-31 23:25:12 +02:00
Kuba Szczodrzyński
0051453cad [beken-72xx] Implement interrupts 2022-07-31 21:35:02 +02:00
Kuba Szczodrzyński
7920ea2dda [beken-72xx] Fix SerialClass character reading 2022-07-31 14:52:09 +02:00
Kuba Szczodrzyński
9416e45a75 [docs] Restructure documentation, clarify some parts 2022-07-31 13:05:24 +02:00
Kuba Szczodrzyński
98a65c81af [boards] Add usage info to board README 2022-07-31 12:47:24 +02:00
Kuba Szczodrzyński
8e1f06e79b [boards] Add LSC LMA35 board, update boardgen 2022-07-30 19:48:58 +02:00
Kuba Szczodrzyński
58a09f453d [realtek-ambz] Fix errors related to lwIP 2022-07-30 17:18:46 +02:00
Kuba Szczodrzyński
7dc69982b6 [beken-72xx] Fix putchar_p UART index 2022-07-30 15:42:30 +02:00
Kuba Szczodrzyński
46e4041ed8 [beken-72xx] Mark mDNS as broken 2022-07-28 22:18:04 +02:00
Kuba Szczodrzyński
0e129130b1 [core] Print errors about starting main task 2022-07-28 20:29:53 +02:00
Kuba Szczodrzyński
33c9868f90 [core] Remove duplicated WMath functions 2022-07-28 13:46:42 +02:00
168 changed files with 3130 additions and 4627 deletions

View File

@@ -13,10 +13,16 @@ jobs:
- name: Checkout main
uses: actions/checkout@v2
- name: Set custom domain
run: |
mkdir -p site/
echo docs.libretuya.ml > site/CNAME
- name: Deploy docs
uses: mhausenblas/mkdocs-deploy-gh-pages@master
uses: libretuya/mkdocs-deploy-gh-pages@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CONFIG_FILE: mkdocs.yml
EXTRA_PACKAGES: build-base doxygen
REQUIREMENTS: docs/requirements.txt
CUSTOM_DOMAIN: docs.libretuya.ml

View File

@@ -35,7 +35,7 @@ LibreTuya also provides a common interface for all family implementations. The i
## Board List
See [Boards & CPU list](https://kuba2k2.github.io/libretuya/docs/supported/).
See [Boards & CPU list](https://kuba2k2.github.io/libretuya/docs/status/supported/).
## Arduino Core support status
@@ -44,7 +44,7 @@ Note: this list will probably change with each functionality update.
&nbsp; | `realtek-ambz` | `beken-72xx`
--------------------|----------------|-------------
Core functions | ✔️ | ✔️
GPIO/PWM/IRQ | ✔️/✔️/✔️ | /✔️/
GPIO/PWM/IRQ | ✔️/✔️/✔️ | ✔️/✔️/✔️
Analog input (ADC) | ✔️ | ✔️
Serial | ✔️ | ✔️
Serial (extra) | 0, 1, 2 | 1, 2
@@ -65,7 +65,7 @@ NVS / Preferences | ❌ | ❌
SPIFFS | ❌ | ❌
BLE | - | ❌
NTP | ❌ | ❌
OTA | ✔️ |
OTA | ✔️ | ✔️
MDNS | ✔️ | ✔️
MQTT | ✅ | ❌
SD | ❌ | ❌

View File

@@ -1,10 +1,29 @@
* [Home](README.md)
* [Getting started](docs/getting-started.md)
* [💻 Boards & CPU list](docs/supported.md)
* [✔️ Implementation status](docs/implementation-status.md)
* [🔧 Configuration](docs/config.md)
* [📁 Project structure](docs/project-structure.md)
* 🔖 Code reference
* 😊 Getting started
* [Start here](docs/getting-started/README.md)
* [Uploading](docs/getting-started/uploading.md)
* [Options & config](docs/reference/config.md)
* Examples
* [PinScan](examples/PinScan/README.md)
* [ESPHome port](docs/projects/esphome.md)
* [Using tuya-cloudcutter](docs/cloudcutter.md)
* [💻 Boards & CPU list](docs/status/supported.md)
* [✔️ Implementation status](docs/status/arduino.md)
* Supported chip families
* Beken BK72xx
* [General info](docs/platform/beken-72xx/README.md)
* [Flashing](docs/platform/beken-72xx/flashing.md)
* Realtek AmebaZ Series
* [General info](docs/platform/realtek/README.md)
* [Flashing (AmebaZ)](docs/platform/realtek-ambz/flashing.md)
* [Debugging](docs/platform/realtek/debugging.md)
* [Exception decoder](docs/platform/realtek/exception-decoder.md)
* C library
* [Built-in functions](docs/platform/realtek-ambz/stdlib.md)
* [Memory management](docs/platform/realtek-ambz/memory-management.md)
* [All supported boards](boards/)
* API & libraries
* [Options & config](docs/reference/config.md)
* [LibreTuya API](docs/reference/lt-api.md)
* [LT class reference](ltapi/class_libre_tuya.md)
* [Common methods](ltapi/_libre_tuya_a_p_i_8h.md)
@@ -38,22 +57,10 @@
* [Functions](ltapi/functions.md)
* [Macros](ltapi/macros.md)
* [File list](ltapi/files.md)
* [✈️ OTA format](docs/ota/README.md)
* [uf2ota.py tool](docs/ota/uf2ota.md)
* [uf2ota.h library](docs/ota/library.md)
* [uf2ota.h reference](ltapi/uf2ota_8h.md)
* Families
* Beken BK72xx
* [General info](docs/platform/beken-72xx/README.md)
* [Flashing](docs/platform/beken-72xx/flashing.md)
* Realtek AmebaZ Series
* [General info](docs/platform/realtek/README.md)
* [Flashing (AmebaZ)](docs/platform/realtek-ambz/flashing.md)
* [Debugging](docs/platform/realtek/debugging.md)
* [Exception decoder](docs/platform/realtek/exception-decoder.md)
* C library
* [Built-in functions](docs/platform/realtek-ambz/stdlib.md)
* [Memory management](docs/platform/realtek-ambz/memory-management.md)
* [All supported boards](boards/)
* [📁 Project structure](docs/reference/project-structure.md)
* [✈️ OTA format](docs/ota/README.md)
* [uf2ota.py tool](docs/ota/uf2ota.md)
* [uf2ota.h library](docs/ota/library.md)
* [uf2ota.h reference](ltapi/uf2ota_8h.md)
* [📓 TODO](TODO.md)
* [🔗 Resources](docs/resources.md)

View File

@@ -14,8 +14,7 @@
### Tools
- move all UF2 assembling/uploading/processing tools (as well as `uf2ota` C library) to a separate repository, possibly rewriting parts of it again. Make these tools CLI-usable
- write OpenOCD flashers, using uf2ota library + FAL for partitions (same repo as above)
- write OpenOCD flashers, using uf2ota library + FAL for partitions (in ltchiptool repository)
### Serial
@@ -31,10 +30,8 @@
## BK7231
- WiFi events
- implement OTA
- fix WiFi on BK7231N, test other functionality
- add generic board definition
- fix SSL (mbedTLS)
- I2C (Wire)
- SPI
@@ -42,6 +39,5 @@
## RTL8710B
- add generic board definition
- move to GNU++11 (and verify that it works) - take all stdio functions from stdio.h
- rewrite most of Wiring (it was copied from `ambd_arduino`, and is ugly)

View File

@@ -1,6 +1,7 @@
/* Copyright (c) Kuba Szczodrzyński 2022-06-19. */
#include <LibreTuyaAPI.h>
#include <libraries/Flash/Flash.h>
// can't include <flash.h> as it collides with <Flash.h> on Windows -_-
#define REG_FLASH_BASE 0x00803000
@@ -109,12 +110,19 @@ uint32_t LibreTuya::getMaxAllocHeap() {
/* OTA-related */
uint8_t LibreTuya::otaGetStoredIndex() {
static int8_t otaImage2Valid = -1;
uint8_t LibreTuya::otaGetRunning() {
// Beken has bootloader-based OTA, running app is always index 1
return 1;
}
uint8_t LibreTuya::otaGetStoredIndex() {
return otaHasImage2() ? 2 : 1;
}
bool LibreTuya::otaSupportsDual() {
return false;
return true;
}
bool LibreTuya::otaHasImage1() {
@@ -122,11 +130,28 @@ bool LibreTuya::otaHasImage1() {
}
bool LibreTuya::otaHasImage2() {
return false;
if (otaImage2Valid != -1)
return otaImage2Valid;
// check download RBL
// TODO: maybe check header CRC or even binary hashes
uint32_t magic;
Flash.readBlock(FLASH_DOWNLOAD_OFFSET, (uint8_t *)&magic, 4);
otaImage2Valid = magic == 0x004C4252; // "RBL\0", little-endian
return otaImage2Valid;
}
bool LibreTuya::otaSwitch(bool force) {
return true;
// no need to check otaGetStoredIndex() as it does the same as otaHasImage2()
// force checking validity again
otaImage2Valid = -1;
if (otaHasImage2() && force) {
// "rollback" - abort bootloader upgrade operation by wiping first sector
return Flash.eraseSector(FLASH_DOWNLOAD_OFFSET);
}
return otaHasImage2(); // false if second image is not valid
}
/* Global instance */

View File

@@ -26,7 +26,10 @@ SerialClass::SerialClass(uint8_t port) {
static void callback(int port, void *param) {
RingBuffer *buf = (RingBuffer *)param;
buf->store_char(uart_read_byte(port));
int ch;
while ((ch = uart_read_byte(port)) != -1) {
buf->store_char(ch);
}
}
void SerialClass::begin(unsigned long baudrate, uint16_t config) {
@@ -54,6 +57,14 @@ void SerialClass::begin(unsigned long baudrate, uint16_t config) {
void SerialClass::end() {
uart_rx_callback_set(port, NULL, NULL);
switch (port) {
case 1:
uart1_exit();
break;
case 2:
uart2_exit();
break;
}
delete this->buf;
}

View File

@@ -23,7 +23,7 @@ bool startMainTask() {
&mainThread,
THD_APPLICATION_PRIORITY,
"main",
(beken_thread_function_t)main_task,
(beken_thread_function_t)mainTask,
8192,
NULL
);

View File

@@ -27,6 +27,7 @@ unsigned long micros() {
}
void yield() {
runPeriodicTasks();
vTaskDelay(1);
taskYIELD();
}

View File

@@ -38,7 +38,7 @@ static GPIO_INDEX adcToGpio[] = {
#endif
static uint8_t gpioToPwm(GPIO_INDEX gpio) {
for (uint8_t i = 0; i < sizeof(pwmToGpio); i++) {
for (uint8_t i = 0; i < sizeof(pwmToGpio) / sizeof(GPIO_INDEX); i++) {
if (pwmToGpio[i] == gpio)
return i;
}
@@ -46,7 +46,7 @@ static uint8_t gpioToPwm(GPIO_INDEX gpio) {
}
static uint8_t gpioToAdc(GPIO_INDEX gpio) {
for (uint8_t i = 0; i < sizeof(adcToGpio); i++) {
for (uint8_t i = 0; i < sizeof(adcToGpio) / sizeof(GPIO_INDEX); i++) {
if (adcToGpio[i] == gpio)
return i;
}
@@ -94,39 +94,50 @@ void analogWrite(pin_size_t pinNumber, int value) {
if (!pinSupported(pin, PIN_PWM))
return;
float percent = value * 1.0 / (1 << _analogWriteResolution);
uint32_t dutyCycle = percent * _analogWritePeriod * 26 - 1;
float percent = value * 1.0 / ((1 << _analogWriteResolution) - 1);
uint32_t frequency = 26 * _analogWritePeriod - 1;
uint32_t dutyCycle = percent * frequency;
pwm.channel = gpioToPwm(pin->gpio);
#if CFG_SOC_NAME != SOC_BK7231N
pwm.duty_cycle = dutyCycle;
#else
pwm.duty_cycle1 = dutyCycle;
pwm.duty_cycle2 = dutyCycle;
pwm.duty_cycle3 = dutyCycle;
pwm.duty_cycle2 = 0;
pwm.duty_cycle3 = 0;
#endif
if (!pinEnabled(pin, PIN_PWM)) {
// enable PWM and set its value
pwm.cfg.bits.en = PWM_ENABLE;
pwm.cfg.bits.int_en = PWM_INT_DIS;
pwm.cfg.bits.mode = PWM_PWM_MODE;
pwm.cfg.bits.clk = PWM_CLK_26M;
pwm.end_value = 26 * _analogWritePeriod - 1;
pwm.p_Int_Handler = NULL;
__wrap_bk_printf_disable();
sddev_control(PWM_DEV_NAME, CMD_PWM_INIT_PARAM, &pwm);
__wrap_bk_printf_enable();
pin->enabled &= ~PIN_GPIO;
pin->enabled |= PIN_PWM;
} else if (value == 0) {
// disable PWM
pwm.cfg.bits.en = PWM_DISABLE;
__wrap_bk_printf_disable();
sddev_control(PWM_DEV_NAME, CMD_PWM_DEINIT_PARAM, &pwm);
__wrap_bk_printf_enable();
pin->enabled &= ~PIN_PWM;
if (value) {
if (!pinEnabled(pin, PIN_PWM)) {
// enable PWM and set its value
pwm.cfg.bits.en = PWM_ENABLE;
pwm.cfg.bits.int_en = PWM_INT_DIS;
pwm.cfg.bits.mode = PWM_PWM_MODE;
pwm.cfg.bits.clk = PWM_CLK_26M;
pwm.end_value = frequency;
pwm.p_Int_Handler = NULL;
__wrap_bk_printf_disable();
sddev_control(PWM_DEV_NAME, CMD_PWM_INIT_PARAM, &pwm);
sddev_control(PWM_DEV_NAME, CMD_PWM_INIT_LEVL_SET_HIGH, &pwm.channel);
sddev_control(PWM_DEV_NAME, CMD_PWM_UNIT_ENABLE, &pwm.channel);
__wrap_bk_printf_enable();
pin->enabled &= ~PIN_GPIO;
pin->enabled |= PIN_PWM;
} else {
// update duty cycle
sddev_control(PWM_DEV_NAME, CMD_PWM_SET_DUTY_CYCLE, &pwm);
}
} else {
// update duty cycle
sddev_control(PWM_DEV_NAME, CMD_PWM_SET_DUTY_CYCLE, &pwm);
if (pinEnabled(pin, PIN_PWM)) {
// disable PWM
pwm.cfg.bits.en = PWM_DISABLE;
__wrap_bk_printf_disable();
sddev_control(PWM_DEV_NAME, CMD_PWM_SET_DUTY_CYCLE, &pwm);
sddev_control(PWM_DEV_NAME, CMD_PWM_DEINIT_PARAM, &pwm);
__wrap_bk_printf_enable();
pin->enabled &= ~PIN_PWM;
}
// force level as LOW
pinMode(pinNumber, OUTPUT);
digitalWrite(pinNumber, LOW);
}
}

View File

@@ -55,7 +55,7 @@ PinStatus digitalRead(pin_size_t pinNumber) {
if (!pin)
return 0;
// pin is not GPIO yet or not INPUT; change the mode
if (!pinEnabled(pin, PIN_GPIO) || !pinIsOutput(pin))
if (!pinEnabled(pin, PIN_GPIO) || !pinIsInput(pin))
pinMode(pinNumber, INPUT);
// read the value
return gpio_input(pin->gpio);

View File

@@ -0,0 +1,76 @@
/* Copyright (c) Kuba Szczodrzyński 2022-07-31. */
#include <Arduino.h>
static void *irqHandlerList[PINS_COUNT] = {NULL};
static void *irqHandlerArgs[PINS_COUNT] = {NULL};
static void irqHandler(unsigned char gpio) {
int pin = -1;
for (pin_size_t i = 0; i < PINS_COUNT; i++) {
if (pinTable[i].gpio == gpio) {
pin = i;
break;
}
}
if (pin == -1)
return;
if (!irqHandlerList[pin])
return;
if (irqHandlerArgs[pin] == NULL) {
((voidFuncPtr)irqHandlerList[pin])();
} else {
((voidFuncPtrParam)irqHandlerList[pin])(irqHandlerArgs[pin]);
}
}
void attachInterrupt(pin_size_t interruptNumber, voidFuncPtr callback, PinStatus mode) {
attachInterruptParam(interruptNumber, (voidFuncPtrParam)callback, mode, NULL);
}
void attachInterruptParam(pin_size_t interruptNumber, voidFuncPtrParam callback, PinStatus mode, void *param) {
PinInfo *pin = pinInfo(interruptNumber);
if (!pin)
return;
if (!pinSupported(pin, PIN_IRQ))
return;
uint32_t event = 0;
PinMode modeNew = 0;
switch (mode) {
case LOW:
event = GPIO_INT_LEVEL_LOW;
modeNew = INPUT_PULLUP;
break;
case HIGH:
event = GPIO_INT_LEVEL_HIGH;
modeNew = INPUT_PULLDOWN;
break;
case FALLING:
event = GPIO_INT_LEVEL_FALLING;
modeNew = INPUT_PULLUP;
break;
case RISING:
event = GPIO_INT_LEVEL_RISING;
modeNew = INPUT_PULLDOWN;
break;
default:
return;
}
irqHandlerList[interruptNumber] = callback;
irqHandlerArgs[interruptNumber] = param;
gpio_int_enable(pin->gpio, event, irqHandler);
pin->enabled |= PIN_IRQ | PIN_GPIO;
pin->mode = modeNew;
}
void detachInterrupt(pin_size_t interruptNumber) {
PinInfo *pin = pinInfo(interruptNumber);
if (!pin)
return;
if (!pinSupported(pin, PIN_IRQ))
return;
irqHandlerList[interruptNumber] = NULL;
irqHandlerArgs[interruptNumber] = NULL;
gpio_int_disable(pin->gpio);
pin->enabled &= ~PIN_IRQ;
}

View File

@@ -3,6 +3,7 @@
#include "WiFiPriv.h"
WiFiClass::WiFiClass() {
memset(&data, 0x00, sizeof(WiFiData));
data.scanSem = xSemaphoreCreateBinary();
}
@@ -10,6 +11,30 @@ WiFiClass::~WiFiClass() {
vSemaphoreDelete(data.scanSem);
}
void WiFiClass::dataInitialize() {
if (data.statusIp)
return;
LT_DM(WIFI, "Data init");
data.configSta = zalloc(sizeof(network_InitTypeDef_st));
data.configAp = zalloc(sizeof(network_InitTypeDef_ap_st));
data.statusIp = malloc(sizeof(IPStatusTypedef));
data.statusLink = malloc(sizeof(LinkStatusTypeDef));
STA_CFG->dhcp_mode = DHCP_CLIENT;
LT_DM(WIFI, "Data = %p", data.configSta);
}
void WiFiClass::dataFree() {
LT_DM(WIFI, "Data free");
free(data.configSta);
free(data.configAp);
free(data.statusIp);
free(data.statusLink);
data.configSta = NULL;
data.configAp = NULL;
data.statusIp = NULL;
data.statusLink = NULL;
}
WiFiStatus eventTypeToStatus(uint8_t type) {
// rw_msg_pub.h:9
switch (type) {

View File

@@ -25,21 +25,22 @@ bool WiFiClass::softAP(const char *ssid, const char *passphrase, int channel, bo
AP_CFG->dhcp_mode = DHCP_SERVER;
AP_CFG->wifi_retry_interval = 100;
LT_I("Creating SoftAP %s", ssid);
LT_IM(WIFI, "Creating SoftAP %s", ssid);
__wrap_bk_printf_disable();
OSStatus ret = bk_wlan_start_ap_adv(AP_CFG);
__wrap_bk_printf_enable();
if (ret != 0) {
LT_E("SoftAP failed; ret=%d", ret);
LT_EM(WIFI, "SoftAP failed; ret=%d", ret);
return false;
}
LT_D_WG("Start OK");
LT_DM(WIFI, "AP start OK");
return true;
}
bool WiFiClass::softAPConfig(IPAddress localIP, IPAddress gateway, IPAddress subnet) {
dataInitialize();
if (!localIP) {
localIP = gateway = IPAddress(192, 168, 43, 1);
subnet = IPAddress(255, 255, 255, 0);
@@ -72,14 +73,14 @@ uint8_t WiFiClass::softAPgetStationNum() {
}
IPAddress WiFiClass::softAPIP() {
bk_wlan_get_ip_status(IP_STATUS, BK_SOFT_AP);
AP_GET_IP_STATUS_RETURN((uint32_t)0);
IPAddress ip;
ip.fromString(IP_STATUS->ip);
return ip;
}
IPAddress WiFiClass::softAPSubnetMask() {
bk_wlan_get_ip_status(IP_STATUS, BK_SOFT_AP);
AP_GET_IP_STATUS_RETURN((uint32_t)0);
IPAddress ip;
ip.fromString(IP_STATUS->mask);
return ip;
@@ -108,5 +109,6 @@ String WiFiClass::softAPmacAddress(void) {
}
const String WiFiClass::softAPSSID(void) {
AP_GET_LINK_STATUS_RETURN("");
return AP_CFG->wifi_ssid;
}

View File

@@ -7,6 +7,7 @@
extern "C" {
#include <FreeRTOS.h>
#include <rw_msg_pub.h>
#include <semphr.h>
} // extern "C"
@@ -18,4 +19,6 @@ typedef struct {
SemaphoreHandle_t scanSem;
void *statusIp;
void *statusLink;
rw_evt_type lastStaEvent;
rw_evt_type lastApEvent;
} WiFiData;

View File

@@ -50,7 +50,12 @@ void wifiEventHandler(rw_evt_type event) {
if (!pWiFi)
return; // failsafe
LT_D_WG("WiFi event %u", event);
LT_DM(WIFI, "BK event %u", event);
if (event <= RW_EVT_STA_GOT_IP)
pWiFi->data.lastStaEvent = event;
else
pWiFi->data.lastApEvent = event;
EventId eventId;
EventInfo eventInfo;

View File

@@ -6,35 +6,36 @@ bool WiFiClass::modePriv(WiFiMode mode, WiFiModeAction sta, WiFiModeAction ap) {
__wrap_bk_printf_disable();
startWifiTask();
if (mode && !data.statusIp) {
data.configSta = zalloc(sizeof(network_InitTypeDef_st));
data.configAp = zalloc(sizeof(network_InitTypeDef_ap_st));
data.statusIp = malloc(sizeof(IPStatusTypedef));
data.statusLink = malloc(sizeof(LinkStatusTypeDef));
STA_CFG->dhcp_mode = DHCP_CLIENT;
}
if (!__bk_rf_is_init) {
LT_D_WG("Initializing func&app");
LT_DM(WIFI, "Initializing func&app");
func_init_extended();
app_pre_start();
// wait for the init_thread to finish its job
while (xTaskGetHandle("init_thread")) {
LT_V_WG("Waiting for init_thread");
LT_VM(WIFI, "Waiting for init_thread");
delay(10);
}
LT_D_WG("Success");
LT_DM(WIFI, "Init OK");
__bk_rf_is_init = true;
}
LT_HEAP_I();
if (mode) {
LT_DM(WIFI, "Wakeup RF");
uint32_t reg = 1; // this is only checked for being true-ish
sddev_control(SCTRL_DEV_NAME, CMD_RF_HOLD_BIT_SET, &reg);
}
if (sta == WLMODE_ENABLE) {
LT_D_WG("Enabling STA");
LT_DM(WIFI, "Enabling STA");
bk_wlan_sta_init(NULL);
#if CFG_WPA_CTRL_IFACE
wlan_sta_enable();
#endif
wifiEventSendArduino(ARDUINO_EVENT_WIFI_STA_START);
} else if (sta == WLMODE_DISABLE) {
LT_D_WG("Disabling STA");
LT_DM(WIFI, "Disabling STA");
bk_wlan_stop(BK_STATION);
wifiEventSendArduino(ARDUINO_EVENT_WIFI_STA_STOP);
}
@@ -42,25 +43,25 @@ bool WiFiClass::modePriv(WiFiMode mode, WiFiModeAction sta, WiFiModeAction ap) {
LT_HEAP_I();
if (ap == WLMODE_ENABLE) {
LT_D_WG("Enabling AP");
LT_DM(WIFI, "Enabling AP");
bk_wlan_ap_init(NULL);
#if CFG_WPA_CTRL_IFACE
wlan_ap_enable();
wlan_ap_reload();
uap_ip_down();
#endif
wifiEventSendArduino(ARDUINO_EVENT_WIFI_AP_START);
} else if (ap == WLMODE_DISABLE) {
LT_D_WG("Disabling AP");
LT_DM(WIFI, "Disabling AP");
bk_wlan_stop(BK_SOFT_AP);
wifiEventSendArduino(ARDUINO_EVENT_WIFI_AP_STOP);
}
if (!mode) {
free(data.configSta);
free(data.configAp);
free(data.statusIp);
free(data.statusLink);
data.configSta = NULL;
data.configAp = NULL;
data.statusIp = NULL;
data.statusLink = NULL;
}
// force checking actual mode again
mode = getMode();
if (!mode)
dataFree();
LT_HEAP_I();
@@ -69,15 +70,13 @@ bool WiFiClass::modePriv(WiFiMode mode, WiFiModeAction sta, WiFiModeAction ap) {
}
WiFiMode WiFiClass::getMode() {
if (!g_wlan_general_param)
return WIFI_MODE_NULL;
uint8_t role = g_wlan_general_param->role;
// change 1->2, 2->1
return (WiFiMode)(role + (role == 1) - (role == 2));
uint8_t sta = !!bk_wlan_has_role(VIF_STA) * WIFI_MODE_STA;
uint8_t ap = !!bk_wlan_has_role(VIF_AP) * WIFI_MODE_AP;
return (WiFiMode)(sta | ap);
}
WiFiStatus WiFiClass::status() {
rw_evt_type status = mhdr_get_station_status();
rw_evt_type status = data.lastStaEvent;
if (status == RW_EVT_STA_CONNECTED && STA_CFG->dhcp_mode == DHCP_DISABLE)
status = RW_EVT_STA_GOT_IP;
return eventTypeToStatus(status);

View File

@@ -20,6 +20,9 @@ extern "C" {
#include <main_none.h>
#include <param_config.h>
#include <rw_msg_rx.h>
#include <sa_ap.h>
#include <sys_ctrl_pub.h>
#include <vif_mgmt.h>
#include <wlan_ui_pub.h>
#include <wpa_supplicant_i.h>
@@ -54,4 +57,34 @@ extern void wifiEventHandler(rw_evt_type event);
#define IP_STATUS ((IPStatusTypedef *)data.statusIp)
#define LINK_STATUS ((LinkStatusTypeDef *)data.statusLink)
#define STA_GET_LINK_STATUS_RETURN(ret) \
{ \
if (!sta_ip_is_start()) \
return ret; \
memset(LINK_STATUS, 0x00, sizeof(LinkStatusTypeDef)); \
bk_wlan_get_link_status(LINK_STATUS); \
}
#define STA_GET_IP_STATUS_RETURN(ret) \
{ \
if (!sta_ip_is_start()) \
return ret; \
memset(IP_STATUS, 0x00, sizeof(IPStatusTypedef)); \
bk_wlan_get_ip_status(IP_STATUS, BK_STATION); \
}
#define AP_GET_LINK_STATUS_RETURN(ret) \
{ \
if (!uap_ip_is_start()) \
return ret; \
}
#define AP_GET_IP_STATUS_RETURN(ret) \
{ \
if (!uap_ip_is_start()) \
return ret; \
memset(IP_STATUS, 0x00, sizeof(IPStatusTypedef)); \
bk_wlan_get_ip_status(IP_STATUS, BK_SOFT_AP); \
}
} // extern "C"

View File

@@ -11,6 +11,8 @@ WiFiClass::begin(const char *ssid, const char *passphrase, int32_t channel, cons
LT_HEAP_I();
disconnect(false);
strcpy(STA_CFG->wifi_ssid, ssid);
if (passphrase) {
strcpy(STA_CFG->wifi_key, passphrase);
@@ -25,8 +27,7 @@ WiFiClass::begin(const char *ssid, const char *passphrase, int32_t channel, cons
}
bool WiFiClass::config(IPAddress localIP, IPAddress gateway, IPAddress subnet, IPAddress dns1, IPAddress dns2) {
// need to initialize data struct first
enableSTA(true);
dataInitialize();
STA_CFG->dhcp_mode = localIP ? DHCP_DISABLE : DHCP_CLIENT;
if (localIP) {
@@ -35,8 +36,16 @@ bool WiFiClass::config(IPAddress localIP, IPAddress gateway, IPAddress subnet, I
sprintf(STA_CFG->gateway_ip_addr, IP_FMT, gateway[0], gateway[1], gateway[2], gateway[3]);
if (dns1) {
sprintf(STA_CFG->dns_server_ip_addr, IP_FMT, dns1[0], dns1[1], dns1[2], dns1[3]);
} else {
STA_CFG->dns_server_ip_addr[0] = '\0';
}
} else {
STA_CFG->local_ip_addr[0] = '\0';
STA_CFG->net_mask[0] = '\0';
STA_CFG->gateway_ip_addr[0] = '\0';
STA_CFG->dns_server_ip_addr[0] = '\0';
}
// from wlan_ui.c:1370
if (sta_ip_is_start()) {
sta_ip_down();
@@ -54,17 +63,20 @@ bool WiFiClass::config(IPAddress localIP, IPAddress gateway, IPAddress subnet, I
}
bool WiFiClass::reconnect(const uint8_t *bssid) {
dataInitialize();
if (!bssid && !STA_CFG->wifi_ssid[0]) {
LT_E("(B)SSID not specified");
LT_EM(WIFI, "(B)SSID not specified");
goto error;
}
if (bssid) {
LT_D_WG("Connecting to " MACSTR, MAC2STR(bssid));
LT_IM(WIFI, "Connecting to " MACSTR, MAC2STR(bssid));
} else {
LT_D_WG("Connecting to %s", STA_CFG->wifi_ssid);
LT_IM(WIFI, "Connecting to %s", STA_CFG->wifi_ssid);
}
LT_DM(WIFI, "Data = %p", data.configSta);
STA_CFG->wifi_mode = BK_STATION;
STA_CFG->wifi_retry_interval = 100;
if (bssid)
@@ -73,19 +85,19 @@ bool WiFiClass::reconnect(const uint8_t *bssid) {
memset(STA_CFG->wifi_bssid, 0x00, 6);
if (STA_CFG->dhcp_mode == DHCP_DISABLE) {
LT_D_WG("Static IP: %s / %s / %s", STA_CFG->local_ip_addr, STA_CFG->net_mask, STA_CFG->gateway_ip_addr);
LT_D_WG("Static DNS: %s", STA_CFG->dns_server_ip_addr);
LT_DM(WIFI, "Static IP: %s / %s / %s", STA_CFG->local_ip_addr, STA_CFG->net_mask, STA_CFG->gateway_ip_addr);
LT_DM(WIFI, "Static DNS: %s", STA_CFG->dns_server_ip_addr);
} else {
LT_D_WG("Using DHCP");
LT_DM(WIFI, "Using DHCP");
}
LT_D_WG("Starting WiFi...");
LT_DM(WIFI, "Starting WiFi...");
__wrap_bk_printf_disable();
bk_wlan_start_sta(STA_CFG);
__wrap_bk_printf_enable();
LT_D_WG("Start OK");
LT_DM(WIFI, "Start OK");
return true;
error:
@@ -93,6 +105,11 @@ error:
}
bool WiFiClass::disconnect(bool wifiOff) {
#if LT_DEBUG_WIFI
memset(LINK_STATUS, 0x00, sizeof(LinkStatusTypeDef));
bk_wlan_get_link_status(LINK_STATUS);
LT_DM(WIFI, "Disconnecting from %s (wifiOff=%d)", LINK_STATUS ? LINK_STATUS->ssid : NULL, wifiOff);
#endif
bk_wlan_connection_loss();
if (wifiOff)
enableSTA(false);
@@ -108,28 +125,28 @@ bool WiFiClass::getAutoReconnect() {
}
IPAddress WiFiClass::localIP() {
bk_wlan_get_ip_status(IP_STATUS, BK_STATION);
STA_GET_IP_STATUS_RETURN((uint32_t)0);
IPAddress ip;
ip.fromString(IP_STATUS->ip);
return ip;
}
IPAddress WiFiClass::subnetMask() {
bk_wlan_get_ip_status(IP_STATUS, BK_STATION);
STA_GET_IP_STATUS_RETURN((uint32_t)0);
IPAddress ip;
ip.fromString(IP_STATUS->mask);
return ip;
}
IPAddress WiFiClass::gatewayIP() {
bk_wlan_get_ip_status(IP_STATUS, BK_STATION);
STA_GET_IP_STATUS_RETURN((uint32_t)0);
IPAddress ip;
ip.fromString(IP_STATUS->gate);
return ip;
}
IPAddress WiFiClass::dnsIP(uint8_t dns_no) {
bk_wlan_get_ip_status(IP_STATUS, BK_STATION);
STA_GET_IP_STATUS_RETURN((uint32_t)0);
IPAddress ip;
ip.fromString(IP_STATUS->dns);
return ip;
@@ -157,7 +174,7 @@ uint8_t *WiFiClass::macAddress(uint8_t *mac) {
bool WiFiClass::setMacAddress(const uint8_t *mac) {
if (mac[0] & 0x01) {
LT_E("Invalid MAC address");
LT_EM(WIFI, "Invalid MAC address");
return false;
}
// ensure "mac_inited" is true
@@ -173,7 +190,7 @@ bool WiFiClass::setMacAddress(const uint8_t *mac) {
}
const String WiFiClass::SSID() {
bk_wlan_get_link_status(LINK_STATUS);
STA_GET_LINK_STATUS_RETURN("");
return (char *)LINK_STATUS->ssid;
}
@@ -187,21 +204,21 @@ const String WiFiClass::psk() {
}
uint8_t *WiFiClass::BSSID() {
bk_wlan_get_link_status(LINK_STATUS);
STA_GET_LINK_STATUS_RETURN(NULL);
return LINK_STATUS->bssid;
}
int32_t WiFiClass::channel() {
bk_wlan_get_link_status(LINK_STATUS);
STA_GET_LINK_STATUS_RETURN(0);
return LINK_STATUS->channel;
}
int8_t WiFiClass::RSSI() {
bk_wlan_get_link_status(LINK_STATUS);
STA_GET_LINK_STATUS_RETURN(0);
return LINK_STATUS->wifi_strength;
}
WiFiAuthMode WiFiClass::getEncryption() {
bk_wlan_get_link_status(LINK_STATUS);
STA_GET_LINK_STATUS_RETURN(WIFI_AUTH_INVALID);
return securityTypeToAuthMode(LINK_STATUS->security);
}

View File

@@ -6,25 +6,25 @@ static void scanHandler(void *ctx, uint8_t param) {
LT_HEAP_I();
WiFiClass *cls = (WiFiClass *)ctx;
if (!cls) {
LT_W("Called without ctx");
LT_WM(WIFI, "Called without ctx");
return;
}
WiFiScanData *scan = cls->scan;
if (!scan) {
LT_W("Called without cls->scan");
LT_WM(WIFI, "Called without cls->scan");
return;
}
ScanResult_adv result;
if (wlan_sta_scan_result(&result)) {
LT_E("Failed to get scan result");
LT_EM(WIFI, "Failed to get scan result");
goto end;
}
LT_D_WG("Found %d APs", result.ApNum);
LT_IM(WIFI, "Found %d APs", result.ApNum);
cls->scanAlloc(result.ApNum);
if (!scan->ap) {
LT_W("scan->ap alloc failed");
LT_WM(WIFI, "scan->ap alloc failed");
goto end;
}
@@ -54,7 +54,7 @@ int16_t WiFiClass::scanNetworks(bool async, bool showHidden, bool passive, uint3
scanDelete();
scanInit();
LT_I("Starting WiFi scan");
LT_IM(WIFI, "Starting WiFi scan");
__wrap_bk_printf_disable();
mhdr_scanu_reg_cb(scanHandler, this);
@@ -66,7 +66,7 @@ int16_t WiFiClass::scanNetworks(bool async, bool showHidden, bool passive, uint3
int16_t ret = WIFI_SCAN_RUNNING;
if (!async) {
LT_I("Waiting for results");
LT_IM(WIFI, "Waiting for results");
xSemaphoreTake(data.scanSem, 1); // reset the semaphore quickly
xSemaphoreTake(data.scanSem, pdMS_TO_TICKS(maxMsPerChannel * 20));
if (scan->running) {

View File

@@ -1,5 +1,6 @@
/* Copyright (c) Kuba Szczodrzyński 2022-06-19. */
#include <lt_logger.h>
#include <sdk_extern.h>
#include <fal.h>
@@ -8,10 +9,27 @@
#define FLASH_ERASE_MIN_SIZE (4 * 1024)
extern uint32_t flash_ctrl(uint32_t cmd, void *param);
extern PROTECT_TYPE get_flash_protect();
extern void flash_protection_op(uint8_t mode, PROTECT_TYPE type);
static void unprotect() {
PROTECT_TYPE type = get_flash_protect();
if (type != FLASH_PROTECT_NONE) {
flash_protection_op(0, FLASH_PROTECT_NONE);
#if LT_LOGLEVEL <= LT_LEVEL_DEBUG
LT_D("Flash protect: %u -> %u", type, get_flash_protect());
uint16_t sr = 0;
flash_ctrl(CMD_FLASH_READ_SR, &sr);
LT_D("SR = %04x", sr);
#endif
}
}
static int init() {
__wrap_bk_printf_disable();
flash_init();
flash_ctrl(CMD_FLASH_WRITE_ENABLE, NULL);
unprotect();
__wrap_bk_printf_enable();
return 0;
}
@@ -22,11 +40,13 @@ static int read(long offset, uint8_t *buf, size_t size) {
}
static int write(long offset, const uint8_t *buf, size_t size) {
unprotect();
flash_write((char *)buf, size, offset);
return size;
}
static int erase(long offset, size_t size) {
unprotect();
size = ((size - 1) / FLASH_ERASE_MIN_SIZE) + 1;
for (uint16_t i = 0; i < size; i++) {
uint32_t addr = offset + i * FLASH_ERASE_MIN_SIZE;

View File

@@ -15,7 +15,7 @@ void putchar_(char c) {
}
void putchar_p(char c, unsigned long port) {
bk_send_byte(port & 0xFF, c);
bk_send_byte((port & 0xFF) - 1, c);
}
WRAP_PRINTF(bk_printf);

View File

@@ -12,8 +12,8 @@ void WiFiClass::printDiag(Print &dest) {
if (getMode() & WIFI_MODE_STA) {
dest.println("-- Station --");
dest.print("SSID: ");
dest.println(SSID());
if (isConnected()) {
dest.println(SSID());
dest.print("Channel: ");
dest.println(channel());
dest.print("BSSID: ");
@@ -28,40 +28,50 @@ void WiFiClass::printDiag(Print &dest) {
dest.println(macAddress());
dest.print("Hostname: ");
dest.println(getHostname());
} else {
dest.println("disconnected");
}
}
if (getMode() & WIFI_MODE_AP) {
dest.println("-- Access Point --");
dest.print("SSID: ");
dest.println(softAPSSID());
dest.print("IP: ");
dest.println(softAPIP());
dest.print("MAC: ");
dest.println(softAPmacAddress());
dest.print("Hostname: ");
dest.println(softAPgetHostname());
if (softAPSSID().length()) {
dest.println(softAPSSID());
dest.print("IP: ");
dest.println(softAPIP());
dest.print("MAC: ");
dest.println(softAPmacAddress());
dest.print("Hostname: ");
dest.println(softAPgetHostname());
} else {
dest.println("disconnected");
}
}
}
bool WiFiClass::validate(const char *ssid, const char *passphrase) {
if (!ssid || *ssid == 0x00 || strlen(ssid) > 32) {
LT_W("SSID not specified or too long");
LT_WM(WIFI, "SSID not specified or too long");
return false;
}
if (passphrase) {
uint16_t length = strlen(passphrase);
if (length < 8) {
LT_W("Passphrase too short (%u)", length);
LT_WM(WIFI, "Passphrase too short (%u)", length);
return false;
}
if (length > 63) {
LT_W("Passphrase too long (%u)", length);
LT_WM(WIFI, "Passphrase too long (%u)", length);
return false;
}
}
return true;
}
__attribute__((weak)) void WiFiClass::dataInitialize() {}
__attribute__((weak)) void WiFiClass::dataFree() {}
WiFiClass WiFi;
WiFiClass *pWiFi = NULL;

View File

@@ -47,6 +47,8 @@ class WiFiClass {
~WiFiClass();
void printDiag(Print &dest);
bool validate(const char *ssid, const char *passphrase);
void dataInitialize();
void dataFree();
public: /* WiFiGeneric.cpp */
bool mode(WiFiMode mode);

View File

@@ -7,7 +7,7 @@ bool WiFiClass::mode(WiFiMode mode) {
pWiFi = this;
WiFiMode currentMode = getMode();
LT_D_WG("Mode changing %u -> %u", currentMode, mode);
LT_DM(WIFI, "Mode changing %u -> %u", currentMode, mode);
if (mode == currentMode)
return true;
@@ -15,11 +15,19 @@ bool WiFiClass::mode(WiFiMode mode) {
WiFiModeAction sta = WiFiModeAction((mode & WIFI_MODE_STA) != (currentMode & WIFI_MODE_STA));
WiFiModeAction ap = WiFiModeAction((mode & WIFI_MODE_AP) != (currentMode & WIFI_MODE_AP));
// change 0/1 to 1/2
sta = WiFiModeAction(sta + sta * (mode & WIFI_MODE_STA));
ap = WiFiModeAction(ap + ap * (mode & WIFI_MODE_AP));
sta = WiFiModeAction(sta + sta * !!(mode & WIFI_MODE_STA));
ap = WiFiModeAction(ap + ap * !!(mode & WIFI_MODE_AP));
// initialize data structures if wifi is enabled
if (mode)
dataInitialize();
// actually change the mode
LT_HEAP_I();
return modePriv(mode, sta, ap);
if (!modePriv(mode, sta, ap))
return false;
if (getMode() != mode) {
LT_WM(WIFI, "Mode changed to %d (requested %d)", getMode(), mode);
}
return true;
}
bool WiFiClass::enableSTA(bool enable) {

View File

@@ -41,15 +41,3 @@ long random(long howsmall, long howbig) {
return random(diff) + howsmall;
}
extern long map(long x, long in_min, long in_max, long out_min, long out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
extern uint16_t makeWord(uint16_t w) {
return w;
}
extern uint16_t makeWord(uint8_t h, uint8_t l) {
return (h << 8) | l;
}

View File

@@ -1,5 +1,7 @@
/* Copyright (c) Kuba Szczodrzyński 2022-05-28. */
#pragma once
#define CHIP_TYPE(family, chip_id) (((family >> 24) << 8) | chip_id)
#define CHIP_TYPE_ENUM(family, chip_id) (ChipType) CHIP_TYPE(family, chip_id)

View File

@@ -14,6 +14,7 @@ String ipToString(const IPAddress &ip) {
* @param buf destination pointer
* @param len how many bytes to generate
*/
extern "C" {
void lt_rand_bytes(uint8_t *buf, size_t len) {
int *data = (int *)buf;
size_t i;
@@ -37,7 +38,7 @@ void lt_rand_bytes(uint8_t *buf, size_t len) {
* @param offset increment printed offset by this value
* @param width how many bytes on a line
*/
void hexdump(uint8_t *buf, size_t len, uint32_t offset, uint8_t width) {
void hexdump(const uint8_t *buf, size_t len, uint32_t offset, uint8_t width) {
uint16_t pos = 0;
while (pos < len) {
// print hex offset
@@ -61,3 +62,4 @@ void hexdump(uint8_t *buf, size_t len, uint32_t offset, uint8_t width) {
pos += lineWidth;
}
}
}

View File

@@ -64,11 +64,17 @@ extern "C" {
"LibreTuya v" LT_VERSION_STR " on " LT_BOARD_STR ", compiled at " __DATE__ " " __TIME__ \
)
void lt_rand_bytes(uint8_t *buf, size_t len);
#ifdef __cplusplus
String ipToString(const IPAddress &ip);
void hexdump(uint8_t *buf, size_t len, uint32_t offset = 0, uint8_t width = 16);
extern "C" {
void lt_rand_bytes(uint8_t *buf, size_t len);
void hexdump(const uint8_t *buf, size_t len, uint32_t offset = 0, uint8_t width = 16);
}
#else
void hexdump(uint8_t *buf, size_t len, uint32_t offset, uint8_t width);
void lt_rand_bytes(uint8_t *buf, size_t len);
void hexdump(const uint8_t *buf, size_t len, uint32_t offset, uint8_t width);
#endif

View File

@@ -74,18 +74,6 @@ __attribute__((weak)) uint32_t LibreTuya::getFlashChipSize() {
#endif
}
static uint8_t otaRunningIndex = 0;
/**
* @brief Get the currently running firmware OTA index.
*/
uint8_t LibreTuya::otaGetRunning() {
if (otaRunningIndex)
return otaRunningIndex;
// otaRunningIndex will be correct even after switchOta()
return otaRunningIndex = otaGetStoredIndex();
}
/**
* @brief Get the OTA index for updated firmware.
*
@@ -98,7 +86,8 @@ uint8_t LibreTuya::otaGetTarget() {
}
/**
* @brief Perform OTA rollback.
* @brief Perform OTA rollback: switch to the previous image, or abort current
* switched OTA update, if not rebooted yet.
*
* @return false if no second image to run, writing failed or dual-OTA not supported
*/

View File

@@ -33,7 +33,6 @@ class LibreTuya {
const char *getDeviceName();
uint32_t getCpuFreqMHz();
uint32_t getFlashChipSize();
uint8_t otaGetRunning();
uint8_t otaGetTarget();
bool otaRollback();
bool otaCanRollback();
@@ -109,12 +108,18 @@ class LibreTuya {
uint32_t getMaxAllocHeap();
public: /* OTA-related */
/**
* @brief Get the currently running firmware OTA index.
*/
uint8_t otaGetRunning();
/**
* @brief Read the currently active OTA index, i.e. the one that will boot upon restart.
*/
uint8_t otaGetStoredIndex();
/**
* @brief Check if the chip supports dual-OTA.
* @brief Check if the chip supports dual-OTA (i.e. OTA is flashed to a different partition).
*
* TODO: make this work for actual dual-OTA chips; remove checking this in otaGetTarget() etc.
*/
bool otaSupportsDual();
/**

View File

@@ -12,6 +12,7 @@
#define LT_LEVEL_WARN 3
#define LT_LEVEL_ERROR 4
#define LT_LEVEL_FATAL 5
#define LT_LEVEL_NONE 6
// Logger enabled/disabled
#ifndef LT_LOGGER
@@ -24,11 +25,11 @@
#endif
#ifndef LT_LOGGER_CALLER
#define LT_LOGGER_CALLER 1
#define LT_LOGGER_CALLER 0
#endif
#ifndef LT_LOGGER_TASK
#define LT_LOGGER_TASK 1
#define LT_LOGGER_TASK 0
#endif
#ifndef LT_LOGGER_COLOR
@@ -44,6 +45,11 @@
#define LT_LOGLEVEL LT_LEVEL_INFO
#endif
#if !LT_LOGGER
#undef LT_LOGLEVEL
#define LT_LOGLEVEL LT_LEVEL_NONE
#endif
// Free heap size debugging
#ifndef LT_LOG_HEAP
#define LT_LOG_HEAP 0
@@ -71,27 +77,48 @@
#define LT_UART_DEFAULT_SERIAL LT_UART_DEFAULT_PORT
#endif
// Per-module debugging
// Misc options
#ifndef LT_USE_TIME
#define LT_USE_TIME 0
#endif
// Per-module logging output - applies to all loglevels
#ifndef LT_DEBUG_ALL
#define LT_DEBUG_ALL 0
#endif
#ifndef LT_DEBUG_WIFI
#define LT_DEBUG_WIFI 0
#define LT_DEBUG_WIFI 1
#endif
#ifndef LT_DEBUG_WIFI_CLIENT
#define LT_DEBUG_WIFI_CLIENT 0
#ifndef LT_DEBUG_CLIENT
#define LT_DEBUG_CLIENT LT_DEBUG_ALL
#endif
#ifndef LT_DEBUG_WIFI_SERVER
#define LT_DEBUG_WIFI_SERVER 0
#endif
#ifndef LT_DEBUG_WIFI_STA
#define LT_DEBUG_WIFI_STA 0
#endif
#ifndef LT_DEBUG_WIFI_AP
#define LT_DEBUG_WIFI_AP 0
#ifndef LT_DEBUG_SERVER
#define LT_DEBUG_SERVER LT_DEBUG_ALL
#endif
#ifndef LT_DEBUG_SSL
#define LT_DEBUG_SSL 0
#define LT_DEBUG_SSL LT_DEBUG_ALL
#endif
#ifndef LT_DEBUG_OTA
#define LT_DEBUG_OTA 1
#endif
#ifndef LT_DEBUG_FDB
#define LT_DEBUG_FDB 0
#endif
#ifndef LT_DEBUG_MDNS
#define LT_DEBUG_MDNS LT_DEBUG_ALL
#endif
#ifndef LT_DEBUG_LWIP
#define LT_DEBUG_LWIP 0
#endif
#ifndef LT_DEBUG_LWIP_ASSERT
#define LT_DEBUG_LWIP_ASSERT 0
#endif

View File

@@ -9,7 +9,9 @@ extern "C" {
#endif
/**
* @brief Run main_task & start OS kernel (family-defined)
* @brief Run mainTask & start OS kernel (family-defined).
* Return false if an error occured; else do not return and
* and keep the OS kernel running.
*/
extern bool startMainTask();
@@ -17,7 +19,14 @@ extern bool startMainTask();
* @brief Main setup() and loop() task.
* Not to be called directly.
*/
extern void main_task(const void *arg);
extern void mainTask(const void *arg);
/**
* @brief Run periodic tasks, like printing free heap or checking millis() overflow.
*
* This is called during delaying operations, like yield() or delay().
*/
extern void runPeriodicTasks();
#define PIN_NONE (1 << 0)
#define PIN_GPIO (1 << 1)

View File

@@ -50,6 +50,9 @@ void lt_log(const uint8_t level, const char *caller, const unsigned short line,
void lt_log(const uint8_t level, const char *format, ...) {
#endif
if (uart_port == 0xFF)
return;
#if LT_LOGGER_TIMESTAMP
float seconds = millis() / 1000.0f;
#if LT_PRINTF_BROKEN
@@ -136,3 +139,7 @@ void lt_log(const uint8_t level, const char *format, ...) {
void lt_log_set_port(uint8_t port) {
uart_port = port;
}
void lt_log_disable() {
uart_port = 0xFF;
}

View File

@@ -7,9 +7,21 @@
#if LT_LOGGER_CALLER
#define LT_LOG(level, caller, line, ...) lt_log(level, caller, line, __VA_ARGS__)
#define LT_LOGM(level, module, caller, line, ...) \
do { \
if (LT_DEBUG_##module) { \
lt_log(level, caller, line, #module ": " __VA_ARGS__); \
} \
} while (0)
void lt_log(const uint8_t level, const char *caller, const unsigned short line, const char *format, ...);
#else
#define LT_LOG(level, caller, line, ...) lt_log(level, __VA_ARGS__)
#define LT_LOGM(level, module, caller, line, ...) \
do { \
if (LT_DEBUG_##module) { \
lt_log(level, #module ": " __VA_ARGS__); \
} \
} while (0)
void lt_log(const uint8_t level, const char *format, ...);
#endif
@@ -20,42 +32,61 @@ void lt_log(const uint8_t level, const char *format, ...);
*/
void lt_log_set_port(uint8_t port);
/**
* @brief Disable LT logger. Enable it back using lt_log_set_port(LT_UART_DEFAULT_LOGGER).
*/
void lt_log_disable();
#if LT_LEVEL_TRACE >= LT_LOGLEVEL
#define LT_T(...) LT_LOG(LT_LEVEL_TRACE, __FUNCTION__, __LINE__, __VA_ARGS__)
#define LT_V(...) LT_LOG(LT_LEVEL_TRACE, __FUNCTION__, __LINE__, __VA_ARGS__)
#define LT_T(...) LT_LOG(LT_LEVEL_TRACE, __FUNCTION__, __LINE__, __VA_ARGS__)
#define LT_V(...) LT_LOG(LT_LEVEL_TRACE, __FUNCTION__, __LINE__, __VA_ARGS__)
#define LT_TM(module, ...) LT_LOGM(LT_LEVEL_TRACE, module, __FUNCTION__, __LINE__, __VA_ARGS__)
#define LT_VM(module, ...) LT_LOGM(LT_LEVEL_TRACE, module, __FUNCTION__, __LINE__, __VA_ARGS__)
#else
#define LT_T(...)
#define LT_V(...)
#define LT_TM(...)
#define LT_VM(...)
#endif
#if LT_LEVEL_DEBUG >= LT_LOGLEVEL
#define LT_D(...) LT_LOG(LT_LEVEL_DEBUG, __FUNCTION__, __LINE__, __VA_ARGS__)
#define LT_D(...) LT_LOG(LT_LEVEL_DEBUG, __FUNCTION__, __LINE__, __VA_ARGS__)
#define LT_DM(module, ...) LT_LOGM(LT_LEVEL_DEBUG, module, __FUNCTION__, __LINE__, __VA_ARGS__)
#else
#define LT_D(...)
#define LT_DM(...)
#endif
#if LT_LEVEL_INFO >= LT_LOGLEVEL
#define LT_I(...) LT_LOG(LT_LEVEL_INFO, __FUNCTION__, __LINE__, __VA_ARGS__)
#define LT_I(...) LT_LOG(LT_LEVEL_INFO, __FUNCTION__, __LINE__, __VA_ARGS__)
#define LT_IM(module, ...) LT_LOGM(LT_LEVEL_INFO, module, __FUNCTION__, __LINE__, __VA_ARGS__)
#else
#define LT_I(...)
#define LT_IM(...)
#endif
#if LT_LEVEL_WARN >= LT_LOGLEVEL
#define LT_W(...) LT_LOG(LT_LEVEL_WARN, __FUNCTION__, __LINE__, __VA_ARGS__)
#define LT_W(...) LT_LOG(LT_LEVEL_WARN, __FUNCTION__, __LINE__, __VA_ARGS__)
#define LT_WM(module, ...) LT_LOGM(LT_LEVEL_WARN, module, __FUNCTION__, __LINE__, __VA_ARGS__)
#else
#define LT_W(...)
#define LT_WM(...)
#endif
#if LT_LEVEL_ERROR >= LT_LOGLEVEL
#define LT_E(...) LT_LOG(LT_LEVEL_ERROR, __FUNCTION__, __LINE__, __VA_ARGS__)
#define LT_E(...) LT_LOG(LT_LEVEL_ERROR, __FUNCTION__, __LINE__, __VA_ARGS__)
#define LT_EM(module, ...) LT_LOGM(LT_LEVEL_ERROR, module, __FUNCTION__, __LINE__, __VA_ARGS__)
#else
#define LT_E(...)
#define LT_EM(...)
#endif
#if LT_LEVEL_FATAL >= LT_LOGLEVEL
#define LT_F(...) LT_LOG(LT_LEVEL_FATAL, __FUNCTION__, __LINE__, __VA_ARGS__)
#define LT_F(...) LT_LOG(LT_LEVEL_FATAL, __FUNCTION__, __LINE__, __VA_ARGS__)
#define LT_FM(module, ...) LT_LOGM(LT_LEVEL_FATAL, module, __FUNCTION__, __LINE__, __VA_ARGS__)
#else
#define LT_F(...)
#define LT_FM(...)
#endif
#if LT_LOG_HEAP
@@ -91,20 +122,6 @@ void lt_log_set_port(uint8_t port);
#define ets_printf(...) LT_I(__VA_ARGS__)
#define ETS_PRINTF(...) LT_I(__VA_ARGS__)
#define LT_T_MOD(module, ...) \
do { \
if (module) { \
LT_T(__VA_ARGS__); \
} \
} while (0)
#define LT_D_MOD(module, ...) \
do { \
if (module) { \
LT_D(__VA_ARGS__); \
} \
} while (0)
#define LT_RET(ret) \
LT_E("ret=%d", ret); \
return ret;
@@ -150,33 +167,3 @@ void lt_log_set_port(uint8_t port);
#else
#define LT_ERRNO()
#endif
// WiFi.cpp
#define LT_T_WG(...) LT_T_MOD(LT_DEBUG_WIFI, __VA_ARGS__)
#define LT_V_WG(...) LT_T_MOD(LT_DEBUG_WIFI, __VA_ARGS__)
#define LT_D_WG(...) LT_D_MOD(LT_DEBUG_WIFI, __VA_ARGS__)
// WiFiClient.cpp
#define LT_T_WC(...) LT_T_MOD(LT_DEBUG_WIFI_CLIENT, __VA_ARGS__)
#define LT_V_WC(...) LT_T_MOD(LT_DEBUG_WIFI_CLIENT, __VA_ARGS__)
#define LT_D_WC(...) LT_D_MOD(LT_DEBUG_WIFI_CLIENT, __VA_ARGS__)
// WiFiServer.cpp
#define LT_T_WS(...) LT_T_MOD(LT_DEBUG_WIFI_SERVER, __VA_ARGS__)
#define LT_V_WS(...) LT_T_MOD(LT_DEBUG_WIFI_SERVER, __VA_ARGS__)
#define LT_D_WS(...) LT_D_MOD(LT_DEBUG_WIFI_SERVER, __VA_ARGS__)
// WiFiSTA.cpp
#define LT_T_WSTA(...) LT_T_MOD(LT_DEBUG_WIFI_STA, __VA_ARGS__)
#define LT_V_WSTA(...) LT_T_MOD(LT_DEBUG_WIFI_STA, __VA_ARGS__)
#define LT_D_WSTA(...) LT_D_MOD(LT_DEBUG_WIFI_STA, __VA_ARGS__)
// WiFiAP.cpp
#define LT_T_WAP(...) LT_T_MOD(LT_DEBUG_WIFI_AP, __VA_ARGS__)
#define LT_V_WAP(...) LT_T_MOD(LT_DEBUG_WIFI_AP, __VA_ARGS__)
#define LT_D_WAP(...) LT_D_MOD(LT_DEBUG_WIFI_AP, __VA_ARGS__)
// WiFiClientSecure.cpp & implementations
#define LT_T_SSL(...) LT_T_MOD(LT_DEBUG_SSL, __VA_ARGS__)
#define LT_V_SSL(...) LT_T_MOD(LT_DEBUG_SSL, __VA_ARGS__)
#define LT_D_SSL(...) LT_D_MOD(LT_DEBUG_SSL, __VA_ARGS__)

View File

@@ -21,7 +21,7 @@ void initVariant() __attribute__((weak));
// Initialize C library
extern "C" void __libc_init_array(void);
void main_task(const void *arg) {
void mainTask(const void *arg) {
setup();
for (;;) {
@@ -32,6 +32,23 @@ void main_task(const void *arg) {
}
}
static unsigned long periodicTasks[] = {0, 0};
void runPeriodicTasks() {
#if LT_LOG_HEAP
if (millis() - periodicTasks[0] > 1000) {
LT_HEAP_I();
periodicTasks[0] = millis();
}
#endif
#if LT_USE_TIME
if (millis() - periodicTasks[1] > 10000) {
gettimeofday(NULL, NULL);
periodicTasks[1] = millis();
}
#endif
}
int main(void) {
// print a startup banner
LT_BANNER();
@@ -46,7 +63,9 @@ int main(void) {
// provide root partition
fal_root_part = (fal_partition_t)fal_partition_find("root");
// start the main task and OS kernel
startMainTask();
if (!startMainTask()) {
LT_F("Couldn't start the main task");
}
while (1) {}
return 0;

View File

@@ -37,7 +37,7 @@ class SocketHandle {
};
LwIPClient::LwIPClient() {
LT_V_WC("LwIPClient()");
LT_VM(CLIENT, "LwIPClient()");
_connected = false;
_sock = NULL;
_rxBuffer = NULL;
@@ -45,7 +45,7 @@ LwIPClient::LwIPClient() {
}
LwIPClient::LwIPClient(int sock) {
LT_V_WC("LwIPClient(%d)", sock);
LT_VM(CLIENT, "LwIPClient(%d)", sock);
_connected = true;
_sock = std::make_shared<SocketHandle>(sock);
_rxBuffer = std::make_shared<LwIPRxBuffer>(sock);
@@ -53,7 +53,7 @@ LwIPClient::LwIPClient(int sock) {
}
LwIPClient::~LwIPClient() {
LT_V_WC("~LwIPClient()");
LT_VM(CLIENT, "~LwIPClient()");
stop();
}
@@ -89,7 +89,7 @@ int LwIPClient::connect(IPAddress ip, uint16_t port, int32_t timeout) {
stop();
int sock = lwip_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sock < 0) {
LT_D_WC("socket failed");
LT_DM(CLIENT, "socket failed");
return -1;
}
@@ -114,19 +114,19 @@ int LwIPClient::connect(IPAddress ip, uint16_t port, int32_t timeout) {
int res = lwip_connect(sock, (struct sockaddr *)&addr, sizeof(addr));
if (res < 0 && errno != EINPROGRESS) {
LT_E("Connect failed; errno=%d", errno);
LT_EM(CLIENT, "Connect failed; errno=%d", errno);
lwip_close(sock);
return -1;
}
res = lwip_select(sock + 1, NULL, &fdset, NULL, timeout < 0 ? NULL : &tv);
if (res < 0) {
LT_E("Select failed; errno=%d", errno);
LT_EM(CLIENT, "Select failed; errno=%d", errno);
lwip_close(sock);
return 0;
}
if (res == 0) {
LT_E("Select timeout; errno=%d", errno);
LT_EM(CLIENT, "Select timeout; errno=%d", errno);
lwip_close(sock);
return 0;
}
@@ -136,7 +136,7 @@ int LwIPClient::connect(IPAddress ip, uint16_t port, int32_t timeout) {
res = lwip_getsockopt(sock, SOL_SOCKET, SO_ERROR, &sockerr, &len);
if (res < 0 || sockerr != 0) {
LT_E("Socket error; res=%d, sockerr=%d", res, sockerr);
LT_EM(CLIENT, "Socket error; res=%d, sockerr=%d", res, sockerr);
lwip_close(sock);
return 0;
}
@@ -198,7 +198,7 @@ size_t LwIPClient::write(const uint8_t *buf, size_t size) {
retry--;
if (lwip_select(fd() + 1, NULL, &fdset, NULL, &tv) < 0) {
LT_W("Select failed; errno=%d", errno);
LT_WM(CLIENT, "Select failed; errno=%d", errno);
return 0;
}
@@ -214,7 +214,7 @@ size_t LwIPClient::write(const uint8_t *buf, size_t size) {
retry = WIFI_CLIENT_WRITE_RETRY;
}
} else if (res < 0 && errno != EAGAIN) {
LT_W("Send failed; errno=%d", errno);
LT_WM(CLIENT, "Send failed; errno=%d", errno);
setWriteError(res);
_connected = false;
retry = 0;
@@ -223,7 +223,7 @@ size_t LwIPClient::write(const uint8_t *buf, size_t size) {
}
}
}
LT_D_WC("wrote %d bytes", written);
LT_DM(CLIENT, "wrote %d bytes", written);
return written;
}
@@ -306,7 +306,7 @@ void LwIPClient::flush() {
}
void LwIPClient::stop() {
LT_V_WC("Stopping TCP");
LT_VM(CLIENT, "Stopping TCP");
_connected = false;
_sock = NULL;
_rxBuffer = NULL;
@@ -327,11 +327,11 @@ uint8_t LwIPClient::connected() {
case ECONNRESET:
case ECONNREFUSED:
case ECONNABORTED:
LT_W("Connection closed; errno=%d", errno);
LT_IM(CLIENT, "Connection closed; errno=%d", errno);
_connected = false;
break;
default:
LT_I("Connection status unknown; errno=%d", errno);
LT_WM(CLIENT, "Connection status unknown; errno=%d", errno);
_connected = true;
break;
}

View File

@@ -14,13 +14,13 @@ extern "C" {
size_t LwIPRxBuffer::r_available() {
if (_sock < 0) {
LT_D_WC("_sock < 0");
LT_DM(CLIENT, "_sock < 0");
return 0;
}
int count = 0; // must be of same size as in lwip_ioctl()
int res = lwip_ioctl(_sock, FIONREAD, &count);
if (res < 0) {
LT_D_WC("lwip_ioctl()=%d, errno=%d", res, errno);
LT_DM(CLIENT, "lwip_ioctl()=%d, errno=%d", res, errno);
_failed = true;
return 0;
}

View File

@@ -32,7 +32,7 @@ bool LwIPServer::begin(uint16_t port, bool reuseAddr) {
_sock = lwip_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (_sock < 0) {
LT_E("Socket failed; errno=%d", errno);
LT_EM(SERVER, "Socket failed; errno=%d", errno);
return false;
}
@@ -45,17 +45,17 @@ bool LwIPServer::begin(uint16_t port, bool reuseAddr) {
addr.sin_port = htons(_port);
if (lwip_bind(_sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
LT_E("Bind failed; errno=%d", errno);
LT_EM(SERVER, "Bind failed; errno=%d", errno);
return false;
}
if (lwip_listen(_sock, _maxClients) < 0) {
LT_E("Bind failed; errno=%d", errno);
LT_EM(SERVER, "Bind failed; errno=%d", errno);
return false;
}
uint8_t *addrB = (uint8_t *)&_addr;
LT_I("Server running on %hhu.%hhu.%hhu.%hhu:%hu", addrB[0], addrB[1], addrB[2], addrB[3], _port);
LT_IM(SERVER, "Server running on %hhu.%hhu.%hhu.%hhu:%hu", addrB[0], addrB[1], addrB[2], addrB[3], _port);
lwip_fcntl(_sock, F_SETFL, O_NONBLOCK);
_active = true;
@@ -99,7 +99,7 @@ WiFiClient LwIPServer::accept() {
// and receive data, so LwIP still sees a connected client that sends nothing. At least
// that's what I understand. And any loop that doesn't call delay() seems to block the TCP
// stack completely and prevents it from even being pinged.
LT_D_WS("Got client");
LT_DM(SERVER, "Got client");
delay(5);
return WiFiClient(sock);
}

View File

@@ -22,12 +22,12 @@ MbedTLSClient::MbedTLSClient(int sock) : WiFiClient(sock) {
}
MbedTLSClient::~MbedTLSClient() {
LT_V_WC("~MbedTLSClient()");
LT_VM(CLIENT, "~MbedTLSClient()");
stop();
}
void MbedTLSClient::stop() {
LT_V_SSL("Stopping SSL");
LT_VM(SSL, "Stopping SSL");
if (_sslCfg.ca_chain) {
mbedtls_x509_crt_free(&_caCert);
@@ -88,7 +88,7 @@ void debug_cb(void *ctx, int level, const char *file, int line, const char *str)
uint16_t len = strlen(str);
char *msg = (char *)str;
msg[len - 1] = '\0';
LT_I("%04d: |%d| %s", line, level, msg);
LT_IM(SSL, "%04d: |%d| %s", line, level, msg);
}
int MbedTLSClient::connect(
@@ -115,13 +115,13 @@ int MbedTLSClient::connect(
int ret = WiFiClient::connect(addr, port, timeout);
if (ret < 0) {
LT_E("SSL socket failed");
LT_EM(SSL, "SSL socket failed");
return ret;
}
char *uid = "lt-ssl"; // TODO
LT_V_SSL("Init SSL");
LT_VM(SSL, "Init SSL");
init();
LT_HEAP_I();
@@ -160,7 +160,7 @@ int MbedTLSClient::connect(
#ifdef MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED
uint16_t len = strlen(psk);
if ((len & 1) != 0 || len > 2 * MBEDTLS_PSK_MAX_LEN) {
LT_E("PSK length invalid");
LT_EM(SSL, "PSK length invalid");
return -1;
}
unsigned char pskBin[MBEDTLS_PSK_MAX_LEN] = {};
@@ -185,13 +185,13 @@ int MbedTLSClient::connect(
if (!_insecure && clientCert && clientKey) {
mbedtls_x509_crt_init(&_clientCert);
mbedtls_pk_init(&_clientKey);
LT_V_SSL("Loading client cert");
LT_VM(SSL, "Loading client cert");
ret = mbedtls_x509_crt_parse(&_clientCert, (const unsigned char *)clientCert, strlen(clientCert) + 1);
if (ret < 0) {
mbedtls_x509_crt_free(&_clientCert);
LT_RET(ret);
}
LT_V_SSL("Loading private key");
LT_VM(SSL, "Loading private key");
ret = mbedtls_pk_parse_key(&_clientKey, (const unsigned char *)clientKey, strlen(clientKey) + 1, NULL, 0);
if (ret < 0) {
mbedtls_x509_crt_free(&_clientCert);
@@ -200,7 +200,7 @@ int MbedTLSClient::connect(
mbedtls_ssl_conf_own_cert(&_sslCfg, &_clientCert, &_clientKey);
}
LT_V_SSL("Setting TLS hostname");
LT_VM(SSL, "Setting TLS hostname");
ret = mbedtls_ssl_set_hostname(&_sslCtx, host);
LT_RET_NZ(ret);
@@ -214,7 +214,7 @@ int MbedTLSClient::connect(
LT_HEAP_I();
LT_V_SSL("SSL handshake");
LT_VM(SSL, "SSL handshake");
if (_handshakeTimeout == 0)
_handshakeTimeout = timeout;
unsigned long start = millis();
@@ -223,7 +223,7 @@ int MbedTLSClient::connect(
LT_RET(ret);
}
if ((millis() - start) > _handshakeTimeout) {
LT_E("SSL handshake timeout");
LT_EM(SSL, "SSL handshake timeout");
return -1;
}
delay(2);
@@ -232,26 +232,27 @@ int MbedTLSClient::connect(
LT_HEAP_I();
if (clientCert && clientKey) {
LT_D_SSL(
LT_DM(
SSL,
"Protocol %s, ciphersuite %s",
mbedtls_ssl_get_version(&_sslCtx),
mbedtls_ssl_get_ciphersuite(&_sslCtx)
);
ret = mbedtls_ssl_get_record_expansion(&_sslCtx);
if (ret >= 0)
LT_D_SSL("Record expansion: %d", ret);
LT_DM(SSL, "Record expansion: %d", ret);
else {
LT_W("Record expansion unknown");
LT_WM(SSL, "Record expansion unknown");
}
}
LT_V_SSL("Verifying certificate");
LT_VM(SSL, "Verifying certificate");
ret = mbedtls_ssl_get_verify_result(&_sslCtx);
if (ret) {
char buf[512];
memset(buf, 0, sizeof(buf));
mbedtls_x509_crt_verify_info(buf, sizeof(buf), " ! ", ret);
LT_E("Failed to verify peer certificate! Verification info: %s", buf);
LT_EM(SSL, "Failed to verify peer certificate! Verification info: %s", buf);
return ret;
}
@@ -417,7 +418,7 @@ bool MbedTLSClient::verify(const char *fingerprint, const char *domainName) {
return false;
if (memcmp(fpLocal, fpRemote, 32)) {
LT_D_SSL("Fingerprints don't match");
LT_DM(SSL, "Fingerprints don't match");
return false;
}
@@ -438,7 +439,7 @@ void MbedTLSClient::setAlpnProtocols(const char **alpnProtocols) {
bool MbedTLSClient::getFingerprintSHA256(uint8_t result[32]) {
const mbedtls_x509_crt *cert = mbedtls_ssl_get_peer_cert(&_sslCtx);
if (!cert) {
LT_E("Failed to get peer certificate");
LT_EM(SSL, "Failed to get peer certificate");
return false;
}
mbedtls_sha256_context shaCtx;

View File

@@ -25,13 +25,8 @@
size_t StreamString::write(const uint8_t *data, size_t size) {
if(size && data) {
const unsigned int newlen = len + size;
if(reserve(newlen + 1)) {
memcpy((void *) (buffer + len), (const void *) data, size);
changeBuffer(newlen);
*(buffer + newlen) = 0x00; // add null for string end
return size;
}
concat(data, size);
return size;
}
return 0;
}

View File

@@ -18,14 +18,20 @@ bool UpdateClass::begin(size_t size, int command, int unused2, uint8_t unused3,
return false;
cleanup();
LT_DM(OTA, "begin(%u, ...) / OTA curr: %u, trgt: %u", size, LT.otaGetRunning(), LT.otaGetTarget());
ctx = uf2_ctx_init(LT.otaGetTarget(), FAMILY);
info = uf2_info_init();
if (!size)
return errorArd(UPDATE_ERROR_SIZE);
if (!size) {
cleanup(UPDATE_ERROR_SIZE);
return false;
}
if (command != U_FLASH)
return errorArd(UPDATE_ERROR_BAD_ARGUMENT);
if (command != U_FLASH) {
cleanup(UPDATE_ERROR_BAD_ARGUMENT);
return false;
}
bytesTotal = size;
return true;
@@ -44,12 +50,15 @@ bool UpdateClass::end(bool evenIfRemaining) {
if (!isFinished() && !evenIfRemaining) {
// abort if not finished
return errorArd(UPDATE_ERROR_ABORT);
cleanup(UPDATE_ERROR_ABORT);
return false;
}
// TODO what is evenIfRemaining for?
if (!LT.otaSwitch())
if (!LT.otaSwitch()) {
// try to activate the second OTA
return errorArd(UPDATE_ERROR_ACTIVATE);
cleanup(UPDATE_ERROR_ACTIVATE);
return false;
}
cleanup();
return true;
@@ -70,6 +79,8 @@ size_t UpdateClass::write(uint8_t *data, size_t len) {
// 0 if not running
return 0;
LT_VM(OTA, "write(%u) / buf %u/512", len, bufSize());
/* while (buf == bufPos && len >= UF2_BLOCK_SIZE) {
// buffer empty and entire block is in data
if (!tryWriteData(data, UF2_BLOCK_SIZE)) {
@@ -82,12 +93,14 @@ size_t UpdateClass::write(uint8_t *data, size_t len) {
} */
// write until buffer space is available
uint16_t toWrite;
uint16_t toWrite; // 1..512
while (len && (toWrite = min(len, bufLeft()))) {
tryWriteData(data, toWrite);
if (hasError())
if (hasError()) {
// return on errors
printErrorContext2(data, toWrite);
return written;
}
data += toWrite;
len -= toWrite;
written += toWrite;
@@ -109,7 +122,7 @@ size_t UpdateClass::writeStream(Stream &data) {
if (available <= 0) {
if (millis() - lastData > UPDATE_TIMEOUT_MS) {
// waited for data too long; abort with error
errorArd(UPDATE_ERROR_STREAM);
cleanup(UPDATE_ERROR_STREAM);
return written;
}
continue;
@@ -123,9 +136,11 @@ size_t UpdateClass::writeStream(Stream &data) {
bufPos += read;
written += read;
tryWriteData();
if (hasError())
if (hasError()) {
// return on errors
printErrorContext2(NULL, read); // buf is not valid anymore
return written;
}
}
return written;
}
@@ -141,6 +156,8 @@ size_t UpdateClass::writeStream(Stream &data) {
size_t UpdateClass::tryWriteData(uint8_t *data, size_t len) {
uf2_block_t *block = NULL;
LT_VM(OTA, "Writing %u to buffer (%u/512)", len, bufSize());
if (len == UF2_BLOCK_SIZE) {
// data has a complete block
block = (uf2_block_t *)data;
@@ -158,7 +175,7 @@ size_t UpdateClass::tryWriteData(uint8_t *data, size_t len) {
// a complete block has been found
if (block) {
if (errorUf2(uf2_check_block(ctx, block)))
if (checkUf2Error(uf2_check_block(ctx, block)))
// block is invalid
return 0;
@@ -168,20 +185,24 @@ size_t UpdateClass::tryWriteData(uint8_t *data, size_t len) {
if (!bytesWritten) {
// parse header block to allow retrieving firmware info
if (errorUf2(uf2_parse_header(ctx, block, info)))
if (checkUf2Error(uf2_parse_header(ctx, block, info)))
// header is invalid
return 0;
LT_IM(OTA, "%s v%s - LT v%s @ %s", info->fw_name, info->fw_version, info->lt_version, info->board);
if (bytesTotal == UPDATE_SIZE_UNKNOWN) {
// set total update size from block count info
bytesTotal = block->block_count * UF2_BLOCK_SIZE;
} else if (bytesTotal != block->block_count * UF2_BLOCK_SIZE) {
// given update size does not match the block count
return errorArd(UPDATE_ERROR_SIZE);
LT_EM(OTA, "Image size wrong; got %u, calculated %u", bytesTotal, block->block_count * UF2_BLOCK_SIZE);
cleanup(UPDATE_ERROR_SIZE);
return 0;
}
} else {
// write data blocks normally
if (errorUf2(uf2_write(ctx, block)))
if (checkUf2Error(uf2_write(ctx, block)))
// block writing failed
return 0;
}

View File

@@ -2,8 +2,7 @@
#include <Arduino.h>
#include <functional>
#include "uf2ota/uf2ota.h"
#include <uf2ota/uf2ota.h>
// No Error
#define UPDATE_ERROR_OK (0)
@@ -76,10 +75,11 @@ class UpdateClass {
const char *getBoardName();
private: /* UpdateUtil.cpp */
void cleanup();
bool errorUf2(uf2_err_t err);
bool errorArd(uint8_t err);
void cleanup(uint8_t ardErr = UPDATE_ERROR_OK, uf2_err_t uf2Err = UF2_ERR_OK);
bool checkUf2Error(uf2_err_t err);
void bufAlloc();
void printErrorContext1();
void printErrorContext2(const uint8_t *data, size_t len);
uint16_t bufLeft();
uint16_t bufSize();
@@ -118,8 +118,12 @@ class UpdateClass {
return errUf2;
}
uint16_t getErrorCode() {
return (errArd << 8) | errUf2;
}
void clearError() {
errorUf2(UF2_ERR_OK);
cleanup(UPDATE_ERROR_OK);
}
bool hasError() {

View File

@@ -30,7 +30,15 @@ UpdateClass &UpdateClass::onProgress(THandlerFunction_Progress callback) {
return *this;
}
void UpdateClass::cleanup() {
void UpdateClass::cleanup(uint8_t ardErr, uf2_err_t uf2Err) {
errUf2 = uf2Err;
errArd = ardErr;
#if LT_DEBUG_OTA
if (hasError())
printErrorContext1();
#endif
free(ctx); // NULL in constructor
ctx = NULL;
uf2_info_free(info); // NULL in constructor
@@ -40,8 +48,6 @@ void UpdateClass::cleanup() {
bytesWritten = 0;
bytesTotal = 0;
errUf2 = UF2_ERR_OK;
errArd = UPDATE_ERROR_OK;
}
/**
@@ -51,33 +57,19 @@ void UpdateClass::cleanup() {
* Use like: "if (errorUf2(...)) return false;"
* @return true if err is not OK, false otherwise
*/
bool UpdateClass::errorUf2(uf2_err_t err) {
bool UpdateClass::checkUf2Error(uf2_err_t err) {
if (err <= UF2_ERR_IGNORE)
return false;
cleanup();
errUf2 = err;
errArd = errorMap[err];
cleanup(errorMap[err], err);
return true;
}
/**
* @brief Set errUf2 and errArd according to given Arduino error code.
* Abort the update.
* Use like: "return errorArd(...);"
* @return false - always
*/
bool UpdateClass::errorArd(uint8_t err) {
cleanup();
errUf2 = UF2_ERR_OK;
errArd = err;
return false;
}
/**
* @brief Abort the update with UPDATE_ERROR_ABORT reason.
*/
void UpdateClass::abort() {
errorArd(UPDATE_ERROR_ABORT);
LT_DM(OTA, "Aborting update");
cleanup(UPDATE_ERROR_ABORT);
}
void UpdateClass::bufAlloc() {
@@ -100,12 +92,48 @@ void UpdateClass::printError(Print &out) {
out.println(errorString());
}
/**
* @brief Print details about the error and current OTA state.
*/
void UpdateClass::printErrorContext1() {
#if LT_DEBUG_OTA
LT_EM(OTA, "Error: %s", errorString());
if (errArd == UPDATE_ERROR_ABORT)
return;
LT_EM(OTA, "- written: %u of %u", bytesWritten, bytesTotal);
LT_EM(OTA, "- buf: size=%u, left=%u", bufSize(), bufLeft());
hexdump(buf, bufSize());
if (ctx)
LT_EM(
OTA,
"- ctx: seq=%u, part1=%s, part2=%s",
ctx->seq - 1, // print last parsed block seq
ctx->part1 ? ctx->part1->name : NULL,
ctx->part2 ? ctx->part2->name : NULL
);
uf2_block_t *block = (uf2_block_t *)buf;
if (buf)
LT_EM(OTA, "- buf: seq=%u/%u, addr=%u, len=%u", block->block_seq, block->block_count, block->addr, block->len);
#endif
}
void UpdateClass::printErrorContext2(const uint8_t *data, size_t len) {
#if LT_DEBUG_OTA
LT_EM(OTA, "- while writing %u bytes", len);
if (data)
hexdump(data, len);
#endif
}
/**
* @brief Get string representation of the error in format
* "ard=..,uf2=..". Returns "" if no error.
*/
const char *UpdateClass::errorString() {
if (!errArd)
if (!errArd && !errUf2)
return "";
sprintf(errorStr, "ard=%u,uf2=%u", errArd, errUf2);
return errorStr;

View File

@@ -1,32 +0,0 @@
/* Copyright (c) Kuba Szczodrzyński 2022-05-29. */
#include "uf2priv.h"
uf2_err_t uf2_binpatch(uint8_t *data, const uint8_t *binpatch, uint8_t binpatch_len) {
const uint8_t *binpatch_end = binpatch + binpatch_len;
// +2 to make sure opcode and length is present
while ((binpatch + 2) < binpatch_end) {
uf2_opcode_t opcode = binpatch[0];
uint8_t len = binpatch[1];
switch (opcode) {
case UF2_OPC_DIFF32:
uf2_binpatch_diff32(data, binpatch + 1);
break;
}
// advance by opcode + length + data
binpatch += len + 2;
}
return UF2_ERR_OK;
}
void uf2_binpatch_diff32(uint8_t *data, const uint8_t *patch) {
uint8_t num_offs = patch[0] - 4; // read offset count
uint32_t diff = *((uint32_t *)(patch + 1)); // read diff value
patch += 5; // skip num_offs and diff value
for (uint8_t i = 0; i < num_offs; i++) {
// patch the data
uint8_t offs = patch[i];
uint32_t *value = (uint32_t *)(data + offs);
*(value) += diff;
}
}

View File

@@ -1,26 +0,0 @@
/* Copyright (c) Kuba Szczodrzyński 2022-05-29. */
#pragma once
#include "uf2types.h"
/**
* @brief Apply binary patch to data.
*
* @param data input data
* @param data_len input data length
* @param binpatch binary patch data
* @param binpatch_len binary patch data length
* @return uf2_err_t error code
*/
uf2_err_t uf2_binpatch(uint8_t *data, const uint8_t *binpatch, uint8_t binpatch_len);
/**
* Apply DIFF32 binary patch.
*
* @param data input data
* @param len input data length
* @param patch patch data, incl. length byte
* @return uf2_err_t error code
*/
void uf2_binpatch_diff32(uint8_t *data, const uint8_t *patch);

View File

@@ -1,100 +0,0 @@
/* Copyright (c) Kuba Szczodrzyński 2022-05-29. */
#include "uf2priv.h"
uf2_ota_t *uf2_ctx_init(uint8_t ota_idx, uint32_t family_id) {
uf2_ota_t *ctx = (uf2_ota_t *)zalloc(sizeof(uf2_ota_t));
ctx->ota_idx = ota_idx;
ctx->family_id = family_id;
return ctx;
}
uf2_info_t *uf2_info_init() {
uf2_info_t *info = (uf2_info_t *)zalloc(sizeof(uf2_info_t));
return info;
}
void uf2_info_free(uf2_info_t *info) {
if (!info)
return;
free(info->fw_name);
free(info->fw_version);
free(info->lt_version);
free(info->board);
free(info);
}
uf2_err_t uf2_check_block(uf2_ota_t *ctx, uf2_block_t *block) {
if (block->magic1 != UF2_MAGIC_1)
return UF2_ERR_MAGIC;
if (block->magic2 != UF2_MAGIC_2)
return UF2_ERR_MAGIC;
if (block->magic3 != UF2_MAGIC_3)
return UF2_ERR_MAGIC;
if (block->file_container)
// ignore file containers, for now
return UF2_ERR_IGNORE;
if (!block->has_family_id || block->file_size != ctx->family_id)
// require family_id
return UF2_ERR_FAMILY;
return UF2_ERR_OK;
}
uf2_err_t uf2_parse_header(uf2_ota_t *ctx, uf2_block_t *block, uf2_info_t *info) {
if (!block->has_tags || block->file_container || block->len)
// header must have tags and no data
return UF2_ERR_NOT_HEADER;
uf2_err_t err = uf2_parse_block(ctx, block, info);
if (err)
return err;
if ((ctx->ota_idx == 1 && !ctx->has_ota1) || !ctx->has_ota2)
return UF2_ERR_OTA_WRONG;
return UF2_ERR_OK;
}
uf2_err_t uf2_write(uf2_ota_t *ctx, uf2_block_t *block) {
if (ctx->seq == 0)
return uf2_parse_header(ctx, block, NULL);
if (block->not_main_flash || !block->len)
// ignore blocks not meant for flashing
return UF2_ERR_IGNORE;
uf2_err_t err = uf2_parse_block(ctx, block, NULL);
if (err)
return err;
if (!ctx->part1 && !ctx->part2)
// no partitions set at all
return UF2_ERR_PART_UNSET;
fal_partition_t part = uf2_get_target_part(ctx);
if (!part)
// image is not for current OTA scheme
return UF2_ERR_IGNORE;
if (ctx->ota_idx == 2 && ctx->binpatch_len) {
// apply binpatch
err = uf2_binpatch(block->data, ctx->binpatch, ctx->binpatch_len);
if (err)
return err;
}
int ret;
// erase sectors if needed
if (!uf2_is_erased(ctx, block->addr, block->len)) {
ret = fal_partition_erase(part, block->addr, block->len);
if (ret < 0)
return UF2_ERR_ERASE_FAILED;
ctx->erased_offset = block->addr;
ctx->erased_length = ret;
}
// write data to flash
ret = fal_partition_write(part, block->addr, block->data, block->len);
if (ret < 0)
return UF2_ERR_WRITE_FAILED;
if (ret != block->len)
return UF2_ERR_WRITE_LENGTH;
return UF2_ERR_OK;
}

View File

@@ -1,68 +0,0 @@
/* Copyright (c) Kuba Szczodrzyński 2022-05-28. */
#pragma once
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
#include "uf2types.h"
/**
* @brief Create an UF2 OTA context.
*
* @param ota_idx target OTA index
* @param family_id expected family ID
* @return uf2_ota_t* heap-allocated structure
*/
uf2_ota_t *uf2_ctx_init(uint8_t ota_idx, uint32_t family_id);
/**
* @brief Create an UF2 Info structure.
*
* @return uf2_info_t* heap-allocated structure
*/
uf2_info_t *uf2_info_init();
/**
* @brief Free values in the info structure AND the structure itself.
*
* @param info structure to free; may be NULL
*/
void uf2_info_free(uf2_info_t *info);
/**
* @brief Check if block is valid.
*
* @param ctx context
* @param block block to check
* @return uf2_err_t error code; UF2_ERR_OK and UF2_ERR_IGNORE denote valid blocks
*/
uf2_err_t uf2_check_block(uf2_ota_t *ctx, uf2_block_t *block);
/**
* @brief Parse header block (LibreTuya UF2 first block).
*
* Note: caller should call uf2_check_block() first.
*
* @param ctx context
* @param block block to parse
* @param info structure to write firmware info, NULL if not used
* @return uf2_err_t error code
*/
uf2_err_t uf2_parse_header(uf2_ota_t *ctx, uf2_block_t *block, uf2_info_t *info);
/**
* @brief Write the block to flash memory.
*
* Note: caller should call uf2_check_block() first.
*
* @param ctx context
* @param block block to write
* @return uf2_err_t error code
*/
uf2_err_t uf2_write(uf2_ota_t *ctx, uf2_block_t *block);
#ifdef __cplusplus
} // extern "C"
#endif

View File

@@ -1,146 +0,0 @@
/* Copyright (c) Kuba Szczodrzyński 2022-05-29. */
#include "uf2priv.h"
uf2_err_t uf2_parse_block(uf2_ota_t *ctx, uf2_block_t *block, uf2_info_t *info) {
if (block->block_seq != ctx->seq)
// sequence number must match
return UF2_ERR_SEQ_MISMATCH;
ctx->seq++; // increment sequence number after checking it
if (!block->has_tags)
// no tags in this block, no further processing needed
return UF2_ERR_OK;
if (block->len > (476 - 4 - 4))
// at least one tag + last tag must fit
return UF2_ERR_DATA_TOO_LONG;
uint8_t *tags_start = block->data + block->len;
uint8_t tags_len = 476 - block->len;
uint8_t tags_pos = 0;
if (block->has_md5)
tags_len -= 24;
ctx->binpatch_len = 0; // binpatch applies to one block only
char *part1 = NULL;
char *part2 = NULL;
uf2_tag_type_t type;
while (tags_pos < tags_len) {
uint8_t len = uf2_read_tag(tags_start + tags_pos, &type);
if (!len)
break;
tags_pos += 4; // skip tag header
uint8_t *tag = tags_start + tags_pos;
char **str_dest = NULL; // char* to copy the tag into
switch (type) {
case UF2_TAG_OTA_VERSION:
if (tag[0] != 1)
return UF2_ERR_OTA_VER;
break;
case UF2_TAG_FIRMWARE:
if (info)
str_dest = &(info->fw_name);
break;
case UF2_TAG_VERSION:
if (info)
str_dest = &(info->fw_version);
break;
case UF2_TAG_LT_VERSION:
if (info)
str_dest = &(info->lt_version);
break;
case UF2_TAG_BOARD:
if (info)
str_dest = &(info->board);
break;
case UF2_TAG_HAS_OTA1:
ctx->has_ota1 = tag[0];
break;
case UF2_TAG_HAS_OTA2:
ctx->has_ota2 = tag[0];
break;
case UF2_TAG_PART_1:
str_dest = &(part1);
break;
case UF2_TAG_PART_2:
str_dest = &(part2);
break;
case UF2_TAG_BINPATCH:
ctx->binpatch = tag;
ctx->binpatch_len = len;
break;
default:
break;
}
if (str_dest) {
*str_dest = (char *)zalloc(len + 1);
memcpy(*str_dest, tag, len);
}
// align position to 4 bytes
tags_pos += (((len - 1) / 4) + 1) * 4;
}
if (part1 && part2) {
// update current target partition
uf2_err_t err = uf2_update_parts(ctx, part1, part2);
if (err)
return err;
} else if (part1 || part2) {
// only none or both partitions can be specified
return UF2_ERR_PART_ONE;
}
return UF2_ERR_OK;
}
uint8_t uf2_read_tag(const uint8_t *data, uf2_tag_type_t *type) {
uint8_t len = data[0];
if (!len)
return 0;
uint32_t tag_type = *((uint32_t *)data);
if (!tag_type)
return 0;
*type = tag_type >> 8; // remove tag length byte
return len - 4;
}
uf2_err_t uf2_update_parts(uf2_ota_t *ctx, char *part1, char *part2) {
// reset both target partitions
ctx->part1 = NULL;
ctx->part2 = NULL;
// reset offsets as they probably don't apply to this partition
ctx->erased_offset = 0;
ctx->erased_length = 0;
if (part1[0]) {
ctx->part1 = (fal_partition_t)fal_partition_find(part1);
if (!ctx->part1)
return UF2_ERR_PART_404;
}
if (part2[0]) {
ctx->part2 = (fal_partition_t)fal_partition_find(part2);
if (!ctx->part2)
return UF2_ERR_PART_404;
}
return UF2_ERR_OK;
}
fal_partition_t uf2_get_target_part(uf2_ota_t *ctx) {
if (ctx->ota_idx == 1)
return ctx->part1;
if (ctx->ota_idx == 2)
return ctx->part2;
return NULL;
}
bool uf2_is_erased(uf2_ota_t *ctx, uint32_t offset, uint32_t length) {
uint32_t erased_end = ctx->erased_offset + ctx->erased_length;
uint32_t end = offset + length;
return (offset >= ctx->erased_offset) && (end <= erased_end);
}

View File

@@ -1,61 +0,0 @@
/* Copyright (c) Kuba Szczodrzyński 2022-05-28. */
#pragma once
// include family stdlib APIs
#include <WVariant.h>
#include "uf2binpatch.h"
#include "uf2types.h"
/**
* @brief Parse a block and extract information from tags.
*
* @param ctx context
* @param block block to parse
* @param info structure to write firmware info, NULL if not used
* @return uf2_err_t error code
*/
uf2_err_t uf2_parse_block(uf2_ota_t *ctx, uf2_block_t *block, uf2_info_t *info);
/**
* @brief Parse a tag.
*
* @param data pointer to tag header beginning
* @param type [out] parsed tag type
* @return uint8_t parsed tag data length (excl. header); 0 if invalid/last tag
*/
uint8_t uf2_read_tag(const uint8_t *data, uf2_tag_type_t *type);
/**
* @brief Update destination partitions in context.
*
* Partition names cannot be NULL.
*
* Returns UF2_ERR_IGNORE if specified partitions don't match the
* current OTA index.
*
* @param ctx context
* @param part1 partition 1 name or empty string
* @param part2 partition 2 name or empty string
* @return uf2_err_t error code
*/
uf2_err_t uf2_update_parts(uf2_ota_t *ctx, char *part1, char *part2);
/**
* @brief Get target flashing partition, depending on OTA index.
*
* @param ctx context
* @return fal_partition_t target partition or NULL if not set
*/
fal_partition_t uf2_get_target_part(uf2_ota_t *ctx);
/**
* Check if specified flash memory region was already erased during update.
*
* @param ctx context
* @param offset offset to check
* @param length length to check
* @return bool true/false
*/
bool uf2_is_erased(uf2_ota_t *ctx, uint32_t offset, uint32_t length);

View File

@@ -1,104 +0,0 @@
/* Copyright (c) Kuba Szczodrzyński 2022-05-28. */
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include <fal.h>
#define UF2_MAGIC_1 0x0A324655
#define UF2_MAGIC_2 0x9E5D5157
#define UF2_MAGIC_3 0x0AB16F30
#define UF2_BLOCK_SIZE sizeof(uf2_block_t)
typedef struct __attribute__((packed)) {
// 32 byte header
uint32_t magic1;
uint32_t magic2;
// flags split as bitfields
bool not_main_flash : 1;
uint16_t dummy1 : 11;
bool file_container : 1;
bool has_family_id : 1;
bool has_md5 : 1;
bool has_tags : 1;
uint16_t dummy2 : 16;
uint32_t addr;
uint32_t len;
uint32_t block_seq;
uint32_t block_count;
uint32_t file_size; // or familyID;
uint8_t data[476];
uint32_t magic3;
} uf2_block_t;
typedef struct {
uint32_t seq; // current block sequence number
uint8_t *binpatch; // current block's binpatch (if any) -> pointer inside block->data
uint8_t binpatch_len; // binpatch length
bool has_ota1; // image has any data for OTA1
bool has_ota2; // image has any data for OTA2
uint8_t ota_idx; // target OTA index
uint32_t family_id; // expected family ID
uint32_t erased_offset; // offset of region erased during update
uint32_t erased_length; // length of erased region
fal_partition_t part1; // OTA1 target partition
fal_partition_t part2; // OTA2 target partition
} uf2_ota_t;
typedef struct {
char *fw_name;
char *fw_version;
char *lt_version;
char *board;
} uf2_info_t;
typedef enum {
UF2_TAG_VERSION = 0x9FC7BC, // version of firmware file - UTF8 semver string
UF2_TAG_PAGE_SIZE = 0x0BE9F7, // page size of target device (32 bit unsigned number)
UF2_TAG_SHA2 = 0xB46DB0, // SHA-2 checksum of firmware (can be of various size)
UF2_TAG_DEVICE = 0x650D9D, // description of device (UTF8)
UF2_TAG_DEVICE_ID = 0xC8A729, // device type identifier
// LibreTuya custom, tags
UF2_TAG_OTA_VERSION = 0x5D57D0, // format version
UF2_TAG_BOARD = 0xCA25C8, // board name (lowercase code)
UF2_TAG_FIRMWARE = 0x00DE43, // firmware description / name
UF2_TAG_BUILD_DATE = 0x822F30, // build date/time as Unix timestamp
UF2_TAG_LT_VERSION = 0x59563D, // LT version (semver)
UF2_TAG_PART_1 = 0x805946, // OTA1 partition name
UF2_TAG_PART_2 = 0xA1E4D7, // OTA2 partition name
UF2_TAG_HAS_OTA1 = 0xBBD965, // image has any data for OTA1
UF2_TAG_HAS_OTA2 = 0x92280E, // image has any data for OTA2
UF2_TAG_BINPATCH = 0xB948DE, // binary patch to convert OTA1->OTA2
} uf2_tag_type_t;
typedef enum {
UF2_OPC_DIFF32 = 0xFE,
} uf2_opcode_t;
typedef enum {
UF2_ERR_OK = 0,
UF2_ERR_IGNORE, // block should be ignored
UF2_ERR_MAGIC, // wrong magic numbers
UF2_ERR_FAMILY, // family ID mismatched
UF2_ERR_NOT_HEADER, // block is not a header
UF2_ERR_OTA_VER, // unknown/invalid OTA format version
UF2_ERR_OTA_WRONG, // no data for current OTA index
UF2_ERR_PART_404, // no partition with that name
UF2_ERR_PART_ONE, // only one partition tag in a block
UF2_ERR_PART_UNSET, // image broken - attempted to write without target partition
UF2_ERR_DATA_TOO_LONG, // data too long - tags won't fit
UF2_ERR_SEQ_MISMATCH, // sequence number mismatched
UF2_ERR_ERASE_FAILED, // erasing flash failed
UF2_ERR_WRITE_FAILED, // writing to flash failed
UF2_ERR_WRITE_LENGTH, // wrote fewer data than requested
} uf2_err_t;

View File

@@ -50,27 +50,27 @@ bool WiFiMulti::addAP(const char *ssid, const char *passphrase) {
if (!ssid || *ssid == 0x00 || strlen(ssid) > 31) {
// fail SSID too long or missing!
LT_E("SSID missing or too long");
LT_EM(WIFI, "SSID missing or too long");
return false;
}
if (passphrase && strlen(passphrase) > 64) {
// fail passphrase too long!
LT_E("Passphrase too long");
LT_EM(WIFI, "Passphrase too long");
return false;
}
newAP.ssid = strdup(ssid);
if (!newAP.ssid) {
LT_E("Fail newAP.ssid == 0");
LT_EM(WIFI, "Fail newAP.ssid == 0");
return false;
}
if (passphrase && *passphrase != 0x00) {
newAP.passphrase = strdup(passphrase);
if (!newAP.passphrase) {
LT_E("Fail newAP.passphrase == 0");
LT_EM(WIFI, "Fail newAP.passphrase == 0");
free(newAP.ssid);
return false;
}
@@ -79,7 +79,7 @@ bool WiFiMulti::addAP(const char *ssid, const char *passphrase) {
}
APlist.push_back(newAP);
LT_V("Add SSID: %s", newAP.ssid);
LT_VM(WIFI, "Add SSID: %s", newAP.ssid);
return true;
}
@@ -108,12 +108,12 @@ uint8_t WiFiMulti::run(uint32_t connectTimeout) {
uint8_t bestBSSID[6];
int32_t bestChannel = 0;
LT_I("Scan finished");
LT_IM(WIFI, "Scan finished");
if (scanResult == 0) {
LT_I("No networks found");
LT_IM(WIFI, "No networks found");
} else {
LT_I("%d networks found", scanResult);
LT_IM(WIFI, "%d networks found", scanResult);
for (int8_t i = 0; i < scanResult; ++i) {
String ssid_scan;
@@ -144,7 +144,8 @@ uint8_t WiFiMulti::run(uint32_t connectTimeout) {
}
if (known) {
LT_D(
LT_DM(
WIFI,
" ---> %d: [%d][%02X:%02X:%02X:%02X:%02X:%02X] %s (%d) %c",
i,
chan_scan,
@@ -159,7 +160,8 @@ uint8_t WiFiMulti::run(uint32_t connectTimeout) {
(sec_scan == WIFI_AUTH_OPEN) ? ' ' : '*'
);
} else {
LT_D(
LT_DM(
WIFI,
" %d: [%d][%02X:%02X:%02X:%02X:%02X:%02X] %s (%d) %c",
i,
chan_scan,
@@ -181,7 +183,8 @@ uint8_t WiFiMulti::run(uint32_t connectTimeout) {
WiFi.scanDelete();
if (bestNetwork.ssid) {
LT_I(
LT_IM(
WIFI,
"Connecting to BSSID: %02X:%02X:%02X:%02X:%02X:%02X SSID: %s Channel: %d (%d)",
bestBSSID[0],
bestBSSID[1],
@@ -208,33 +211,33 @@ uint8_t WiFiMulti::run(uint32_t connectTimeout) {
IPAddress ip;
switch (status) {
case WL_CONNECTED:
LT_I("Connecting done");
LT_D("SSID: %s", WiFi.SSID().c_str());
LT_IM(WIFI, "Connecting done");
LT_DM(WIFI, "SSID: %s", WiFi.SSID().c_str());
// TODO fix this after implementing IP format for printf()
ip = WiFi.localIP();
LT_D("IP: %u.%u.%u.%u", ip[0], ip[1], ip[2], ip[3]);
LT_D("MAC: %s", WiFi.BSSIDstr().c_str());
LT_D("Channel: %d", WiFi.channel());
LT_DM(WIFI, "IP: %u.%u.%u.%u", ip[0], ip[1], ip[2], ip[3]);
LT_DM(WIFI, "MAC: %s", WiFi.BSSIDstr().c_str());
LT_DM(WIFI, "Channel: %d", WiFi.channel());
break;
case WL_NO_SSID_AVAIL:
LT_E("Connecting failed; AP not found");
LT_EM(WIFI, "Connecting failed; AP not found");
break;
case WL_CONNECT_FAILED:
LT_E("Connecting failed");
LT_EM(WIFI, "Connecting failed");
break;
default:
LT_E("Connecting failed (%d)", status);
LT_EM(WIFI, "Connecting failed (%d)", status);
break;
}
} else {
LT_E("No matching network found!");
LT_EM(WIFI, "No matching network found!");
}
} else {
// start scan
LT_V("Delete old wifi config...");
LT_VM(WIFI, "Delete old wifi config...");
WiFi.disconnect();
LT_D("Start scan");
LT_DM(WIFI, "Start scan");
// scan wifi async mode
WiFi.scanNetworks(true);
}

View File

@@ -3,70 +3,65 @@
#ifdef LT_HAS_LWIP2
#include "mDNS.h"
#include <vector>
extern "C" {
#include <errno.h>
#include <lwip/apps/mdns.h>
#include <lwip/igmp.h>
#include <lwip/init.h>
#include <lwip/netif.h>
}
static u8_t mdns_netif_client_id = 0; // TODO fix this
struct mdns_domain {
/* Encoded domain name */
u8_t name[256];
/* Total length of domain name, including zero */
u16_t length;
/* Set if compression of this domain is not allowed */
u8_t skip_compression;
};
/** Description of a service */
struct mdns_service {
/** TXT record to answer with */
struct mdns_domain txtdata;
/** Name of service, like 'myweb' */
char name[MDNS_LABEL_MAXLEN + 1];
/** Type of service, like '_http' */
char service[MDNS_LABEL_MAXLEN + 1];
/** Callback function and userdata
* to update txtdata buffer */
service_get_txt_fn_t txt_fn;
void *txt_userdata;
/** TTL in seconds of SRV/TXT replies */
u32_t dns_ttl;
/** Protocol, TCP or UDP */
u16_t proto;
/** Port of the service */
u16_t port;
};
/** Description of a host/netif */
struct mdns_host {
/** Hostname */
char name[MDNS_LABEL_MAXLEN + 1];
/** Pointer to services */
struct mdns_service *services[MDNS_MAX_SERVICES];
/** TTL in seconds of A/AAAA/PTR replies */
u32_t dns_ttl;
};
static String mdnsInstanceName = "default_instance";
static std::vector<char *> services;
static std::vector<uint8_t> protos;
static std::vector<std::vector<char *>> records;
mDNS::mDNS() {}
mDNS::~mDNS() {}
static void mdnsTxtCallback(struct mdns_service *service, void *userdata) {
size_t index = (size_t)userdata;
if (index >= records.size())
return;
for (const auto record : records[index]) {
err_t err = mdns_resp_add_service_txtitem(service, record, strlen(record));
if (err != ERR_OK)
return;
}
}
static void mdnsStatusCallback(struct netif *netif, uint8_t result) {
LT_DM(MDNS, "Status: netif %u, status %u", netif->num, result);
}
bool mDNS::begin(const char *hostname) {
LT_DM(MDNS, "Starting (%s)", hostname);
#if LWIP_VERSION_MAJOR >= 2 && LWIP_VERSION_MINOR >= 1
mdns_resp_register_name_result_cb(mdnsStatusCallback);
#endif
mdns_resp_init();
struct netif *netif = netif_list;
uint8_t enabled = 0;
while (netif != NULL) {
// TODO: detect mdns_netif_client_id by checking netif_get_client_data()
// and finding the requested hostname in struct mdns_host
if (netif_is_up(netif) && mdns_resp_add_netif(netif, hostname, 255) == ERR_OK) {
enabled++;
uint8_t enabled = 0;
struct netif *netif;
for (netif = netif_list; netif != NULL; netif = netif->next) {
if (!netif_is_up(netif))
continue;
LT_DM(MDNS, "Adding netif %u", netif->num);
if ((netif->flags & NETIF_FLAG_IGMP) == 0) {
LT_DM(MDNS, "Enabling IGMP");
netif->flags |= NETIF_FLAG_IGMP;
igmp_start(netif);
}
netif = netif->next;
err_t ret = mdns_resp_add_netif(netif, hostname, 255);
if (ret == ERR_OK)
enabled++;
else
LT_DM(MDNS, "Cannot add netif %u; ret=%d, errno=%d", netif->num, ret, errno);
}
return enabled > 0;
}
@@ -80,72 +75,53 @@ void mDNS::end() {
}
}
void mDNS::setInstanceName(String name) {
mdnsInstanceName = name;
}
bool mDNS::addService(char *service, char *proto, uint16_t port) {
char _service[strlen(service) + 2];
char _proto[strlen(proto) + 2];
_service[0] = '_';
_proto[0] = '_';
// prepend names with _
strcpy(_service + 1, service + (service[0] == '_'));
strcpy(_proto + 1, proto + (proto[0] == '_'));
mdns_sd_proto protocol = DNSSD_PROTO_UDP;
if (strncmp(_proto + 1, "tcp", 3) == 0)
protocol = DNSSD_PROTO_TCP;
bool mDNS::addServiceImpl(const char *name, const char *service, uint8_t proto, uint16_t port) {
bool added = false;
struct netif *netif = netif_list;
while (netif != NULL) {
if (netif_is_up(netif)) {
mdns_resp_add_service(netif, mdnsInstanceName.c_str(), service, protocol, port, 255, NULL, NULL);
// register TXT callback;
// pass service index as userdata parameter
LT_DM(MDNS, "Add service: netif %u / %s / %s / %u / %u", netif->num, name, service, proto, port);
mdns_resp_add_service(
netif,
name,
service,
(mdns_sd_proto)proto,
port,
255,
mdnsTxtCallback,
(void *)services.size() // index of newly added service
);
added = true;
}
netif = netif->next;
}
if (!added)
return false;
// add the service to TXT record arrays
services.push_back(strdup(service));
protos.push_back(proto);
records.emplace_back();
return true;
}
bool mDNS::addServiceTxt(char *name, char *proto, char *key, char *value) {
char _name[strlen(name) + 2];
char _proto[strlen(proto) + 2];
_name[0] = '_';
_proto[0] = '_';
// prepend names with _
strcpy(_name + 1, name + (name[0] == '_'));
strcpy(_proto + 1, proto + (proto[0] == '_'));
mdns_sd_proto protocol = DNSSD_PROTO_UDP;
if (strncmp(_proto + 1, "tcp", 3) == 0)
protocol = DNSSD_PROTO_TCP;
struct netif *netif = netif_list;
struct mdns_host *mdns;
struct mdns_service *service;
uint8_t txt_len = strlen(key) + strlen(value) + 1;
char *txt = (char *)malloc(txt_len + 1);
sprintf(txt, "%s=%s", key, value);
while (netif != NULL) {
if (netif_is_up(netif)) {
mdns = (struct mdns_host *)netif_get_client_data(netif, mdns_netif_client_id);
for (uint8_t i = 0; i < MDNS_MAX_SERVICES; i++) {
service = mdns->services[i];
if (service == NULL)
continue;
if (strcmp(service->service, _name) || service->proto != protocol)
continue;
if (mdns_resp_add_service_txtitem(service, txt, txt_len) != ERR_OK) {
free(txt);
return false;
}
}
bool mDNS::addServiceTxtImpl(const char *service, uint8_t proto, const char *item) {
int8_t index = -1;
for (uint8_t i = 0; i < services.size(); i++) {
// find a matching service
if (strcmp(services[i], service) == 0 && protos[i] == proto) {
index = i;
break;
}
netif = netif->next;
}
free(txt);
if (index == -1)
return false;
records[index].push_back(strdup(item));
return true;
}

View File

@@ -0,0 +1,40 @@
/* Copyright (c) Kuba Szczodrzyński 2022-08-26. */
#include "mDNS.h"
static char *ensureUnderscore(const char *value) {
uint8_t len = strlen(value) + 1;
char *result = (char *)malloc(len);
result[0] = '_';
strcpy(result + 1, value + (value[0] == '_'));
return result;
}
void mDNS::setInstanceName(const char *name) {
if (instanceName)
free(instanceName);
instanceName = strdup(name);
}
bool mDNS::addService(char *service, char *proto, uint16_t port) {
char *_service = ensureUnderscore(service);
uint8_t _proto = strncmp(proto + (proto[0] == '_'), "tcp", 3) == 0 ? MDNS_TCP : MDNS_UDP;
bool result = addServiceImpl(instanceName ? instanceName : "LT mDNS", _service, _proto, port);
free(_service);
return result;
}
bool mDNS::addServiceTxt(char *service, char *proto, char *key, char *value) {
char *_service = ensureUnderscore(service);
uint8_t _proto = strncmp(proto + (proto[0] == '_'), "tcp", 3) == 0 ? MDNS_TCP : MDNS_UDP;
uint8_t txt_len = strlen(key) + strlen(value) + 1;
char *txt = (char *)malloc(txt_len + 1);
sprintf(txt, "%s=%s", key, value);
bool result = addServiceTxtImpl(_service, _proto, txt);
free(_service);
free(txt);
return result;
}

View File

@@ -44,7 +44,16 @@ License (MIT license):
#include <Arduino.h>
#include <api/IPv6Address.h>
#define MDNS_UDP 0
#define MDNS_TCP 1
class mDNS {
private:
bool addServiceImpl(const char *name, const char *service, uint8_t proto, uint16_t port);
bool addServiceTxtImpl(const char *service, uint8_t proto, const char *item);
char *instanceName = NULL;
public:
mDNS();
~mDNS();
@@ -52,9 +61,9 @@ class mDNS {
bool begin(const char *hostname);
void end();
void setInstanceName(String name);
void setInstanceName(const char *name);
bool addService(char *service, char *proto, uint16_t port);
bool addServiceTxt(char *name, char *proto, char *key, char *value);
bool addServiceTxt(char *service, char *proto, char *key, char *value);
// void enableArduino(uint16_t port = 3232, bool auth = false);
// void disableArduino();
// void enableWorkstation(esp_interface_t interface = ESP_IF_WIFI_STA);
@@ -73,12 +82,12 @@ class mDNS {
String txt(int idx, int txtIdx);
String txtKey(int idx, int txtIdx);
void setInstanceName(const char *name) {
setInstanceName(String(name));
void setInstanceName(String name) {
setInstanceName(name.c_str());
}
void setInstanceName(char *name) {
setInstanceName(String(name));
setInstanceName((const char *)name);
}
bool addService(const char *service, const char *proto, uint16_t port) {
@@ -89,12 +98,12 @@ class mDNS {
return addService(service.c_str(), proto.c_str(), port);
}
void addServiceTxt(const char *name, const char *proto, const char *key, const char *value) {
addServiceTxt((char *)name, (char *)proto, (char *)key, (char *)value);
void addServiceTxt(const char *service, const char *proto, const char *key, const char *value) {
addServiceTxt((char *)service, (char *)proto, (char *)key, (char *)value);
}
void addServiceTxt(String name, String proto, String key, String value) {
addServiceTxt(name.c_str(), proto.c_str(), key.c_str(), value.c_str());
void addServiceTxt(String service, String proto, String key, String value) {
addServiceTxt(service.c_str(), proto.c_str(), key.c_str(), value.c_str());
}
IPAddress queryHost(const char *host, uint32_t timeout = 2000) {

View File

@@ -36,10 +36,14 @@
/* MCU Endian Configuration, default is Little Endian Order. */
// #define FDB_BIG_ENDIAN
/* log print macro. default EF_PRINT macro is printf() */
#define FDB_PRINT(...)
#include <printf_config.h>
/* print debug information */
// #define FDB_DEBUG_ENABLE
#if LT_DEBUG_FDB
#include <printf/printf.h>
#define FDB_PRINT(...) __wrap_printf(__VA_ARGS__)
#define FDB_DEBUG_ENABLE
#else
#define FDB_PRINT(...)
#endif
#endif /* _FDB_CFG_H_ */

View File

@@ -1,5 +1,7 @@
/* Copyright (c) Kuba Szczodrzyński 2022-05-16. */
#include <sys/time.h>
extern char *strdup(const char *);
extern int strcasecmp(const char *s1, const char *s2);
extern int strncasecmp(const char *s1, const char *s2, size_t n);

View File

@@ -0,0 +1,50 @@
/* Copyright (c) Kuba Szczodrzyński 2022-09-03. */
#include <Arduino.h>
#include <errno.h>
static uint32_t reset_epoch = 0; // epoch corresponding to millis() == 0
static uint32_t reset_millis = 0; // millis() when epoch reset was performed
int __wrap_gettimeofday(struct timeval *tv, void *tz) {
if (millis() < reset_millis) {
// the clock overflowed
reset_epoch += UINT32_MAX / 1000;
reset_millis = millis();
}
if (!tv) {
errno = EINVAL;
return -1;
}
unsigned long m = millis();
tv->tv_sec = reset_epoch + (m / 1000);
tv->tv_usec = (m % 1000) * 1000;
return 0;
}
int __wrap_settimeofday(const struct timeval *tv, const struct timezone *tz) {
if (!tv) {
errno = EINVAL;
return -1;
}
unsigned long m = millis();
reset_epoch = tv->tv_sec - (m / 1000);
reset_millis = m;
return 0;
}
int gettimeofday(struct timeval *tv, void *tz) {
return __wrap_gettimeofday(tv, tz);
}
int settimeofday(const struct timeval *tv, const struct timezone *tz) {
return __wrap_settimeofday(tv, tz);
}
int _gettimeofday(struct timeval *tv, void *tz) {
return __wrap_gettimeofday(tv, tz);
}
int _settimeofday(const struct timeval *tv, const struct timezone *tz) {
return __wrap_settimeofday(tv, tz);
}

View File

@@ -99,6 +99,13 @@ uint32_t LibreTuya::getMaxAllocHeap() {
/* OTA-related */
uint8_t LibreTuya::otaGetRunning() {
// RTL8710B is XIP, so check the code offset in flash
uint32_t addr = (uint32_t)lt_log;
uint32_t offs = addr - SPI_FLASH_BASE;
return offs > FLASH_OTA2_OFFSET ? 2 : 1;
}
uint8_t LibreTuya::otaGetStoredIndex() {
uint32_t *otaAddress = (uint32_t *)0x8009000;
if (*otaAddress == 0xFFFFFFFF)

View File

@@ -10,9 +10,9 @@ static void *gpio_irq_handler_args[PINS_COUNT] = {NULL};
extern bool pinInvalid(pin_size_t pinNumber);
extern void pinRemoveMode(pin_size_t pinNumber);
void gpioIrqHandler(uint32_t id, gpio_irq_event event) {
static void gpioIrqHandler(uint32_t id, gpio_irq_event event) {
if (gpio_irq_handler_list[id] != NULL) {
if (gpio_irq_handler_args[id] != NULL)
if (gpio_irq_handler_args[id] == NULL)
((voidFuncPtr)gpio_irq_handler_list[id])();
else
((voidFuncPtrParam)gpio_irq_handler_list[id])(gpio_irq_handler_args[id]);

View File

@@ -23,8 +23,8 @@ void initArduino() {
}
bool startMainTask() {
osThreadDef(main_task, osPriorityRealtime, 1, 4096 * 4);
main_tid = osThreadCreate(osThread(main_task), NULL);
osThreadDef(mainTask, osPriorityRealtime, 1, 4096 * 4);
main_tid = osThreadCreate(osThread(mainTask), NULL);
osKernelStart();
return true;
}

View File

@@ -34,7 +34,7 @@ bool WiFiClass::softAP(const char *ssid, const char *passphrase, int channel, bo
dhcps_deinit();
LT_I("Creating SoftAP %s", ssid);
LT_IM(WIFI, "Creating SoftAP %s", ssid);
int ret;
if (!ssidHidden) {
@@ -60,7 +60,7 @@ bool WiFiClass::softAP(const char *ssid, const char *passphrase, int channel, bo
wifi_indication(WIFI_EVENT_CONNECT, NULL, ARDUINO_EVENT_WIFI_AP_START, -2);
if (ret < 0) {
LT_E("SoftAP failed; ret=%d", ret);
LT_EM(WIFI, "SoftAP failed; ret=%d", ret);
return false;
}

View File

@@ -15,7 +15,7 @@ bool WiFiClass::modePriv(WiFiMode mode, WiFiModeAction sta, WiFiModeAction ap) {
if (!data.initialized) {
// initialize wifi first
LT_I("Initializing LwIP");
LT_IM(WIFI, "Initializing LwIP");
LwIP_Init();
reset_wifi_struct();
data.initialized = true;
@@ -23,7 +23,7 @@ bool WiFiClass::modePriv(WiFiMode mode, WiFiModeAction sta, WiFiModeAction ap) {
LT_HEAP_I();
if (getMode()) {
// stop wifi to change mode
LT_D_WG("Stopping WiFi to change mode");
LT_DM(WIFI, "Stopping WiFi to change mode");
if (wifi_off() != RTW_SUCCESS)
goto error;
vTaskDelay(20);
@@ -32,7 +32,7 @@ bool WiFiClass::modePriv(WiFiMode mode, WiFiModeAction sta, WiFiModeAction ap) {
}
if (wifi_on((rtw_mode_t)mode) != RTW_SUCCESS) {
LT_E("Error while changing mode(%u)", mode);
LT_EM(WIFI, "Error while changing mode(%u)", mode);
goto error;
}
@@ -72,12 +72,14 @@ WiFiStatus WiFiClass::status() {
}
bool WiFiClass::setSleep(bool enable) {
LT_D_WG("WiFi sleep mode %u", enable);
if (enable)
LT_DM(WIFI, "WiFi sleep mode %u", enable);
if (enable) {
if (wifi_enable_powersave() != RTW_SUCCESS)
return false;
else if (wifi_disable_powersave() != RTW_SUCCESS)
} else {
if (wifi_disable_powersave() != RTW_SUCCESS)
return false;
}
data.sleep = enable;
return true;
}

View File

@@ -63,7 +63,7 @@ bool WiFiClass::reconnect(const uint8_t *bssid) {
int ret;
uint8_t dhcpRet;
LT_I("Connecting to %s", wifi.ssid.val);
LT_IM(WIFI, "Connecting to %s", wifi.ssid.val);
__wrap_rtl_printf_disable();
__wrap_DiagPrintf_disable();
@@ -110,11 +110,11 @@ bool WiFiClass::reconnect(const uint8_t *bssid) {
__wrap_DiagPrintf_enable();
return true;
}
LT_E("DHCP failed; dhcpRet=%d", dhcpRet);
LT_EM(WIFI, "DHCP failed; dhcpRet=%d", dhcpRet);
wifi_disconnect();
goto error;
}
LT_E("Connection failed; ret=%d", ret);
LT_EM(WIFI, "Connection failed; ret=%d", ret);
error:
__wrap_rtl_printf_enable();
__wrap_DiagPrintf_enable();

View File

@@ -39,7 +39,7 @@ int16_t WiFiClass::scanNetworks(bool async, bool showHidden, bool passive, uint3
scanDelete();
scanInit();
LT_I("Starting WiFi scan");
LT_IM(WIFI, "Starting WiFi scan");
if (wifi_scan_networks(scanHandler, this) != RTW_SUCCESS)
return WIFI_SCAN_FAILED;
@@ -47,7 +47,7 @@ int16_t WiFiClass::scanNetworks(bool async, bool showHidden, bool passive, uint3
scan->running = true;
if (!async) {
LT_I("Waiting for results");
LT_IM(WIFI, "Waiting for results");
xSemaphoreTake(data.scanSem, 1); // reset the semaphore quickly
xSemaphoreTake(data.scanSem, pdMS_TO_TICKS(maxMsPerChannel * 20));
return scan->count;

View File

@@ -21,4 +21,5 @@
- [WR2LE](../boards/wr2le/README.md)
- [WR3L](../boards/wr3l/README.md)
- [WR3LE](../boards/wr3le/README.md)
- [LSC LMA35](../boards/lsc-lma35/README.md)
- [Generic - Host-native](../boards/generic-native/README.md)

View File

@@ -1,7 +1,13 @@
{
"build": {
"f_cpu": "120000000L",
"prefix": "arm-none-eabi-"
"prefix": "arm-none-eabi-",
"bkota": {
"encryption": "aes256",
"compression": "gzip",
"key": "0123456789ABCDEF0123456789ABCDEF",
"iv": "0123456789ABCDEF"
}
},
"connectivity": [
"wifi",

View File

@@ -0,0 +1,102 @@
{
"pcb": {
"templates": [
"custom-20x24-22",
"rf-20mm-type1"
],
"vars": {
"MASK_PRESET": "mask_blue_light",
"TRACE_COLOR": "#58839B",
"SILK_COLOR": "white",
"PINTYPE_VERT": "pin_vert_2mm_cast_nohole",
"PINTYPE_HORZ": "pin_horz_2mm_cast_nohole"
},
"pinout_hidden": "I2S,JTAG,FLASH,SD,SPI,SDA1",
"pinout": {
"1": {
"PWR": 3.3
},
"2": {
"IC": 15,
"ARD": "D0"
},
"3": {
"IC": 11,
"ARD": "D1"
},
"4": {
"IC": 12,
"ARD": "D2"
},
"5": {
"IC": 16,
"ARD": "D3"
},
"6": {
"GND": null
},
"7": {
"IC": 18,
"ARD": "D4"
},
"8": {
"IC": 29,
"ARD": "D5"
},
"9": {
"IC": 17,
"ARD": [
"D6",
"A0"
]
},
"10": {
"CTRL": "?"
},
"11": {
"GND": null
},
"12": {
"IC": 24,
"ARD": "D7"
},
"13": {
"IC": 25,
"ARD": "D8"
},
"14": {
"GND": null
},
"15": {
"IC": 19,
"ARD": "D9"
},
"16": {
"IC": 22,
"ARD": "D10"
},
"17": {
"IC": 23,
"ARD": "D11"
},
"18": {
"IC": 26,
"ARD": "D12"
},
"19": {
"GND": null
},
"20": {
"IC": 27,
"ARD": "D13"
},
"21": {
"CTRL": "?"
},
"22": {
"IC": 28,
"ARD": "D14"
}
}
}
}

View File

@@ -12,6 +12,7 @@
Parameter | Value
-------------|----------------------------------
Board code | `bw12`
MCU | RTL8710BX
Manufacturer | Realtek
Series | AmebaZ
@@ -22,6 +23,19 @@ Voltage | 3.0V - 3.6V
I/O | 11x GPIO, 6x PWM, 2x UART, 1x ADC
Wi-Fi | 802.11 b/g/n
## Usage
**Board code:** `bw12`
In `platformio.ini`:
```ini
[env:bw12]
platform = libretuya
board = bw12
framework = arduino
```
## Pinout
![Pinout](pinout_bw12.svg)

View File

@@ -9,6 +9,7 @@
Parameter | Value
-------------|--------------------------
Board code | `bw15`
MCU | RTL8720CF
Manufacturer | Realtek
Series | AmebaZ2
@@ -20,6 +21,19 @@ I/O | 13x GPIO, 8x PWM, 3x UART
Wi-Fi | 802.11 b/g/n
BLE | v4.2
## Usage
**Board code:** `bw15`
In `platformio.ini`:
```ini
[env:bw15]
platform = libretuya
board = bw15
framework = arduino
```
## Pinout
![Pinout](pinout_bw15.svg)

View File

@@ -10,6 +10,7 @@
Parameter | Value
-------------|----------------------------------
Board code | `cb2s`
MCU | BK7231N
Manufacturer | Beken
Series | BK72XX
@@ -21,6 +22,19 @@ I/O | 11x GPIO, 5x PWM, 2x UART, 1x ADC
Wi-Fi | 802.11 b/g/n
Bluetooth | BLE v5.1
## Usage
**Board code:** `cb2s`
In `platformio.ini`:
```ini
[env:cb2s]
platform = libretuya
board = cb2s
framework = arduino
```
## Pinout
![Pinout](pinout_cb2s.svg)

View File

@@ -10,6 +10,7 @@
Parameter | Value
-------------|----------------------------------
Board code | `generic-bk7231n-qfn32-tuya`
MCU | BK7231N
Manufacturer | Beken
Series | BK72XX
@@ -21,6 +22,19 @@ I/O | 19x GPIO, 6x PWM, 2x UART, 1x ADC
Wi-Fi | 802.11 b/g/n
Bluetooth | BLE v5.1
## Usage
**Board code:** `generic-bk7231n-qfn32-tuya`
In `platformio.ini`:
```ini
[env:generic-bk7231n-qfn32-tuya]
platform = libretuya
board = generic-bk7231n-qfn32-tuya
framework = arduino
```
## Arduino Core pin mapping
No. | Pin | UART | I²C | SPI | PWM | Other

View File

@@ -10,6 +10,7 @@
Parameter | Value
-------------|----------------------------------
Board code | `generic-bk7231t-qfn32-tuya`
MCU | BK7231T
Manufacturer | Beken
Series | BK72XX
@@ -21,6 +22,19 @@ I/O | 19x GPIO, 6x PWM, 2x UART, 1x ADC
Wi-Fi | 802.11 b/g/n
Bluetooth | BLE v4.2
## Usage
**Board code:** `generic-bk7231t-qfn32-tuya`
In `platformio.ini`:
```ini
[env:generic-bk7231t-qfn32-tuya]
platform = libretuya
board = generic-bk7231t-qfn32-tuya
framework = arduino
```
## Arduino Core pin mapping
No. | Pin | UART | I²C | SPI | PWM | Other

View File

@@ -5,7 +5,8 @@
[Product page](https://kuba2k2.github.io/libretuya/)
Parameter | Value
-------------|-------
-------------|-----------------
Board code | `generic-native`
MCU | NATIVE
Manufacturer | N/A
Series | N/A
@@ -14,6 +15,19 @@ Flash size | 4 MiB
RAM size | 4 MiB
Voltage | 5V
## Usage
**Board code:** `generic-native`
In `platformio.ini`:
```ini
[env:generic-native]
platform = libretuya
board = generic-native
framework = arduino
```
## Flash memory map
Flash size: 4 MiB / 4,194,304 B / 0x400000

View File

@@ -11,6 +11,7 @@
Parameter | Value
-------------|----------------------------------
Board code | `generic-rtl8710bn-2mb-468k`
MCU | RTL8710BN
Manufacturer | Realtek
Series | AmebaZ
@@ -21,6 +22,19 @@ Voltage | 3.0V - 3.6V
I/O | 17x GPIO, 6x PWM, 2x UART, 2x ADC
Wi-Fi | 802.11 b/g/n
## Usage
**Board code:** `generic-rtl8710bn-2mb-468k`
In `platformio.ini`:
```ini
[env:generic-rtl8710bn-2mb-468k]
platform = libretuya
board = generic-rtl8710bn-2mb-468k
framework = arduino
```
## Arduino Core pin mapping
No. | Pin | UART | I²C | SPI | PWM | Other

View File

@@ -11,6 +11,7 @@
Parameter | Value
-------------|----------------------------------
Board code | `generic-rtl8710bn-2mb-788k`
MCU | RTL8710BN
Manufacturer | Realtek
Series | AmebaZ
@@ -21,6 +22,19 @@ Voltage | 3.0V - 3.6V
I/O | 17x GPIO, 6x PWM, 2x UART, 2x ADC
Wi-Fi | 802.11 b/g/n
## Usage
**Board code:** `generic-rtl8710bn-2mb-788k`
In `platformio.ini`:
```ini
[env:generic-rtl8710bn-2mb-788k]
platform = libretuya
board = generic-rtl8710bn-2mb-788k
framework = arduino
```
## Arduino Core pin mapping
No. | Pin | UART | I²C | SPI | PWM | Other

View File

@@ -7,7 +7,8 @@
- [General info](../../docs/platform/realtek/README.md)
Parameter | Value
-------------|--------------------------
-------------|-----------------------------
Board code | `generic-rtl8720cf-2mb-992k`
MCU | RTL8720CF
Manufacturer | Realtek
Series | AmebaZ2
@@ -19,6 +20,19 @@ I/O | 20x GPIO, 8x PWM, 3x UART
Wi-Fi | 802.11 b/g/n
BLE | v4.2
## Usage
**Board code:** `generic-rtl8720cf-2mb-992k`
In `platformio.ini`:
```ini
[env:generic-rtl8720cf-2mb-992k]
platform = libretuya
board = generic-rtl8720cf-2mb-992k
framework = arduino
```
## Flash memory map
Flash size: 2 MiB / 2,097,152 B / 0x200000

29
boards/lsc-lma35.json Normal file
View File

@@ -0,0 +1,29 @@
{
"_base": [
"beken-72xx",
"beken-7231n",
"beken-7231n-tuya",
"pcb/ic-bk7231-qfn32",
"pcb/lsc-lma35"
],
"build": {
"mcu": "bk7231n",
"variant": "lsc-lma35"
},
"name": "LSC LMA35",
"symbol": "LSC LMA35",
"url": "https://www.action.com/de-at/p/lsc-smart-connect-outdoor-led-streifen/",
"vendor": "Unknown",
"pcb": {
"symbol": "LMA35"
},
"doc": {
"extra": [
"## Information",
"This board has no marking on the front side, only something that looks like PCB manufacturing info on the back; thus it was named based on these symbols.",
"It can be found in 'LSC Smart Connect Outdoor LED Strip', and is likely custom-made for this product.",
"The pinout was established by writing to and probing consecutive GPIOs, using the generic board definition.",
"Pins marked with '?' are currently unknown, with a possibility of being CEN. Pin 22 (P1/D14) is also not confirmed."
]
}
}

View File

@@ -0,0 +1,89 @@
# LSC LMA35
*by Unknown*
[Product page](https://www.action.com/de-at/p/lsc-smart-connect-outdoor-led-streifen/)
- [General info](../../docs/platform/beken-72xx/README.md)
- [Flashing guide](../../docs/platform/beken-72xx/flashing.md)
- [BkWriter v1.6.0](https://images.tuyacn.com/smart/bk_writer1.60/bk_writer1.60.exe)
Parameter | Value
-------------|----------------------------------
Board code | `lsc-lma35`
MCU | BK7231N
Manufacturer | Beken
Series | BK72XX
Frequency | 120 MHz
Flash size | 2 MiB
RAM size | 256 KiB
Voltage | 3.0V - 3.6V
I/O | 15x GPIO, 6x PWM, 2x UART, 1x ADC
Wi-Fi | 802.11 b/g/n
Bluetooth | BLE v5.1
## Usage
**Board code:** `lsc-lma35`
In `platformio.ini`:
```ini
[env:lsc-lma35]
platform = libretuya
board = lsc-lma35
framework = arduino
```
## Pinout
![Pinout](pinout_lsc-lma35.svg)
## Arduino Core pin mapping
No. | Pin | UART | I²C | SPI | PWM | Other
----|-----------|----------|----------|------|------|------
D0 | P26 | | | | PWM5 |
D1 | P14 | | | SCK | |
D2 | P16 | | | MOSI | |
D3 | P24 | | | | PWM4 |
D4 | P22 | | | | | TDI
D5 | P0 | UART2_TX | I2C2_SCL | | |
D6 | P23 | | | | | TDO
D7 | P8 | | | | PWM2 |
D8 | P9 | | | | PWM3 |
D9 | P21 | | I2C1_SDA | | | TMS
D10 | P6 | | | | PWM0 |
D11 | P7 | | | | PWM1 |
D12 | P10 | UART1_RX | | | |
D13 | P11 | UART1_TX | | | |
D14 | P1 | UART2_RX | I2C2_SDA | | |
A0 | P23, ADC3 | | | | |
## Flash memory map
Flash size: 2 MiB / 2,097,152 B / 0x200000
Hex values are in bytes.
Name | Start | Length | End
----------------|----------|--------------------|---------
Bootloader | 0x000000 | 68 KiB / 0x11000 | 0x011000
App Image | 0x011000 | 1.1 MiB / 0x119000 | 0x12A000
OTA Image | 0x12A000 | 664 KiB / 0xA6000 | 0x1D0000
TLV Store | 0x1D0000 | 4 KiB / 0x1000 | 0x1D1000
Network Data | 0x1D1000 | 8 KiB / 0x2000 | 0x1D3000
Key-Value Store | 0x1D3000 | 32 KiB / 0x8000 | 0x1DB000
User Data | 0x1DB000 | 148 KiB / 0x25000 | 0x200000
Bootloader and app partitions contain CRC16 sums every 32 bytes. That results in the actual flash offsets/sizes not aligned to sector boundaries. To simplify calculations, the values shown in the table (extracted from bootloader's partition table) were aligned to 4096 bytes.
## Information
This board has no marking on the front side, only something that looks like PCB manufacturing info on the back; thus it was named based on these symbols.
It can be found in 'LSC Smart Connect Outdoor LED Strip', and is likely custom-made for this product.
The pinout was established by writing to and probing consecutive GPIOs, using the generic board definition.
Pins marked with '?' are currently unknown, with a possibility of being CEN. Pin 22 (P1/D14) is also not confirmed.

View File

@@ -0,0 +1,325 @@
<?xml version="1.0" encoding="utf-8" ?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xlink="http://www.w3.org/1999/xlink" baseProfile="full" height="500" version="1.1" viewBox="0,0,85.33333333333333,41.666666666666664" width="1024">
<defs/>
<rect fill="white" height="41.666666666666664" stroke="black" stroke-width="0.1" width="85.33333333333333" x="0" y="0"/>
<linearGradient gradientUnits="objectBoundingBox" id="id1" x1="1.0" x2="0.0" y1="0.0" y2="1.0">
<stop offset="0%" stop-color="#47a8cd"/>
<stop offset="100%" stop-color="#008fb5"/>
</linearGradient>
<rect fill="url(#id1) none" height="23.9" stroke="#b5a739" stroke-width="0.1" width="19.9" x="32.66666666666666" y="4.433333333333333"/>
<rect fill="#e5b472" height="1.2" id="custom-20x24-22.front.left.pin1.trace" width="0.7" x="32.61666666666666" y="12.133333333333333"/>
<circle cx="32.61666666666666" cy="12.733333333333333" fill="#fff" id="custom-20x24-22.front.left.pin1.cast" r="0.35"/>
<rect fill="#e5b472" height="1.2" id="custom-20x24-22.front.left.pin2.trace" width="0.7" x="32.61666666666666" y="14.133333333333333"/>
<circle cx="32.61666666666666" cy="14.733333333333333" fill="#fff" id="custom-20x24-22.front.left.pin2.cast" r="0.35"/>
<rect fill="#e5b472" height="1.2" id="custom-20x24-22.front.left.pin3.trace" width="0.7" x="32.61666666666666" y="16.133333333333333"/>
<circle cx="32.61666666666666" cy="16.733333333333334" fill="#fff" id="custom-20x24-22.front.left.pin3.cast" r="0.35"/>
<rect fill="#e5b472" height="1.2" id="custom-20x24-22.front.left.pin4.trace" width="0.7" x="32.61666666666666" y="18.133333333333333"/>
<circle cx="32.61666666666666" cy="18.733333333333334" fill="#fff" id="custom-20x24-22.front.left.pin4.cast" r="0.35"/>
<rect fill="#e5b472" height="1.2" id="custom-20x24-22.front.left.pin5.trace" width="0.7" x="32.61666666666666" y="20.133333333333333"/>
<circle cx="32.61666666666666" cy="20.733333333333334" fill="#fff" id="custom-20x24-22.front.left.pin5.cast" r="0.35"/>
<rect fill="#e5b472" height="1.2" id="custom-20x24-22.front.left.pin6.trace" width="0.7" x="32.61666666666666" y="22.133333333333333"/>
<circle cx="32.61666666666666" cy="22.733333333333334" fill="#fff" id="custom-20x24-22.front.left.pin6.cast" r="0.35"/>
<rect fill="#e5b472" height="1.2" id="custom-20x24-22.front.left.pin7.trace" width="0.7" x="32.61666666666666" y="24.133333333333333"/>
<circle cx="32.61666666666666" cy="24.733333333333334" fill="#fff" id="custom-20x24-22.front.left.pin7.cast" r="0.35"/>
<rect fill="#e5b472" height="1.2" id="custom-20x24-22.front.right.pin1.trace" width="0.7" x="51.91666666666666" y="12.133333333333333"/>
<circle cx="52.61666666666666" cy="12.733333333333333" fill="#fff" id="custom-20x24-22.front.right.pin1.cast" r="0.35"/>
<rect fill="#e5b472" height="1.2" id="custom-20x24-22.front.right.pin2.trace" width="0.7" x="51.91666666666666" y="14.133333333333333"/>
<circle cx="52.61666666666666" cy="14.733333333333333" fill="#fff" id="custom-20x24-22.front.right.pin2.cast" r="0.35"/>
<rect fill="#e5b472" height="1.2" id="custom-20x24-22.front.right.pin3.trace" width="0.7" x="51.91666666666666" y="16.133333333333333"/>
<circle cx="52.61666666666666" cy="16.733333333333334" fill="#fff" id="custom-20x24-22.front.right.pin3.cast" r="0.35"/>
<rect fill="#e5b472" height="1.2" id="custom-20x24-22.front.right.pin4.trace" width="0.7" x="51.91666666666666" y="18.133333333333333"/>
<circle cx="52.61666666666666" cy="18.733333333333334" fill="#fff" id="custom-20x24-22.front.right.pin4.cast" r="0.35"/>
<rect fill="#e5b472" height="1.2" id="custom-20x24-22.front.right.pin5.trace" width="0.7" x="51.91666666666666" y="20.133333333333333"/>
<circle cx="52.61666666666666" cy="20.733333333333334" fill="#fff" id="custom-20x24-22.front.right.pin5.cast" r="0.35"/>
<rect fill="#e5b472" height="1.2" id="custom-20x24-22.front.right.pin6.trace" width="0.7" x="51.91666666666666" y="22.133333333333333"/>
<circle cx="52.61666666666666" cy="22.733333333333334" fill="#fff" id="custom-20x24-22.front.right.pin6.cast" r="0.35"/>
<rect fill="#e5b472" height="1.2" id="custom-20x24-22.front.right.pin7.trace" width="0.7" x="51.91666666666666" y="24.133333333333333"/>
<circle cx="52.61666666666666" cy="24.733333333333334" fill="#fff" id="custom-20x24-22.front.right.pin7.cast" r="0.35"/>
<rect fill="#e5b472" height="0.7" id="pins_horz8_2mm_0.7mm.pin1.trace" width="1.2" x="35.06666666666666" y="27.683333333333334"/>
<circle cx="35.66666666666666" cy="28.383333333333333" fill="#fff" id="pins_horz8_2mm_0.7mm.pin1.cast" r="0.35"/>
<rect fill="#e5b472" height="0.7" id="pins_horz8_2mm_0.7mm.pin2.trace" width="1.2" x="37.06666666666666" y="27.683333333333334"/>
<circle cx="37.66666666666666" cy="28.383333333333333" fill="#fff" id="pins_horz8_2mm_0.7mm.pin2.cast" r="0.35"/>
<rect fill="#e5b472" height="0.7" id="pins_horz8_2mm_0.7mm.pin3.trace" width="1.2" x="39.06666666666666" y="27.683333333333334"/>
<circle cx="39.66666666666666" cy="28.383333333333333" fill="#fff" id="pins_horz8_2mm_0.7mm.pin3.cast" r="0.35"/>
<rect fill="#e5b472" height="0.7" id="pins_horz8_2mm_0.7mm.pin4.trace" width="1.2" x="41.06666666666666" y="27.683333333333334"/>
<circle cx="41.66666666666666" cy="28.383333333333333" fill="#fff" id="pins_horz8_2mm_0.7mm.pin4.cast" r="0.35"/>
<rect fill="#e5b472" height="0.7" id="pins_horz8_2mm_0.7mm.pin5.trace" width="1.2" x="43.06666666666666" y="27.683333333333334"/>
<circle cx="43.66666666666666" cy="28.383333333333333" fill="#fff" id="pins_horz8_2mm_0.7mm.pin5.cast" r="0.35"/>
<rect fill="#e5b472" height="0.7" id="pins_horz8_2mm_0.7mm.pin6.trace" width="1.2" x="45.06666666666666" y="27.683333333333334"/>
<circle cx="45.66666666666666" cy="28.383333333333333" fill="#fff" id="pins_horz8_2mm_0.7mm.pin6.cast" r="0.35"/>
<rect fill="#e5b472" height="0.7" id="pins_horz8_2mm_0.7mm.pin7.trace" width="1.2" x="47.06666666666666" y="27.683333333333334"/>
<circle cx="47.66666666666666" cy="28.383333333333333" fill="#fff" id="pins_horz8_2mm_0.7mm.pin7.cast" r="0.35"/>
<rect fill="#e5b472" height="0.7" id="pins_horz8_2mm_0.7mm.pin8.trace" width="1.2" x="49.06666666666666" y="27.683333333333334"/>
<circle cx="49.66666666666666" cy="28.383333333333333" fill="#fff" id="pins_horz8_2mm_0.7mm.pin8.cast" r="0.35"/>
<rect fill="#4e4c4c" height="2.0" width="0.2" x="35.56666666666666" y="28.583333333333332"/>
<rect fill="#4e4c4c" height="0.2" width="0.2" x="35.36666666666666" y="30.383333333333333"/>
<rect height="0.0" id="custom-20x24-22.front.down.label1.anchor" width="0.0" x="35.86666666666666" y="30.483333333333334"/>
<rect fill="#4e4c4c" height="4.0" width="0.2" x="37.56666666666666" y="28.583333333333332"/>
<rect fill="#4e4c4c" height="0.2" width="2.2" x="35.36666666666666" y="32.38333333333333"/>
<rect height="0.0" id="custom-20x24-22.front.down.label2.anchor" width="0.0" x="35.86666666666666" y="32.483333333333334"/>
<rect fill="#4e4c4c" height="6.0" width="0.2" x="39.56666666666666" y="28.583333333333332"/>
<rect fill="#4e4c4c" height="0.2" width="4.2" x="35.36666666666666" y="34.38333333333333"/>
<rect height="0.0" id="custom-20x24-22.front.down.label3.anchor" width="0.0" x="35.86666666666666" y="34.483333333333334"/>
<rect fill="#4e4c4c" height="8.0" width="0.2" x="41.56666666666666" y="28.583333333333332"/>
<rect fill="#4e4c4c" height="0.2" width="6.2" x="35.36666666666666" y="36.38333333333333"/>
<rect height="0.0" id="custom-20x24-22.front.down.label4.anchor" width="0.0" x="35.86666666666666" y="36.483333333333334"/>
<rect fill="#4e4c4c" height="8.0" width="0.2" x="43.56666666666666" y="28.583333333333332"/>
<rect fill="#4e4c4c" height="0.2" width="6.2" x="43.66666666666666" y="36.38333333333333"/>
<rect height="0.0" id="custom-20x24-22.front.down.label5.anchor" width="0.0" x="49.36666666666666" y="36.483333333333334"/>
<rect fill="#4e4c4c" height="6.0" width="0.2" x="45.56666666666666" y="28.583333333333332"/>
<rect fill="#4e4c4c" height="0.2" width="4.2" x="45.66666666666666" y="34.38333333333333"/>
<rect height="0.0" id="custom-20x24-22.front.down.label6.anchor" width="0.0" x="49.36666666666666" y="34.483333333333334"/>
<rect fill="#4e4c4c" height="4.0" width="0.2" x="47.56666666666666" y="28.583333333333332"/>
<rect fill="#4e4c4c" height="0.2" width="2.2" x="47.66666666666666" y="32.38333333333333"/>
<rect height="0.0" id="custom-20x24-22.front.down.label7.anchor" width="0.0" x="49.36666666666666" y="32.483333333333334"/>
<rect fill="#4e4c4c" height="2.0" width="0.2" x="49.56666666666666" y="28.583333333333332"/>
<rect fill="#4e4c4c" height="0.2" width="0.2" x="49.66666666666666" y="30.383333333333333"/>
<rect height="0.0" id="custom-20x24-22.front.down.label8.anchor" width="0.0" x="49.36666666666666" y="30.483333333333334"/>
<linearGradient gradientUnits="objectBoundingBox" id="id2" x1="1.0" x2="0.0" y1="0.0" y2="1.0">
<stop offset="0%" stop-color="whitesmoke"/>
<stop offset="100%" stop-color="#999"/>
</linearGradient>
<rect fill="url(#id2) none" height="15.8" rx="0.5" ry="0.5" width="17.6" x="33.81666666666666" y="11.333333333333332"/>
<rect fill="#58839b" height="5.2" width="0.5" x="35.71666666666666" y="5.183333333333333"/>
<rect fill="#58839b" height="0.5" width="4.6" x="35.71666666666666" y="5.183333333333333"/>
<rect fill="#58839b" height="5.2" width="0.5" x="37.91666666666666" y="5.183333333333333"/>
<rect fill="#58839b" height="3.0" width="0.5" x="39.81666666666666" y="5.183333333333333"/>
<rect fill="#58839b" height="0.5" width="3.0" x="39.81666666666666" y="7.683333333333333"/>
<rect fill="#58839b" height="3.0" width="0.5" x="42.31666666666666" y="5.183333333333333"/>
<rect fill="#58839b" height="0.5" width="2.7" x="42.31666666666666" y="5.183333333333333"/>
<rect fill="#58839b" height="3.0" width="0.5" x="44.51666666666666" y="5.183333333333333"/>
<rect fill="#58839b" height="0.5" width="3.0" x="44.51666666666666" y="7.683333333333333"/>
<rect fill="#58839b" height="3.0" width="0.5" x="47.01666666666666" y="5.183333333333333"/>
<rect fill="#58839b" height="0.5" width="2.5" x="47.01666666666666" y="5.183333333333333"/>
<rect fill="#58839b" height="4.4" width="0.5" x="49.01666666666666" y="5.183333333333333"/>
<rect fill="#4e4c4c" height="0.2" width="2.6" x="29.51666666666666" y="12.633333333333333"/>
<g transform="translate(25.731026020611555,11.933333333333332)">
<rect fill="#cd3c24" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="3.4" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="white" font-family="Consolas" font-size="1.2" text-anchor="middle" x="27.216666666666658" y="12.733333333333333">3V3</text>
<rect fill="#4e4c4c" height="0.2" width="2.6" x="29.51666666666666" y="14.633333333333333"/>
<g transform="translate(25.731026020611555,13.933333333333332)">
<rect fill="#800000" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="3.4" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="white" font-family="Consolas" font-size="1.2" text-anchor="middle" x="27.216666666666658" y="14.733333333333333">P26</text>
<g transform="translate(22.73102602061156,13.933333333333332)">
<rect fill="#99188d" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="2.8" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="white" font-family="Consolas" font-size="1.2" text-anchor="middle" x="23.91666666666666" y="14.733333333333333">D0</text>
<g transform="translate(19.131026020611557,13.933333333333332)">
<rect fill="#aeafc1" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="3.4" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="#423F42" font-family="Consolas" font-size="1.2" text-anchor="middle" x="20.61666666666666" y="14.733333333333333">IRDA</text>
<g transform="translate(15.531026020611561,13.933333333333332)">
<rect fill="#afa35e" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="3.4" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="#423F42" font-family="Consolas" font-size="1.2" text-anchor="middle" x="17.016666666666662" y="14.733333333333333">PWM5</text>
<rect fill="#4e4c4c" height="0.2" width="2.6" x="29.51666666666666" y="16.633333333333333"/>
<g transform="translate(25.731026020611555,15.933333333333334)">
<rect fill="#800000" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="3.4" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="white" font-family="Consolas" font-size="1.2" text-anchor="middle" x="27.216666666666658" y="16.733333333333334">P14</text>
<g transform="translate(22.73102602061156,15.933333333333334)">
<rect fill="#99188d" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="2.8" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="white" font-family="Consolas" font-size="1.2" text-anchor="middle" x="23.91666666666666" y="16.733333333333334">D1</text>
<rect fill="#4e4c4c" height="0.2" width="2.6" x="29.51666666666666" y="18.633333333333333"/>
<g transform="translate(25.731026020611555,17.933333333333334)">
<rect fill="#800000" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="3.4" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="white" font-family="Consolas" font-size="1.2" text-anchor="middle" x="27.216666666666658" y="18.733333333333334">P16</text>
<g transform="translate(22.73102602061156,17.933333333333334)">
<rect fill="#99188d" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="2.8" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="white" font-family="Consolas" font-size="1.2" text-anchor="middle" x="23.91666666666666" y="18.733333333333334">D2</text>
<rect fill="#4e4c4c" height="0.2" width="2.6" x="29.51666666666666" y="20.633333333333333"/>
<g transform="translate(25.731026020611555,19.933333333333334)">
<rect fill="#800000" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="3.4" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="white" font-family="Consolas" font-size="1.2" text-anchor="middle" x="27.216666666666658" y="20.733333333333334">P24</text>
<g transform="translate(22.73102602061156,19.933333333333334)">
<rect fill="#99188d" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="2.8" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="white" font-family="Consolas" font-size="1.2" text-anchor="middle" x="23.91666666666666" y="20.733333333333334">D3</text>
<g transform="translate(19.131026020611557,19.933333333333334)">
<rect fill="#afa35e" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="3.4" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="#423F42" font-family="Consolas" font-size="1.2" text-anchor="middle" x="20.61666666666666" y="20.733333333333334">PWM4</text>
<rect fill="#4e4c4c" height="0.2" width="2.6" x="29.51666666666666" y="22.633333333333333"/>
<g transform="translate(25.731026020611555,21.933333333333334)">
<rect fill="#000" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="3.4" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="white" font-family="Consolas" font-size="1.2" text-anchor="middle" x="27.216666666666658" y="22.733333333333334">GND</text>
<rect fill="#4e4c4c" height="0.2" width="2.6" x="29.51666666666666" y="24.633333333333333"/>
<g transform="translate(25.731026020611555,23.933333333333334)">
<rect fill="#800000" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="3.4" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="white" font-family="Consolas" font-size="1.2" text-anchor="middle" x="27.216666666666658" y="24.733333333333334">P22</text>
<g transform="translate(22.73102602061156,23.933333333333334)">
<rect fill="#99188d" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="2.8" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="white" font-family="Consolas" font-size="1.2" text-anchor="middle" x="23.91666666666666" y="24.733333333333334">D4</text>
<rect fill="#4e4c4c" height="0.2" width="2.6" x="53.11666666666666" y="24.633333333333333"/>
<g transform="translate(56.53102602061156,23.933333333333334)">
<rect fill="#800000" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="3.4" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="white" font-family="Consolas" font-size="1.2" text-anchor="middle" x="58.016666666666666" y="24.733333333333334">P0</text>
<g transform="translate(60.131026020611564,23.933333333333334)">
<rect fill="#99188d" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="2.8" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="white" font-family="Consolas" font-size="1.2" text-anchor="middle" x="61.31666666666666" y="24.733333333333334">D5</text>
<g transform="translate(63.131026020611564,23.933333333333334)">
<rect fill="#dcd4ee" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="3.4" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="#423F42" font-family="Consolas" font-size="1.2" text-anchor="middle" x="64.61666666666666" y="24.733333333333334">TX2</text>
<g transform="translate(66.73102602061155,23.933333333333334)">
<rect fill="#f95" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="3.4" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="#423F42" font-family="Consolas" font-size="1.2" text-anchor="middle" x="68.21666666666665" y="24.733333333333334">SCL2</text>
<rect fill="#4e4c4c" height="0.2" width="2.6" x="53.11666666666666" y="22.633333333333333"/>
<g transform="translate(56.53102602061156,21.933333333333334)">
<rect fill="#800000" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="3.4" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="white" font-family="Consolas" font-size="1.2" text-anchor="middle" x="58.016666666666666" y="22.733333333333334">P23</text>
<g transform="translate(60.131026020611564,21.933333333333334)">
<rect fill="#8ad039" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="3.4" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="#423F42" font-family="Consolas" font-size="1.2" text-anchor="middle" x="61.61666666666667" y="22.733333333333334">ADC3</text>
<g transform="translate(63.731026020611566,21.933333333333334)">
<rect fill="#99188d" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="2.8" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="white" font-family="Consolas" font-size="1.2" text-anchor="middle" x="64.91666666666667" y="22.733333333333334">D6</text>
<g transform="translate(66.73102602061155,21.933333333333334)">
<rect fill="#16a352" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="2.8" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="white" font-family="Consolas" font-size="1.2" text-anchor="middle" x="67.91666666666666" y="22.733333333333334">A0</text>
<rect fill="#4e4c4c" height="0.2" width="2.6" x="53.11666666666666" y="20.633333333333333"/>
<g transform="translate(56.53102602061156,19.933333333333334)">
<rect fill="#ed602e" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="3.4" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="#423F42" font-family="Consolas" font-size="1.2" text-anchor="middle" x="58.016666666666666" y="20.733333333333334">?</text>
<rect fill="#4e4c4c" height="0.2" width="2.6" x="53.11666666666666" y="18.633333333333333"/>
<g transform="translate(56.53102602061156,17.933333333333334)">
<rect fill="#000" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="3.4" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="white" font-family="Consolas" font-size="1.2" text-anchor="middle" x="58.016666666666666" y="18.733333333333334">GND</text>
<rect fill="#4e4c4c" height="0.2" width="2.6" x="53.11666666666666" y="16.633333333333333"/>
<g transform="translate(56.53102602061156,15.933333333333334)">
<rect fill="#800000" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="3.4" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="white" font-family="Consolas" font-size="1.2" text-anchor="middle" x="58.016666666666666" y="16.733333333333334">P8</text>
<g transform="translate(60.131026020611564,15.933333333333334)">
<rect fill="#99188d" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="2.8" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="white" font-family="Consolas" font-size="1.2" text-anchor="middle" x="61.31666666666666" y="16.733333333333334">D7</text>
<g transform="translate(63.131026020611564,15.933333333333334)">
<rect fill="#afa35e" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="3.4" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="#423F42" font-family="Consolas" font-size="1.2" text-anchor="middle" x="64.61666666666666" y="16.733333333333334">PWM2</text>
<rect fill="#4e4c4c" height="0.2" width="2.6" x="53.11666666666666" y="14.633333333333333"/>
<g transform="translate(56.53102602061156,13.933333333333332)">
<rect fill="#800000" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="3.4" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="white" font-family="Consolas" font-size="1.2" text-anchor="middle" x="58.016666666666666" y="14.733333333333333">P9</text>
<g transform="translate(60.131026020611564,13.933333333333332)">
<rect fill="#99188d" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="2.8" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="white" font-family="Consolas" font-size="1.2" text-anchor="middle" x="61.31666666666666" y="14.733333333333333">D8</text>
<g transform="translate(63.131026020611564,13.933333333333332)">
<rect fill="#afa35e" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="3.4" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="#423F42" font-family="Consolas" font-size="1.2" text-anchor="middle" x="64.61666666666666" y="14.733333333333333">PWM3</text>
<rect fill="#4e4c4c" height="0.2" width="2.6" x="53.11666666666666" y="12.633333333333333"/>
<g transform="translate(56.53102602061156,11.933333333333332)">
<rect fill="#000" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="3.4" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="white" font-family="Consolas" font-size="1.2" text-anchor="middle" x="58.016666666666666" y="12.733333333333333">GND</text>
<rect fill="#4e4c4c" height="0.2" width="2.6" x="32.76666666666666" y="30.383333333333333"/>
<g transform="translate(28.981026020611555,29.683333333333334)">
<rect fill="#800000" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="3.4" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="white" font-family="Consolas" font-size="1.2" text-anchor="middle" x="30.466666666666658" y="30.483333333333334">P21</text>
<g transform="translate(25.98102602061156,29.683333333333334)">
<rect fill="#99188d" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="2.8" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="white" font-family="Consolas" font-size="1.2" text-anchor="middle" x="27.16666666666666" y="30.483333333333334">D9</text>
<rect fill="#4e4c4c" height="0.2" width="2.6" x="32.76666666666666" y="32.38333333333333"/>
<g transform="translate(28.981026020611555,31.683333333333334)">
<rect fill="#800000" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="3.4" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="white" font-family="Consolas" font-size="1.2" text-anchor="middle" x="30.466666666666658" y="32.483333333333334">P6</text>
<g transform="translate(25.98102602061156,31.683333333333334)">
<rect fill="#99188d" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="2.8" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="white" font-family="Consolas" font-size="1.2" text-anchor="middle" x="27.16666666666666" y="32.483333333333334">D10</text>
<g transform="translate(22.381026020611557,31.683333333333334)">
<rect fill="#afa35e" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="3.4" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="#423F42" font-family="Consolas" font-size="1.2" text-anchor="middle" x="23.86666666666666" y="32.483333333333334">PWM0</text>
<rect fill="#4e4c4c" height="0.2" width="2.6" x="32.76666666666666" y="34.38333333333333"/>
<g transform="translate(28.981026020611555,33.68333333333334)">
<rect fill="#800000" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="3.4" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="white" font-family="Consolas" font-size="1.2" text-anchor="middle" x="30.466666666666658" y="34.483333333333334">P7</text>
<g transform="translate(25.98102602061156,33.68333333333334)">
<rect fill="#99188d" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="2.8" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="white" font-family="Consolas" font-size="1.2" text-anchor="middle" x="27.16666666666666" y="34.483333333333334">D11</text>
<g transform="translate(22.381026020611557,33.68333333333334)">
<rect fill="#afa35e" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="3.4" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="#423F42" font-family="Consolas" font-size="1.2" text-anchor="middle" x="23.86666666666666" y="34.483333333333334">PWM1</text>
<rect fill="#4e4c4c" height="0.2" width="2.6" x="32.76666666666666" y="36.38333333333333"/>
<g transform="translate(28.981026020611555,35.68333333333334)">
<rect fill="#800000" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="3.4" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="white" font-family="Consolas" font-size="1.2" text-anchor="middle" x="30.466666666666658" y="36.483333333333334">P10</text>
<g transform="translate(25.98102602061156,35.68333333333334)">
<rect fill="#99188d" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="2.8" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="white" font-family="Consolas" font-size="1.2" text-anchor="middle" x="27.16666666666666" y="36.483333333333334">D12</text>
<g transform="translate(22.381026020611557,35.68333333333334)">
<rect fill="#dcd4ee" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="3.4" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="#423F42" font-family="Consolas" font-size="1.2" text-anchor="middle" x="23.86666666666666" y="36.483333333333334">RX1</text>
<rect fill="#4e4c4c" height="0.2" width="2.6" x="49.86666666666666" y="36.38333333333333"/>
<g transform="translate(53.28102602061156,35.68333333333334)">
<rect fill="#000" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="3.4" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="white" font-family="Consolas" font-size="1.2" text-anchor="middle" x="54.766666666666666" y="36.483333333333334">GND</text>
<rect fill="#4e4c4c" height="0.2" width="2.6" x="49.86666666666666" y="34.38333333333333"/>
<g transform="translate(53.28102602061156,33.68333333333334)">
<rect fill="#800000" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="3.4" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="white" font-family="Consolas" font-size="1.2" text-anchor="middle" x="54.766666666666666" y="34.483333333333334">P11</text>
<g transform="translate(56.881026020611564,33.68333333333334)">
<rect fill="#99188d" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="2.8" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="white" font-family="Consolas" font-size="1.2" text-anchor="middle" x="58.06666666666666" y="34.483333333333334">D13</text>
<g transform="translate(59.881026020611564,33.68333333333334)">
<rect fill="#dcd4ee" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="3.4" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="#423F42" font-family="Consolas" font-size="1.2" text-anchor="middle" x="61.36666666666667" y="34.483333333333334">TX1</text>
<rect fill="#4e4c4c" height="0.2" width="2.6" x="49.86666666666666" y="32.38333333333333"/>
<g transform="translate(53.28102602061156,31.683333333333334)">
<rect fill="#ed602e" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="3.4" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="#423F42" font-family="Consolas" font-size="1.2" text-anchor="middle" x="54.766666666666666" y="32.483333333333334">?</text>
<rect fill="#4e4c4c" height="0.2" width="2.6" x="49.86666666666666" y="30.383333333333333"/>
<g transform="translate(53.28102602061156,29.683333333333334)">
<rect fill="#800000" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="3.4" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="white" font-family="Consolas" font-size="1.2" text-anchor="middle" x="54.766666666666666" y="30.483333333333334">P1</text>
<g transform="translate(56.881026020611564,29.683333333333334)">
<rect fill="#99188d" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="2.8" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="white" font-family="Consolas" font-size="1.2" text-anchor="middle" x="58.06666666666666" y="30.483333333333334">D14</text>
<g transform="translate(59.881026020611564,29.683333333333334)">
<rect fill="#dcd4ee" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="3.4" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="#423F42" font-family="Consolas" font-size="1.2" text-anchor="middle" x="61.36666666666667" y="30.483333333333334">RX2</text>
<g transform="translate(63.481026020611566,29.683333333333334)">
<rect fill="#f95" height="1.6" rx="0.3" ry="0.3" transform="skewX(-15)" width="3.4" x="0" y="0"/>
</g>
<text dominant-baseline="central" fill="#423F42" font-family="Consolas" font-size="1.2" text-anchor="middle" x="64.96666666666667" y="30.483333333333334">SDA2</text>
</svg>

After

Width:  |  Height:  |  Size: 30 KiB

View File

@@ -0,0 +1 @@
#include "variant.h"

View File

@@ -0,0 +1,42 @@
/* This file was auto-generated from lsc-lma35.json using boardgen */
#include <Arduino.h>
extern "C" {
// clang-format off
PinInfo pinTable[PINS_COUNT] = {
// D0: P26, PWM5, IRDA
{GPIO26, PIN_GPIO | PIN_IRQ | PIN_PWM, PIN_NONE, 0},
// D1: P14, SD_CLK, SCK
{GPIO14, PIN_GPIO | PIN_IRQ | PIN_SPI, PIN_NONE, 0},
// D2: P16, SD_D0, MOSI
{GPIO16, PIN_GPIO | PIN_IRQ | PIN_SPI, PIN_NONE, 0},
// D3: P24, PWM4
{GPIO24, PIN_GPIO | PIN_IRQ | PIN_PWM, PIN_NONE, 0},
// D4: P22, TDI, FSI
{GPIO22, PIN_GPIO | PIN_IRQ | PIN_JTAG, PIN_NONE, 0},
// D5: P0, UART2_TX, I2C2_SCL
{GPIO0, PIN_GPIO | PIN_IRQ | PIN_I2C | PIN_UART, PIN_NONE, 0},
// D6: P23, ADC3, TDO, FSO
{GPIO23, PIN_GPIO | PIN_IRQ | PIN_ADC | PIN_JTAG, PIN_NONE, 0},
// D7: P8, PWM2
{GPIO8, PIN_GPIO | PIN_IRQ | PIN_PWM, PIN_NONE, 0},
// D8: P9, PWM3
{GPIO9, PIN_GPIO | PIN_IRQ | PIN_PWM, PIN_NONE, 0},
// D9: P21, I2C1_SDA, TMS, MCLK, ^FCS
{GPIO21, PIN_GPIO | PIN_IRQ | PIN_I2C | PIN_I2S | PIN_JTAG, PIN_NONE, 0},
// D10: P6, PWM0
{GPIO6, PIN_GPIO | PIN_IRQ | PIN_PWM, PIN_NONE, 0},
// D11: P7, PWM1
{GPIO7, PIN_GPIO | PIN_IRQ | PIN_PWM, PIN_NONE, 0},
// D12: P10, UART1_RX
{GPIO10, PIN_GPIO | PIN_IRQ | PIN_UART, PIN_NONE, 0},
// D13: P11, UART1_TX
{GPIO11, PIN_GPIO | PIN_IRQ | PIN_UART, PIN_NONE, 0},
// D14: P1, UART2_RX, I2C2_SDA
{GPIO1, PIN_GPIO | PIN_IRQ | PIN_I2C | PIN_UART, PIN_NONE, 0},
};
// clang-format on
} // extern "C"

View File

@@ -0,0 +1,37 @@
/* This file was auto-generated from lsc-lma35.json using boardgen */
#pragma once
#include <WVariant.h>
// clang-format off
// Pins
// ----
#define PINS_COUNT 15
#define NUM_DIGITAL_PINS 15
#define NUM_ANALOG_INPUTS 1
#define NUM_ANALOG_OUTPUTS 0
// Analog pins
// -----------
#define PIN_A0 6u // GPIO23
#define A0 PIN_A0
// SPI Interfaces
// --------------
#define SPI_INTERFACES_COUNT 0
// Wire Interfaces
// ---------------
#define WIRE_INTERFACES_COUNT 1
#define PIN_WIRE2_SCL 5u // GPIO0
#define PIN_WIRE2_SDA 14u // GPIO1
// Serial ports
// ------------
#define SERIAL_INTERFACES_COUNT 2
#define PIN_SERIAL1_RX 12u // GPIO10
#define PIN_SERIAL1_TX 13u // GPIO11
#define PIN_SERIAL2_RX 14u // GPIO1
#define PIN_SERIAL2_TX 5u // GPIO0

View File

@@ -10,6 +10,7 @@
Parameter | Value
-------------|----------------------------------
Board code | `wb2l`
MCU | BK7231T
Manufacturer | Beken
Series | BK72XX
@@ -21,6 +22,19 @@ I/O | 13x GPIO, 5x PWM, 2x UART, 1x ADC
Wi-Fi | 802.11 b/g/n
Bluetooth | BLE v4.2
## Usage
**Board code:** `wb2l`
In `platformio.ini`:
```ini
[env:wb2l]
platform = libretuya
board = wb2l
framework = arduino
```
## Pinout
![Pinout](pinout_wb2l.svg)

View File

@@ -10,6 +10,7 @@
Parameter | Value
-------------|----------------------------------
Board code | `wb2s`
MCU | BK7231T
Manufacturer | Beken
Series | BK72XX
@@ -21,6 +22,19 @@ I/O | 14x GPIO, 6x PWM, 2x UART, 1x ADC
Wi-Fi | 802.11 b/g/n
Bluetooth | BLE v4.2
## Usage
**Board code:** `wb2s`
In `platformio.ini`:
```ini
[env:wb2s]
platform = libretuya
board = wb2s
framework = arduino
```
## Pinout
![Pinout](pinout_wb2s.svg)

View File

@@ -10,6 +10,7 @@
Parameter | Value
-------------|----------------------------------
Board code | `wb3l`
MCU | BK7231T
Manufacturer | Beken
Series | BK72XX
@@ -21,6 +22,19 @@ I/O | 16x GPIO, 6x PWM, 2x UART, 1x ADC
Wi-Fi | 802.11 b/g/n
Bluetooth | BLE v4.2
## Usage
**Board code:** `wb3l`
In `platformio.ini`:
```ini
[env:wb3l]
platform = libretuya
board = wb3l
framework = arduino
```
## Pinout
![Pinout](pinout_wb3l.svg)

View File

@@ -10,6 +10,7 @@
Parameter | Value
-------------|----------------------------------
Board code | `wb3s`
MCU | BK7231T
Manufacturer | Beken
Series | BK72XX
@@ -21,6 +22,19 @@ I/O | 15x GPIO, 6x PWM, 2x UART, 1x ADC
Wi-Fi | 802.11 b/g/n
Bluetooth | BLE v4.2
## Usage
**Board code:** `wb3s`
In `platformio.ini`:
```ini
[env:wb3s]
platform = libretuya
board = wb3s
framework = arduino
```
## Pinout
![Pinout](pinout_wb3s.svg)

View File

@@ -11,6 +11,7 @@
Parameter | Value
-------------|---------------------------------
Board code | `wr2`
MCU | RTL8710BN
Manufacturer | Realtek
Series | AmebaZ
@@ -21,6 +22,19 @@ Voltage | 3.0V - 3.6V
I/O | 7x GPIO, 5x PWM, 1x UART, 1x ADC
Wi-Fi | 802.11 b/g/n
## Usage
**Board code:** `wr2`
In `platformio.ini`:
```ini
[env:wr2]
platform = libretuya
board = wr2
framework = arduino
```
## Pinout
![Pinout](pinout_wr2.svg)

View File

@@ -11,6 +11,7 @@
Parameter | Value
-------------|---------------------------------
Board code | `wr2e`
MCU | RTL8710BN
Manufacturer | Realtek
Series | AmebaZ
@@ -21,6 +22,19 @@ Voltage | 3.0V - 3.6V
I/O | 7x GPIO, 4x PWM, 1x UART, 2x ADC
Wi-Fi | 802.11 b/g/n
## Usage
**Board code:** `wr2e`
In `platformio.ini`:
```ini
[env:wr2e]
platform = libretuya
board = wr2e
framework = arduino
```
## Pinout
![Pinout](pinout_wr2e.svg)

View File

@@ -11,6 +11,7 @@
Parameter | Value
-------------|---------------------------------
Board code | `wr2l`
MCU | RTL8710BX
Manufacturer | Realtek
Series | AmebaZ
@@ -21,6 +22,19 @@ Voltage | 3.0V - 3.6V
I/O | 5x GPIO, 4x PWM, 1x UART, 1x ADC
Wi-Fi | 802.11 b/g/n
## Usage
**Board code:** `wr2l`
In `platformio.ini`:
```ini
[env:wr2l]
platform = libretuya
board = wr2l
framework = arduino
```
## Pinout
![Pinout](pinout_wr2l.svg)

View File

@@ -11,6 +11,7 @@
Parameter | Value
-------------|-------------------------
Board code | `wr2le`
MCU | RTL8710BX
Manufacturer | Realtek
Series | AmebaZ
@@ -21,6 +22,19 @@ Voltage | 3.0V - 3.6V
I/O | 5x GPIO, 5x PWM, 1x UART
Wi-Fi | 802.11 b/g/n
## Usage
**Board code:** `wr2le`
In `platformio.ini`:
```ini
[env:wr2le]
platform = libretuya
board = wr2le
framework = arduino
```
## Pinout
![Pinout](pinout_wr2le.svg)

View File

@@ -11,6 +11,7 @@
Parameter | Value
-------------|----------------------------------
Board code | `wr3`
MCU | RTL8710BN
Manufacturer | Realtek
Series | AmebaZ
@@ -21,6 +22,19 @@ Voltage | 3.0V - 3.6V
I/O | 11x GPIO, 6x PWM, 2x UART, 2x ADC
Wi-Fi | 802.11 b/g/n
## Usage
**Board code:** `wr3`
In `platformio.ini`:
```ini
[env:wr3]
platform = libretuya
board = wr3
framework = arduino
```
## Pinout
![Pinout](pinout_wr3.svg)

View File

@@ -11,6 +11,7 @@
Parameter | Value
-------------|----------------------------------
Board code | `wr3e`
MCU | RTL8710BN
Manufacturer | Realtek
Series | AmebaZ
@@ -21,6 +22,19 @@ Voltage | 3.0V - 3.6V
I/O | 11x GPIO, 6x PWM, 2x UART, 2x ADC
Wi-Fi | 802.11 b/g/n
## Usage
**Board code:** `wr3e`
In `platformio.ini`:
```ini
[env:wr3e]
platform = libretuya
board = wr3e
framework = arduino
```
## Pinout
![Pinout](pinout_wr3e.svg)

View File

@@ -11,6 +11,7 @@
Parameter | Value
-------------|----------------------------------
Board code | `wr3l`
MCU | RTL8710BX
Manufacturer | Realtek
Series | AmebaZ
@@ -21,6 +22,19 @@ Voltage | 3.0V - 3.6V
I/O | 11x GPIO, 6x PWM, 2x UART, 2x ADC
Wi-Fi | 802.11 b/g/n
## Usage
**Board code:** `wr3l`
In `platformio.ini`:
```ini
[env:wr3l]
platform = libretuya
board = wr3l
framework = arduino
```
## Pinout
![Pinout](pinout_wr3l.svg)

View File

@@ -11,6 +11,7 @@
Parameter | Value
-------------|----------------------------------
Board code | `wr3le`
MCU | RTL8710BX
Manufacturer | Realtek
Series | AmebaZ
@@ -21,6 +22,19 @@ Voltage | 3.0V - 3.6V
I/O | 11x GPIO, 6x PWM, 2x UART, 2x ADC
Wi-Fi | 802.11 b/g/n
## Usage
**Board code:** `wr3le`
In `platformio.ini`:
```ini
[env:wr3le]
platform = libretuya
board = wr3le
framework = arduino
```
## Pinout
![Pinout](pinout_wr3le.svg)

View File

@@ -11,6 +11,7 @@
Parameter | Value
-------------|---------------------------------
Board code | `wr3n`
MCU | RTL8710BN
Manufacturer | Realtek
Series | AmebaZ
@@ -21,6 +22,19 @@ Voltage | 3.0V - 3.6V
I/O | 9x GPIO, 5x PWM, 2x UART, 1x ADC
Wi-Fi | 802.11 b/g/n
## Usage
**Board code:** `wr3n`
In `platformio.ini`:
```ini
[env:wr3n]
platform = libretuya
board = wr3n
framework = arduino
```
## Pinout
![Pinout](pinout_wr3n.svg)

View File

@@ -30,6 +30,9 @@ env.Append(
# wrappers from port/printf/
"-Wl,-wrap,putchar",
"-Wl,-wrap,puts",
# wrappers from posix/time.c
"-Wl,-wrap,gettimeofday",
"-Wl,-wrap,settimeofday",
],
)
# Arduino core uses __libc_init_array
@@ -76,6 +79,19 @@ env.AddLibrary(
],
)
# Sources - uf2ota library
ltchiptool_dir = platform.get_package_dir(f"tool-ltchiptool")
env.AddLibrary(
name="uf2ota",
base_dir=ltchiptool_dir,
srcs=[
"+<uf2ota/*.c>",
],
includes=[
"+<.>",
],
)
# Sources - board variant
env.AddLibrary(
name="board_${VARIANT}",

View File

@@ -7,6 +7,12 @@ from SCons.Script import Builder, DefaultEnvironment
env = DefaultEnvironment()
board = env.BoardConfig()
# Install PyCryptodome for OTA packaging with AES
try:
import Cryptodome
except ImportError:
env.Execute("$PYTHONEXE -m pip install pycryptodomex")
ROOT_DIR = join("$SDK_DIR", "beken378")
APP_DIR = join(ROOT_DIR, "app")
DRIVER_DIR = join(ROOT_DIR, "driver")
@@ -243,6 +249,7 @@ env.AddLibrary(
"+<usb>",
"+<../ip/**>",
],
options=dict(CCFLAGS=["-Wno-unused-variable"]),
)
# Sources - functional components
@@ -257,6 +264,7 @@ env.AddLibrary(
"+<camera_intf/*.c>",
"+<hostapd_intf/*.c>",
"+<joint_up/*.c>",
"+<lwip_intf/dhcpd/*.c>",
"+<misc/*.c>",
"+<net_param_intf/*.c>",
"+<power_save/*.c>",
@@ -282,6 +290,7 @@ env.AddLibrary(
"+<ethernet_intf>",
"+<include>",
"+<joint_up>",
"+<lwip_intf>", # for config/lwipopts.h
"+<power_save>",
"+<rf_test>",
"+<rf_use>",
@@ -336,31 +345,8 @@ env.AddLibrary(
),
)
# Sources - lwIP 2.0.2
env.AddLibrary(
name="bdk_lwip",
base_dir=join(FUNC_DIR, "lwip_intf"),
srcs=[
"+<lwip-2.0.2/port/*.c>",
"+<lwip-2.0.2/src/api/*.c>",
"+<lwip-2.0.2/src/apps/ping/*.c>",
"+<lwip-2.0.2/src/apps/mdns/*.c>",
"+<lwip-2.0.2/src/core/*.c>",
"+<lwip-2.0.2/src/core/ipv4/*.c>",
"+<lwip-2.0.2/src/core/ipv6/*.c>",
"+<lwip-2.0.2/src/netif/ethernet.c>",
"+<dhcpd/*.c>",
# use ethernetif.c from AliOS since it enables netif IGMP flag
"-<lwip-2.0.2/port/ethernetif.c>",
"+<$SDK_DIR/beken378/alios/lwip-2.0.2/port/ethernetif.c>",
],
includes=[
"+<lwip-2.0.2/port>",
"+<lwip-2.0.2/src/include>",
"+<lwip-2.0.2/src/include/netif>",
],
options=dict(CCFLAGS=["-Wno-missing-braces"]),
)
# Sources - lwIP 2.1.3
env.AddLibraryLwIP(version="2.1.3", port="bdk")
# Sources - mbedTLS 2.6.0
env.AddLibrary(
@@ -587,7 +573,7 @@ env.BuildLibraries()
# Main firmware outputs and actions
env.Replace(
# linker command (encryption + packaging)
LINK="${LINK2BIN} ${VARIANT} '' ''",
LINK="${LTCHIPTOOL} link2bin ${VARIANT} '' ''",
# UF2OTA input list
UF2OTA=[
# app binary image (enc+crc), OTA1 (uploader) only
@@ -604,5 +590,12 @@ env.Replace(
"", # not used for OTA2
"",
),
# OTA RBL package, OTA2 (uf2ota lib) only
(
"", # not used for OTA1
"",
"download",
"${BUILD_DIR}/${MCULC}_app.ota.rbl",
),
],
)

View File

@@ -294,7 +294,7 @@ env.BuildLibraries()
# Main firmware outputs and actions
env.Replace(
# linker command (dual .bin outputs)
LINK="${LINK2BIN} ${VARIANT} xip1 xip2",
LINK="${LTCHIPTOOL} link2bin ${VARIANT} xip1 xip2",
# default output .bin name
IMG_FW="image_${FLASH_OTA1_OFFSET}.ota1.bin",
# UF2OTA input list

View File

@@ -25,6 +25,13 @@ def env_add_lwip(
"+<port/realtek>",
"+<port/realtek/freertos>",
]
elif port in ["bdk"]:
port_srcs = [
"+<port/*.c>",
]
port_includes = [
"+<port>",
]
env.AddLibrary(
name=f"lwip{version}_{port}",

View File

@@ -2,16 +2,15 @@
from os.path import join
from ltchiptool import Family
from SCons.Script import DefaultEnvironment
from tools.util.platform import get_family
env = DefaultEnvironment()
def env_add_defaults(env, platform, board):
# Get Family object for this board
family = get_family(short_name=board.get("build.family"))
family = Family.get(short_name=board.get("build.family"))
# Default environment variables
vars = dict(
SDK_DIR=platform.get_package_dir(family.framework),
@@ -36,10 +35,8 @@ def env_add_defaults(env, platform, board):
VARIANT=board.get("build.variant"),
LDSCRIPT_SDK=board.get("build.ldscript_sdk"),
LDSCRIPT_ARDUINO=board.get("build.ldscript_arduino"),
# Link2Bin tool
LINK2BIN='"${PYTHONEXE}" "${LT_DIR}/tools/link2bin.py"',
UF2OTA_PY='"${PYTHONEXE}" "${LT_DIR}/tools/uf2ota/uf2ota.py"',
UF2UPLOAD_PY='"${PYTHONEXE}" "${LT_DIR}/tools/upload/uf2upload.py"',
# ltchiptool variables
LTCHIPTOOL='"${PYTHONEXE}" -m ltchiptool',
# Fix for link2bin to get tmpfile name in argv
LINKCOM="${LINK} ${LINKARGS}",
LINKARGS="${TEMPFILE('-o $TARGET $LINKFLAGS $__RPATH $SOURCES $_LIBDIRFLAGS $_LIBFLAGS', '$LINKCOMSTR')}",
@@ -50,6 +47,7 @@ def env_add_defaults(env, platform, board):
# Default build options
env.Prepend(
CPPPATH=[
"$LT_DIR/platform/common/config",
"$LT_DIR/platform/common/fixups",
"$LT_DIR/platform/common/fixups/lib_inc",
"$BOARD_DIR",

Some files were not shown because too many files have changed in this diff Show More