22 this->
mark_failed(LOG_STR(
"Failed to create microphone task"));
32 " Sample rate: %" PRIu32
" Hz\n"
33 " Bits per sample: %u\n"
35 " Buffer size: %" PRIu32,
37 this->audio_stream_info_.get_channels(), this->buffer_size_);
41 const uint8_t commands = this->
commands_.exchange(0);
74 this->
commands_.fetch_and(
static_cast<uint8_t
>(~clear));
90 }
while (!this->
listeners_.compare_exchange_weak(listeners, listeners + 1));
102 }
while (!this->
listeners_.compare_exchange_weak(listeners, listeners - 1));
103 if (listeners == 1) {
123 ESP_LOGW(TAG,
"USB device disconnected, waiting for it to return");
151 ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
154 size_t bytes_read = 0;
162 if (err == ESP_OK && bytes_read > 0) {
163 this->
frame_.resize(bytes_read);
165 }
else if (err == ESP_ERR_TIMEOUT) {
167 }
else if (err == ESP_ERR_INVALID_STATE) {
170 }
else if (err != ESP_OK) {
171 ESP_LOGW(TAG,
"Read error: %s", esp_err_to_name(err));
void mark_failed()
Mark this component as failed.
void enable_loop_soon_any_context()
Thread and ISR-safe version of enable_loop() that can be called from any context.
bool cancel_timeout(const char *name)
Cancel a timeout function.
void set_timeout(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a const char* name.
void disable_loop()
Disable this component's loop.
USBAudioComponent * parent_
TaskHandle_t get_handle() const
Get the FreeRTOS task handle.
bool create(TaskFunction_t fn, const char *name, uint32_t stack_size, void *param, UBaseType_t priority, bool use_psram, BaseType_t core_id=tskNO_AFFINITY)
Allocate the TCB (always internal RAM) and the stack, then create the task.
size_t ms_to_bytes(uint32_t ms) const
Converts duration to bytes.
uint32_t get_sample_rate() const
audio::AudioStreamInfo audio_stream_info_
CallbackManager< void(const std::vector< uint8_t > &)> data_callbacks_
void dump_config() override
std::atomic< bool > running_
static constexpr uint32_t RETRY_START_ID
std::atomic< uint8_t > listeners_
static constexpr uint32_t RETRY_MIN_MS
static constexpr uint8_t MAX_LISTENERS
std::vector< uint8_t > frame_
void on_stream_state(StreamEvent event) override
std::atomic< bool > task_idle_
static constexpr uint32_t RETRY_MAX_MS
static constexpr uint32_t MIC_TASK_STACK_SIZE
static void mic_task(void *param)
void request_(uint8_t set, uint8_t clear)
static constexpr uint8_t COMMAND_START
std::atomic< uint8_t > commands_
static constexpr UBaseType_t MIC_TASK_PRIORITY
static constexpr uint32_t READ_TIMEOUT_MS
static constexpr uint8_t COMMAND_STOP
ESPHOME_LOG_TAG(TAG, "usb_audio.mic")
StreamEvent
What the hub reports to a platform about its stream.