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" 95 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);
118 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);
148 bool read(uint8_t *buf, uint32_t size);
160 void read_nb(uint8_t *buf, uint32_t size, uint32_t *actual);
190 bool write(uint8_t *buf, uint32_t size);
202 void write_nb(uint8_t *buf, uint32_t size, uint32_t *actual);
258 virtual void callback_set_configuration(uint8_t configuration);
259 virtual void callback_set_interface(uint16_t interface, uint8_t alternate);
261 virtual const uint8_t *string_iproduct_desc();
262 virtual const uint8_t *string_iinterface_desc();
263 virtual const uint8_t *configuration_desc(uint8_t index);
276 void _init(uint32_t frequency_rx, uint8_t channel_count_rx, uint32_t frequency_tx, uint8_t channel_count_tx, uint32_t buffer_ms);
287 void _build_configuration_desc();
289 void _receive_change(ChannelState new_state);
291 void _send_change(ChannelState new_state);
292 void _send_isr_start();
293 void _send_isr_next_sync();
327 uint32_t _rx_overflow;
330 uint32_t _tx_underflow;
337 uint8_t _rx_channel_count;
338 uint8_t _tx_channel_count;
341 uint16_t _tx_frame_fract;
342 uint16_t _tx_whole_frames_per_xfer;
343 uint16_t _tx_fract_frames_per_xfer;
346 uint16_t _tx_packet_size_max;
347 uint16_t _rx_packet_size_max;
350 uint8_t *_tx_packet_buf;
351 uint8_t *_rx_packet_buf;
358 ChannelState _tx_state;
359 ChannelState _rx_state;
376 uint16_t _channel_config_rx;
377 uint16_t _channel_config_tx;
380 uint8_t _config_descriptor[183];
383 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.