Development Environment Setup When Using Tuya Wi-Fi SDK

Change log

Version

Description

Date

1.0.0

The initial version.

20200601

Overview

The Tuya device OS is a proprietary IoT operating system, which provides abundant components and you can make SDK customization according to your business requirements. It has the characteristic of lightweight, interconnection, secure transmission, fully functional components and rapid development, effectively lowering the development threshold and shortening the development cycle. It can be widely used in wearable devices, video monitors, compute gateways, smart speakers, smart locks and other smart home appliances.

The Tuya Wi-Fi SDK is developed based on Tuya device OS technology and tailored according to the Wi-Fi application in the Internet of Things scenarios. It is applicable to any Wi-Fi chip that is configured according to the Tuya Smart platform interconnection rules.

For different developing requirement, Tuya provides different strategies and services. If you have independent development ability and can develop the underlying hardware and drivers, you can use the provided SDK to adapt to the abstract interface of the development environment, so as to achieve higher flexibility for device functions.

This topic describes how to set up the development environment for Tuya Wi-Fi SDK. The development environment includes the tool chain, script, library file and other information. However, it is not necessary if you use the module provided by Tuya, or Tuya has designed the SDK to work well with the specific chip platforms. The SDK products released by Tuya have completed the compilation adaptation, interface adaptation and other configuration, you can see the README.md file for more information.

Set up the development environment

The development environment includes the tool chain, script, library file and other information provided by the chip manufacturer, which are necessary to compile the Tuya Wi-Fi SDK. Therefore, you must set up the development environment according to the following rules to compile the SDK and firmware.

  • Collect the tools, libraries, and scripts of the genuine chip, send them together with compilation option and functional requirement to your Tuya account manager.

  • Upon receiving the material, Tuya engineers make adaptation to the toolchain of genuine chip according your requirement. Taking the RTL8720CF as an example, see the following description for details.

  • Create a toolchain folder under the root directory of the tool chain provided by the chip manufacturer.

  • Create a build_path folder to export the compilation location for the toolchain.

  • TUYA_SDK_TOOLCHAIN_ZIP: identifies the location of toolchain compression package. During the compilation, if this value is detected, the compression package will be decompressed.

  • Create a platform.mk folder to interact with the Tuya continuous integration system, and perform automated SDK compilation according to your requirement.

  • TUYA_PLATFORM_DIR: identifies the location of current development environment.

  • Create a build.conf folder to customize your functional features requirement. For more information, see Appendix.

  • After you receive the compiled Tuya Wi-Fi SDK, you can adjust the firmware compilation process according to the following section to compile the firmware, and then burn it to the chip for implementation.

Firmware compilation and setup

After decompressing the compiled Tuya Wi-Fi SDK, the directory is shown in the following table.

Directory

Subdirectory

Description

Reference

apps

/

Stores your application and samples of the Tuya Wi-Fi SDK. It is better to create a folder for every application or sample.

See the sample of Tuya Wi-Fi SDK for usage instruction.

one_plug_demo

Contains one or more samples.

N/A.

sdk

sdk

Stores the header files and library files of Tuya Wi-Fi SDK.

See the API reference section for details.

include

Stores all of the APIs provided by Tuya Wi-Fi SDK.

N/A

lib

The libtuya_iot.a file that is compiled by Tuya Wi-Fi SDK.

N/A

platforms

/

Stores the development environment and toolchains of Tuya Wi-Fi SDK. The platform is an empty folder at first. Related toolchains are downloaded automatically to this folder during compiling.

N/A.

build_app.sh

/

The compiling entry point for applications and samples. Sets up development and compilation environment.

N/A.

CHANGELOG.md

/

Records all the notable changes for each version.

N/A.

README.md

/

User guide written in Markdown.

N/A.

Based on this environment, Tuya provides a set of compilation features. You can also customize the compilation process. The following instructions taking the one_plug_demo to describe the firmware compilation process.

one_plug_demo: downloads the development environment packages to perform the compilation script. Alternatively, the shell script and makefile are supported for compilation.

./apps/one_plug_demo/build.sh: enters into the development environment, run the compile script, and make packages.

The compiled product will be saved to the apps/one_plug_demo/output/ directory.

The porting of tuya_common

The tuya_common is stored in the Tuya Wi-Fi SDK package.

It is included in the development environment that are configured by running build_app.sh. You can directly use the related functions in the tuya_common folder.

The tuya_os_adapter configuration

The tuya_os_adapter uses a widely applicable registration method, which provides interface description and definition, and realizes the relevant interfaces and registration, so as to achieve the platform independence of Tuya Wi-Fi SDK. You need to implement tuya_os_adapter manually and place it in the root directory of development environment.

System

The Tuya HAL System provides several interfaces of the operating system. For Linux platforms, the Tuya Wi-Fi SDK provides a set of widely-used system related interfaces. These interfaces can be implemented for your customization requirements.

os_adapter_get_systemtickcount

SYS_TICK_T os_adapter_get_systemtickcount(void)
  • Description

    Gets the current ticket value of the system.

  • Parameter

    None.

  • Return value

    The current tick value of the system.

os_adapter_get_tickratems

unsigned int os_adapter_get_tickratems(void)
  • Description

    How many milliseconds to get a ticket for the system.

  • Parameter

    None.

  • Return value

    How many milliseconds is 1 ticket in the system.

os_adapter_system_sleep

void os_adapter_system_sleep(const unsigned long msTime)
  • Description

    Thread sleep.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    msTime

    System sleep time, unit: ms.

  • Return value

    None.

os_adapter_system_isrstatus

bool os_adapter_system_isrstatus(void)
  • Description

    Gets whether the system is in the interrupt routine.

  • Parameter

    None.

  • Return value

    TRUE: in interrupt routine.

    FALSE: not in interrupt routine.

