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

Committer:
dkato
Date:
Wed Apr 01 10:29:31 2015 +0000
Revision:
0:3a3146f89bcc
Child:
1:9ff4cba6524d
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dkato 0:3a3146f89bcc 1 /*******************************************************************************
dkato 0:3a3146f89bcc 2 * DISCLAIMER
dkato 0:3a3146f89bcc 3 * This software is supplied by Renesas Electronics Corporation and is only
dkato 0:3a3146f89bcc 4 * intended for use with Renesas products. No other uses are authorized. This
dkato 0:3a3146f89bcc 5 * software is owned by Renesas Electronics Corporation and is protected under
dkato 0:3a3146f89bcc 6 * all applicable laws, including copyright laws.
dkato 0:3a3146f89bcc 7 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
dkato 0:3a3146f89bcc 8 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
dkato 0:3a3146f89bcc 9 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
dkato 0:3a3146f89bcc 10 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
dkato 0:3a3146f89bcc 11 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
dkato 0:3a3146f89bcc 12 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
dkato 0:3a3146f89bcc 13 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
dkato 0:3a3146f89bcc 14 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
dkato 0:3a3146f89bcc 15 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
dkato 0:3a3146f89bcc 16 * Renesas reserves the right, without notice, to make changes to this software
dkato 0:3a3146f89bcc 17 * and to discontinue the availability of this software. By using this software,
dkato 0:3a3146f89bcc 18 * you agree to the additional terms and conditions found by accessing the
dkato 0:3a3146f89bcc 19 * following link:
dkato 0:3a3146f89bcc 20 * http://www.renesas.com/disclaimer
dkato 0:3a3146f89bcc 21 * Copyright (C) 2015 Renesas Electronics Corporation. All rights reserved.
dkato 0:3a3146f89bcc 22 *******************************************************************************/
dkato 0:3a3146f89bcc 23
dkato 0:3a3146f89bcc 24 #ifndef USBHOSTAUDIO_H
dkato 0:3a3146f89bcc 25 #define USBHOSTAUDIO_H
dkato 0:3a3146f89bcc 26
dkato 0:3a3146f89bcc 27 #include "USBHostConf.h"
dkato 0:3a3146f89bcc 28 #include "USBHost.h"
dkato 0:3a3146f89bcc 29 #include "USBIsochronous.h"
dkato 0:3a3146f89bcc 30
dkato 0:3a3146f89bcc 31 #define USBDAC_DATA_SIZE (192 * 8)
dkato 0:3a3146f89bcc 32
dkato 0:3a3146f89bcc 33 /**
dkato 0:3a3146f89bcc 34 * A class to communicate a USB dac (only 48kHz,16bit,2ch)
dkato 0:3a3146f89bcc 35 */
dkato 0:3a3146f89bcc 36 class USBHostDac : public IUSBEnumerator {
dkato 0:3a3146f89bcc 37 public:
dkato 0:3a3146f89bcc 38
dkato 0:3a3146f89bcc 39 /**
dkato 0:3a3146f89bcc 40 * Constructor
dkato 0:3a3146f89bcc 41 */
dkato 0:3a3146f89bcc 42 USBHostDac();
dkato 0:3a3146f89bcc 43
dkato 0:3a3146f89bcc 44 /**
dkato 0:3a3146f89bcc 45 * Try to connect a audio device
dkato 0:3a3146f89bcc 46 *
dkato 0:3a3146f89bcc 47 * @return true if connection was successful
dkato 0:3a3146f89bcc 48 */
dkato 0:3a3146f89bcc 49 bool connect();
dkato 0:3a3146f89bcc 50
dkato 0:3a3146f89bcc 51 /**
dkato 0:3a3146f89bcc 52 * Check if a audio is connected
dkato 0:3a3146f89bcc 53 *
dkato 0:3a3146f89bcc 54 * @returns true if a audio is connected
dkato 0:3a3146f89bcc 55 */
dkato 0:3a3146f89bcc 56 bool connected();
dkato 0:3a3146f89bcc 57
dkato 0:3a3146f89bcc 58 /**
dkato 0:3a3146f89bcc 59 * Data send : It's sent by the 1536byte unit.
dkato 0:3a3146f89bcc 60 *
dkato 0:3a3146f89bcc 61 * @param buf pointer on a buffer which will be written
dkato 0:3a3146f89bcc 62 * @param len length of the transfer
dkato 0:3a3146f89bcc 63 * @param flush if true, less than 1536 bytes of data is sent
dkato 0:3a3146f89bcc 64 *
dkato 0:3a3146f89bcc 65 * @returns the number of bytes written is returned
dkato 0:3a3146f89bcc 66 */
dkato 0:3a3146f89bcc 67 uint32_t send(uint8_t* buf, uint32_t len, bool flush = true);
dkato 0:3a3146f89bcc 68
dkato 0:3a3146f89bcc 69 protected:
dkato 0:3a3146f89bcc 70 //From IUSBEnumerator
dkato 0:3a3146f89bcc 71 virtual void setVidPid(uint16_t vid, uint16_t pid);
dkato 0:3a3146f89bcc 72 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
dkato 0:3a3146f89bcc 73 virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used
dkato 0:3a3146f89bcc 74
dkato 0:3a3146f89bcc 75 private:
dkato 0:3a3146f89bcc 76 USBHost * host;
dkato 0:3a3146f89bcc 77 USBDeviceConnected * dev;
dkato 0:3a3146f89bcc 78
dkato 0:3a3146f89bcc 79 bool dev_connected;
dkato 0:3a3146f89bcc 80 bool audio_device_found;
dkato 0:3a3146f89bcc 81 int audio_intf;
dkato 0:3a3146f89bcc 82 int audio_intf_cnt;
dkato 0:3a3146f89bcc 83
dkato 0:3a3146f89bcc 84 IsochronousEp* m_isoEp;
dkato 0:3a3146f89bcc 85 uint16_t wMaxPacketSize;
dkato 0:3a3146f89bcc 86 uint8_t bEndpointAddress;
dkato 0:3a3146f89bcc 87 uint8_t bInterfaceNumber;
dkato 0:3a3146f89bcc 88 uint8_t bAlternateSetting;
dkato 0:3a3146f89bcc 89 uint8_t* p_rest_data;
dkato 0:3a3146f89bcc 90 uint32_t rest_data_index;
dkato 0:3a3146f89bcc 91
dkato 0:3a3146f89bcc 92 void init();
dkato 0:3a3146f89bcc 93 void onDisconnect();
dkato 0:3a3146f89bcc 94 bool chkAudioStreaming();
dkato 0:3a3146f89bcc 95 USB_TYPE setInterface(uint16_t alt, uint16_t index);
dkato 0:3a3146f89bcc 96 void setSamplingRate(uint32_t sampling_rate);
dkato 0:3a3146f89bcc 97 };
dkato 0:3a3146f89bcc 98 #endif