本帖最后由 及辰 于 2024-10-16 21:32 编辑
一、产品开箱
首先感谢安信可赠送的小安派。
开箱视频如下:
小安派R2测评---开箱_哔哩哔哩_bilibili
物品清单:
小安派R2清单
里面包括:小安派 R2 开发板*1,摄像头模组-酷视 CV031C50 *1,4 寸触摸显示屏-优奕 UE040WV *1,65dB 咪头 *1,8R2W 扬声器 *2,及连接线 2 条。
问题:内部包装十分十分仔细,但是外包装纸壳太软,容易导致内部硬件损坏。
二、环境搭建
本次编译采用的是VScode,环境搭建参考:零基础搭建小安派Windows 开发环境 - 小安派&M61环境搭建、编译烧录教程 - 物联网开发者社区-安信可论坛 - Powered by Discuz! (ai-thinker.com)
其中编译的时候遇到问题:
这个问题的解决办法为:打开aithinker_Ai-M6X_SDK\project.build文件,编辑它,对第75和76行开头加上“#”,意思是注释掉这2行,记得保存.
修改后代码如下
# cp $(BL_SDK_BASE)/bsp/board/bl616dk/config/edata.bin build/build_out
# cp $(BL_SDK_BASE)/bsp/board/bl616dk/config/Rx_boot2_m61.bin build/build_out
三、例程测试
此时测试例程,由于没有板载LED(这里还是比较推荐有一个板载LED),否则没有屏幕还真不好测试板子是否正常。先对板载例程进行测试,视频如下:
重新烧录LVGL官方例程,代码编译采用make,烧录采用make flash COMX=COM3,其中COM3是当前连接开发板的端口,采用USB转TTL,连线图如下:
例程运行视频如下:
小安派R2测评---官方dome演示_哔哩哔哩_bilibili
四、LVGL搭建与测试
LVGL搭建在原本的例程AiPi-Eyes-Rx上进行修改,由于这里LVGL已经配置完成,下载guiguider后,进行自己的屏幕设计,设计完成后点击生成代码,然后将generated文件夹替换demos\ai_lvgl\src\generated即可。具体操作方法及效果演示见视频:
小安派R2测评---LVGL_哔哩哔哩_bilibili
五、SPI读取TF卡及FATFS文件系统
用连接线连接板载SPI接口和TF卡模块(或者焊接背面的TF卡卡槽)注意修改相应的接口,连接图如下:
SPI初始化代码参考aithinker_Ai-M6X_SDK\examples\peripherals\spi\spi_poll,其中关键代码,及需要修改如下:
SPI代码部分,这个自己创建和文件书写就可以。
- void spi_isr(int irq, void *arg)
- {
- uint32_t intstatus = bflb_spi_get_intstatus(spi0);
- if (intstatus & SPI_INTSTS_TC) {
- bflb_spi_int_clear(spi0, SPI_INTCLR_TC);
- //printf("tc done\r\n");
- spi_tc_done_count++;
- }
- if (intstatus & SPI_INTSTS_TX_FIFO) {
- //printf("tx fifo\r\n");
- }
- if (intstatus & SPI_INTSTS_RX_FIFO) {
- //printf("rx fifo\r\n");
- }
- }
- void SPI_init(u32 freqm)
- {
- struct bflb_spi_config_s spi_cfg =
- {
- #if (SPI_CASE_SELECT == SPI_MASTER_CASE)
- .freq = freqm,
- .role = SPI_ROLE_MASTER,
- #else
- .freq = 32 * 1000 * 1000,
- .role = SPI_ROLE_SLAVE,
- #endif
- .mode = SPI_MODE3,
- .data_width = SPI_DATA_WIDTH_8BIT,
- .bit_order = SPI_BIT_MSB,
- .byte_order = SPI_BYTE_LSB,
- .tx_fifo_threshold = 0,
- .rx_fifo_threshold = 0,
- };
- spi0 = bflb_device_get_by_name("spi0");
- bflb_spi_init(spi0, &spi_cfg);
- bflb_spi_tcint_mask(spi0, false);
- bflb_irq_attach(spi0->irq_num, spi_isr, NULL);
- bflb_irq_enable(spi0->irq_num);
- bflb_spi_feature_control(spi0, SPI_CMD_SET_CS_INTERVAL, 0);
- }
复制代码 打开board.h,修改
- void board_spi0_gpio_init()
- {
- struct bflb_device_s* gpio;
- gpio = bflb_device_get_by_name("gpio");
- /* spi cs */
- bflb_gpio_init(gpio, GPIO_PIN_20, GPIO_FUNC_SPI0 | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
- /* spi clk */
- bflb_gpio_init(gpio, GPIO_PIN_17, GPIO_FUNC_SPI0 | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
- /* spi miso */
- bflb_gpio_init(gpio, GPIO_PIN_22, GPIO_FUNC_SPI0 | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
- /* spi mosi */
- bflb_gpio_init(gpio, GPIO_PIN_15, GPIO_FUNC_SPI0 | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
- }
复制代码 SPI读取TF卡代码如下:
- u8 SD_Initialize(void)
- {
- u8 r1; // 存放SD卡的返回值
- u16 retry; // 用来进行超时计数
- u8 buf[4];
- u16 i;
- SPI_init(281000); //设置到低速模式
- SD_DisSelect();
- for(i=0;i<10;i++)
- {
- SD_SPI_ReadWriteByte(0XFF); //发送最少74个脉冲
- }
- retry=20;
- do
- {
- r1=SD_SendCmd(CMD0,0,0x95); //进入IDLE状态
- }while((r1!=0X01) && retry--);
- SD_DisSelect();
- SD_Type=0; //默认无卡
- if(r1==0X01)
- {
- r1=SD_SendCmd(CMD8,0x1AA,0x87);
- if(r1==1)
- {
- for(i=0;i<4;i++)
- {
- buf[i]=SD_SPI_ReadWriteByte(0xFF);
- }
- SD_DisSelect();
- if(buf[2]==0X01&&buf[3]==0XAA)
- {
- retry=0XFFFE;
- do
- {
- r1=SD_SendCmd(CMD55,0,0x01); //发送CMD55
- r1=SD_SendCmd(0x69,0x40000000,0x01);//发送CMD41
- SD_DisSelect();
- }while(r1&&retry--);
- if(retry&&SD_SendCmd(CMD58,0,0X01)==0)//鉴别SD2.0卡版本开始
- {
- for(i=0;i<4;i++)
- {
- buf[i]=SD_SPI_ReadWriteByte(0xFF);
- }
- SD_DisSelect();
- if(buf[0]&0x40)
- {
- SD_Type=SD_TYPE_V2HC; //检查CCS
- }
- else
- {
- SD_Type=SD_TYPE_V2;
- }
- }
- }
- }
- else//SD V1.x/ MMC V3
- {
- SD_SendCmd(CMD55,0,0X01); //发送CMD55
- r1=SD_SendCmd(CMD41,0,0X01); //发送CMD41
- SD_DisSelect();
- if(r1<=1)
- {
- SD_Type=SD_TYPE_V1;
- retry=0XFFFE;
- do //等待退出IDLE模式
- {
- SD_SendCmd(CMD55,0,0X01); //发送CMD55
- r1=SD_SendCmd(CMD41,0,0X01);//发送CMD41
- SD_DisSelect();
- }while(r1&&retry--);
- }
- else//MMC卡不支持CMD55+CMD41识别
- {
- SD_Type=SD_TYPE_MMC;//MMC V3
- retry=0XFFFE;
- do //等待退出IDLE模式
- {
- r1=SD_SendCmd(CMD1,0,0X01);//发送CMD1
- SD_DisSelect();
- }while(r1&&retry--);
- }
- r1=SD_SendCmd(CMD16,512,0X01);
- SD_DisSelect();
- if(retry==0||r1!=0)
- {
- SD_Type=SD_TYPE_ERR;//错误的卡
- }
- }
- }
- SD_DisSelect();
- SPI_init(16000000);
- if(SD_Type)
- {
- return 0;
- }
- else if(r1)
- {
- return r1;
- }
- return 0xaa;//其他错误
- }
复制代码- u8 SD_SPI_ReadWriteByte(u8 data)
- {
- u8 retnum;
- Spi_Send_Read_Data_Arr(&data,&retnum,1);
- return retnum;
- }
- void SD_DisSelect(void)
- {
- SD_SPI_ReadWriteByte(0XFF);//提供额外的8个时钟
- }
- u8 SD_WaitReady(void)
- {
- u32 t=0;
- u8 rStr=0;
- do
- {
- rStr=SD_SPI_ReadWriteByte(0xFF);
- if(rStr==0XFF)
- {
- return 0;//OK
- }
- t++;
- }while(t<0XFFFFFF);//等待
- return 1;
- }
- u8 SD_Select(void)
- {
- if(SD_WaitReady()==0)
- {
- return 0;//等待成功
- }
- SD_DisSelect();
- return 1;//等待失败
- }
- u8 SD_SendCmd(u8 cmd, u32 arg, u8 crc)
- {
- u8 r1;
- u8 Retry=0;
- SD_DisSelect();
- if(SD_Select())return 0XFF;//片选失效
- //发送
- SD_SPI_ReadWriteByte(cmd | 0x40);//分别写入命令
- SD_SPI_ReadWriteByte((u8)(arg >> 24));
- SD_SPI_ReadWriteByte((u8)(arg >> 16));
- SD_SPI_ReadWriteByte((u8)(arg >> 8));
- SD_SPI_ReadWriteByte((u8)(arg));
- SD_SPI_ReadWriteByte(crc);
- if(cmd==12)
- {
- SD_SPI_ReadWriteByte(0xff);//Skip a stuff byte when stop reading
- }
- //等待响应,或超时退出
- Retry=0X1F;
- do
- {
- r1=SD_SPI_ReadWriteByte(0xFF);
- }while((r1&0X80) && Retry--);
- //返回状态值
- return r1;
- }
复制代码- u8 SD_RecvData(u8*buf,u16 len)
- {
- if(SD_GetResponse(0xFE)) //等待SD卡发回数据起始令牌0xFE
- {
- return 1;
- }
- while(len--)//开始接收数据
- {
- *buf=SD_SPI_ReadWriteByte(0xFF);
- buf++;
- }
- //下面是2个伪CRC(dummy CRC)
- SD_SPI_ReadWriteByte(0xFF);
- SD_SPI_ReadWriteByte(0xFF);
- return 0;//读取成功
- }
- u8 SD_GetResponse(u8 Response)
- {
- u16 Count=0xFFFF;//等待次数
- while ((SD_SPI_ReadWriteByte(0xFF)!=Response)&&Count) //等待得到准确的回应
- {
- Count--;
- }
- if (Count==0)
- {
- return MSD_RESPONSE_FAILURE; //得到回应失败
- }
- else
- {
- return MSD_RESPONSE_NO_ERROR; //正确回应
- }
- }
- u8 SD_ReadDisk(u8*buf,u32 sector,u8 cnt)
- {
- u8 r1;
- if(SD_Type!=SD_TYPE_V2HC)sector <<= 9; //转换为字节地址
- if(cnt==1)
- {
- r1=SD_SendCmd(CMD17,sector,0X01); //读命令
- if(r1==0) //指令发送成功
- {
- r1=SD_RecvData(buf,512); //接收512个字节
- }
- }
- else
- {
- r1=SD_SendCmd(CMD18,sector,0X01); //连续读命令
- do
- {
- r1=SD_RecvData(buf,512); //接收512个字节
- buf+=512;
- }while(--cnt && r1==0);
- SD_SendCmd(CMD12,0,0X01); //发送停止命令
- }
- SD_DisSelect(); //取消片选
- return r1;
- }
- u8 SD_WriteDisk(u8 *buf,u32 sector,u8 cnt)
- {
- u8 r1;
- if(SD_Type!=SD_TYPE_V2HC)sector *= 512; //转换为字节地址
- if(cnt==1)
- {
- r1=SD_SendCmd(CMD24,sector,0X01); //读命令
- if(r1==0) //指令发送成功
- {
- r1=SD_SendBlock(buf,0xFE); //写512个字节
- }
- }
- else
- {
- if(SD_Type!=SD_TYPE_MMC)
- {
- SD_SendCmd(CMD55,0,0X01);
- SD_SendCmd(CMD23,cnt,0X01); //发送指令
- }
- r1=SD_SendCmd(CMD25,sector,0X01); //连续读命令
- if(r1==0)
- {
- do
- {
- r1=SD_SendBlock(buf,0xFC); //接收512个字节
- buf+=512;
- }while(--cnt && r1==0);
- r1=SD_SendBlock(0,0xFD); //接收512个字节
- }
- }
- SD_DisSelect(); //取消片选
- return r1;
- }
- u8 SD_SendBlock(u8*buf,u8 cmd)
- {
- u16 t;
- if(SD_WaitReady())return 1;//等待准备失效
- SD_SPI_ReadWriteByte(cmd);
- if(cmd!=0XFD)//不是结束指令
- {
- for(t=0;t<512;t++)
- {
- SD_SPI_ReadWriteByte(buf[t]);//提高速度,减少函数传参时间
- }
- SD_SPI_ReadWriteByte(0xFF);//忽略crc
- SD_SPI_ReadWriteByte(0xFF);
- t=SD_SPI_ReadWriteByte(0xFF);//接收响应
- if((t&0x1F)!=0x05)return 2;//响应错误
- }
- return 0;//写入成功
- }
复制代码 FATFS系统修改代码块如下:
打开diskio.c,修改如下部分:
disk_initialize函数:
- case SD_CARD://SD卡
- res = SD_Initialize();//SD_Initialize()
- if(res)//STM32 SPI的bug,在sd卡操作失败的时候如果不执行下面的语句,可能导致SPI读写异常
- {
- SPI_init(281000);
- SD_SPI_ReadWriteByte(0xff);//提供额外的8个时钟
- SPI_init(16000000);
- }
- break;
复制代码 disk_read函数:
- case SD_CARD://SD卡
- res=SD_ReadDisk(buff,sector,(u8)count);
- if(res)//STM32 SPI的bug,在sd卡操作失败的时候如果不执行下面的语句,可能导致SPI读写异常
- {
- SPI_init(281000);
- SD_SPI_ReadWriteByte(0xff);//提供额外的8个时钟
- SPI_init(16000000);
- }
- break;
复制代码 disk_write函数:
- case SD_CARD://SD卡
- res=SD_WriteDisk((u8*)buff,sector,(u8)count);
- break;
复制代码 disk_ioctl函数:
- if(pdrv==SD_CARD)//SD卡
- {
- switch(cmd)
- {
- case CTRL_SYNC:
- SD_Select();
- if(SD_WaitReady()==0)
- res = RES_OK;
- else
- res = RES_ERROR;
- SD_DisSelect();
- break;
- case GET_SECTOR_SIZE:
- *(WORD*)buff = 512;
- res = RES_OK;
- break;
- case GET_BLOCK_SIZE:
- *(WORD*)buff = 8;
- res = RES_OK;
- break;
- case GET_SECTOR_COUNT:
- *(DWORD*)buff = SD_GetSectorCount();
- res = RES_OK;
- break;
- default:
- res = RES_PARERR;
- break;
- }
- }
复制代码 get_fattime函数:
- DWORD get_fattime (void)
- {
- //rtc_time_t RTC_Timer;
- //R_RTC_CalendarTimeGet (rtc.p_ctrl, &RTC_Timer); //获取RTC计数时间
- return (DWORD)((81-80)<<25| //年
- (10+1)<<21| //月
- (21+1)<<16| //日
- 12<<11| //时
- 21<<5| //分
- 22); //秒
- }
复制代码 如果有系统时间,可以把系统时间放进去,如果没有直接随便给一个就行。
文件系统的其他文件直接复制到文件夹内就可以使用了,具体接口如下:
- FRESULT f_open (FIL* fp, const TCHAR* path, BYTE mode); /* Open or create a file */
- FRESULT f_close (FIL* fp); /* Close an open file object */
- FRESULT f_read (FIL* fp, void* buff, UINT btr, UINT* br); /* Read data from the file */
- FRESULT f_write (FIL* fp, const void* buff, UINT btw, UINT* bw); /* Write data to the file */
- FRESULT f_lseek (FIL* fp, FSIZE_t ofs); /* Move file pointer of the file object */
- FRESULT f_truncate (FIL* fp); /* Truncate the file */
- FRESULT f_sync (FIL* fp); /* Flush cached data of the writing file */
- FRESULT f_opendir (DIR* dp, const TCHAR* path); /* Open a directory */
- FRESULT f_closedir (DIR* dp); /* Close an open directory */
- FRESULT f_readdir (DIR* dp, FILINFO* fno); /* Read a directory item */
- FRESULT f_findfirst (DIR* dp, FILINFO* fno, const TCHAR* path, const TCHAR* pattern); /* Find first file */
- FRESULT f_findnext (DIR* dp, FILINFO* fno); /* Find next file */
- FRESULT f_mkdir (const TCHAR* path); /* Create a sub directory */
- FRESULT f_unlink (const TCHAR* path); /* Delete an existing file or directory */
- FRESULT f_rename (const TCHAR* path_old, const TCHAR* path_new); /* Rename/Move a file or directory */
- FRESULT f_stat (const TCHAR* path, FILINFO* fno); /* Get file status */
- FRESULT f_chmod (const TCHAR* path, BYTE attr, BYTE mask); /* Change attribute of a file/dir */
- FRESULT f_utime (const TCHAR* path, const FILINFO* fno); /* Change timestamp of a file/dir */
- FRESULT f_chdir (const TCHAR* path); /* Change current directory */
- FRESULT f_chdrive (const TCHAR* path); /* Change current drive */
- FRESULT f_getcwd (TCHAR* buff, UINT len); /* Get current directory */
- FRESULT f_getfree (const TCHAR* path, DWORD* nclst, FATFS** fatfs); /* Get number of free clusters on the drive */
- FRESULT f_getlabel (const TCHAR* path, TCHAR* label, DWORD* vsn); /* Get volume label */
- FRESULT f_setlabel (const TCHAR* label); /* Set volume label */
- FRESULT f_forward (FIL* fp, UINT(*func)(const BYTE*,UINT), UINT btf, UINT* bf); /* Forward data to the stream */
- FRESULT f_expand (FIL* fp, FSIZE_t fsz, BYTE opt); /* Allocate a contiguous block to the file */
- FRESULT f_mount (FATFS* fs, const TCHAR* path, BYTE opt); /* Mount/Unmount a logical drive */
- FRESULT f_mkfs (const TCHAR* path, const MKFS_PARM* opt, void* work, UINT len); /* Create a FAT volume */
- FRESULT f_fdisk (BYTE pdrv, const LBA_t ptbl[], void* work); /* Divide a physical drive into some partitions */
- FRESULT f_setcp (WORD cp); /* Set current code page */
- int f_putc (TCHAR c, FIL* fp); /* Put a character to the file */
- int f_puts (const TCHAR* str, FIL* cp); /* Put a string to the file */
- int f_printf (FIL* fp, const TCHAR* str, ...); /* Put a formatted string to the file */
- TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the file */
复制代码 小安派R2测评---LVGL效果_哔哩哔哩_bilibili
六、WIFI连接与TCP/IP通信
WIFI连接初始化及WIFI连接代码参考:aithinker_Ai-M6X_SDK\examples\wifi\sta\wifi_tcp,其中需要注意关键代码如下:
- uint8_t wifi_connect(char* ssid, char* passwd)
- {
- int ret = 255;
- // struct fhost_vif_ip_addr_cfg ip_cfg = { 0 };
- uint32_t ipv4_addr = 0;
- scan_item_cb_t resd;
- char we1;
- char we2;
- if (NULL==ssid || 0==strlen(ssid)) {
- return 1;
- }
- if (wifi_mgmr_sta_state_get() == 1) {
- wifi_sta_disconnect();
- }
- printf("wait000");
- //wifi_mgmr_scan_ap_all(&we1,&we2,resd);
- if (wifi_sta_connect(ssid, passwd, NULL, NULL, 0, 0, 0, 1))
- //if (wifi_mgmr_sta_quickconnect(ssid, passwd, 0, 0))
- {
- return 4;
- }
- LOG_I("Wating wifi connet");
- //等待连接成功
- sta_ConnectStatus = 0;
- for (int i = 0;i<10*30;i++) {
- vTaskDelay(100/portTICK_PERIOD_MS);
- switch (sta_ConnectStatus) {
- case CODE_WIFI_ON_MGMR_DONE:
- return 3;
- case CODE_WIFI_ON_SCAN_DONE:
- return 2;
- case CODE_WIFI_ON_DISCONNECT: //连接失败(超过了重连次数还没有连接成功的状态)
- return 4;
- case CODE_WIFI_ON_CONNECTED: //连接成功(表示wifi sta状态的时候表示同时获取IP(DHCP)成功,或者使用静态IP)
- LOG_I("Wating wifi connet OK");
- break;
- case CODE_WIFI_ON_GOT_IP:
- return 0;
- default:
- //等待连接成功
- break;
- }
- }
- return 14; //连接超时
- }
复制代码- int wifi_start_firmware_task(void)
- {
- LOG_I("Starting wifi ...");
- /* enable wifi clock */
- GLB_PER_Clock_UnGate(GLB_AHB_CLOCK_IP_WIFI_PHY | GLB_AHB_CLOCK_IP_WIFI_MAC_PHY | GLB_AHB_CLOCK_IP_WIFI_PLATFORM);
- GLB_AHB_MCU_Software_Reset(GLB_AHB_MCU_SW_WIFI);
- /* set ble controller EM Size */
- GLB_Set_EM_Sel(GLB_WRAM160KB_EM0KB);
- if (0 != rfparam_init(0, NULL, 0)) {
- LOG_I("PHY RF init failed!");
- return 0;
- }
- LOG_I("PHY RF init success!");
- /* Enable wifi irq */
- extern void interrupt0_handler(void);
- bflb_irq_attach(WIFI_IRQn, (irq_callback)interrupt0_handler, NULL);
- bflb_irq_enable(WIFI_IRQn);
- xTaskCreate(wifi_main, (char*)"fw", WIFI_STACK_SIZE, NULL, TASK_PRIORITY_FW, &wifi_fw_task);
- return 0;
- }
- /**
- * @brief wifi event handler
- * WiFi 事件回调
- *
- * @param code
- */
- void wifi_event_handler(uint32_t code)
- {
- sta_ConnectStatus = code;
- BaseType_t xHigherPriorityTaskWoken;
- switch (code) {
- case CODE_WIFI_ON_INIT_DONE:
- {
- LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_INIT_DONE", __func__);
- wifi_mgmr_init(&conf);
- }
- break;
- case CODE_WIFI_ON_MGMR_DONE:
- {
- LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_MGMR_DONE", __func__);
- }
- break;
- case CODE_WIFI_ON_SCAN_DONE:
- {
- wifi_mgmr_sta_scanlist();
- LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_SCAN_DONE SSID numbles:%d", __func__, wifi_mgmr_sta_scanlist_nums_get());
- }
- break;
- case CODE_WIFI_ON_CONNECTED:
- {
- LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_CONNECTED", __func__);
- void mm_sec_keydump();
- mm_sec_keydump();
- }
- break;
- case CODE_WIFI_ON_GOT_IP:
- {
- ui_load_scr_animation(&guider_ui, &guider_ui.screen_1, guider_ui.screen_1_del, &guider_ui.screen_del, setup_scr_screen_1, LV_SCR_LOAD_ANIM_OVER_LEFT, 0, 0, true, true);
- LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_GOT_IP", __func__);
- }
- break;
- case CODE_WIFI_ON_DISCONNECT:
- {
- LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_DISCONNECT", __func__);
- }
- break;
- case CODE_WIFI_ON_AP_STARTED:
- {
- LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_AP_STARTED", __func__);
- }
- break;
- case CODE_WIFI_ON_AP_STOPPED:
- {
- LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_AP_STOPPED", __func__);
- }
- break;
- case CODE_WIFI_ON_AP_STA_ADD:
- {
- LOG_I("[APP] [EVT] [AP] [ADD] %lld", xTaskGetTickCount());
- }
- break;
- case CODE_WIFI_ON_AP_STA_DEL:
- {
- LOG_I("[APP] [EVT] [AP] [DEL] %lld", xTaskGetTickCount());
- }
- break;
- default:
- {
- LOG_I("[APP] [EVT] Unknown code %u ", code);
- }
- }
- }
复制代码 调用方法如下:
在主函数中开启线程
tcpip_init(NULL, NULL);
wifi_start_firmware_task();
- char * wifi_code;
- char * wifi_name;
- wifi_name = lv_textarea_get_text(guider_ui.screen_ta_1);
- wifi_code = lv_textarea_get_text(guider_ui.screen_ta_2);
- wifi_connect(wifi_name,wifi_code);
复制代码 这里是从LVGL屏幕的文本框获取WIFI名称和密码。
TCP/IP参考代码与WIFI代码参考同一位置,关键代码如下:
- void wifi_test_tcp_client_init(int argc, char **argv)
- {
- abort_exec = shell_signal(SHELL_SIGINT, test_close_client);
- printf("tcp client task start ...\r\n");
- char *addr;
- char *port;
- struct sockaddr_in remote_addr;
- if (argc < 3) {
- printf("%s", PING_USAGE);
- return;
- }
- printf("111...\r\n");
- /* get address (argv[1] if present) */
- addr = "192.168.31.236";//argv[1];
- /* get port number (argv[2] if present) */
- port = "8888";//argv[2];
- while (1) {
- printf("222...\r\n");
- if ((sock_client = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
- printf("TCP Client create socket error\r\n");
- return;
- }
- printf("333...\r\n");
- remote_addr.sin_family = AF_INET;
- remote_addr.sin_port = htons(atoi(port));
- remote_addr.sin_addr.s_addr = inet_addr(addr);
- memset(&(remote_addr.sin_zero), 0, sizeof(remote_addr.sin_zero));
- printf("444...\r\n");
- printf("Server ip Address : %s:%s\r\n", addr, port);
- if (connect(sock_client, (struct sockaddr *)&remote_addr, sizeof(struct sockaddr)) != 0) {
- printf("TCP client connect server falied!\r\n");
- closesocket(sock_client);
- return;
- }
- printf("TCP client connect server success!\r\n");
- printf("Press CTRL-C to exit.\r\n");
- total_cnt = 0;
- while (1) {
- if (write(sock_client, send_buf, sizeof(send_buf)) < 0) {
- printf("write falied!\r\n");
- break;
- }
- total_cnt += sizeof(send_buf);
- vTaskDelay(500);
- }
- closesocket(sock_client);
- return;
- }
- }
复制代码 调用方法如下:
- char *ip_addr="192.168.31.62";
- char *ip_port="333";
- *ip_port = lv_textarea_get_text(guider_ui.screen_1_ta_1);
- wifi_test_tcp_server_init(ip_addr,ip_port);
复制代码 在LVGL屏幕中按下按钮调用。
如下为视频,小安派与手机/电脑进行TCP/IP通信测试,并与电脑进行速度测试。
小安派R2测评---WIFI及TCP-IP测试_哔哩哔哩_bilibili
七、总结与开发想法
经过上诉测试,小安派作为智能家居终端十分适合,屏幕刷新及网络传输速度适合,可以读取TF卡。目前时间原因只测试了这么多,后续想法为
1、以小安派为智能终端,控制已知智能家居,连接米家。
2、读取TF卡数据,制作MP3,暂时不具备制作MP4条件(软件解码速度不太够)。
遇到问题:目前网络传输速度仅够传输一些关键数据,无法进行高速图片,视频传输。(个人能力问题,仍在学习),如果解决,可以尝试制作远程终端。
八、遇到问题与建议
1、小安派的屏幕接上开发板后,屏幕与Type-C会发生冲突,这个很多大佬都已经提到了;
2、官方下载器因为(猜测)加密,无法直接进行下载,而VScode下载对于USB转TTL略微麻烦,Type-C无法烧录;
B站视频链接:
小安派R2测评---官方dome演示_哔哩哔哩_bilibili
小安派R2测评---开箱_哔哩哔哩_bilibili
小安派R2测评---LVGL_哔哩哔哩_bilibili
小安派R2测评---WIFI及TCP-IP测试_哔哩哔哩_bilibili
小安派R2测评---LVGL效果_哔哩哔哩_bilibili
|