os_adapter_system_reset

void os_adapter_system_reset(void)
  • Description

    Restarts the system.

  • Parameter

    None.

  • Return value

    None.

os_adapter_system_getheapsize

unsigned int os_adapter_system_getheapsize(void)
  • Description

    Gets the remaining memory size of the system.

  • Parameter

    None.

  • Return value

    Remaining memory.

os_adapter_system_get_rst_info

TY_RST_REASON_E os_adapter_system_get_rst_info(void)
  • Description

    Gets the reason for system restart.

    TY_RST_REASON_E

    ——

    TY_RST_POWER_OFF

    Power restart

    TY_RST_HARDWARE_WATCHDOG

    Hardware watchdog reset

    TY_RST_FATAL_EXCEPTION

    Exception

    TY_RST_SOFTWARE_WATCHDOG

    Software watchdog restart

    TY_RST_SOFTWARE

    Software reset

    TY_RST_DEEPSLEEP

    Deep sleep

    TY_RST_HARDWARE

    Hardware reset

    TY_RST_OTHER

    Other causes

    TY_RST_UNSUPPORT

    Not supported

  • Parameter

    None.

  • Return value

    Reason for restart.

os_adapter_get_random_data

int os_adapter_get_random_data(const unsigned int range)
  • Description

    Generates a random number.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    range

    Random number range

  • Return value

    A random value.

  • Notice

    True random number.

os_adapter_set_cpu_lp_mode

int os_adapter_set_cpu_lp_mode(const bool en,const TY_CPU_SLEEP_MODE_E mode)
  • Description

    Sets CPU low power consumption mode.

    mode

    ——

    TY_CPU_SLEEP

    Low power consumption mode, os auto wake up, within 15mA.

    TY_CPU_DEEP_SLEEP

    Deep sleep.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    en

    Whether to enable CPU low power mode.

    [in]

    mode

    CPU low power mode.

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_INVALID_PARM: pass parameter error

    OPRT_OS_ADAPTER_CPU_LPMODE_SET_FAILED: fail

Memory

Tuya HAL Memory provides several interfaces for memory application and release. For Linux platforms, the Tuya Wi-Fi SDK provides a set of widely-used system related interfaces. These interfaces can be implemented for your customization requirements.

os_adapter_system_malloc

void *os_adapter_system_malloc(const size_t size)
  • Description

    Memory allocation.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    size

    Allocated memory size.

  • Return value

    NULL: Memory allocation failed.

    Other: Assigned successfully.

  • Notice

    Other file APIs of the adaptation layer need to apply for memory, and all calls to os_adapter_system_malloc.

os_adapter_system_free

void os_adapter_system_free(void* ptr)
  • Description

    Frees up memory.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    ptr

    Free memory address.

  • Return value

    None.

  • Notice

    The other file APIs of the adaptation layer need to release memory, and all calls to os_adapter_system_free.

Semaphore

Tuya HAL Semaphore provides several interfaces for semaphore operations. For Linux platforms, the Tuya Wi-Fi SDK provides a set of widely-used system related interfaces. These interfaces can be implemented for your customization requirements.

os_adapter_semaphore_create_init

int os_adapter_semaphore_create_init(SEM_HANDLE *pHandle, const unsigned int semCnt, const unsigned int sem_max)
  • Description

    Creates and initializes semaphore.

  • Parameter

    Input or output

    Parameter name

    Description

    [out]

    pHandle

    Pointer to semaphore handle.

    [in]

    semCnt

    Number of initialization semaphores.

    [in]

    sem_max

    Maximum semaphore number.

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_INVALID_PARM: pass parameter error

    OPRT_OS_ADAPTER_MALLOC_FAILED: failed to apply for memory

    OPRT_OS_ADAPTER_THRD_CREAT_FAILED: fail

os_adapter_semaphore_wait

int os_adapter_semaphore_wait(const SEM_HANDLE semHandle)
  • Description

    Waits for semaphore.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    semHandle

    Semaphore handle

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_INVALID_PARM: pass parameter error

    OPRT_OS_ADAPTER_SEM_WAIT_FAILED: fail

os_adapter_semaphore_post

int os_adapter_semaphore_post(const SEM_HANDLE semHandle)
  • Description

    Sends semaphore.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    mutexHandle

    Semaphore handle.

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_INVALID_PARM: pass parameter error

    OPRT_OS_ADAPTER_SEM_POST_FAILED: fail

  • Notice

    You need to distinguish between thread context and interrupt context.

os_adapter_semaphore_release

int os_adapter_semaphore_release(const SEM_HANDLE semHandle)
  • Description

    Frees up semaphore resources.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    semHandle

    Semaphore handle

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_INVALID_PARM: pass parameter error

    OPRT_OS_ADAPTER_SEM_RELEASE_FAILED: fail

Mutex

Tuya HAL Mutex provides a mutex operation interface, these interfaces can be implemented for your customization requirements. If it is a Linux platform, it may not be provided. Tuya Wi-Fi SDK provides a set of common interfaces for Linux platforms.

os_adapter_mutex_create_init

int os_adapter_mutex_create_init(MUTEX_HANDLE *pMutexHandle)
  • Description

    Creates and initializes a mutex.

  • Parameter

    Input or output

    Parameter name

    Description

    [out]

    pMutexHandle

    Pointer to the mutex handle

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_INVALID_PARM: pass parameter error

    OPRT_OS_ADAPTER_MALLOC_FAILED: failed to apply for memory

    OPRT_OS_ADAPTER_MUTEX_CREAT_FAILED: fail

os_adapter_mutex_release

int os_adapter_mutex_release(const MUTEX_HANDLE mutexHandle)
  • Description

    Releases mutex resources.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    mutexHandle

    Semaphore handle

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_INVALID_PARM: pass parameter error

    OPRT_OS_ADAPTER_MUTEX_RELEASE_FAILED: fail

