// mic_broker.h — single owner of the I2S RX mic; routes frames to one
// active consumer chosen by mode. No frame is delivered in MIC_IDLE.
//
// A second mic_broker_init() call returns ESP_ERR_INVALID_STATE (single
// init; callers may treat that as benign if the broker is already up).
#pragma once
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "esp_err.h"

typedef enum { MIC_IDLE, MIC_NPC_LISTEN, MIC_P1_SOUND } mic_mode_t;

// cb receives PCM16 mono frames (count = samples) when its mode is active.
typedef void (*mic_frame_cb_t)(const int16_t *pcm, size_t samples, void *ctx);

esp_err_t  mic_broker_init(int bclk_pin, int ws_pin, int din_pin, int sample_rate_hz);
void       mic_broker_register(mic_mode_t mode, mic_frame_cb_t cb, void *ctx);
void       mic_broker_set_mode(mic_mode_t mode);
mic_mode_t mic_broker_mode(void);
