diff --git a/bsp/meta-hisilicon/recipes-bsp/ss928/files/mcu_tool/mcu_tool.c b/bsp/meta-hisilicon/recipes-bsp/ss928/files/mcu_tool/mcu_tool.c index 821b8bb40d56fe23c7520c3a1b6d74060e9c1c0d..5e659dc4564bafcadea5fde6a689e1c4488a9799 100644 --- a/bsp/meta-hisilicon/recipes-bsp/ss928/files/mcu_tool/mcu_tool.c +++ b/bsp/meta-hisilicon/recipes-bsp/ss928/files/mcu_tool/mcu_tool.c @@ -1,14 +1,3 @@ -/** - * Copyright (c) 2024 Ebaina - * hieuler u-boot is licensed under Mulan PSL v2. - * You can use this software according to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * http://license.coscl.org.cn/MulanPSL2 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PSL v2 for more details. - */ #include #include #include @@ -16,36 +5,7 @@ #include #include #include - -enum gpio_type{ - GPIO_SYS_RSTN_IN, - GPIO_NEARLINK_EN, - GPIO_LED, - GPIO_CFG1, - GPIO_CFG2, - GPIO_CFG3, - - GPIO_TYPE_NUM, -}; - -void show_msg(struct i2c_msg* msg) -{ - printf("\tADDR:0x%02x\n",msg->addr); - printf("\tRW:%c\n",(msg->flags==0)?'W':'R'); - printf("\tLEN:0x%x\n",msg->len); - printf("\tDATA:"); - for(int i=0;ilen;i++){ - printf("%02x ",msg->buf[i]); - } - printf("\n"); -} -void show_msg_list(struct i2c_msg* msg,int len) -{ - for(int i=0;i #define FLAG_OCT 1 #define FLAG_DEC 2 @@ -112,10 +72,12 @@ void show_help() "\tmcu [args]\n" "\n" "\t:\n" -"\t\tled \n" +"\t\tversion(ver)\n" +"\t\tled [time_ms]\n" "\t\tnearlink(nl) \n" -"\t\temperature(t)\n" -"\t\tvoltage(v)\n\n" +"\t\ttemperature(t)\n" +"\t\tvoltage(v)\n" +"\t\terror\n\n" ); } @@ -151,67 +113,128 @@ int main(int argc,char*argv[]) return 1; } - if(!strcmp(argv[ARGS_OPT],"led")) { - struct i2c_msg msg; - char buffer[4] = {0x03,0x00,0x02,0x01}; - msg.buf = buffer; - msg.addr = i2c_addr; - msg.flags = 0; - msg.len = 4; - if(!strcmp(argv[ARGS_OPT+1],"off")) - buffer[3] = 0x00; - if(send_msg(i2c_dev,&msg,1)) + struct i2c_msg msgs[2]; + memset(msgs,0,sizeof(struct i2c_msg)*2); + msgs[0].addr = i2c_addr; + msgs[1].addr = i2c_addr; + msgs[1].flags = I2C_M_RD; + + if( + (!strcmp(argv[ARGS_OPT],"version")) || + (!strcmp(argv[ARGS_OPT],"ver"))) { + char buffer[2] = {0x00,0x00}; + msgs[0].buf = buffer; + msgs[0].len = 2; + msgs[1].buf = buffer; + msgs[1].len = 2; + if(send_msg(i2c_dev,msgs,2)) + goto error; + uint16_t * value = (uint16_t*)buffer; + + printf("version: %d.%d.%d\n", ((*value) >> 8) & 0x0F, ((*value) >> 4) & 0x0F, (*value) & 0x0F); + } + else if(!strcmp(argv[ARGS_OPT],"led")) { +#pragma pack(push, 1) +struct led_cmd { + uint8_t cmd; + uint8_t len; + uint8_t led; + uint8_t opt; + uint32_t time_ms; +}; +#pragma pack(pop) + struct led_cmd cmd; + cmd.cmd = 0x01; + switch (argv[ARGS_OPT+1][0]) + { + case 'r': cmd.led = 0x00; break; + case 'g': cmd.led = 0x01; break; + case 'o': cmd.led = 0x02; break; + default: + printf("error led:%s\n",argv[ARGS_OPT+1]); + return -1; + break; + } + + if(!strcmp(argv[ARGS_OPT+2],"on")) { + cmd.opt = 0x00; + cmd.len = 0x02; + } + else if (!strcmp(argv[ARGS_OPT+2],"off")) { + cmd.opt = 0x01; + cmd.len = 0x02; + } + else if (!strcmp(argv[ARGS_OPT+2],"blink")) { + cmd.opt = 0x02; + cmd.len = 0x06; + } + else if (!strcmp(argv[ARGS_OPT+2],"breath")) { + cmd.opt = 0x03; + cmd.len = 0x06; + } + else if (!strcmp(argv[ARGS_OPT+2],"brightness")) { + cmd.opt = 0x04; + cmd.len = 0x06; + } + + if(cmd.opt >= 0x02) { + cmd.time_ms = atoi_auto(argv[ARGS_OPT+3]); + } + + msgs[0].buf = (uint8_t*)&cmd; + msgs[0].len = cmd.len + 2; + if(send_msg(i2c_dev,msgs,1)) goto error; } else if( (!strcmp(argv[ARGS_OPT],"nearlink")) || (!strcmp(argv[ARGS_OPT],"nl"))) { - struct i2c_msg msg; - char buffer[4] = {0x03,0x00,0x01,0x01}; - msg.buf = buffer; - msg.addr = i2c_addr; - msg.flags = 0; - msg.len = 4; - if(!strcmp(argv[ARGS_OPT+1],"off")) - buffer[3] = 0x00; - if(send_msg(i2c_dev,&msg,1)) + + char buffer[4] = {0x02,0x02,0x01,0x00}; + msgs[0].buf = buffer; + msgs[0].len = 4; + if(!strcmp(argv[ARGS_OPT+1],"on")) + buffer[3] = 0x01; + if(send_msg(i2c_dev,msgs,1)) goto error; } else if( (!strcmp(argv[ARGS_OPT],"temperature")) || (!strcmp(argv[ARGS_OPT],"t"))) { - char buffer[6] = {0x01,0x01}; - struct i2c_msg msgs[2]; - msgs[0].addr = i2c_addr; + float temp = 0; + char buffer[2] = {0x03,0x00}; msgs[0].buf = buffer; - msgs[0].flags = 0; msgs[0].len = 2; - msgs[1].addr = i2c_addr; - msgs[1].buf = buffer + 2; - msgs[1].flags = I2C_M_RD; - msgs[1].len = 4; + msgs[1].buf = (uint8_t*)&temp; + msgs[1].len = sizeof(float); if(send_msg(i2c_dev,msgs,2)) goto error; - float* data = (float*)(msgs[1].buf); - printf("%f\n",*data); + printf("%f\n",temp); } else if( (!strcmp(argv[ARGS_OPT],"voltage")) || (!strcmp(argv[ARGS_OPT],"v"))) { - char buffer[6] = {0x01,0x02}; - struct i2c_msg msgs[2]; - msgs[0].addr = i2c_addr; + float temp = 0; + char buffer[2] = {0x04,0x00}; + msgs[0].buf = buffer; + msgs[0].len = 2; + msgs[1].buf = (uint8_t*)&temp; + msgs[1].len = sizeof(float); + if(send_msg(i2c_dev,msgs,2)) + goto error; + printf("%f\n",temp); + } + else if(!strcmp(argv[ARGS_OPT],"error")) { + char buffer[2] = {0x00,0x00}; msgs[0].buf = buffer; - msgs[0].flags = 0; msgs[0].len = 2; - msgs[1].addr = i2c_addr; - msgs[1].buf = buffer + 2; - msgs[1].flags = I2C_M_RD; - msgs[1].len = 4; + msgs[1].buf = buffer; + msgs[1].len = 2; if(send_msg(i2c_dev,msgs,2)) goto error; - float* data = (float*)(msgs[1].buf); - printf("%f\n",*data); + uint16_t * value = (uint16_t*)buffer; + + printf("error count:%d\n", *value); } close(i2c_dev);