os_adapter_mutex_lock

int os_adapter_mutex_lock(const MUTEX_HANDLE mutexHandle)
  • Description

    Locks mutex.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    mutexHandle

    Semaphore handle

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_INVALID_PARM: pass parameter error

    OPRT_OS_ADAPTER_MUTEX_LOCK_FAILED: fail

os_adapter_mutex_unlock

int os_adapter_mutex_unlock(const MUTEX_HANDLE mutexHandle)
  • Description

    Unlocks mutex.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    mutexHandle

    Semaphore handle

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_INVALID_PARM: pass parameter error

    OPRT_OS_ADAPTER_MUTEX_UNLOCK_FAILED: fail

  • Notice

    You need to distinguish between thread context and interrupt context.

Thread

Tuya HAL Thread provides interfaces for thread creation and release, these interfaces can be implemented for your customization requirements. If it is a Linux platform, it may not be provided. Tuya Wi-Fi SDK provides a set of common interfaces for Linux platforms.

os_adapter_thread_create

int os_adapter_thread_create(THREAD_HANDLE* thread,
                           const char* name,
                           const unsigned int stack_size,
                           const unsigned int priority,
                           const THREAD_FUNC_T func,
                           const void* arg)
  • Description

    Creates and starts a thread.

  • Parameter

    Input or output

    Parameter name

    Description

    [out]

    thread

    Pointer to thread handle

    [in]

    name

    Thread name

    [in]

    stack_size

    Thread stack size, unit is byte, not 4 bytes

    [in]

    priority

    Thread priority

    [in]

    func

    Thread function

    [in]

    arg

    User parameters

  • Return value

    OPRT_OS_ADAPTER_OK: create success

    OPRT_OS_ADAPTER_INVALID_PARM: pass parameter error

    OPRT_OS_ADAPTER_MALLOC_FAILED: failed to apply for memory

    OPRT_OS_ADAPTER_THRD_CREAT_FAILED: fail

  • Notice

    1. The stack_size parameter is 1 byte as a unit.

    2. Tuya business will use six thread priorities of 0, 1, 2, 3, 4, and 5, a lower number indicates a higher priority.

os_adapter_thread_release

int os_adapter_thread_release(THREAD_HANDLE thread)
  • Description

    Releases thread resources.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    thread

    Semaphore handle

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_INVALID_PARM: pass parameter error

    OPRT_OS_ADAPTER_THRD_RELEASE_FAILED: fail

os_adapter_thread_is_self

int os_adapter_thread_is_self(THREAD_HANDLE thread, bool* is_self)
  • Description

    Determines whether the running context is in the specified thread.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    thread

    Semaphore handle

    [out]

    is_self

    Is the specified thread

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_INVALID_PARM: pass parameter error

    OPRT_OS_ADAPTER_THRD_JUDGE_SELF_FAILED: fail

Watch Dog

Tuya HAL Watch Dog provides an interface for Watch Dog creation and refresh, which can be implemented for your customization requirements.

os_adapter_watchdog_init_start

unsigned int os_adapter_watchdog_init_start(const unsigned int timeval);
  • Description

    Initializes and runs watchdog.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    timeval

    Watchdog time

  • Return value

    int Watchdog time actually set by the chip.

  • Notice

    The upper layer of the graffiti will set the watchdog time to 60s. If the chip does not support the 60s watchdog, the actual set time will be returned.

os_adapter_watchdog_refresh

void os_adapter_watchdog_refresh(void);
  • Description

    Refreshes watch dog.

  • Return value

    void

os_adapter_watchdog_stop

void os_adapter_watchdog_stop(void);
  • Description

    Stops watch dog.

  • Return value

    void

RTC

Tuya HAL RTC provides an interface for RTC operation and requires different platforms to implement it, which can be implemented for your customization requirements.

os_adapter_rtc_init

void os_adapter_rtc_init(void)
  • Description

    Initializes the internal RTC of the chip.

  • Return value

    void no return value.

os_adapter_rtc_set_time

void os_adapter_rtc_set_time(const time_t write_time)
  • Description

    Sets time to RTC inside the chip.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    write_time

    Timestamp in seconds

  • Return value

    Void.

os_adapter_rtc_get_time

time_t os_adapter_rtc_get_time(void)
  • Description

    Gets the time from the internal RTC clock of chip.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    void

    None.

  • Return value

    time_t RTC: time inside the chip, in seconds.

OTA

Tuya HAL OTA provides an interface for OTA operation, which requires different platforms to implement it.

os_adapter_ota_start_inform

int os_adapter_ota_start_inform(unsigned int file_size);
  • Description

    Sends the notification of upgrade start.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    file_size

    Total firmware upgrade package size.

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_INVALID_PARM: pass parameter error

    OPRT_OS_ADAPTER_MALLOC_FAILED: failed to apply for memory

    OPRT_OS_ADAPTER_OTA_START_INFORM_FAILED: fail

  • Notice

    Inform the HAL layer that the OTA upgrade is about to start. The HAL layer needs to apply in advance to upgrade OTA management resources and record the size of the OTA firmware package.

os_adapter_ota_data_process

