本文主要是天猫蓝牙Mesh开发——SDK目录解析的相关笔记,若笔记中有错误或者不合适的地方,欢迎批评指正😃。
点击查看使用工具及版本
Windows版本 windows11 Ubuntu版本 Ubuntu22.04的64位版本 VMware® Workstation 16 Pro 16.2.3 build-19376536 终端软件 MobaXterm(Professional Edition v23.0 Build 5042 (license))
点击查看本文参考资料
点击查看相关文件下载
一、GPIO 需要知道的是,这个蓝牙开发板里面其实使用的也是AliOSThings的内核,所以对于GPIO的一些接口函数什么的,跟前面学习AliOSThings的时候是一样的。
1. 官方文档 我们可以看一下官方文档:GPIO · 开发指南 (alicdn.com) ,这里有对GPIO接口函数的详细说明:
2. 使用实例 2.1 led.c 点击查看详情
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 #include <stdio.h> #include <aos/aos.h> #include <hal/soc/gpio.h> #include "drivers/8258/gpio_8258.h" #define LED0_PIN TC825X_GET_PIN_NUM(GPIO_PB4) #define LED1_PIN TC825X_GET_PIN_NUM(GPIO_PB5) #define LED2_PIN TC825X_GET_PIN_NUM(GPIO_PC1) static gpio_dev_t led_dev[3 ];int32_t sys_led_init (void ) { int32_t ret = 0 ; led_dev[0 ].port = LED0_PIN; led_dev[0 ].config = OUTPUT_PUSH_PULL; ret = hal_gpio_init(&led_dev[0 ]); if (ret != 0 ) { printf ("gpio init error !\n" ); } led_dev[1 ].port = LED1_PIN; led_dev[1 ].config = OUTPUT_PUSH_PULL; ret = hal_gpio_init(&led_dev[1 ]); if (ret != 0 ) { printf ("gpio init error !\n" ); } led_dev[2 ].port = LED2_PIN; led_dev[2 ].config = OUTPUT_PUSH_PULL; ret = hal_gpio_init(&led_dev[2 ]); if (ret != 0 ) { printf ("gpio init error !\n" ); } return 0 ; } int application_start (int argc, char **argv) { printf ("BUILD_TIME:%s\n" , __DATE__"," __TIME__); sys_led_init(); while (1 ) { hal_gpio_output_toggle(&led_dev[0 ]); hal_gpio_output_toggle(&led_dev[1 ]); hal_gpio_output_toggle(&led_dev[2 ]); aos_msleep(1000 ); } return 0 ; }
2.2 led.mk 点击查看详情
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 NAME := led $(NAME) _COMPONENTS += genie_app bluetooth.bt_host bluetooth.bt_mesh yloop cli$(NAME) _INCLUDES += ../../../../genie_app \ ../../../../genie_app/base \ ../../../../genie_app/bluetooth/host \ ../../../../genie_app/bluetooth/mesh $(NAME) _SOURCES := led.cifeq ($(HOST_MCU_FAMILY) ,ch6121)bt_host_tinycrypt = 0 else ifeq ($(HOST_MCU_FAMILY) ,tg7100b)bt_host_tinycrypt = 0 else ble = 1 bt_mesh = 1 endif en_bt_smp = 1 GLOBAL_DEFINES += CONFIG_BLUETOOTH ifeq ($(HOST_MCU_FAMILY) ,ch6121)GLOBAL_DEFINES += CONFIG_BT_RX_BUF_LEN=252 GLOBAL_DEFINES += CONFIG_BT_L2CAP_TX_MTU=244 GLOBAL_DEFINES += CONFIG_BT_MESH_ADV_BLOCK else ifeq ($(HOST_MCU_FAMILY) ,tg7100b)GLOBAL_DEFINES += CONFIG_BT_RX_BUF_LEN=252 GLOBAL_DEFINES += CONFIG_BT_L2CAP_TX_MTU=244 GLOBAL_DEFINES += CONFIG_BT_MESH_ADV_BLOCK else GLOBAL_DEFINES += CONFIG_BT_SMP GLOBAL_DEFINES += CONFIG_BT_HCI_VS_EXT GLOBAL_DEFINES += CONFIG_BT_TINYCRYPT_ECC endif GLOBAL_DEFINES += CONFIG_BT_CONN GLOBAL_DEFINES += CONFIG_BT_PERIPHERAL GLOBAL_DEFINES += CONFIG_BT_MESH GLOBAL_DEFINES += CONFIG_BT_MESH_PROV GLOBAL_DEFINES += CONFIG_BT_MESH_PB_ADV GLOBAL_DEFINES += CONFIG_BT_MESH_PB_GATT GLOBAL_DEFINES += CONFIG_BT_MESH_PROXY GLOBAL_DEFINES += CONFIG_BT_MESH_GATT_PROXY GLOBAL_DEFINES += CONFIG_BT_MESH_RELAY GLOBAL_DEFINES += CONFIG_BT_MESH_CFG_SRV GLOBAL_DEFINES += CONFIG_BT_MESH_HEALTH_SRV GLOBAL_DEFINES += GENIE_DEBUG_COLOR GLOBAL_DEFINES += MESH_DEBUG_RX GLOBAL_DEFINES += MESH_DEBUG_TX GLOBAL_DEFINES += MESH_DEBUG_PROV GLOBAL_INCLUDES += ../ GLOBAL_DEFINES += PROJECT_SW_VERSION=0x00010000 GLOBAL_DEFINES += PROJECT_SECRET_KEY=\"00112233445566770011223344556677\" MESH_MODEL_GEN_ONOFF_SRV = 1 MESH_MODEL_DIABLE_TRANS = 1 #MESH_MODEL_LIGHTNESS_SRV = 1 #MESH_MODEL_CTL_SRV = 1 #MESH_MODEL_VENDOR_SRV = 1 ALI_SIMPLE_MODLE = 1 GLOBAL_DEFINES += GENIE_OLD_AUTH
3. 编译工程 1 aos make bluetooth.led@tc825x
4. 烧录程序
5. 实验现象 串口会有以下打印信息:
然后我们会看到三个灯同时间隔1秒闪烁。
二、PWM 1. 官方文档 文档接口说明在这里:PWM · 开发指南 (alicdn.com)
2. 使用实例 2.1 pwm.c 点击查看详情
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 #include <stdio.h> #include <aos/aos.h> #include <hal/soc/gpio.h> #include <hal/soc/pwm.h> #include "drivers/8258/gpio_8258.h" #define BLUE_LED_PWM #define LED0_PIN TC825X_GET_PIN_NUM(GPIO_PB4) #define LED1_PIN TC825X_GET_PIN_NUM(GPIO_PB5) #define LED2_PIN TC825X_GET_PIN_NUM(GPIO_PC1) static gpio_dev_t led_dev[3 ] = {0 };int32_t sys_led_init (void ) { int32_t ret = 0 ; led_dev[0 ].port = LED0_PIN; led_dev[0 ].config = OUTPUT_PUSH_PULL; ret = hal_gpio_init(&led_dev[0 ]); if (ret != 0 ) { printf ("gpio init error !\n" ); } led_dev[1 ].port = LED1_PIN; led_dev[1 ].config = OUTPUT_PUSH_PULL; ret = hal_gpio_init(&led_dev[1 ]); if (ret != 0 ) { printf ("gpio init error !\n" ); } #ifndef BLUE_LED_PWM led_dev[2 ].port = LED2_PIN; led_dev[2 ].config = OUTPUT_PUSH_PULL; ret = hal_gpio_init(&led_dev[2 ]); if (ret != 0 ) { printf ("gpio init error !\n" ); } #endif printf ("++++++++++ led init! ++++++++++\n" ); return ret; } #ifdef BLUE_LED_PWM void hal_pwm_app_dynamic_out (void ) { int cnt; int32_t ret; pwm_dev_t pwm = {0 }; printf ("hal_pwm_app_dynamic_out start\r\n" ); pwm.port = LED2_PIN; pwm.config.freq = 1000 ; pwm.config.duty_cycle = 0.00 ; pwm.priv = NULL ; ret = hal_pwm_init(&pwm); if (ret){ printf ("hal_pwm_init fail,ret:%d\r\n" ,ret); return ; } hal_pwm_start(&pwm); cnt = 10 ; while (cnt--) { printf ("duty_cycle count up cnt=%d\r\n" , cnt); pwm_config_t para = {0.000 , 1000 }; for (int i = 0 ; i < 100 ; i++) { para.duty_cycle += 0.01 ; aos_msleep(10 ); hal_pwm_para_chg(&pwm, para); } printf ("duty_cycle count down cnt=%d\r\n" , cnt); para.duty_cycle = 1.0 ; para.freq = 1000 ; for (int i = 0 ; i < 100 ; i++) { para.duty_cycle -= 0.01 ; aos_msleep(10 ); hal_pwm_para_chg(&pwm, para); } } hal_pwm_stop(&pwm); hal_pwm_finalize(&pwm); printf ("hal_pwm_app_dynamic_out end!\r\n" ); } #endif int application_start (int argc, char **argv) { printf ("BUILD_TIME:%s\n" , __DATE__"," __TIME__); sys_led_init(); #ifdef BLUE_LED_PWM hal_pwm_app_dynamic_out(); #endif while (1 ) { hal_gpio_output_toggle(&led_dev[0 ]); aos_msleep(1000 ); } return 0 ; }
2.2 pwm.mk 点击查看详情
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 NAME := pwm $(NAME)_COMPONENTS += genie_app bluetooth.bt_host bluetooth.bt_mesh yloop cli $(NAME)_INCLUDES += ../../../../genie_app \ ../../../../genie_app/base \ ../../../../genie_app/bluetooth/host \ ../../../../genie_app/bluetooth/mesh $(NAME)_SOURCES := pwm.c ifeq ($(HOST_MCU_FAMILY),ch6121) bt_host_tinycrypt = 0 else ifeq ($(HOST_MCU_FAMILY),tg7100b)bt_host_tinycrypt = 0 else ble = 1 bt_mesh = 1 endif en_bt_smp = 1 # Host configurations GLOBAL_DEFINES += CONFIG_BLUETOOTH ifeq ($(HOST_MCU_FAMILY),ch6121) GLOBAL_DEFINES += CONFIG_BT_RX_BUF_LEN=252 GLOBAL_DEFINES += CONFIG_BT_L2CAP_TX_MTU=244 GLOBAL_DEFINES += CONFIG_BT_MESH_ADV_BLOCK else ifeq ($(HOST_MCU_FAMILY),tg7100b)GLOBAL_DEFINES += CONFIG_BT_RX_BUF_LEN=252 GLOBAL_DEFINES += CONFIG_BT_L2CAP_TX_MTU=244 GLOBAL_DEFINES += CONFIG_BT_MESH_ADV_BLOCK else GLOBAL_DEFINES += CONFIG_BT_SMP GLOBAL_DEFINES += CONFIG_BT_HCI_VS_EXT GLOBAL_DEFINES += CONFIG_BT_TINYCRYPT_ECC endif GLOBAL_DEFINES += CONFIG_BT_CONN #GLOBAL_DEFINES += CONFIG_BT_CENTRAL GLOBAL_DEFINES += CONFIG_BT_PERIPHERAL #GLOBAL_DEFINES += CONFIG_BLE_50 # Mesh function select GLOBAL_DEFINES += CONFIG_BT_MESH GLOBAL_DEFINES += CONFIG_BT_MESH_PROV GLOBAL_DEFINES += CONFIG_BT_MESH_PB_ADV GLOBAL_DEFINES += CONFIG_BT_MESH_PB_GATT GLOBAL_DEFINES += CONFIG_BT_MESH_PROXY GLOBAL_DEFINES += CONFIG_BT_MESH_GATT_PROXY GLOBAL_DEFINES += CONFIG_BT_MESH_RELAY #GLOBAL_DEFINES += CONFIG_BT_MESH_FRIEND #GLOBAL_DEFINES += CONFIG_BT_MESH_LOW_POWER #GLOBAL_DEFINES += CONFIG_BT_MESH_SHELL #GLOBAL_DEFINES += CONFIG_BT_MESH_BQB #GLOBAL_DEFINES += CONFIG_BT_MESH_IV_UPDATE_TEST # Mesh foundation model select GLOBAL_DEFINES += CONFIG_BT_MESH_CFG_SRV GLOBAL_DEFINES += CONFIG_BT_MESH_HEALTH_SRV # Mesh debug message enable #GLOBAL_DEFINES += USE_BT_MESH_CUSTOM_LOG GLOBAL_DEFINES += GENIE_DEBUG_COLOR GLOBAL_DEFINES += MESH_DEBUG_RX GLOBAL_DEFINES += MESH_DEBUG_TX GLOBAL_DEFINES += MESH_DEBUG_PROV #GLOBAL_DEFINES += CONFIG_INIT_STACKS #GLOBAL_DEFINES += CONFIG_PRINTK GLOBAL_INCLUDES += ../ GLOBAL_DEFINES += PROJECT_SW_VERSION=0x00010000 GLOBAL_DEFINES += PROJECT_SECRET_KEY=\"00112233445566770011223344556677\" MESH_MODEL_GEN_ONOFF_SRV = 1 MESH_MODEL_DIABLE_TRANS = 1 #MESH_MODEL_LIGHTNESS_SRV = 1 #MESH_MODEL_CTL_SRV = 1 #MESH_MODEL_VENDOR_SRV = 1 ALI_SIMPLE_MODLE = 1 GLOBAL_DEFINES += GENIE_OLD_AUTH
3. 编译工程 1 aos make bluetooth.pwm@tc825x
4. 烧录程序
5. 实验现象
蓝灯会由亮变暗,再由暗变量重复10次,然后红灯开始闪烁。