Skip to content

Commit

Permalink
Fix examples compilation fail in T3, T5 (#27)
Browse files Browse the repository at this point in the history
* fix: Stop build when t2 in drawin

* fix: t2 build wifi examples fail

* feat: Supports calling the vendor interface

* fix: Replace the vendor api with the tal api

* fix: all station info list memory is not freed

* feat: Add file system

* fix: Spell error

* fix: Spell error

* feat: add upload speed options and update upload tool configuration

* fix: update WiFiAP and WiFiSTA to include necessary headers and improve IP configuration handling

* fix: ensure setSDA and setSCL methods return true

* feat: Support T3 SPI

* Update package.json

* Update package_cn.json

* fix: update CMakeLists.txt for board configuration and library inclusion

---------

Co-authored-by: YangJie <[email protected]>
  • Loading branch information
shiliu-yang and YangJie authored Dec 10, 2024
1 parent 89be820 commit b8aa6e3
Show file tree
Hide file tree
Showing 36 changed files with 1,484 additions and 105 deletions.
37 changes: 29 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ get_filename_component(MODULE_NAME ${MODULE_PATH} NAME)
if(NOT DEFINED CONFIG_ARDUINO_BOARD)
message(FATAL_ERROR "Use [menuconfig] choice [ARDUINO_BOARD].")
endif()
if(${CONFIG_ARDUINO_BOARD} STREQUAL "ARDUINO_TUYA_T3")
if(${CONFIG_ARDUINO_BOARD} STREQUAL "ARDUINO_T3")
set(ARDUINO_BOARD "t3")
set(LD_FILE "${MODULE_PATH}/port/${PLATFORM_NAME}/bk7236_out.ld")
else()
set(CONFIG_ARDUINO_BOARD "ARDUINO_TUYA_T2")
set(CONFIG_ARDUINO_BOARD "ARDUINO_T2")
set(ARDUINO_BOARD "t2")
set(LD_FILE "${MODULE_PATH}/port/${PLATFORM_NAME}/bk7231n_ota.ld")
endif()

# LIB_SRCS
Expand All @@ -31,12 +29,26 @@ file(GLOB_RECURSE
)
file(GLOB_RECURSE
LIB_SRCS_LIB
"${MODULE_PATH}/libraries/BLE/src/*.cpp"
"${MODULE_PATH}/libraries/BLE/src/*.c"
"${MODULE_PATH}/libraries/FS/src/*.cpp"
"${MODULE_PATH}/libraries/FS/src/*.c"
"${MODULE_PATH}/libraries/HTTPClient/src/*.cpp"
"${MODULE_PATH}/libraries/HTTPClient/src/*.c"
"${MODULE_PATH}/libraries/LittleFS/src/*.cpp"
"${MODULE_PATH}/libraries/LittleFS/src/*.c"
"${MODULE_PATH}/libraries/Log/src/*.cpp"
"${MODULE_PATH}/libraries/Log/src/*.c"
"${MODULE_PATH}/libraries/MQTTClient/src/*.cpp"
"${MODULE_PATH}/libraries/MQTTClient/src/*.c"
"${MODULE_PATH}/libraries/SPI/src/*.cpp"
"${MODULE_PATH}/libraries/SPI/src/*.c"
"${MODULE_PATH}/libraries/Ticker/src/*.cpp"
"${MODULE_PATH}/libraries/Ticker/src/*.c"
"${MODULE_PATH}/libraries/TuyaIoT/src/*.cpp"
"${MODULE_PATH}/libraries/TuyaIoT/src/*.c"
)

file(GLOB_RECURSE
LIB_SRCS_VAR
"${MODULE_PATH}/variants/${ARDUINO_BOARD}/*.c"
Expand All @@ -45,15 +57,24 @@ list(APPEND LIB_SRCS ${LIB_SRCS_CORE})
list(APPEND LIB_SRCS ${LIB_SRCS_LIB})
list(APPEND LIB_SRCS ${LIB_SRCS_VAR})

# LIB_PUBLIC_INC
set(LIBRARIES_INC
"${MODULE_PATH}/libraries/BLE/src/"
"${MODULE_PATH}/libraries/FS/src/"
"${MODULE_PATH}/libraries/HTTPClient/src/"
"${MODULE_PATH}/libraries/LittleFS/src/"
"${MODULE_PATH}/libraries/Log/src/"
"${MODULE_PATH}/libraries/MQTTClient/src/"
"${MODULE_PATH}/libraries/SPI/src/"
"${MODULE_PATH}/libraries/Ticker/src/"
"${MODULE_PATH}/libraries/TuyaIoT/src/"
)

set(LIB_PUBLIC_INC
"${MODULE_PATH}/cores/tuya_open"
"${LIBRARIES_INC}"
"${MODULE_PATH}/variants/${ARDUINO_BOARD}"
)

# FLAGS
set(CMAKE_CXX_FLAGS "@${MODULE_PATH}/port/${PLATFORM_NAME}/flags/cpp_flags.txt")

########################################
# Target Configure
########################################
Expand Down
52 changes: 46 additions & 6 deletions boards.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
menu.UploadSpeed=Upload Speed

# --------------------------------------------------
# T2
Expand All @@ -8,6 +9,19 @@ t2.build.board=T2
t2.build.core=tuya_open
t2.build.variant=t2

t2.menu.UploadSpeed.921600=921600
t2.menu.UploadSpeed.921600.upload.speed=921600
t2.menu.UploadSpeed.115200=115200
t2.menu.UploadSpeed.115200.upload.speed=115200
t2.menu.UploadSpeed.230400=230400
t2.menu.UploadSpeed.230400.upload.speed=230400
t2.menu.UploadSpeed.460800=460800
t2.menu.UploadSpeed.460800.upload.speed=460800
t2.menu.UploadSpeed.1500000=1500000
t2.menu.UploadSpeed.1500000.upload.speed=1500000
t2.menu.UploadSpeed.2000000=2000000
t2.menu.UploadSpeed.2000000.upload.speed=2000000

t2.compiler.path={runtime.tools.gcc-arm-none-eabi.path}
t2.compiler.cmd.S={compiler.path}/bin/arm-none-eabi-gcc
t2.compiler.cmd.c={compiler.path}/bin/arm-none-eabi-gcc
Expand All @@ -25,15 +39,15 @@ t2.appBuild.flags=@{build.path}/tuyaTmp/appConfig/appBuildDefine.txt

t2.compiler.includes.tuya_open=-iprefix {runtime.tools.vendor-t2.path}/ @{runtime.tools.vendor-t2.path}/flags/include_tuya_open.txt
t2.compiler.includes.tkl=-iprefix {runtime.tools.vendor-t2.path}/ @{runtime.tools.vendor-t2.path}/flags/include_tkl.txt
t2.compiler.includes={compiler.includes.tuya_open} {compiler.includes.tkl}
t2.compiler.includes.vendor=-iprefix {runtime.tools.vendor-t2.path}/ @{runtime.tools.vendor-t2.path}/flags/include_vendor.txt
t2.compiler.includes={compiler.includes.tuya_open} {compiler.includes.tkl} {compiler.includes.vendor}

t2.compiler.flags.ld=@{runtime.tools.vendor-t2.path}/flags/ld_flags.txt
t2.compiler.flags.libs=-L{runtime.tools.vendor-t2.path}/libs @{runtime.tools.vendor-t2.path}/flags/libs_flags.txt
t2.compiler.flags.ld_scripts=-Wl,--cref -Wl,-Map={build.path}/{build.project_name}.map -T{runtime.tools.vendor-t2.path}/packager-tools/t2.ld -o {build.path}/{build.project_name}.elf

t2.upload.tool=tyutool
t2.upload.tool.default=tyutool
t2.upload.tool.baud_rate=921600

t2.monitor_port.serial.baudrate=115200

Expand All @@ -46,6 +60,19 @@ t3.build.board=T3
t3.build.core=tuya_open
t3.build.variant=t3

t3.menu.UploadSpeed.921600=921600
t3.menu.UploadSpeed.921600.upload.speed=921600
t3.menu.UploadSpeed.115200=115200
t3.menu.UploadSpeed.115200.upload.speed=115200
t3.menu.UploadSpeed.230400=230400
t3.menu.UploadSpeed.230400.upload.speed=230400
t3.menu.UploadSpeed.460800=460800
t3.menu.UploadSpeed.460800.upload.speed=460800
t3.menu.UploadSpeed.1500000=1500000
t3.menu.UploadSpeed.1500000.upload.speed=1500000
t3.menu.UploadSpeed.2000000=2000000
t3.menu.UploadSpeed.2000000.upload.speed=2000000

t3.compiler.path={runtime.tools.gcc-arm-none-eabi.path}
t3.compiler.cmd.S={compiler.path}/bin/arm-none-eabi-gcc
t3.compiler.cmd.c={compiler.path}/bin/arm-none-eabi-gcc
Expand All @@ -63,15 +90,15 @@ t3.appBuild.flags=@{build.path}/tuyaTmp/appConfig/appBuildDefine.txt

t3.compiler.includes.tuya_open=-iprefix {runtime.tools.vendor-t3.path}/ @{runtime.tools.vendor-t3.path}/flags/include_tuya_open.txt
t3.compiler.includes.tkl=-iprefix {runtime.tools.vendor-t3.path}/ @{runtime.tools.vendor-t3.path}/flags/include_tkl.txt
t3.compiler.includes={compiler.includes.tuya_open} {compiler.includes.tkl}
t3.compiler.includes.vendor=-iprefix {runtime.tools.vendor-t3.path}/ @{runtime.tools.vendor-t3.path}/flags/include_vendor.txt
t3.compiler.includes={compiler.includes.tuya_open} {compiler.includes.tkl} {compiler.includes.vendor}

t3.compiler.flags.ld=@{runtime.tools.vendor-t3.path}/flags/ld_flags.txt
t3.compiler.flags.libs=-L{runtime.tools.vendor-t3.path}/libs @{runtime.tools.vendor-t3.path}/flags/libs_flags.txt
t3.compiler.flags.ld_scripts=-Wl,--cref -Wl,-Map={build.path}/{build.project_name}.map -T{runtime.tools.vendor-t3.path}/packager-tools/t3.ld -o {build.path}/{build.project_name}.elf

t3.upload.tool=tyutool
t3.upload.tool.default=tyutool
t3.upload.tool.baud_rate=921600

t3.monitor_port.serial.baudrate=115200

Expand All @@ -84,6 +111,19 @@ t5.build.board=T5
t5.build.core=tuya_open
t5.build.variant=t5

t5.menu.UploadSpeed.921600=921600
t5.menu.UploadSpeed.921600.upload.speed=921600
t5.menu.UploadSpeed.115200=115200
t5.menu.UploadSpeed.115200.upload.speed=115200
t5.menu.UploadSpeed.230400=230400
t5.menu.UploadSpeed.230400.upload.speed=230400
t5.menu.UploadSpeed.460800=460800
t5.menu.UploadSpeed.460800.upload.speed=460800
t5.menu.UploadSpeed.1500000=1500000
t5.menu.UploadSpeed.1500000.upload.speed=1500000
t5.menu.UploadSpeed.2000000=2000000
t5.menu.UploadSpeed.2000000.upload.speed=2000000

t5.compiler.path={runtime.tools.gcc-arm-none-eabi.path}
t5.compiler.cmd.S={compiler.path}/bin/arm-none-eabi-gcc
t5.compiler.cmd.c={compiler.path}/bin/arm-none-eabi-gcc
Expand All @@ -101,14 +141,14 @@ t5.appBuild.flags=@{build.path}/tuyaTmp/appConfig/appBuildDefine.txt

t5.compiler.includes.tuya_open=-iprefix {runtime.tools.vendor-t5.path}/ @{runtime.tools.vendor-t5.path}/flags/include_tuya_open.txt
t5.compiler.includes.tkl=-iprefix {runtime.tools.vendor-t5.path}/ @{runtime.tools.vendor-t5.path}/flags/include_tkl.txt
t5.compiler.includes={compiler.includes.tuya_open} {compiler.includes.tkl}
t5.compiler.includes.vendor=-iprefix {runtime.tools.vendor-t5.path}/ @{runtime.tools.vendor-t5.path}/flags/include_vendor.txt
t5.compiler.includes={compiler.includes.tuya_open} {compiler.includes.tkl} {compiler.includes.vendor}

t5.compiler.flags.ld=@{runtime.tools.vendor-t5.path}/flags/ld_flags.txt
t5.compiler.flags.libs=-L{runtime.tools.vendor-t5.path}/libs @{runtime.tools.vendor-t5.path}/flags/libs_flags.txt
t5.compiler.flags.ld_scripts=-Wl,--cref -Wl,-Map={build.path}/{build.project_name}.map -T{runtime.tools.vendor-t5.path}/packager-tools/t5.ld -o {build.path}/{build.project_name}.elf

t5.upload.tool=tyutool
t5.upload.tool.default=tyutool
t5.upload.tool.baud_rate=921600

t5.monitor_port.serial.baudrate=115200
38 changes: 38 additions & 0 deletions cores/tuya_open/Tone.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "Arduino.h"
#include "tkl_pwm.h"

void tone(uint8_t _pin, unsigned int frequency, unsigned long duration)
{
OPERATE_RET rt = OPRT_OK;
static uint8_t is_init = 0;

TUYA_PWM_NUM_E pwmNum = pwmPinToNum(_pin);
if (TUYA_PWM_NUM_MAX == pwmNum) {
return;
}

TUYA_PWM_BASE_CFG_T pwmCfg = pwmCfgGet(_pin);
pwmCfg.frequency = frequency;

pwmCfg.duty = 5000; // duty 0-10000, 5000 is 50%

if (0 == is_init) {
rt = tkl_pwm_init(pwmNum, &pwmCfg);
if (OPRT_OK != rt) {
return;
}
is_init = 1;
}

tkl_pwm_start(pwmNum);

return;
}

void noTone(uint8_t _pin)
{
tkl_pwm_stop(pwmPinToNum(_pin));

return;
}

6 changes: 6 additions & 0 deletions cores/tuya_open/wiring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

#include "tal_system.h"

unsigned long micros(void)
{
unsigned long us = tal_system_get_millisecond() * 1000;
return us;
}

unsigned long millis()
{
unsigned long ms = tal_system_get_millisecond();
Expand Down
5 changes: 3 additions & 2 deletions libraries/BLE/src/BLEAdvertising.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "BLEAdvertising.h"
#include "tal_api.h"

void BLEAdvertising::setMinInterval(uint16_t mininterval)
{
Expand All @@ -18,7 +19,7 @@ void BLEAdvertising::setScanResponse(bool set)
void BLEAdvertising::setAdvertisementData(uint8_t *adv_data, uint8_t len)
{
TKL_BLE_DATA_T p_adv;
p_adv.p_data = (uint8_t *)malloc(sizeof(uint8_t)*len);
p_adv.p_data = (uint8_t *)tal_malloc(sizeof(uint8_t)*len);
memcpy(p_adv.p_data, adv_data, len);
p_adv.length = len;
tkl_ble_gap_adv_rsp_data_set(&p_adv, NULL);
Expand All @@ -27,7 +28,7 @@ void BLEAdvertising::setAdvertisementData(uint8_t *adv_data, uint8_t len)
void BLEAdvertising::setScanResponseData(uint8_t *adv_rsp_data,uint8_t len)
{
TKL_BLE_DATA_T p_scan_rsp;
p_scan_rsp.p_data = (uint8_t *)malloc(sizeof(uint8_t)*len);
p_scan_rsp.p_data = (uint8_t *)tal_malloc(sizeof(uint8_t)*len);
memcpy(p_scan_rsp.p_data, adv_rsp_data, len);
p_scan_rsp.length = len;
tkl_ble_gap_adv_rsp_data_set(NULL, &p_scan_rsp);
Expand Down
7 changes: 4 additions & 3 deletions libraries/BLE/src/BLEService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "BLEServer.h"
#include "BLECharacteristic.h"
#include <string.h>
#include "tal_api.h"

static int hex2num(char c)
{
Expand Down Expand Up @@ -53,13 +54,13 @@ BLEService::BLEService(std::string uuid)
char_index = 0;

if (!ble_gatt_service) {
ble_gatt_service = (TKL_BLE_GATTS_PARAMS_T*)malloc(sizeof(TKL_BLE_GATTS_PARAMS_T));
ble_gatt_service = (TKL_BLE_GATTS_PARAMS_T*)tal_malloc(sizeof(TKL_BLE_GATTS_PARAMS_T));
}
if (!ble_service) {
ble_service = (TKL_BLE_SERVICE_PARAMS_T*)malloc(sizeof(TKL_BLE_SERVICE_PARAMS_T));
ble_service = (TKL_BLE_SERVICE_PARAMS_T*)tal_malloc(sizeof(TKL_BLE_SERVICE_PARAMS_T));
}
if (!ble_service_char) {
ble_service_char = (TKL_BLE_CHAR_PARAMS_T *)malloc(sizeof(TKL_BLE_CHAR_PARAMS_T) * TKL_BLE_GATT_CHAR_MAX_NUM);
ble_service_char = (TKL_BLE_CHAR_PARAMS_T *)tal_malloc(sizeof(TKL_BLE_CHAR_PARAMS_T) * TKL_BLE_GATT_CHAR_MAX_NUM);
}

ble_gatt_service->svc_num = 1 ;
Expand Down
2 changes: 1 addition & 1 deletion libraries/DNSServer/src/DNSServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ void DNSServer::replyWithIP()
_Udp.write( (unsigned char*) &_DnsQuestion->QClass, 2 ) ;

// Write the answer
// Use DNS name compression : instead of repeating the name in this RNAME occurence,
// Use DNS name compression : instead of repeating the name in this RNAME occurrence,
// set the two MSB of the byte corresponding normally to the length to 1. The following
// 14 bits must be used to specify the offset of the domain name in the message
// (<255 here so the first byte has the 6 LSB at 0)
Expand Down
2 changes: 1 addition & 1 deletion libraries/DNSServer/src/DNSServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct DNSHeader
struct {
uint16_t RD : 1; // recursion desired
uint16_t Trunc : 1; // truncated message
uint16_t AuthAns : 1; // authoritive answer
uint16_t AuthAns : 1; // authoritative answer
uint16_t OPCode : 4; // message_type
uint16_t QRFlag : 1; // query/response flag
uint16_t RspCode : 4; // response code
Expand Down
9 changes: 9 additions & 0 deletions libraries/FS/library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name=FS
version=2.0.0
author=tuya
maintainer=tuya
sentence=tuya
paragraph=
category=Data Storage
url=
architectures=*
Loading

0 comments on commit b8aa6e3

Please sign in to comment.