int os_adapter_ota_data_process(const unsigned int total_len, const unsigned int offset,
                              const unsigned char* data, const unsigned int len, unsigned int* remain_len, void* pri_data);
  • Description

    Processes The OTA packet.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    total_len

    The OTA upgrade firmware total size.

    [in]

    offset

    The offset of data pointer in OTA upgrade firmware.

    [in]

    data

    The buffer pointer of this OTA packet.

    [in]

    len

    The length of this OTA packet.

    [out]

    remain_len

    Length of data packets that have been delivered but not processed

    [in]

    pri_data

    Keep parameters, not used for now

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_INVALID_PARM: pass parameter error

    OPRT_OS_ADAPTER_MALLOC_FAILED: failed to apply for memory

    OPRT_OS_ADAPTER_OTA_PROCESS_FAILED: fail

  • Notice

    This function is used to support OTA upgrade, which needs to be implemented in conjunction with the Tuya upgrade package pull service. There are currently two upgrade methods in Tuya:

    • HTTP firmware upgrade.

    • Private serial port protocol firmware upgrade; but for the HAL function, there is no need to care about the source of the data packet.

    During the OTA upgrade process, Tuya Wi-Fi SDK will receive packets in a loop and notify this function to the OTA data packet. This function completes the work of writing the OTA data packet into the flash.

os_adapter_ota_end_inform

int os_adapter_ota_end_inform(bool reset);
  • Description

    Informs the end of OTA data download.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    reset

    Inform the hal layer whether the download needs to be restarted.

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_OTA_VERIFY_FAILED: verification failed

    OPRT_OS_ADAPTER_OTA_END_INFORM_FAILED: fail

  • Notice

    This notification function will be called after the transmission of the OTA data packet is completed, which needs to be implemented in the secondary function: 1. Release the resources requested by the HAL layer at the beginning of OTA. 2. Do firmware integrity check 3. Modify the OTA parameter area and run the new firmware after restarting 4. Decide whether to restart according to the input parameter reset (restart logic after successful Tuya serial port upgrade is not implemented in this API)

Storage

Tuya HAL Storage provides an interface for flash operations, which can be implemented for your customization requirements.

os_adapter_flash_read

int os_adapter_flash_read(const unsigned int addr, unsigned char *dst, const unsigned int size);
  • Description

    Reads data from flash.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    addr

    The first flash address read.

    [out]

    dst

    The buffer pointer that receives the read data.

    [in]

    size

    The size of the buffer read.

  • Return value

    0: success;

    Other: failure error code

  • Notice

    1. Since it is possible for multiple threads on the Tuya upper layer to call the OS_adapter_FLASH layer API interface simultaneously, the os_adapter_flash_read, OS_adapter_flash_write, and OS_adapter_flash_erase three operation functions need to share the mutex. If the called chip Flash API itself is mutually exclusive, no locking is required.If the calling chip Flash API itself is not mutex exclusive, a mutex is added to the OS_adapter_FLASH layer.

    2. If supported to run on the chip, operating flash may cause the system to tick, after operating Flash need to make up system tick (important).

    3. Read a sector within 3ms.

os_adapter_flash_write

int os_adapter_flash_write(const unsigned int addr, const unsigned char *src, const unsigned int size);
  • Description

    Writes data to flash.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    addr

    Writes the first flash address.

    [in]

    dst

    A buffer pointer to which data is written.

    [in]

    size

    The size of the buffer to be written.

  • Return value

    0: success

    Other: failure error code

  • Notice

    Write a sector within 20ms.

os_adapter_flash_erase

int os_adapter_flash_erase(const unsigned int addr, const unsigned int size);
  • Description

    Erases flash block.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    addr

    Erase the flash first address.

    [in]

    size

    Flash size erased.

  • Return value

    0: success;

    Other: failure error code

  • Notice

    Wipe a sector within 65ms.

os_adapter_storage_get_desc

UNI_STORAGE_DESC_S* os_adapter_storage_get_desc(void);
  • Description

    Gets the KV(key-value) -Flash partition information of the chip SDK for data partitioning of graffiti application.

  • Parameter

    None.

  • Return value

    UNI_STORAGE_DESC_S*: KV- Flash partition information structure pointer.

  • Notice

    1. You can define a static structure variable in os_adapter_storge.c that describes the KV-Flash partition information of the chip for Tuya application data partitioning. For example:

        static UNI_STORAGE_DESC_S storage = {
            SIMPLE_FLASH_START,
            SIMPLE_FLASH_SIZE,
            PARTITION_SIZE,
            SIMPLE_FLASH_SWAP_START,
            SIMPLE_FLASH_SWAP_SIZE,
            SIMPLE_FLASH_KEY_ADDR
        };
      
        UNI_STORAGE_DESC_S* os_adapter_storage_get_desc(void)
        {
            return &storage;
        }
      
    2. Recommended area:

      The partition name

      Description

      Length (recommended value)

      instructions

      SIMPLE_FLASH

      KV data

      0x10000(64K)

      At least 32 k

      SIMPLE_FLASH_SWAP

      Backup area for KV data

      0x4000(16K)

      At least 12 k

      SIMPLE_FLASH_KEY_ADDR

      KV encryption key storage area

      0x1000(4K)

      Size immutable

    3. After KV Flash has determined the Flash partition, it cannot be changed. If there is any change, forward compatibility is not supported.

    4. Tuya authorization information is stored in KV zone.

os_adapter_uf_get_desc

UF_PARTITION_TABLE_S* os_adapter_uf_get_desc(void);
  • Description

    Gets the UF_file-Flash partition information of the chip SDK for the data of the graffiti application.

  • Parameter

    None.

  • Return value

    UF_PARTITION_TABLE_S*: Uf_file-flash partition information structure pointer.

  • Notice

    1. Tuya Uf-file is a Flash storage component of Linux file IO operation API (Open, Write,read,close, etc.). It supports the application layer to operate Flash through uf_file.h interface.

    2. You can define a static structure variable in OS_adapter_storge. C that describes the uf_file-Flash partition information that the chip USES to partition data for Tuya.For example,

        static UF_PARTITION_TABLE_S uf_file = {
            .sector_size = PARTITION_SIZE,
            .uf_partition_num = 2,
            .uf_partition = {
                {xx, 0x8000},
                {xx, 0x18000}
            }
        };
      
    3. Recommended partitions (the combined size of several partitions is not less than 128K) :

      partition name

      Description

      Description length (recommended)

      instructions

      UF_FILE_1

      UF_FILE data 1 block

      0x8000(32K)

      32K, starting position can be adjusted

      UF_FILE_2

      UF_FILE data area 2

      0x18000(96K)

      96K, starting position can be adjusted

