doku newon / DokuUSBHost
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers USBHost6ChDac.h Source File

USBHost6ChDac.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 #define USBDAC_DATA_SIZE_6CH   (192 * 8 * 3)    //doku
00033 
00034 #define USBDAC_
00035 
00036 /**
00037  * A class to communicate a USB dac (send:only 48kHz,16bit,2ch , receive:only 48kHz,16bit,1ch)
00038  */
00039 class USBHostDac : public IUSBEnumerator {
00040 public:
00041 
00042     /**
00043     * Constructor
00044     */
00045     USBHostDac();
00046 
00047     /** Destructor
00048      *
00049      */
00050     virtual ~USBHostDac();
00051 
00052     /**
00053      * Try to connect a audio device
00054      *
00055      * @return true if connection was successful
00056      */
00057     bool connect();
00058 
00059     /**
00060     * Check if a audio is connected
00061     *
00062     * @returns true if a audio is connected
00063     */
00064     bool connected();
00065 
00066     /**
00067     * Data send : only 48kHz,16bit,2ch. It's sent by the 1536byte unit.
00068     *
00069     * @param buf pointer on a buffer which will be written
00070     * @param len length of the transfer
00071     * @param flush if true, less than 1536 bytes of data is sent
00072     *
00073     * @returns the number of bytes written is returned
00074     */
00075     uint32_t send(uint8_t* buf, uint32_t len, bool flush = true);
00076 
00077 
00078     /**
00079     * Data receive : only 48kHz,16bit,1ch
00080     *
00081     * @param buf pointer on a buffer which will be read
00082     * @param len length of the transfer
00083     *
00084     * @returns the number of bytes read is returned
00085     */
00086     uint32_t receive(uint8_t* buf, uint32_t len);
00087 
00088     void FUMute(int unit, int ch, int mute);   //doku
00089     void FUVolume(int unit, int ch, int mute); //doku
00090     void USBHostDac::FUSelect(int unit, int sel); //doku 
00091     void USBHostDac::setMuteAndVolume(void); //doku
00092 
00093 protected:
00094     //From IUSBEnumerator
00095     virtual void setVidPid(uint16_t vid, uint16_t pid);
00096     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
00097     virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used
00098 
00099 private:
00100     typedef struct {
00101         IsochronousEp* m_isoEp;
00102         uint16_t wMaxPacketSize;
00103         uint8_t  bEndpointAddress;
00104         uint8_t  bInterfaceNumber;
00105         uint8_t  bAlternateSetting;
00106         uint8_t* p_rest_data;
00107         uint32_t rest_data_index;
00108         uint32_t rest_data_size;
00109     } iso_if_t;
00110 
00111     USBHost * host;
00112     USBDeviceConnected * dev;
00113 
00114     bool dev_connected;
00115     bool audio_device_found;
00116     int audio_intf;
00117     int audio_intf_cnt;
00118 
00119     iso_if_t iso_send;
00120     iso_if_t iso_recv;
00121 
00122     void init();
00123     void onDisconnect();
00124     bool chkAudioStreaming();
00125     USB_TYPE setInterface(uint16_t alt, uint16_t index);
00126     void setSamplingRate(uint8_t endpoint_adder, uint32_t sampling_rate);
00127 };
00128 #endif