1+ /**
2+ * @file tuya_t5ai_core.c
3+ * @brief tuya_t5ai_core module is used to
4+ * @version 0.1
5+ * @copyright Copyright (c) 2021-2025 Tuya Inc. All Rights Reserved.
6+ */
7+
8+ #include "tuya_cloud_types.h"
9+
10+ #include "tal_api.h"
11+
12+ #include "tdd_audio.h"
13+ #include "tdd_led_gpio.h"
14+ #include "tdd_button_gpio.h"
15+ /***********************************************************
16+ ************************macro define************************
17+ ***********************************************************/
18+ #define BOARD_SPEAKER_EN_PIN TUYA_GPIO_NUM_39
19+
20+ #define BOARD_BUTTON_PIN TUYA_GPIO_NUM_29
21+ #define BOARD_BUTTON_ACTIVE_LV TUYA_GPIO_LEVEL_LOW
22+
23+ #define BOARD_LED_PIN TUYA_GPIO_NUM_9
24+ #define BOARD_LED_ACTIVE_LV TUYA_GPIO_LEVEL_HIGH
25+
26+ /***********************************************************
27+ ***********************typedef define***********************
28+ ***********************************************************/
29+
30+ /***********************************************************
31+ ********************function declaration********************
32+ ***********************************************************/
33+
34+ /***********************************************************
35+ ***********************variable define**********************
36+ ***********************************************************/
37+
38+ /***********************************************************
39+ ***********************function define**********************
40+ ***********************************************************/
41+ OPERATE_RET __board_register_audio (void )
42+ {
43+ OPERATE_RET rt = OPRT_OK ;
44+
45+ #if defined(AUDIO_CODEC_NAME )
46+ TDD_AUDIO_T5AI_T cfg = {0 };
47+ memset (& cfg , 0 , sizeof (TDD_AUDIO_T5AI_T ));
48+
49+ cfg .aec_enable = 1 ;
50+
51+ cfg .ai_chn = TKL_AI_0 ;
52+ cfg .sample_rate = TKL_AUDIO_SAMPLE_16K ;
53+ cfg .data_bits = TKL_AUDIO_DATABITS_16 ;
54+ cfg .channel = TKL_AUDIO_CHANNEL_MONO ;
55+
56+ cfg .spk_sample_rate = TKL_AUDIO_SAMPLE_16K ;
57+ cfg .spk_pin = BOARD_SPEAKER_EN_PIN ;
58+ cfg .spk_pin_polarity = TUYA_GPIO_LEVEL_LOW ;
59+
60+ TUYA_CALL_ERR_RETURN (tdd_audio_register (AUDIO_CODEC_NAME , cfg ));
61+ #endif
62+ return rt ;
63+ }
64+
65+ static OPERATE_RET __board_register_button (void )
66+ {
67+ OPERATE_RET rt = OPRT_OK ;
68+
69+ #if defined(BUTTON_NAME )
70+ BUTTON_GPIO_CFG_T button_hw_cfg = {
71+ .pin = BOARD_BUTTON_PIN ,
72+ .level = BOARD_BUTTON_ACTIVE_LV ,
73+ .mode = BUTTON_TIMER_SCAN_MODE ,
74+ .pin_type .gpio_pull = TUYA_GPIO_PULLUP ,
75+ };
76+
77+ TUYA_CALL_ERR_RETURN (tdd_gpio_button_register (BUTTON_NAME , & button_hw_cfg ));
78+ #endif
79+
80+ return rt ;
81+ }
82+
83+ static OPERATE_RET __board_register_led (void )
84+ {
85+ OPERATE_RET rt = OPRT_OK ;
86+
87+ #if defined(LED_NAME )
88+ TDD_LED_GPIO_CFG_T led_gpio ;
89+
90+ led_gpio .pin = BOARD_LED_PIN ;
91+ led_gpio .level = BOARD_LED_ACTIVE_LV ;
92+ led_gpio .mode = TUYA_GPIO_PUSH_PULL ;
93+
94+ TUYA_CALL_ERR_RETURN (tdd_led_gpio_register (LED_NAME , & led_gpio ));
95+ #endif
96+
97+ return rt ;
98+ }
99+
100+ /**
101+ * @brief Registers all the hardware peripherals (audio, button, LED) on the board.
102+ *
103+ * @return Returns OPERATE_RET_OK on success, or an appropriate error code on failure.
104+ */
105+ OPERATE_RET board_register_hardware (void )
106+ {
107+ OPERATE_RET rt = OPRT_OK ;
108+
109+ TUYA_CALL_ERR_LOG (__board_register_audio ());
110+
111+ TUYA_CALL_ERR_LOG (__board_register_button ());
112+
113+ TUYA_CALL_ERR_LOG (__board_register_led ());
114+
115+ return rt ;
116+ }
0 commit comments