Output

The Tuya HAL Output interface provides interfaces for redirecting logs, such as printing to a file or the cloud. These interfaces can be implemented for your customization requirements.

os_adapter_output_log

void os_adapter_output_log(const char *str)
  • Description

    Prints a string.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    str

    String pointer

  • Return value

    Void.

os_adapter_log_close

int os_adapter_log_close(void)
  • Description

    Closes the log I/O pin. The business needs to use log UART IO as normal IO to turn off the UART function.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    str

    String pointer

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_LOG_CLOSE_FAILED: fail

os_adapter_log_open

int os_adapter_log_open(void)
  • Description

    Restores the log I/O pin.

  • Parameter

    None.

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_LOG_OPEN_FAILED: fail

Wi-Fi

Tuya HAL Wi-Fi provides interfaces for Wi-Fi operations that requires different platforms to implement.

os_adapter_wifi_all_ap_scan

int os_adapter_wifi_all_ap_scan(AP_IF_S **ap_ary, unsigned int *num)
  • Description

    Scans all AP information for the current environment.

  • Parameter

    Input or output

    Parameter name

    Description

    [out]

    ap_ary

    Scan results

    [out]

    num

    Number of SCANNED AP

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_AP_SCAN_FAILED: fail

  • Notice

    1. blocking function.

    2. can only scan AP in the current country code channel list.

    3. The ap_ary needs to allocate memory within the API (scan multiple APS, need to allocate contiguous memory space).

    4. The memory is released by the Tuya SDK which actively calls os_adapter_wifi_release_ap.

os_adapter_wifi_assign_ap_scan

int os_adapter_wifi_assign_ap_scan(const char *ssid, AP_IF_S **ap)
  • Description

    Scans AP information for the SSID specified in the current environment.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    ssid

    Specify the ssid

    [out]

    ap

    Scan results

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_AP_SCAN_FAILED: Scan failed

  • Notice

    1. Blocking function.

    2. Only scan AP in the current country code channel list.

    3. When an AP specifying an SSID exists in the environment, the success rate of scanning the SSID is more than 98%.

    4. AP needs to allocate memory within the API (scanning multiple APS requires allocating continuous memory space).

    5. The memory is released by the Tuya SDK which actively calls os_adapter_wifi_release_ap.

os_adapter_wifi_release_ap

int os_adapter_wifi_release_ap(AP_IF_S *ap)
  • Description

    Frees up the AP information resources.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    ap

    Ap information that needs to be released

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_AP_RELEASE_FAILED: fail

os_adapter_wifi_set_cur_channel

int os_adapter_wifi_set_cur_channel(const unsigned char chan)
  • Description

    Sets the signal channel.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    chan

    channel

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_CHAN_SET_FAILED: fail

  • Notice

    1. Failed to set a channel signal outside the current national code channel range.

    2. support to set channels in sniffer callback.

os_adapter_wifi_get_cur_channel

int os_adapter_wifi_get_cur_channel(unsigned char *chan)
  • Description

    Gets the current channel.

  • Parameter

    Input or output

    Parameter name

    Description

    [out]

    chan

    channel

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_CHAN_GET_FAILED: fail

os_adapter_wifi_get_ip

int os_adapter_wifi_get_ip(const WF_IF_E wf, NW_IP_S *ip)
  • Description

    Gets WIFI IP information (IP address, gateway address, address mask).

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    wf

    Wi-Fi model

    [out]

    ip

    IP information

    --------

    --------

    WF_STATION

    station type

    WF_AP

    ap type

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_IP_GET_FAILED: fail

  • Notice

    IP information under different modes (based on transmission reference WF) needs to be distinguished.

os_adapter_wifi_set_mac

int os_adapter_wifi_set_mac(const WF_IF_E wf, const NW_MAC_S *mac)
  • Description

    Sets the MAC address.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    wf

    Wi-Fi model

    [in]

    mac

    The MAC address

    --------

    --------

    WF_STATION

    station type

    WF_AP

    ap type

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_MAC_SET_FAILED: fail

  • Notice

    Permanent effect, no loss of power cut.

os_adapter_wifi_get_mac

int os_adapter_wifi_get_mac(const WF_IF_E wf, NW_MAC_S *mac)
  • Description

    Gets the MAC address.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    wf

    Wi-Fi model

    [out]

    mac

    The MAC address

    --------

    --------

    WF_STATION

    station type

    WF_AP

    ap type

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_MAC_GET_FAILED: fail

  • Notice

    MAC addresses in STATIONAP mode need to distinguish between operating modes (according to transmission parameter WF).

os_adapter_wifi_set_work_mode

int os_adapter_wifi_set_work_mode(const WF_WK_MD_E mode)
  • Description

    Sets the Wi-Fi working mode.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    mode

    Wi-Fi working mode

    --------

    --------

    WWM_LOWPOWER

    Low power consumption (refer to turn off Wi-Fi module)

    N/A

    WWM_SNIFFER

    monitor

    N/A

    WWM_STATION

    station

    N/A

    WWM_SOFTAP

    softap

    N/A

    WWM_STATIONAP

    stationap

    N/A

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_WORKMODE_SET_FAILED: fail

  • Notice

    1. From the power on the device to the call of Tuya entrance, it is required to be within 200ms.

    2. If the device initialization time exceeds 200ms, the bottom layer can make some necessary initialization and then call Tuya entrance.Place the time consuming Wi-Fi initialization on another thread for execution.

    3. Os_adapter_wifi_set_work_mode is the first API that Tuya service calls with Wi-Fi. In this API, it is necessary to determine whether Wi-Fi initialization has ended.If it's not finished, wait here until it's finished before proceeding to the next step (only need to judge once).

    4. If the device is less than 200ms from electric to Tuya entrance, there is no need to consider this point.

