22 #include "USBDescriptor.h" 23 #include "USBDevice_Types.h" 25 #include "USBDevice.h" 27 #include "OperationList.h" 28 #include "ByteBuffer.h" 29 #include "rtos/EventFlags.h" 84 USBAudio(
bool connect =
true, uint32_t frequency_rx = 48000, uint8_t channel_count_rx = 1, uint32_t frequency_tx = 8000, uint8_t channel_count_tx = 1, uint32_t buffer_ms = 10, uint16_t vendor_id = 0x7bb8, uint16_t product_id = 0x1111, uint16_t product_release = 0x0100);
107 USBAudio(
USBPhy *phy, uint32_t frequency_rx, uint8_t channel_count_rx, uint32_t frequency_tx, uint8_t channel_count_tx, uint32_t buffer_ms, uint16_t vendor_id, uint16_t product_id, uint16_t product_release);
137 bool read(uint8_t *buf, uint32_t size);
149 void read_nb(uint8_t *buf, uint32_t size, uint32_t *actual);
179 bool write(uint8_t *buf, uint32_t size);
191 void write_nb(uint8_t *buf, uint32_t size, uint32_t *actual);
247 virtual void callback_set_configuration(uint8_t configuration);
248 virtual void callback_set_interface(uint16_t interface, uint8_t alternate);
250 virtual const uint8_t *string_iproduct_desc();
251 virtual const uint8_t *string_iinterface_desc();
252 virtual const uint8_t *configuration_desc(uint8_t index);
265 void _init(uint32_t frequency_rx, uint8_t channel_count_rx, uint32_t frequency_tx, uint8_t channel_count_tx, uint32_t buffer_ms);
276 void _build_configuration_desc();
278 void _receive_change(ChannelState new_state);
280 void _send_change(ChannelState new_state);
281 void _send_isr_start();
282 void _send_isr_next_sync();
316 uint32_t _rx_overflow;
319 uint32_t _tx_underflow;
326 uint8_t _rx_channel_count;
327 uint8_t _tx_channel_count;
330 uint16_t _tx_frame_fract;
331 uint16_t _tx_whole_frames_per_xfer;
332 uint16_t _tx_fract_frames_per_xfer;
335 uint16_t _tx_packet_size_max;
336 uint16_t _rx_packet_size_max;
339 uint8_t *_tx_packet_buf;
340 uint8_t *_rx_packet_buf;
347 ChannelState _tx_state;
348 ChannelState _rx_state;
365 uint8_t _channel_config_rx;
366 uint8_t _channel_config_tx;
369 uint8_t _config_descriptor[183];
372 uint8_t _control_receive[2];
void attach_rx(mbed::Callback< void(AudioEvent)> &cb)
attach a Callback to Rx Done
void attach(mbed::Callback< void()> &cb)
Attach a Callback to update the volume.
bool write(uint8_t *buf, uint32_t size)
Write audio data.
The EventFlags class is used to control event flags or wait for event flags other threads control...
void write_nb(uint8_t *buf, uint32_t size, uint32_t *actual)
Nonblocking audio data write.
bool read(uint8_t *buf, uint32_t size)
Read audio data.
bool write_ready()
Check if the audio write channel is open.
USBAudio(bool connect=true, uint32_t frequency_rx=48000, uint8_t channel_count_rx=1, uint32_t frequency_tx=8000, uint8_t channel_count_tx=1, uint32_t buffer_ms=10, uint16_t vendor_id=0x7bb8, uint16_t product_id=0x1111, uint16_t product_release=0x0100)
Basic constructor.
Abstract interface to physical USB hardware.
float get_volume()
Get current volume between 0.0 and 1.0.
void connect()
Connect USBAudio.
virtual ~USBAudio()
Destroy this object.
void read_nb(uint8_t *buf, uint32_t size, uint32_t *actual)
Nonblocking audio data read.
uint32_t write_underflows(bool clear=false)
Return the number write packets not sent due to underflow.
bool read_ready()
Check if the audio read channel is open.
virtual void callback_state_change(DeviceState new_state)
Called when USB changes state.
void read_wait_ready()
Wait until the audio read channel is open.
virtual void callback_request_xfer_done(const setup_packet_t *setup, bool aborted)
Called by USBDevice on data stage completion.
virtual void callback_request(const setup_packet_t *setup)
Called by USBDevice on Endpoint0 request.
void disconnect()
Disconnect USBAudio.
void attach_tx(mbed::Callback< void(AudioEvent)> &cb)
attach a Callback to Tx Done
Callback class based on template specialization.
void write_wait_ready()
Wait until the audio write channel is open.
uint32_t read_overflows(bool clear=false)
Return the number read packets dropped due to overflow.