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 Sep 30 06:08:15 2015 +0000
Revision:
2:4afe26b3d48b
Parent:
1:9ff4cba6524d
Comments update.

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 1:9ff4cba6524d 33 #define USBDAC_
dkato 1:9ff4cba6524d 34
dkato 0:3a3146f89bcc 35 /**
dkato 2:4afe26b3d48b 36 * A class to communicate a USB dac (send:only 48kHz,16bit,2ch , receive:only 48kHz,16bit,1ch)
dkato 0:3a3146f89bcc 37 */
dkato 0:3a3146f89bcc 38 class USBHostDac : public IUSBEnumerator {
dkato 0:3a3146f89bcc 39 public:
dkato 0:3a3146f89bcc 40
dkato 0:3a3146f89bcc 41 /**
dkato 0:3a3146f89bcc 42 * Constructor
dkato 0:3a3146f89bcc 43 */
dkato 0:3a3146f89bcc 44 USBHostDac();
dkato 0:3a3146f89bcc 45
dkato 1:9ff4cba6524d 46 /** Destructor
dkato 1:9ff4cba6524d 47 *
dkato 1:9ff4cba6524d 48 */
dkato 1:9ff4cba6524d 49 virtual ~USBHostDac();
dkato 1:9ff4cba6524d 50
dkato 0:3a3146f89bcc 51 /**
dkato 0:3a3146f89bcc 52 * Try to connect a audio device
dkato 0:3a3146f89bcc 53 *
dkato 0:3a3146f89bcc 54 * @return true if connection was successful
dkato 0:3a3146f89bcc 55 */
dkato 0:3a3146f89bcc 56 bool connect();
dkato 0:3a3146f89bcc 57
dkato 0:3a3146f89bcc 58 /**
dkato 0:3a3146f89bcc 59 * Check if a audio is connected
dkato 0:3a3146f89bcc 60 *
dkato 0:3a3146f89bcc 61 * @returns true if a audio is connected
dkato 0:3a3146f89bcc 62 */
dkato 0:3a3146f89bcc 63 bool connected();
dkato 0:3a3146f89bcc 64
dkato 0:3a3146f89bcc 65 /**
dkato 2:4afe26b3d48b 66 * Data send : only 48kHz,16bit,2ch. It's sent by the 1536byte unit.
dkato 0:3a3146f89bcc 67 *
dkato 0:3a3146f89bcc 68 * @param buf pointer on a buffer which will be written
dkato 0:3a3146f89bcc 69 * @param len length of the transfer
dkato 0:3a3146f89bcc 70 * @param flush if true, less than 1536 bytes of data is sent
dkato 0:3a3146f89bcc 71 *
dkato 0:3a3146f89bcc 72 * @returns the number of bytes written is returned
dkato 0:3a3146f89bcc 73 */
dkato 0:3a3146f89bcc 74 uint32_t send(uint8_t* buf, uint32_t len, bool flush = true);
dkato 0:3a3146f89bcc 75
dkato 1:9ff4cba6524d 76 /**
dkato 2:4afe26b3d48b 77 * Data receive : only 48kHz,16bit,1ch
dkato 1:9ff4cba6524d 78 *
dkato 1:9ff4cba6524d 79 * @param buf pointer on a buffer which will be read
dkato 1:9ff4cba6524d 80 * @param len length of the transfer
dkato 1:9ff4cba6524d 81 *
dkato 1:9ff4cba6524d 82 * @returns the number of bytes read is returned
dkato 1:9ff4cba6524d 83 */
dkato 1:9ff4cba6524d 84 uint32_t receive(uint8_t* buf, uint32_t len);
dkato 1:9ff4cba6524d 85
dkato 0:3a3146f89bcc 86 protected:
dkato 0:3a3146f89bcc 87 //From IUSBEnumerator
dkato 0:3a3146f89bcc 88 virtual void setVidPid(uint16_t vid, uint16_t pid);
dkato 0:3a3146f89bcc 89 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 90 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 91
dkato 0:3a3146f89bcc 92 private:
dkato 1:9ff4cba6524d 93 typedef struct {
dkato 1:9ff4cba6524d 94 IsochronousEp* m_isoEp;
dkato 1:9ff4cba6524d 95 uint16_t wMaxPacketSize;
dkato 1:9ff4cba6524d 96 uint8_t bEndpointAddress;
dkato 1:9ff4cba6524d 97 uint8_t bInterfaceNumber;
dkato 1:9ff4cba6524d 98 uint8_t bAlternateSetting;
dkato 1:9ff4cba6524d 99 uint8_t* p_rest_data;
dkato 1:9ff4cba6524d 100 uint32_t rest_data_index;
dkato 1:9ff4cba6524d 101 uint32_t rest_data_size;
dkato 1:9ff4cba6524d 102 } iso_if_t;
dkato 1:9ff4cba6524d 103
dkato 0:3a3146f89bcc 104 USBHost * host;
dkato 0:3a3146f89bcc 105 USBDeviceConnected * dev;
dkato 0:3a3146f89bcc 106
dkato 0:3a3146f89bcc 107 bool dev_connected;
dkato 0:3a3146f89bcc 108 bool audio_device_found;
dkato 0:3a3146f89bcc 109 int audio_intf;
dkato 0:3a3146f89bcc 110 int audio_intf_cnt;
dkato 0:3a3146f89bcc 111
dkato 1:9ff4cba6524d 112 iso_if_t iso_send;
dkato 1:9ff4cba6524d 113 iso_if_t iso_recv;
dkato 0:3a3146f89bcc 114
dkato 0:3a3146f89bcc 115 void init();
dkato 0:3a3146f89bcc 116 void onDisconnect();
dkato 0:3a3146f89bcc 117 bool chkAudioStreaming();
dkato 0:3a3146f89bcc 118 USB_TYPE setInterface(uint16_t alt, uint16_t index);
dkato 1:9ff4cba6524d 119 void setSamplingRate(uint8_t endpoint_adder, uint32_t sampling_rate);
dkato 0:3a3146f89bcc 120 };
dkato 0:3a3146f89bcc 121 #endif