os_adapter_wifi_get_work_mode

int os_adapter_wifi_get_work_mode(WF_WK_MD_E *mode)
  • Description

    Gets Wi-Fi working mode.

  • Parameter

    Input or output

    Parameter name

    Description

    [out]

    mode

    Wi-Fi working mode

    --------

    --------

    N/A

    WWM_LOWPOWER

    Low power consumption (refer to turn off Wi-Fi module)

    N/A

    WWM_SNIFFER

    monitor

    N/A

    WWM_STATION

    station

    N/A

    WWM_SOFTAP

    softap

    N/A

    WWM_STATIONAP

    stationap

    N/A

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_WORKMODE_GET_FAILED: fail

os_adapter_wifi_sniffer_set

int os_adapter_wifi_sniffer_set(const bool en, const SNIFFER_CALLBACK cb)
  • Description

    Sets the sniffer function switch.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    en

    Turn sniffer on or off

    [in]

    cb

    Grab packet data callback

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_SNIFFER_SET_FAILED: fail

  • Notice

    The data returned to the application includes the management data.

os_adapter_wifi_ap_start

int os_adapter_wifi_ap_start( const WF_AP_CFG_IF_S *cfg)
  • Description

    Starts AP mode.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    cfg

    AP configuration parameters

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_AP_START_FAILED: fail

  • Notice

    1. According to MAX_CONN, the maximum number of STA can be connected in AP mode.

    2. IP information in AP mode needs to be set according to IP information.

    3. StationAP mode, station Port to connect router, connection process and connection if AP port has connection. The AP port should not be disconnected and broadcast packets can be sent or sent after a failure.

    4. Ez + AP coexistence:

      1. Softap or StationAP mode enables sniffer function and channel switching.

      2. After enabling sniffer, the data thrown back to the callback shall include the device connection request packet of the AP port.

os_adapter_wifi_ap_stop

int os_adapter_wifi_ap_stop(void)
  • Description

    Stops AP mode.

  • Parameter

    None.

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_AP_STOP_FAILED: fail

  • Notice

    1. Different closing logic needs to be done for the current mode of softap or StationAP.

    2. In the mode of StationAP, if the station port terminal is connected, close the AP Port process and the station port cannot be disconnected.

os_adapter_wifi_get_connected_ap_info_v2

int os_adapter_wifi_get_connected_ap_info_v2(FAST_WF_CONNECTED_AP_INFO_V2_S **fast_ap_info)
  • Description

    Gets AP information for fast connection.

  • Parameter

    Input or output

    Parameter name

    Description

    [out]

    fast_ap_info

    Associated AP information

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_APINFO_GET_FAILED: fail

  • Notice

    1. Fast_ap_info needs to dynamically request memory within the API.

    2. Each time the router is reconnected successfully, the router information will be obtained once, and if there is an update, it will be synchronized to Flash.

os_adapter_fast_station_connect_v2

int os_adapter_fast_station_connect_v2(const FAST_WF_CONNECTED_AP_INFO_V2_S *fast_ap_info)
  • Description

    Connects with router quickly.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    fast_ap_info

    Ap information required for fast connection

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_FAST_CONN_FAILED: fail

  • Notice

    This function is not called until the first connection has been connected and restarted.

os_adapter_wifi_station_connect

int os_adapter_wifi_station_connect(const char *ssid, const char *passwd)
  • Description

    Connects with router.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    ssid

    ssid

    [in]

    passwd

    passwd

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_CONN_FAILED: fail

  • Notice

    1. Non-blocking. After starting the connection process successfully, the upper layer will call OS_adapter_wifi_STATION_get_status to query the Wi-Fi connection status every 1s.

    2. The function of automatic re-connection should be enabled. The re-connection time should be less than 1min.

os_adapter_wifi_station_disconnect

int os_adapter_wifi_station_disconnect(void)
  • Description

    Disconnects with router.

  • Parameter

    None.

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_DISCONN_FAILED: fail

os_adapter_wifi_station_get_conn_ap_rssi

int os_adapter_wifi_station_get_conn_ap_rssi(char *rssi)
  • Description

    Gets the signal strength of the associated AP.

  • Parameter

    Input or output

    Parameter name

    Description

    [out]

    rssi

    Signal strength

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_RSSI_GET_FAILED: fail

  • Notice

    1. If the location of the device and router is not moved, multiple RSSI acquisition can only produce a small range of fluctuation.

    2. The location of mobile devices and routers; rsSI acquisition will have corresponding changes.

os_adapter_wifi_get_bssid

int os_adapter_wifi_get_bssid(unsigned char *mac)
  • Description

    Gets the MAC address of the ASSOCIATED AP.

  • Parameter

    Input or output

    Parameter name

    Description

    [out]

    mac

    The MAC address

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_BSSID_GET_FAILED: fail

os_adapter_wifi_station_get_status

int os_adapter_wifi_station_get_status(WF_STATION_STAT_E *stat)
  • Description

    Gets the current connection status of Wi-Fi.

  • Parameter

    Input or output

    Parameter name

    Description

    [out]

    stat

    Connection status

    WSS_IDLE

    N/A

    WSS_CONNECTING

    In the connection

    N/A

    WSS_PASSWD_WRONG

    Password mistake

    N/A

    WSS_CONN_FAIL

    The connection fails

    N/A

    WSS_CONN_SUCCESS

    The connection is successful

    N/A

    WSS_GOT_IP

    DHCP success

    N/A

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_STAT_GET_FAILED: fail

os_adapter_wifi_set_country_code

