diff --git a/libraries/USBHOST/src/class/host/tusbh.h b/libraries/USBHOST/src/class/host/tusbh.h index 580ca58c9..fd325689c 100644 --- a/libraries/USBHOST/src/class/host/tusbh.h +++ b/libraries/USBHOST/src/class/host/tusbh.h @@ -46,7 +46,7 @@ #define TUSHH_ROOT_CHILD_COUNT 1 -#define TUSBH_MAX_CHILD 4 +#define TUSBH_MAX_CHILD 10 #define TUSBH_MAX_CONFIG_LENGTH 256 #define TUSBH_MAX_INTERFACE 8 #define TUSBH_MAX_EP 4 diff --git a/libraries/WiFi/src/WiFi.cpp b/libraries/WiFi/src/WiFi.cpp index 85f2a16c3..3dde521c4 100644 --- a/libraries/WiFi/src/WiFi.cpp +++ b/libraries/WiFi/src/WiFi.cpp @@ -44,24 +44,57 @@ int arduino::WiFiClass::begin(const char* ssid, const char *passphrase) { int arduino::WiFiClass::beginAP(const char* ssid, const char *passphrase, uint8_t channel) { -#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) - _softAP = WhdSoftAPInterface::get_default_instance(); -#endif + #if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) + _softAP = WhdSoftAPInterface::get_default_instance(); + #endif if (_softAP == NULL) { - return WL_AP_FAILED; + return (_currentNetworkStatus = WL_AP_FAILED); } ensureDefaultAPNetworkConfiguration(); + WhdSoftAPInterface* softAPInterface = static_cast(_softAP); + //Set ap ssid, password and channel - static_cast(_softAP)->set_network(_ip, _netmask, _gateway); - nsapi_error_t result = static_cast(_softAP)->start(ssid, passphrase, NSAPI_SECURITY_WPA2, channel, true /* dhcp server */, NULL, true /* cohexistance */); + softAPInterface->set_network(_ip, _netmask, _gateway); + nsapi_error_t result = softAPInterface->start(ssid, passphrase, NSAPI_SECURITY_WPA2, channel, true /* dhcp server */, NULL, true /* cohexistance */); + nsapi_error_t registrationResult; + softAPInterface->unregister_event_handler(); + registrationResult = softAPInterface->register_event_handler(arduino::WiFiClass::handleAPEvents); + + if (registrationResult != NSAPI_ERROR_OK) { + return (_currentNetworkStatus = WL_AP_FAILED); + } + _currentNetworkStatus = (result == NSAPI_ERROR_OK && setSSID(ssid)) ? WL_AP_LISTENING : WL_AP_FAILED; return _currentNetworkStatus; } +void * arduino::WiFiClass::handleAPEvents(whd_interface_t ifp, const whd_event_header_t *event_header, const uint8_t *event_data, void *handler_user_data){ + if(event_header->event_type == WLC_E_ASSOC_IND){ + WiFi._currentNetworkStatus = WL_AP_CONNECTED; + } else if(event_header->event_type == WLC_E_DISASSOC_IND){ + WiFi._currentNetworkStatus = WL_AP_LISTENING; + } + + // Default Event Handler + whd_driver_t whd_driver = ifp->whd_driver; + WHD_IOCTL_LOG_ADD_EVENT(whd_driver, event_header->event_type, event_header->flags, event_header->reason); + + if ((event_header->event_type == (whd_event_num_t)WLC_E_LINK) || (event_header->event_type == WLC_E_IF)) { + if (osSemaphoreGetCount(whd_driver->ap_info.whd_wifi_sleep_flag) < 1) { + osStatus_t result = osSemaphoreRelease(whd_driver->ap_info.whd_wifi_sleep_flag); + if (result != osOK) { + printf("Release whd_wifi_sleep_flag ERROR: %d", result); + } + } + } + + return handler_user_data; +} + void arduino::WiFiClass::ensureDefaultAPNetworkConfiguration() { if(_ip == nullptr){ _ip = SocketAddress(DEFAULT_IP_ADDRESS); @@ -80,10 +113,15 @@ void arduino::WiFiClass::end() { int arduino::WiFiClass::disconnect() { if (_softAP != nullptr) { - return static_cast(_softAP)->stop(); + WhdSoftAPInterface* softAPInterface = static_cast(_softAP); + softAPInterface->unregister_event_handler(); + _currentNetworkStatus = (softAPInterface->stop() == NSAPI_ERROR_OK ? WL_DISCONNECTED : WL_AP_FAILED); } else { - return wifi_if->disconnect(); + wifi_if->disconnect(); + _currentNetworkStatus = WL_DISCONNECTED; } + + return _currentNetworkStatus; } void arduino::WiFiClass::config(arduino::IPAddress local_ip){ diff --git a/libraries/WiFi/src/WiFi.h b/libraries/WiFi/src/WiFi.h index 394d1c7c4..8231ae6e9 100644 --- a/libraries/WiFi/src/WiFi.h +++ b/libraries/WiFi/src/WiFi.h @@ -303,13 +303,14 @@ class WiFiClass SocketAddress _dnsServer1 = nullptr; SocketAddress _dnsServer2 = nullptr; char* _ssid = nullptr; - wl_status_t _currentNetworkStatus = WL_IDLE_STATUS; + volatile wl_status_t _currentNetworkStatus = WL_IDLE_STATUS; WiFiInterface* wifi_if = nullptr; voidPrtFuncPtr _initializerCallback; WiFiAccessPoint* ap_list = nullptr; uint8_t connected_ap; int setSSID(const char* ssid); void ensureDefaultAPNetworkConfiguration(); + static void * handleAPEvents(whd_interface_t ifp, const whd_event_header_t *event_header, const uint8_t *event_data, void *handler_user_data); bool isVisible(const char* ssid); arduino::IPAddress ipAddressFromSocketAddress(SocketAddress socketAddress); SocketAddress socketAddressFromIpAddress(arduino::IPAddress ip, uint16_t port);