15#include "freertos/FreeRTOS.h"
16#include "freertos/queue.h"
17#include "freertos/task.h"
18#include "usb/uac_host.h"
60 enum class Type : uint8_t {
70 uac_host_device_handle_t
handle{
nullptr};
85 void setup()
override;
116 std::atomic<uac_host_device_handle_t>
handle{
nullptr};
163 uac_host_device_handle_t
handle{
nullptr};
202 uac_host_stream_config_t &stream_config,
bool &rejected);
205 bool apply_control_(ControlState &control, esp_err_t err,
const LogString *name);
207 static void driver_event_stub(uint8_t addr, uint8_t iface_num, uac_host_driver_event_t event,
void *user_data);
208 static void device_event_stub(uac_host_device_handle_t
handle, uac_host_device_event_t event,
void *user_data);
Helper for FreeRTOS static task management.
const EndpointState & endpoint_(Endpoint endpoint) const
void lock_driver_()
Keep platform reads and writes out of the driver while the worker uses it.
void register_microphone(USBAudioStream *microphone)
static void worker_task(void *param)
void on_started_(const USBAudioEvent &event)
void dump_config() override
StaticQueue_t event_queue_struct_
void run_op_(const Op &op)
bool finish_closes_(uint32_t now)
void on_closed_(const USBAudioEvent &event, uint32_t now)
void process_events_(uint32_t now)
bool populate_stream_config_(Endpoint endpoint, uac_host_device_handle_t handle, uac_host_stream_config_t &stream_config, bool &rejected)
void begin_close_(Endpoint endpoint)
void register_speaker(USBAudioStream *speaker)
void set_speaker_mute_state(bool mute_state)
bool apply_control_(ControlState &control, esp_err_t err, const LogString *name)
void stream_failed_(Endpoint endpoint)
std::atomic< bool > driver_busy_
void open_stream_(Endpoint endpoint, uint8_t addr, uint8_t iface_num)
static constexpr size_t EVENT_QUEUE_LENGTH
std::atomic< bool > speaker_muted_
bool apply_pending_speaker_controls_()
Send pending volume and mute; returns true when one should be retried later.
static void device_event_stub(uac_host_device_handle_t handle, uac_host_device_event_t event, void *user_data)
std::array< EndpointState, 2 > endpoints_
std::array< uac_host_device_handle_t, 2 > lost_while_opening_
void start_stream_(Endpoint endpoint)
void handle_disconnect_(uac_host_device_handle_t handle)
std::atomic< bool > controls_queued_
static constexpr uint32_t SPEAKER_RING_SLACK
QueueHandle_t event_queue_
EndpointState & endpoint_(Endpoint endpoint)
std::atomic< uint32_t > transfer_errors_
void process_event_(const USBAudioEvent &event, uint32_t now)
std::array< uint8_t, EVENT_QUEUE_LENGTH *sizeof(USBAudioEvent)> event_queue_storage_
StaticQueue_t op_queue_struct_
std::array< uint8_t, OP_QUEUE_LENGTH *sizeof(Op)> op_queue_storage_
void post_event_(const USBAudioEvent &event)
bool queue_op_(const Op &op)
void suspend(Endpoint endpoint)
void on_resumed_(const USBAudioEvent &event)
esp_err_t read_microphone(uint8_t *buffer, size_t size, size_t *bytes_read, uint32_t timeout_ms)
void on_opened_(const USBAudioEvent &event)
void resume(Endpoint endpoint)
Start streaming as soon as the device is connected; the platform hears back through on_stream_state()...
float get_setup_priority() const override
static constexpr size_t OP_QUEUE_LENGTH
static void driver_event_stub(uint8_t addr, uint8_t iface_num, uac_host_driver_event_t event, void *user_data)
esp_err_t write_speaker(const uint8_t *data, size_t length, uint32_t timeout_ms)
bool enter_driver_(uint32_t &timeout_ms)
Platform side: wait, within timeout_ms, until the worker is not using the driver, and count the calle...
std::atomic< uint8_t > driver_users_
void set_speaker_volume_level(float volume)
Safe from any task; the worker sends the values to the device.
std::atomic< uint8_t > speaker_volume_
A speaker or microphone platform that streams through the hub. The hub calls it on the main loop only...
virtual bool stream_idle() const =0
No platform task is inside a read or write call on the device; the hub closes a lost device only then...
virtual void on_stream_state(StreamEvent event)=0
virtual audio::AudioStreamInfo get_usb_stream_info()=0
The fixed format the hub opens the stream with.
uint32_t get_buffer_size() const
virtual void on_transfer_taken()
Speaker only: the driver tried to take its next transfer from the ring buffer, which it does each tim...
USBAudioStream(uint32_t buffer_size)
constexpr float BUS
For communication buses like i2c/spi.
StreamEvent
What the hub reports to a platform about its stream.
std::atomic< bool > pending
uac_host_device_handle_t closing
USBAudioStream * platform
std::atomic< uac_host_device_handle_t > handle
A blocking driver call, run on the worker.
uac_host_device_handle_t handle
Posted to the main loop, by the USB driver task (CONNECTED, DISCONNECTED) or the hub's worker (the re...
uac_host_device_handle_t handle
spi_device_handle_t handle