int os_adapter_wifi_set_country_code(const COUNTRY_CODE_E ccode)
  • Description

    Sets the country code.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    ccode

    Country code

    --------

    --------

    COUNTRY_CODE_CN

    China 1-13

    COUNTRY_CODE_US

    The United States district 1-11

    COUNTRY_CODE_JP

    Japan 1-14

    COUNTRY_CODE_EU

    European1-13 European adaptation needs to be considered

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_CCODE_SET_FAILED: fail

  • Notice

    1. The country code only needs to support China (CN 1-13), US (US 1-11), Japan (JP 1-14) and Europe (EU 1-13).

    2. For different country codes, the requirements are as follows:

      1. When scanning routers, only AP corresponding to channel list of country code can be scanned.

      2. The European region needs to realize the European adaptive function.

      3. When setting the channel, the channel set is not within the range of the channel list of the current country code, and set the channel return error.

os_adapter_wifi_send_mgnt

int os_adapter_wifi_send_mgnt(const unsigned char *buf, const unsigned int len)
  • Description

    Sends management packet data.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    buf

    Manage package data BUF

    [in]

    len

    Manage packet data length

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_MGNT_SEND_FAILED: fail

os_adapter_wifi_register_recv_mgnt_callback

int os_adapter_wifi_register_recv_mgnt_callback(const bool enable, const WIFI_REV_MGNT_CB recv_cb)
  • Description

    Sets whether the application layer receives management package data.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    enable

    Whether to open receive management package data

    [in]

    recv_cb

    Receives the management package data callback

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_MGNT_REG_FAILED: fail

os_adapter_set_wifi_lp_mode

int os_adapter_set_wifi_lp_mode(IN const bool en, IN const unsigned int dtim)
  • Description

    Sets to the low power mode.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    en

    Whether Wi-Fi low power mode is on

    [in]

    dtim

    The dtim parameters

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_WF_LPMODE_SET_FAILED: fail

BLE

Tuya HAL BLE provides an interface to BLE operations that requires different platforms to implement.

ty_bt_param_t

typedef VOID (*TY_BT_MSG_CB)(int id, ty_bt_cb_event_t e, unsigned char *buf, unsigned int len);

typedef struct {
    char name[DEVICE_NAME_LEN]; //Bluetooth name
    ty_bt_mode_t mode; 
    unsigned char link_num; // Maximum number of supported client connections. Default is 1
    TY_BT_MSG_CB cb; // Event and data callback functions
    tuya_ble_data_buf_t adv; // Broadcast content
    tuya_ble_data_buf_t scan_rsp; // The client (APP) scans the response data
}ty_bt_param_t;

ty_bt_scan_info_t

typedef struct {
    ty_bt_scan_type_t scan_type; /* Scan type */
    char name[DEVICE_NAME_LEN]; // Bluetooth name, which takes effect when set to TY_BT_SCAN_BY_NAME
    char bd_addr[6]; //Bluetooth MAC, when set to TY_BT_SCAN_BY_MAC
    char rssi; // After scanning, return the signal strength
    unsigned char channel;  // After scanning, return to the channel
    unsigned char timeout_s; /* Scan timeout, not scanned in the specified time, return failure, the unit is second. */
}ty_bt_scan_info_t;

os_adapter_bt_port_init

int os_adapter_bt_port_init(ty_bt_param_t *p)
  • Description

    Initializes Bluetooth. In cases where RF is shared between Wi-Fi and Bluetooth, this function needs to support multiple calls, that is, it can be called again after tuya_bt_port_deinit turns off Bluetooth.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    p

    Bluetooth parameter structure pointer

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_INVALID_PARM: pass parameter error

    OPRT_OS_ADAPTER_MALLOC_FAILED: Memory application failed

    OPRT_OS_ADAPTER_BT_INIT_FAILED: fail

  • Notice

    1. You cannot add sleep to this function to wait for initialization to complete.

    2. After Bluetooth initialization is complete, the notification is returned to the application layer via the TY_BT_EVENT_ADV_READY event.

os_adapter_bt_port_deinit

int os_adapter_bt_port_deinit(void)
  • Description

    Stops the Bluetooth initialization.

  • Parameter

    None.

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_INVALID_PARM: pass parameter error

    OPRT_OS_ADAPTER_BT_DEINIT_FAILED: fail

  • Notice

    1. In the case of RF sharing between Wi-Fi and Bluetooth, it is necessary to call this function to turn off Bluetooth before turning off Wi-Fi.

    2. In the case of low power consumption, this function is called to turn off Bluetooth to achieve low power consumption.

os_adapter_bt_gap_disconnect

int os_adapter_bt_gap_disconnect(void)
  • Description

    Disconnects via the Bluetooth as a child node.

  • Parameter

    None.

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_INVALID_PARM: pass parameter error

    OPRT_OS_ADAPTER_BT_DISCONN_FAILED: fail

os_adapter_bt_send

int os_adapter_bt_send(unsigned char *data, unsigned char len)
  • Description

    Sends data via the Bluetooth as a child node.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    data

    Pointer to the data

    [in]

    len

    The length of the data

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_INVALID_PARM: pass parameter error

    OPRT_OS_ADAPTER_BT_SEND_FAILED: fail

os_adapter_bt_reset_adv

int os_adapter_bt_reset_adv(tuya_ble_data_buf_t *adv, tuya_ble_data_buf_t *scan_resp)
  • Description

    Resets Bluetooth broadcast content and scan response content.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    adv

    Bluetooth broadcast data

    [in]

    lscan_respen

    Bluetooth scans the response data

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_INVALID_PARM: pass parameter error

    OPRT_OS_ADAPTER_BT_ADV_RESET_FAILED: fail

os_adapter_bt_get_rssi

