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 GR-PEACH_producer_meeting

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers USBHostDac.h Source File

USBHostDac.h

00001 /*******************************************************************************
00002 * DISCLAIMER
00003 * This software is supplied by Renesas Electronics Corporation and is only
00004 * intended for use with Renesas products. No other uses are authorized. This
00005 * software is owned by Renesas Electronics Corporation and is protected under
00006 * all applicable laws, including copyright laws.
00007 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
00008 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
00009 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
00010 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
00011 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
00012 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
00013 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
00014 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
00015 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
00016 * Renesas reserves the right, without notice, to make changes to this software
00017 * and to discontinue the availability of this software. By using this software,
00018 * you agree to the additional terms and conditions found by accessing the
00019 * following link:
00020 * http://www.renesas.com/disclaimer
00021 * Copyright (C) 2015 Renesas Electronics Corporation. All rights reserved.
00022 *******************************************************************************/
00023 
00024 #ifndef USBHOSTAUDIO_H
00025 #define USBHOSTAUDIO_H
00026 
00027 #include "USBHostConf.h"
00028 #include "USBHost.h"
00029 #include "USBIsochronous.h"
00030 
00031 #define USBDAC_DATA_SIZE       (192 * 8)
00032 
00033 #define USBDAC_
00034 
00035 /**
00036  * A class to communicate a USB dac (send:only 48kHz,16bit,2ch , receive:only 48kHz,16bit,1ch)
00037  */
00038 class USBHostDac : public IUSBEnumerator {
00039 public:
00040 
00041     /**
00042     * Constructor
00043     */
00044     USBHostDac();
00045 
00046     /** Destructor
00047      *
00048      */
00049     virtual ~USBHostDac();
00050 
00051     /**
00052      * Try to connect a audio device
00053      *
00054      * @return true if connection was successful
00055      */
00056     bool connect();
00057 
00058     /**
00059     * Check if a audio is connected
00060     *
00061     * @returns true if a audio is connected
00062     */
00063     bool connected();
00064 
00065     /**
00066     * Data send : only 48kHz,16bit,2ch. It's sent by the 1536byte unit.
00067     *
00068     * @param buf pointer on a buffer which will be written
00069     * @param len length of the transfer
00070     * @param flush if true, less than 1536 bytes of data is sent
00071     *
00072     * @returns the number of bytes written is returned
00073     */
00074     uint32_t send(uint8_t* buf, uint32_t len, bool flush = true);
00075 
00076     /**
00077     * Data receive : only 48kHz,16bit,1ch
00078     *
00079     * @param buf pointer on a buffer which will be read
00080     * @param len length of the transfer
00081     *
00082     * @returns the number of bytes read is returned
00083     */
00084     uint32_t receive(uint8_t* buf, uint32_t len);
00085 
00086 protected:
00087     //From IUSBEnumerator
00088     virtual void setVidPid(uint16_t vid, uint16_t pid);
00089     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
00090     virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used
00091 
00092 private:
00093     typedef struct {
00094         IsochronousEp* m_isoEp;
00095         uint16_t wMaxPacketSize;
00096         uint8_t  bEndpointAddress;
00097         uint8_t  bInterfaceNumber;
00098         uint8_t  bAlternateSetting;
00099         uint8_t* p_rest_data;
00100         uint32_t rest_data_index;
00101         uint32_t rest_data_size;
00102     } iso_if_t;
00103 
00104     USBHost * host;
00105     USBDeviceConnected * dev;
00106 
00107     bool dev_connected;
00108     bool audio_device_found;
00109     int audio_intf;
00110     int audio_intf_cnt;
00111 
00112     iso_if_t iso_send;
00113     iso_if_t iso_recv;
00114 
00115     void init();
00116     void onDisconnect();
00117     bool chkAudioStreaming();
00118     USB_TYPE setInterface(uint16_t alt, uint16_t index);
00119     void setSamplingRate(uint8_t endpoint_adder, uint32_t sampling_rate);
00120 };
00121 #endif