Added WiFi kernel drivers and refactored Wifi service (#557)
+ other improvements
This commit is contained in:
committed by
GitHub
parent
dbb96a891c
commit
1c2806bddf
@@ -1,18 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include "tactility/concurrent/dispatcher.h"
|
||||
#include "tactility/device.h"
|
||||
#include "tactility/module.h"
|
||||
#include <Tactility/Dispatcher.h>
|
||||
#include <Tactility/app/AppManifest.h>
|
||||
#include <Tactility/hal/Configuration.h>
|
||||
#include <Tactility/service/ServiceManifest.h>
|
||||
|
||||
#include <functional>
|
||||
|
||||
extern "C" {
|
||||
struct DtsDevice;
|
||||
}
|
||||
|
||||
namespace tt {
|
||||
|
||||
/**
|
||||
* A thin C++ wrapper around the TactilityKernel dispatcher, allowing
|
||||
* std::function (and therefore capturing lambdas) to be dispatched.
|
||||
*/
|
||||
class MainDispatcher final {
|
||||
|
||||
public:
|
||||
|
||||
using Function = std::function<void()>;
|
||||
|
||||
explicit MainDispatcher(DispatcherHandle_t handle) : handle(handle) {}
|
||||
|
||||
/**
|
||||
* Queue a function to be consumed on the main task.
|
||||
* @param[in] function the function to execute elsewhere
|
||||
* @param[in] timeout lock acquisition timeout
|
||||
* @return true if dispatching was successful (timeout not reached)
|
||||
*/
|
||||
bool dispatch(Function function, TickType_t timeout = portMAX_DELAY) const;
|
||||
|
||||
private:
|
||||
|
||||
DispatcherHandle_t handle;
|
||||
};
|
||||
|
||||
/** @brief The configuration for the operating system
|
||||
* It contains the hardware configuration, apps and services
|
||||
*/
|
||||
@@ -39,7 +66,7 @@ const Configuration* getConfiguration();
|
||||
* @warning This dispatcher is used for WiFi and might block for some time during WiFi connection.
|
||||
* @return the dispatcher
|
||||
*/
|
||||
Dispatcher& getMainDispatcher();
|
||||
MainDispatcher getMainDispatcher();
|
||||
|
||||
namespace hal {
|
||||
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <tactility/drivers/spi_controller.h>
|
||||
#include <tactility/device.h>
|
||||
|
||||
#include <Tactility/Lock.h>
|
||||
|
||||
namespace tt {
|
||||
|
||||
class SpiDeviceLock : public Lock {
|
||||
::Device* device;
|
||||
public:
|
||||
explicit SpiDeviceLock(::Device* device) : device(device) { }
|
||||
|
||||
bool lock(TickType_t timeout) const override {
|
||||
return spi_controller_try_lock(device, timeout) == ERROR_NONE;
|
||||
}
|
||||
|
||||
void unlock() const override {
|
||||
spi_controller_unlock(device);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
#pragma once
|
||||
#ifdef ESP_PLATFORM
|
||||
|
||||
#include <esp_http_server.h>
|
||||
#include <Tactility/RecursiveMutex.h>
|
||||
#include <Tactility/kernel/SystemEvents.h>
|
||||
#include <esp_http_server.h>
|
||||
|
||||
namespace tt::network {
|
||||
|
||||
|
||||
@@ -6,52 +6,16 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "WifiApSettings.h"
|
||||
#include <tactility/drivers/wifi.h>
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#include <esp_wifi.h>
|
||||
#else
|
||||
#include <cstdint>
|
||||
// From esp_wifi_types.h in ESP-IDF 5.2
|
||||
typedef enum {
|
||||
WIFI_AUTH_OPEN = 0, /**< authenticate mode : open */
|
||||
WIFI_AUTH_WEP, /**< authenticate mode : WEP */
|
||||
WIFI_AUTH_WPA_PSK, /**< authenticate mode : WPA_PSK */
|
||||
WIFI_AUTH_WPA2_PSK, /**< authenticate mode : WPA2_PSK */
|
||||
WIFI_AUTH_WPA_WPA2_PSK, /**< authenticate mode : WPA_WPA2_PSK */
|
||||
WIFI_AUTH_ENTERPRISE, /**< authenticate mode : WiFi EAP security */
|
||||
WIFI_AUTH_WPA2_ENTERPRISE = WIFI_AUTH_ENTERPRISE, /**< authenticate mode : WiFi EAP security */
|
||||
WIFI_AUTH_WPA3_PSK, /**< authenticate mode : WPA3_PSK */
|
||||
WIFI_AUTH_WPA2_WPA3_PSK, /**< authenticate mode : WPA2_WPA3_PSK */
|
||||
WIFI_AUTH_WAPI_PSK, /**< authenticate mode : WAPI_PSK */
|
||||
WIFI_AUTH_OWE, /**< authenticate mode : OWE */
|
||||
WIFI_AUTH_WPA3_ENT_192, /**< authenticate mode : WPA3_ENT_SUITE_B_192_BIT */
|
||||
WIFI_AUTH_WPA3_EXT_PSK, /**< authenticate mode : WPA3_PSK_EXT_KEY */
|
||||
WIFI_AUTH_WPA3_EXT_PSK_MIXED_MODE, /**< authenticate mode: WPA3_PSK + WPA3_PSK_EXT_KEY */
|
||||
WIFI_AUTH_MAX
|
||||
} wifi_auth_mode_t;
|
||||
#endif
|
||||
#include "WifiApSettings.h"
|
||||
|
||||
namespace tt::service::wifi {
|
||||
|
||||
enum class WifiEvent {
|
||||
/** Radio was turned on */
|
||||
RadioStateOn,
|
||||
/** Radio is turning on. */
|
||||
RadioStateOnPending,
|
||||
/** Radio is turned off */
|
||||
RadioStateOff,
|
||||
/** Radio is turning off */
|
||||
RadioStateOffPending,
|
||||
/** Started scanning for access points */
|
||||
ScanStarted,
|
||||
/** Finished scanning for access points */ // TODO: 1 second validity
|
||||
ScanFinished,
|
||||
Disconnected,
|
||||
ConnectionPending,
|
||||
ConnectionSuccess,
|
||||
ConnectionFailed
|
||||
};
|
||||
/** The kernel wifi driver's event type: a WifiEventType tag plus a union
|
||||
* payload (radio_state/station_state/access_point_state/connection_error
|
||||
* depending on the tag). See tactility/drivers/wifi.h. */
|
||||
using WifiEvent = ::WifiEvent;
|
||||
|
||||
enum class RadioState {
|
||||
OnPending,
|
||||
@@ -62,13 +26,6 @@ enum class RadioState {
|
||||
Off,
|
||||
};
|
||||
|
||||
struct ApRecord {
|
||||
std::string ssid;
|
||||
int8_t rssi;
|
||||
int32_t channel;
|
||||
wifi_auth_mode_t auth_mode;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Get wifi pubsub that broadcasts Event objects
|
||||
* @return PubSub
|
||||
@@ -93,7 +50,7 @@ bool isScanning();
|
||||
std::string getConnectionTarget();
|
||||
|
||||
/** @return the access points from the last scan (if any). It only contains public APs. */
|
||||
std::vector<ApRecord> getScanResults();
|
||||
std::vector<WifiApRecord> getScanResults();
|
||||
|
||||
/**
|
||||
* @brief Overrides the default scan result size of 16.
|
||||
|
||||
Reference in New Issue
Block a user