A class to communicate a USB dac (send:only 48kHz,16bit,2ch , receive:only 48kHz,16bit,1ch). Need "USBHost_AddIso" library.
Dependents: USBHostDac_Audio_in_out
Fork of USBHostDac by
Diff: USBHostDac.h
- Revision:
- 0:3a3146f89bcc
- Child:
- 1:9ff4cba6524d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/USBHostDac.h Wed Apr 01 10:29:31 2015 +0000
@@ -0,0 +1,98 @@
+/*******************************************************************************
+* DISCLAIMER
+* This software is supplied by Renesas Electronics Corporation and is only
+* intended for use with Renesas products. No other uses are authorized. This
+* software is owned by Renesas Electronics Corporation and is protected under
+* all applicable laws, including copyright laws.
+* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
+* THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
+* LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
+* AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
+* TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
+* ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
+* FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
+* ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
+* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+* Renesas reserves the right, without notice, to make changes to this software
+* and to discontinue the availability of this software. By using this software,
+* you agree to the additional terms and conditions found by accessing the
+* following link:
+* http://www.renesas.com/disclaimer
+* Copyright (C) 2015 Renesas Electronics Corporation. All rights reserved.
+*******************************************************************************/
+
+#ifndef USBHOSTAUDIO_H
+#define USBHOSTAUDIO_H
+
+#include "USBHostConf.h"
+#include "USBHost.h"
+#include "USBIsochronous.h"
+
+#define USBDAC_DATA_SIZE (192 * 8)
+
+/**
+ * A class to communicate a USB dac (only 48kHz,16bit,2ch)
+ */
+class USBHostDac : public IUSBEnumerator {
+public:
+
+ /**
+ * Constructor
+ */
+ USBHostDac();
+
+ /**
+ * Try to connect a audio device
+ *
+ * @return true if connection was successful
+ */
+ bool connect();
+
+ /**
+ * Check if a audio is connected
+ *
+ * @returns true if a audio is connected
+ */
+ bool connected();
+
+ /**
+ * Data send : It's sent by the 1536byte unit.
+ *
+ * @param buf pointer on a buffer which will be written
+ * @param len length of the transfer
+ * @param flush if true, less than 1536 bytes of data is sent
+ *
+ * @returns the number of bytes written is returned
+ */
+ uint32_t send(uint8_t* buf, uint32_t len, bool flush = true);
+
+protected:
+ //From IUSBEnumerator
+ virtual void setVidPid(uint16_t vid, uint16_t pid);
+ virtual bool parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol); //Must return true if the interface should be parsed
+ virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used
+
+private:
+ USBHost * host;
+ USBDeviceConnected * dev;
+
+ bool dev_connected;
+ bool audio_device_found;
+ int audio_intf;
+ int audio_intf_cnt;
+
+ IsochronousEp* m_isoEp;
+ uint16_t wMaxPacketSize;
+ uint8_t bEndpointAddress;
+ uint8_t bInterfaceNumber;
+ uint8_t bAlternateSetting;
+ uint8_t* p_rest_data;
+ uint32_t rest_data_index;
+
+ void init();
+ void onDisconnect();
+ bool chkAudioStreaming();
+ USB_TYPE setInterface(uint16_t alt, uint16_t index);
+ void setSamplingRate(uint32_t sampling_rate);
+};
+#endif
