Ver código fonte

feat(wifi/bl616): add bl616 usbwifi

sakumisu 1 ano atrás
pai
commit
4f3a3f496e
5 arquivos alterados com 116 adições e 3 exclusões
  1. 1 1
      README.md
  2. 1 1
      README_zh.md
  3. 4 0
      cherryusb.cmake
  4. 6 0
      class/vendor/wifi/README.md
  5. 104 1
      platform/none/usbh_lwip.c

+ 1 - 1
README.md

@@ -99,7 +99,7 @@ CherryUSB Host Stack has the following functions:
 - Support USB Audio CLASS (UAC1.0)
 - Support Remote NDIS (RNDIS)
 - Support USB Bluetooth class (support nimble and zephyr bluetooth stack, support **CLASS:0xE0** or vendor class like cdc acm)
-- Support Vendor class
+- Support Vendor class (serial, net, wifi)
 - Support USB modeswitch
 - Support multi host with the same USB IP
 

+ 1 - 1
README_zh.md

@@ -99,7 +99,7 @@ CherryUSB Host 协议栈当前实现以下功能:
 - Support USB Audio CLASS (UAC1.0)
 - 支持 Remote NDIS (RNDIS)
 - 支持 USB Bluetooth (支持 nimble and zephyr bluetooth 协议栈,支持 **CLASS: 0xE0** 或者厂家自定义类,类似于 cdc acm 功能)
-- 支持 Vendor 类 class
+- 支持 Vendor 类 class (serial, net, wifi)
 - 支持 USB modeswitch
 - 支持相同 USB IP 的多主机
 

+ 4 - 0
cherryusb.cmake

@@ -38,6 +38,7 @@ ${CMAKE_CURRENT_LIST_DIR}/class/wireless
 ${CMAKE_CURRENT_LIST_DIR}/class/midi
 ${CMAKE_CURRENT_LIST_DIR}/class/vendor/net
 ${CMAKE_CURRENT_LIST_DIR}/class/vendor/serial
+${CMAKE_CURRENT_LIST_DIR}/class/vendor/wifi
 )
 
 if(CONFIG_CHERRYUSB_DEVICE)
@@ -209,6 +210,9 @@ if(CONFIG_CHERRYUSB_HOST)
     if(CONFIG_CHERRYUSB_HOST_PL2303)
     list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/vendor/serial/usbh_pl2303.c)
     endif()
+    if(CONFIG_CHERRYUSB_HOST_BL616)
+    list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/vendor/wifi/usbh_bl616.c)
+    endif()
 
     if(DEFINED CONFIG_CHERRYUSB_HOST_HCD)
         if("${CONFIG_CHERRYUSB_HOST_HCD}" STREQUAL "ehci_bouffalo")

+ 6 - 0
class/vendor/wifi/README.md

@@ -0,0 +1,6 @@
+# BL616 USB WIFI
+
+Usbwifi firmware please contact bouffalolab. You can purchase a module in the following ways:
+
+- https://iot.mi.com/moduleBrowser.html
+- https://docs.ai-thinker.com/ai_m61

+ 104 - 1
platform/none/usbh_lwip.c

@@ -36,6 +36,7 @@
 #define CONFIG_USBHOST_PLATFORM_CDC_NCM
 #define CONFIG_USBHOST_PLATFORM_ASIX
 #define CONFIG_USBHOST_PLATFORM_RTL8152
+// #define CONFIG_USBHOST_PLATFORM_BL616
 
 ip_addr_t g_ipaddr;
 ip_addr_t g_netmask;
@@ -84,18 +85,24 @@ TimerHandle_t dhcp_handle;
 static void dhcp_timeout(TimerHandle_t xTimer)
 {
     struct netif *netif = (struct netif *)pvTimerGetTimerID(xTimer);
+#if LWIP_DHCP
     struct dhcp *dhcp;
-
+#endif
     if (netif_is_up(netif)) {
+#if LWIP_DHCP
         dhcp = netif_dhcp_data(netif);
 
         if (dhcp && (dhcp->state == DHCP_STATE_BOUND)) {
+#endif
             USB_LOG_INFO("IPv4 Address     : %s\r\n", ipaddr_ntoa(&netif->ip_addr));
             USB_LOG_INFO("IPv4 Subnet mask : %s\r\n", ipaddr_ntoa(&netif->netmask));
             USB_LOG_INFO("IPv4 Gateway     : %s\r\n\r\n", ipaddr_ntoa(&netif->gw));
 
             xTimerStop(xTimer, 0);
+#if LWIP_DHCP
         }
+#endif
+    } else {
     }
 }
 
