接上文【星闪派物联网开发套件体验连载】用HiHope星闪server端发代码控制BearPi
BearPi星闪Client端配置程序不变
int last_led=0;
static void example_ssaps_write_request_cbk(uint8_t server_id,
uint16_t conn_id,
ssaps_req_write_cb_t *write_cb_para,
errcode_t status)
{
PRINT("[SLE Server] ssaps write request cbk server_id:0x%x, conn_id:0x%x, handle:0x%x, status:0x%x\\r\\n", server_id,
conn_id, write_cb_para->handle, status);
// for (uint16_t idx = 0; idx < write_cb_para->length; idx++) {
// PRINT("[SLE Server] write request cbk[0x%x] 0x%02x\\r\\n", idx, write_cb_para->value[idx]);
// }
if (status == ERRCODE_SUCC) {
if (data->data_len == strlen("RLED_ON") && data->data[0] == 'R' && data->data[1] == 'L' && data->data[2] == 'E' &&
data->data[3] == 'D' && data->data[4] == '_' && data->data[5] == 'O' && data->data[6] == 'N') {
last_led=0Xff00;
}
if (data->data_len == strlen("RLED_OFF") && data->data[0] == 'R' && data->data[1] == 'L' && data->data[2] == 'E' &&
data->data[3] == 'D' && data->data[4] == '_' && data->data[5] == 'O' && data->data[6] == 'F' &&
data->data[7] == 'F') {
last_led=0X00;
}
if (data->data_len == strlen("YLED_ON") && data->data[0] == 'Y' && data->data[1] == 'L' && data->data[2] == 'E' &&
data->data[3] == 'D' && data->data[4] == '_' && data->data[5] == 'O' && data->data[6] == 'N') {
last_led=0Xff0000;
}
if (data->data_len == strlen("YLED_OFF") && data->data[0] == 'Y' && data->data[1] == 'L' && data->data[2] == 'E' &&
data->data[3] == 'D' && data->data[4] == '_' && data->data[5] == 'O' && data->data[6] == 'F' &&
data->data[7] == 'F') {
last_led=0X0000;
}
if (data->data_len == strlen("GLED_ON") && data->data[0] == 'G' && data->data[1] == 'L' && data->data[2] == 'E' &&
data->data[3] == 'D' && data->data[4] == '_' && data->data[5] == 'O' && data->data[6] == 'N') {
last_led=0Xff;
}
if (data->data_len == strlen("GLED_OFF") && data->data[0] == 'G' && data->data[1] == 'L' && data->data[2] == 'E' &&
data->data[3] == 'D' && data->data[4] == '_' && data->data[5] == 'O' && data->data[6] == 'F' &&
data->data[7] == 'F') {
last_led=0X00;
}
}
}
增加| 【星闪派物联网开发套件体验连载】核心板三色灯 |部分
选择案例:点击工具栏中的“系统配置”选项,选择Application目录,勾选“Enable Sample”、“Enable the Sample of peripheral”,中选择“support TRICOLORED Sample”,点击Save,关闭弹窗。
在application\samples\peripheral\tricolored\tricolored_sample.c中:
extern int last_led;
void one_num(void)
{
uapi_reg_setbit(0x44028030, 5); // 0x44028030代表GPIO电平拉高寄存器,5代表GPIO5,将gpio5拉高,可以参考platform_core.h
uapi_tcxo_delay_count(8);
uapi_reg_setbit(0x44028034, 5); // 0x44028034代表GPIO电平拉低寄存器,5代表GPIO5,将gpio5拉低,可以参考platform_core.h
uapi_tcxo_delay_us(2);
}
void zero_num(void)
{
uint32_t preg = 0;
preg = preg;
uapi_reg_setbit(0x44028030, 5);
for (int i = 0; i < 7; i++) {
// 由于uapi_tcxo_delay_us在低于1us以后,延时不准确,通过测试发现读一次寄存器大概50ns
uapi_reg_read32(0x44028030, preg);
}
uapi_reg_setbit(0x44028034, 5);
uapi_tcxo_delay_us(2);
}
void green_led(void)
{
for (int i = 0; i < 8; i++) {
one_num();
}
for (int i = 0; i < 8; i++) {
zero_num();
}
for (int i = 0; i < 8; i++) {
zero_num();
}
}
void red_led(void)
{
for (int i = 0; i < 8; i++) {
zero_num();
}
for (int i = 0; i < 8; i++) {
one_num();
}
for (int i = 0; i < 8; i++) {
zero_num();
}
}
void blue_led(void)
{
for (int i = 0; i < 8; i++) {
zero_num();
}
for (int i = 0; i < 8; i++) {
zero_num();
}
for (int i = 0; i < 8; i++) {
one_num();
}
}
static int tricolored_task(const char *arg)
{
UNUSED(arg);
uapi_pin_set_mode(BSP_LED_0, BSP_LED_MODE);
uapi_gpio_set_dir(BSP_LED_0, GPIO_DIRECTION_OUTPUT);
uapi_reg_setbit(0x44028034, 5);
uapi_tcxo_delay_us(100); // 初始化三色灯,等待三色灯正常工作,延时需要大于80us,可以参考三色灯规格书
int last_led1=0;
while(1){
if (last_led1 <> last_led) {
last_led1 = last_led;
for (int i = 0; i < 24; i++) {
if(last_led1&0x1){one_num();}else{zero_num();}
last_led1=last_led1>>1;
}
last_led1 = last_led;
}
osal_mdelay(500);
}
return 0;
}
编译: 点击工具栏中的“重编译”按钮,编译代码
时间比较长。
INFO:root:map_path: ./output/ws63/acore/ws63-liteos-app/ws63-liteos-app.map
INFO:root:compiler_path: d:\bearpi\HiSpark Studio\tools\Windows\cc_riscv32_musl_fp_win\bin
INFO:root:build_config_path: None
INFO:root:prefix: riscv32-linux-musl
INFO:root:environment: windows
INFO:root:undef_addr_sections: ['.debug_info', '.debug_abbrev', '.debug_loc', '.debug_aranges', '.debug_ranges', '.debug_line', '.debug_str', '.comment', '.riscv.attributes', '.debug_frame']
INFO:root:no_size_sections: ['.plat_romtext', '.wifi_romtext', '.btc_romtext', '.bth_romtext', '.bth_romdata', '.plat_rombss', '.plat_text_tcm', '.wifi_text_tcm', '.plat_data_tcm', '.wifi_text_sram', '.btc_text_sram', '.bth_text_sram', '.wifi_data_sram', '.btc_data_sram', '.bth_data_sram', '.heap']
INFO:root:analysis sections: ['.text', '.data', '.bss', 'startup', '.sysintcall.init', '.patch', '.rom_ram_cb_text', '.plat_romdata', '.wifi_romdata', '.btc_romdata', '.bth_rombss', '.wifi_pkt_ram', '.btc_text_tcm', '.patch_on_tcm', '.btc_data_tcm', '.wifi_data_tcm', '.btc_bss_tcm', '.wifi_bss_tcm', '.plat_text_sram', '.patch_on_sram', '.plat_text_flash', '.wifi_text_flash', '.patch_on_flash', '.btc_text_flash', '.bth_text_flash', '.radar_text_flash', '.radar_ai_text_flash', '.btc_data_flash', '.bth_data_flash', '.plat_bss_sram', '.plat_bss_flash', '.wifi_bss_flash', '.radar_bss_flash', '.radar_ai_bss_flash', '.btc_bss_flash', '.bth_bss_flash', '.preserve', '.stacks']
INFO:root:--------------------Load Sections:--------------------
INFO:root:section_name section_size
INFO:root:startup 428
INFO:root:.sysintcall.init 52
INFO:root:.patch 2344
INFO:root:.rom_ram_cb_text 1816
INFO:root:.plat_romdata 212
INFO:root:.wifi_romdata 98
INFO:root:.btc_romdata 672
INFO:root:.btc_text_tcm 7206
INFO:root:.patch_on_tcm 1528
INFO:root:.btc_data_tcm 57
INFO:root:.wifi_data_tcm 3408
INFO:root:.plat_text_sram 10948
INFO:root:.patch_on_sram 2520
INFO:root:.plat_text_flash 176648
INFO:root:.wifi_text_flash 585358
INFO:root:.patch_on_flash 1908
INFO:root:.btc_text_flash 131560
INFO:root:.bth_text_flash 235482
INFO:root:.radar_text_flash 32012
INFO:root:.radar_ai_text_flash 5868
INFO:root:.text 42040
INFO:root:.btc_data_flash 4896
INFO:root:.bth_data_flash 2419
INFO:root:.data 380
INFO:root:total_size: 1249860
INFO:root:------------------------------------------------------
INFO:root:++++++++++++++++++++++++++++++end buildAnalyzer++++++++++++++++++++++++++++++
project analysis Done!
================================ [SUCCESS] Took 172.78 seconds ================================
此程序包括烧录
点击工具栏中的“工程配置”, 找到“程序加载”选项, 选择开发板与电脑连接后映射出来的端口。
点击工具栏中的“程序加载”,按一下开发板的复位按键就会进行烧录![未标题-8 拷贝.png]
下载完毕后,开发板复位,使用串口工具即可查看运行日志,日志打印波特率为115200。
此程序
com信息:
APP|[SLE Adv] set announce data success.APP|[SLE Adv] set sle addr SUCC
[ACore] sle start announce in, adv_id:1
[ACore] sle adv cbk in, event:0 status:0
[ACore] sle adv cbk in, event:1 status:0
[ACore] sle adv cbk in, event:2 status:0
[ACore] sle adv cbk in, event:3 status:0
APP|[SLE Adv] sle announce enable id:01, state:00
APP|[SLE Adv] example_sle_server_adv_init out
APP|[SLE Server] init ok
[Connected]
addr:ee:**:**:**:8d:5c, handle:00
[ACore] sle adv cbk in, event:7 status:0
APP|[SLE Server] connect state changed conn_id:0x00, conn_state:0x1, pair_state: 0x1, disc_reason:0x0
APP|[SLE Server] connect state changed addr:ee:**:**:**:8d:5c
APP|[SLE Adv] sle announce terminal id:01
APP|[SLE Server] pair complete conn_id:0x00, status:0x0
APP|[SLE Server] pair complete addr:ee:**:**:**:8d:5c
APP|[SLE Server] start led control task
APP|[SLE Server] ssaps mtu changed cbk server_id:0x0, conn_id:0x0, mtu_size:0x20 8, status:0x0
APP|[SLE Server] ssaps write request cbk server_id:0x1, conn_id:0x0, handle:0x2, status:0x0
APP|[SLE Server] ssaps write request cbk server_id:0x1, conn_id:0x0, handle:0x2, status:0x0
APP|[SLE Server] ssaps write request cbk server_id:0x1, conn_id:0x0, handle:0x2, status:0x0
APP|[SLE Server] ssaps write request cbk server_id:0x1, conn_id:0x0, handle:0x2, status:0x0
xo update temp:3,diff:0,xo:0x3083c
APP|[SLE Server] ssaps write request cbk server_id:0x1, conn_id:0x0, handle:0x2, status:0x0
APP|[SLE Server] ssaps write request cbk server_id:0x1, conn_id:0x0, handle:0x2, status:0x0
APP|[SLE Server] ssaps write request cbk server_id:0x1, conn_id:0x0, handle:0x2, status:0x0
APP|[SLE Server] ssaps write request cbk server_id:0x1, conn_id:0x0, handle:0x2, status:0x0
update ssap send report handle: pre handle:ffff, current:0
APP|[SLE Server] ssaps write request cbk server_id:0x1, conn_id:0x0, handle:0x2, status:0x0
APP|[SLE Server] ssaps write request cbk server_id:0x1, conn_id:0x0, handle:0x2, status:0x0
APP|[SLE Server] ssaps write request cbk server_id:0x1, conn_id:0x0, handle:0x2, status:0x0
APP|[SLE Server] ssaps write request cbk server_id:0x1, conn_id:0x0, handle:0x2, status:0x0
APP|[SLE Server] ssaps write request cbk server_id:0x1, conn_id:0x0, handle:0x2, status:0x0
APP|[SLE Server] ssaps write request cbk server_id:0x1, conn_id:0x0, handle:0x2, status:0x0
APP|[SLE Server] ssaps write request cbk server_id:0x1, conn_id:0x0, handle:0x2, status:0x0
APP|[SLE Server] ssaps write request cbk server_id:0x1, conn_id:0x0, handle:0x2, status:0x0
APP|[SLE Server] ssaps write request cbk server_id:0x1, conn_id:0x0, handle:0x2, status:0x0
APP|[SLE Server] ssaps write request cbk server_id:0x1, conn_id:0x0, handle:0x2, status:0x0
APP|[SLE Server] ssaps write request cbk server_id:0x1, conn_id:0x0, handle:0x2, status:0x0
APP|[SLE Server] ssaps write request cbk server_id:0x1, conn_id:0x0, handle:0x2, status:0x0
APP|[SLE Server] ssaps write request cbk server_id:0x1, conn_id:0x0, handle:0x2, status:0x0
APP|[SLE Server] ssaps write request cbk server_id:0x1, conn_id:0x0, handle:0x2, status:0x0
APP|[SLE Server] ssaps write request cbk server_id:0x1, conn_id:0x0, handle:0x2, status:0x0
APP|[SLE Server] ssaps write request cbk server_id:0x1, conn_id:0x0, handle:0x2, status:0x0
APP|[SLE Server] ssaps write request cbk server_id:0x1, conn_id:0x0, handle:0x2, status:0x0
APP|[SLE Server] ssaps write request cbk server_id:0x1, conn_id:0x0, handle:0x2, status:0x0
APP|[SLE Server] ssaps write request cbk server_id:0x1, conn_id:0x0, handle:0x2, status:0x0
APP|[SLE Server] ssaps write request cbk server_id:0x1, conn_id:0x0, handle:0x2, status:0x0
APP|[SLE Server] ssaps write request cbk server_id:0x1, conn_id:0x0, handle:0x2, status:0x0
APP|[SLE Server] ssaps write request cbk server_id:0x1, conn_id:0x0, handle:0x2, status:0x0
APP|[SLE Server] ssaps write request cbk server_id:0x1, conn_id:0x0, handle:0x2, status:0x0
APP|[SLE Server] ssaps write request cbk server_id:0x1, conn_id:0x0, handle:0x2, status:0x0
APP|[SLE Server] ssaps write request cbk server_id:0x1, conn_id:0x0, handle:0x2, status:0x0
APP|[SLE Server] ssaps write request cbk server_id:0x1, conn_id:0x0, handle:0x2, status:0x0
APP|[SLE Server] ssaps write request cbk server_id:0x1, conn_id:0x0, handle:0x2, status:0x0
APP|[SLE Server] ssaps write request cbk server_id:0x1, conn_id:0x0, handle:0x2, status:0x0
达到预期状态。
更多回帖