usb_audio.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /******************************************************************************
  2. *
  3. * Freescale Semiconductor Inc.
  4. * (c) Copyright 2004-2010 Freescale Semiconductor, Inc.
  5. * ALL RIGHTS RESERVED.
  6. *
  7. ******************************************************************************
  8. *
  9. * THIS SOFTWARE IS PROVIDED BY FREESCALE "AS IS" AND ANY EXPRESSED OR
  10. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  11. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  12. * IN NO EVENT SHALL FREESCALE OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  13. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  14. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  15. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  16. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  17. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  18. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  19. * THE POSSIBILITY OF SUCH DAMAGE.
  20. *
  21. **************************************************************************//*!
  22. *
  23. * @file usb_audio.h
  24. *
  25. * @author
  26. *
  27. * @version
  28. *
  29. * @date
  30. *
  31. * @brief The file contains USB stack Audio class layer API header function.
  32. *
  33. *****************************************************************************/
  34. #ifndef _USB_AUDIO_H
  35. #define _USB_AUDIO_H
  36. /******************************************************************************
  37. * Includes
  38. *****************************************************************************/
  39. #include "types.h"
  40. #include "usb_descriptor.h"
  41. #include "usb_class.h"
  42. #ifdef COMPOSITE_DEV
  43. #include "usb_composite.h"
  44. #endif
  45. /******************************************************************************
  46. * Constants - None
  47. *****************************************************************************/
  48. /******************************************************************************
  49. * Macro's
  50. *****************************************************************************/
  51. #define KBI_STAT_MASK (0x0F)
  52. #define BUTTON_0 (0x01)
  53. #define BUTTON_1 (0x02)
  54. #define BUTTON_2 (0x04)
  55. #define BUTTON_3 (0x08)
  56. #define MAX_QUEUE_ELEMS (4)
  57. /* class specific requests */
  58. #define USB_AUDIO_SET_REQUEST_INTF (0x21)
  59. #define USB_AUDIO_GET_REQUEST_INTF (0xA1)
  60. #define REQEUST_CODE_UNDEFINED (0x00)
  61. #define SET_CUR (0x01)
  62. #define GET_CUR (0x81)
  63. #define SET_MIN (0x02)
  64. #define GET_MIN (0x82)
  65. #define SET_MAX (0x03)
  66. #define GET_MAX (0x83)
  67. #define SET_RES (0x04)
  68. #define GET_RES (0x84)
  69. #define SET_MEM (0x05)
  70. #define GET_MEM (0x85)
  71. #define GET_STAT (0xFF)
  72. #define MUTE_CONTROL (0x01)
  73. #define VOLUME_CONTROL (0x02)
  74. /* for class specific requests */
  75. #define HIGH_BYTE_SHIFT (8)
  76. #define MSB_MASK (0xFF00)
  77. #define USB_AUDIO_REQUEST_DIR_MASK (0x08)
  78. #define USB_AUDIO_REQUEST_TYPE_MASK (0x01)
  79. #define REPORT_SIZE (4)
  80. #define CLASS_REQ_DATA_SIZE (0x01)
  81. /* Code of bmRequest Type */
  82. #define SET_REQUEST_ITF (0x21) /* for Entities */
  83. #define SET_REQUEST_EP (0x22) /* for Endpoints */
  84. #define GET_REQUEST_ITF (0xA1) /* for Entities */
  85. #define GET_REQUEST_EP (0xA2) /* for Endpoints */
  86. /* Audio Interface Class Code */
  87. #define AUDIO (0x01)
  88. /* Audio Interface Subclass Codes */
  89. #define AUDIOCONTROL (0x01)
  90. #define AUDIOSTREAMING (0x02)
  91. #define MIDISTRAMING (0x03)
  92. /* Audio Interface Protocol codes */
  93. #define PR_PROTOCOL_UNDEFINED (0x00)
  94. /* Audio Class Specific Descriptor Types */
  95. #define CS_UNDEFINED (0x20)
  96. #define CS_DEVICE (0x21)
  97. #define CS_CONFIGURATION (0x22)
  98. #define CS_STRING (0x23)
  99. #define CS_INTERFACE (0x24)
  100. #define CS_ENDPOINT (0x25)
  101. /* Audio Class Specific AC Interface Descriptor */
  102. #define HEADER (0x01)
  103. #define INPUT_TERMINAL (0x02)
  104. #define OUTPUT_TERMINAL (0x03)
  105. #define MIXER_UNIT (0x04)
  106. #define SELECTOR_UNIT (0x05)
  107. #define FEATURE_UNIT (0x06)
  108. #define PROCESSING_UNIT (0x07)
  109. #define EXTENSION_UNIT (0x08)
  110. /* Audio Class Specific AS Interface Descriptor Subtypes */
  111. #define AS_GENERAL (0x01)
  112. #define FORMAT_TYPE (0x02)
  113. #define FORMAT_SPECIFIC (0x03)
  114. /* Audio Class Specific Endpoint Descriptor subtypes */
  115. #define EP_GENRAL (0x01)
  116. /* Audio Class Specific Request Codes */
  117. #define SET_CUR (0x01)
  118. #define GET_CUR (0x81)
  119. #define SET_MIN (0x02)
  120. #define GET_MIN (0x82)
  121. #define SET_MAX (0x03)
  122. #define GET_MAX (0x83)
  123. #define SET_RES (0x04)
  124. #define GET_RES (0x84)
  125. #define SET_MEM (0x05)
  126. #define GET_MEM (0x85)
  127. #define GET_STAT (0xFF)
  128. /* Terminal Control Selector codes */
  129. #define COPY_PROTECT_CONTROL (0x01)
  130. /* Feature Unit Control Selector codes */
  131. #define MUTE_CONTROL (0x01)
  132. #define VOLUME_CONTROL (0x02)
  133. #define BASS_CONTROL (0x03)
  134. #define MID_CONTROL (0x04)
  135. #define TREBLE_CONTROL (0x05)
  136. #define GRAPHIC_EQUALIZER_CONTROL (0x06)
  137. #define AUTOMATIC_GAIN_CONTROL (0x07)
  138. #define DELAY_CONTROL (0x08)
  139. #define BASS_BOOST_CONTROL (0x09)
  140. #define LOUDNESS_CONTROL (0x0A)
  141. /* Endpoint Definition */
  142. #define SAMPLING_FREQ_CONTROL (0x01)
  143. #define PITCH_CONTROL (0x02)
  144. /* Definition Size */
  145. #define SIZE_COPY_PROTECT_CONTROL (1)
  146. #if AUDIO_CLASS_2_0
  147. /* Clock Source Control Selectors(A.17.1) */
  148. #define CS_CONTROL_UNDEFINED (0x00)
  149. #define CS_SAM_FREQ_CONTROL (0x01)
  150. #define CS_CLOCK_VALID_CONTROL (0x02)
  151. #endif /* AUDIO_CLASS_2_0 */
  152. /******************************************************************************
  153. * Types
  154. *****************************************************************************/
  155. /* structure to hold a request in the endpoint queue */
  156. typedef struct _usb_class_audio_queue
  157. {
  158. uint_8 controller_ID; /* Controller ID*/
  159. uint_8 channel; /* Endpoint number */
  160. uint_8_ptr app_buff; /* Buffer to send */
  161. USB_PACKET_SIZE size; /* Size of the transfer */
  162. }USB_CLASS_AUDIO_QUEUE, *PTR_USB_CLASS_AUDIO_QUEUE;
  163. /* USB class Audio endpoint data */
  164. typedef struct _usb_class_audio_endpoint
  165. {
  166. uint_8 endpoint; /* Endpoint number */
  167. uint_8 type; /* Type of endpoint (interrupt,
  168. bulk or isochronous) */
  169. uint_8 bin_consumer; /* Num of queued elements */
  170. uint_8 bin_producer; /* Num of de-queued elements */
  171. uint_8 queue_num; /* Num of queue */
  172. USB_CLASS_AUDIO_QUEUE queue[MAX_QUEUE_ELEMS]; /* Queue data */
  173. }USB_CLASS_AUDIO_ENDPOINT;
  174. /* contains the endpoint data for non control endpoints */
  175. typedef struct _usb_class_audio_endpoint_data
  176. {
  177. /* Num of non control endpoints */
  178. uint_8 count;
  179. /* contains the endpoint info */
  180. #ifndef COMPOSITE_DEV
  181. USB_CLASS_AUDIO_ENDPOINT ep[AUDIO_DESC_ENDPOINT_COUNT];
  182. #else
  183. USB_CLASS_AUDIO_ENDPOINT ep[COMPOSITE_DESC_ENDPOINT_COUNT];
  184. #endif
  185. }USB_CLASS_AUDIO_ENDPOINT_DATA, *PTR_USB_CLASS_AUDIO_ENDPOINT_DATA;
  186. /******************************************************************************
  187. * Global Functions
  188. *****************************************************************************/
  189. extern uint_8 kbi_stat; /*records the status of the buttons (PTG0-PTG3) */
  190. extern uint_8 USB_Class_Audio_Init (
  191. uint_8 controller_ID,
  192. USB_CLASS_CALLBACK Audio_class_callback,
  193. USB_REQ_FUNC vendor_req_callback,
  194. USB_CLASS_CALLBACK param_callback
  195. );
  196. uint_8 USB_Class_Audio_DeInit
  197. (
  198. uint_8 controller_ID
  199. );
  200. extern uint_8 USB_Class_Audio_Send_Data (
  201. uint_8 controller_ID,
  202. uint_8 ep_num,
  203. uint_8_ptr buff_ptr,
  204. USB_PACKET_SIZE size
  205. );
  206. extern uint_8 USB_Class_Audio_Recv_Data (
  207. uint_8 controller_ID,
  208. uint_8 ep_num,
  209. uint_8_ptr buff_ptr,
  210. USB_PACKET_SIZE size
  211. );
  212. extern void USB_Class_Audio_Event (
  213. uint_8 controller_ID,
  214. uint_8 event,
  215. void* val
  216. );
  217. #ifdef COMPOSITE_DEV
  218. uint_8 USB_Audio_Other_Requests(uint_8 controller_ID,
  219. USB_SETUP_STRUCT * setup_packet,
  220. uint_8_ptr *data,
  221. USB_PACKET_SIZE *size);
  222. #endif
  223. #define USB_Class_Audio_Periodic_Task USB_Class_Periodic_Task
  224. /*****************************************************************************
  225. * Local Functions
  226. *****************************************************************************/
  227. void USB_Service_Audio_Status_Interrupt(PTR_USB_DEV_EVENT_STRUCT event);
  228. void USB_Service_Audio_Isochronous_IN(PTR_USB_DEV_EVENT_STRUCT event);
  229. void USB_Service_Audio_Isochronous_OUT(PTR_USB_DEV_EVENT_STRUCT event);
  230. #endif