@@ -529,3 +536,99 @@ void usbh_rtl8152_stop(struct usbh_rtl8152 *rtl8152_class)
     netif_remove(netif);
 }
 #endif
+
+#ifdef CONFIG_USBHOST_PLATFORM_BL616
+#include "usbh_bl616.h"
+
+struct netif g_bl616_netif;
+static err_t usbh_bl616_linkoutput(struct netif *netif, struct pbuf *p)
+{
+    int ret;
+
+    usbh_lwip_eth_output_common(p, usbh_bl616_get_eth_txbuf());
+    ret = usbh_bl616_eth_output(p->tot_len);
+    if (ret < 0) {
+        return ERR_BUF;
+    } else {
+        return ERR_OK;
+    }
+}
+
+void usbh_bl616_eth_input(uint8_t *buf, uint32_t buflen)
+{
+    usbh_lwip_eth_input_common(&g_bl616_netif, buf, buflen);
+}
+
+static err_t usbh_bl616_if_init(struct netif *netif)
+{
+    LWIP_ASSERT("netif != NULL", (netif != NULL));
+
+    netif->mtu = 1500;
+    netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP;
+    netif->state = NULL;
+    netif->name[0] = 'E';
+    netif->name[1] = 'X';
+    netif->output = etharp_output;
+    netif->linkoutput = usbh_bl616_linkoutput;
+    return ERR_OK;
+}
+
+void usbh_bl616_sta_connect_callback(void)
+{
+}
+
+void usbh_bl616_sta_disconnect_callback(void)
+{
+    struct netif *netif = &g_bl616_netif;
+
+    netif_set_down(netif);
+}
+void usbh_bl616_sta_update_ip(uint8_t ip4_addr[4], uint8_t ip4_mask[4], uint8_t ip4_gw[4])
+{
+    struct netif *netif = &g_bl616_netif;
+
+    IP4_ADDR(&netif->ip_addr, ip4_addr[0], ip4_addr[1], ip4_addr[2], ip4_addr[3]);
+    IP4_ADDR(&netif->netmask, ip4_mask[0], ip4_mask[1], ip4_mask[2], ip4_mask[3]);
+    IP4_ADDR(&netif->gw, ip4_gw[0], ip4_gw[1], ip4_gw[2], ip4_gw[3]);
+
+    netif_set_up(netif);
+}
+void usbh_bl616_run(struct usbh_bl616 *bl616_class)
+{
+    struct netif *netif = &g_bl616_netif;
+
+    netif->hwaddr_len = 6;
+    memcpy(netif->hwaddr, bl616_class->sta_mac, 6);
+
+    IP4_ADDR(&g_ipaddr, 0, 0, 0, 0);
+    IP4_ADDR(&g_netmask, 0, 0, 0, 0);
+    IP4_ADDR(&g_gateway, 0, 0, 0, 0);
+
+    netif = netif_add(netif, &g_ipaddr, &g_netmask, &g_gateway, NULL, usbh_bl616_if_init, tcpip_input);
+    netif_set_down(netif);
+    netif_set_default(netif);
+
+    dhcp_handle = xTimerCreate((const char *)"dhcp", (TickType_t)200, (UBaseType_t)pdTRUE, (void *const)netif, (TimerCallbackFunction_t)dhcp_timeout);
+    if (dhcp_handle == NULL) {
+        USB_LOG_ERR("timer creation failed! \r\n");
+        while (1) {
+        }
+    }
+    xTimerStart(dhcp_handle, 0);
+
+    usb_osal_thread_create("usbh_bl616", 2048, CONFIG_USBHOST_PSC_PRIO + 1, usbh_bl616_rx_thread, NULL);
+}
+
+void usbh_bl616_stop(struct usbh_bl616 *bl616_class)
+{
+    struct netif *netif = &g_bl616_netif;
+
+    netif_set_down(netif);
+    netif_remove(netif);
+}
+
+// #include "shell.h"
+
+// CSH_CMD_EXPORT(wifi_sta_connect, );
+// CSH_CMD_EXPORT(wifi_scan, );
+#endif