int os_adapter_bt_get_rssi(signed char *rssi)
  • Description

    Gets the signal strength of Bluetooth.

  • Parameter

    Input or output

    Parameter name

    Description

    [out]

    rssi

    Signal strength pointer

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_INVALID_PARM: pass parameter error

    OPRT_OS_ADAPTER_BT_RSSI_GET_FAILED: fail

os_adapter_bt_start_adv

int os_adapter_bt_start_adv()
  • Description

    Starts Bluetooth broadcasting, using the original parameters.

  • Parameter

    None.

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_INVALID_PARM: pass parameter error

    OPRT_OS_ADAPTER_MALLOC_FAILED: Memory application failed

    OPRT_OS_ADAPTER_BT_ADV_START_FAILED: fail

os_adapter_bt_stop_adv

int os_adapter_bt_stop_adv()
  • Description

    Stops Bluetooth broadcasting.

  • Parameter

    None.

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_INVALID_PARM: pass parameter error

    OPRT_OS_ADAPTER_BT_ADV_STOP_FAILED: fail

9-os_adapter_bt_assign_scan

int os_adapter_bt_assign_scan(ty_bt_scan_info_t *info)
  • Description

    Scans the specified Bluetooth name to obtain Bluetooth information for production testing.

  • Parameter

    Input or output

    Parameter name

    Description

    [inout]

    info

    Bluetooth information

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_INVALID_PARM: pass parameter error

    OPRT_OS_ADAPTER_MALLOC_FAILED: Memory application failed

    OPRT_OS_ADAPTER_BT_SCAN_FAILED: fail

  • Notice

    1. Scan_type is TY_BT_SCAN_BY_NAME, then the beacon for the specific Bluetooth name is scanned.

    2. Scan_type is TY_BT_SCAN_BY_MAC, then the beacon for a particular MAC address is scanned.

    3. The signal strength must be carried in the returned information.

UART

Tuya HAL UART provides the interface for UART operation and requires different platforms to implement it.

TY_UART_PORT_E

typedef enum {
    TY_UART0 = 0x00,
    TY_UART1,
    TY_UART2,
    TY_UART3,
    TY_UART_NUM,
} TY_UART_PORT_E;

The TY_UART0 is the default log port, TY_UART1 is the account, TY_UART2, TY_UART3 is the extension serial port.

The serial port authorized by graffiti upper layer and used by users for docking is TY_UART1. If the serial port set by graffiti is corresponding to the serial port and the core.

The platform is in conflict, please make adjustments in the adaptation layer.

os_adapter_uart_init

int *os_adapter_uart_init(const TY_UART_DEV_S *uart)
  • Description

    Initializes the serial port.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    uart

    Serial port handle, which needs to initialize the relevant parameters

    [in]

    port

    A serial port ID

    [in]

    arg

    Configuration parameters

    [in]

    cb

    UART RX interrupts the callback

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_INVALID_PARM: pass parameter error

    OPRT_OS_ADAPTER_MALLOC_FAILED: Memory application failed

    OPRT_OS_ADAPTER_UART_INIT_FAILED: fail

os_adapter_uart_deinit

int os_adapter_uart_deinit(const TY_UART_PORT_E port)
  • Description

    The serial port de-initialization function.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    port

    A serial port

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_INVALID_PARM: pass parameter error

    OPRT_OS_ADAPTER_UART_DEINIT_FAILED: fail

os_adapter_uart_send_char

int os_adapter_uart_send_char(const TY_UART_PORT_E port, const unsigned char ch)
  • Description

    Sends data via serial port.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    port

    A serial port

    [in]

    ch

    The data to be sent

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_INVALID_PARM: pass parameter error

    OPRT_OS_ADAPTER_UART_SEND_FAILED: fail

os_adapter_uart_pool_read_char

int os_adapter_uart_pool_read_char(const TY_UART_PORT_E port, unsigned char *ch)
  • Description

    Polls data via serial port.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    port

    A serial port

    [out]

    ch

    A pointer to the received data

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_INVALID_PARM: pass parameter error

    OPRT_OS_ADAPTER_UART_READ_FAILED: fail

GPIO

Tuya HAL GPIO provides interfaces to the GPIO operation and requires different platforms to implement it.

os_adapter_gpio_inout_set

int os_adapter_gpio_inout_set(const TY_GPIO_PORT_E port, const bool in)
  • Description

    Sets the GPIO I/O state.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    port

    GPIO PORT

    [in]

    in

    0: output. 1: input.

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_INVALID_PARM: pass parameter error

    OPRT_OS_ADAPTER_MALLOC_FAILED: Memory application failed

    OPRT_OS_ADAPTER_GPIO_INOUT_SET_FAILED: fail

os_adapter_gpio_mode_set

int os_adapter_gpio_mode_set(const TY_GPIO_PORT_E port, const TY_GPIO_MODE_E mode)
  • Description

    Sets the GPIO mode function.

    Mode

    Description

    TY_GPIO_PULLUP

    Pull mode

    TY_GPIO_PULLDOWN

    Dropdown mode

    TY_GPIO_PULLUP_PULLDOWN

    Push-pull output mode

    TY_GPIO_OPENDRAIN

    Open leaky output mode

    TY_GPIO_FLOATING

    Input mode

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    port

    GPIO PORT

    [in]

    mode

    GPIO working mode

  • Return value

    OPRT_OS_ADAPTER_OK: success

    OPRT_OS_ADAPTER_INVALID_PARM: pass parameter error

    OPRT_OS_ADAPTER_MALLOC_FAILED: Memory application failed

    OPRT_OS_ADAPTER_GPIO_MODE_SET_FAILED: fail

os_adapter_gpio_read

int os_adapter_gpio_read(const TY_GPIO_PORT_E port)
  • Description

    Reads the GPIO port level state function.

  • Parameter

    Input or output

    Parameter name

    Description

    [in]

    port