1 /*---------------------------------------------------------------------------* 2 3 Copyright (C) Nintendo. All rights reserved. 4 5 These coded instructions, statements, and computer programs contain 6 proprietary information of Nintendo of America Inc. and/or Nintendo 7 Company Ltd., and are protected by Federal copyright law. They may 8 not be disclosed to third parties or copied or duplicated in any form, 9 in whole or in part, without the prior written consent of Nintendo. 10 11 *---------------------------------------------------------------------------*/ 12 /* 13 * USB UAC Microphone Driver Defines, Types, and Prototypes 14 * Created by Gunter M. Zieber, September 13, 2011 15 * Modified for USB UAC Gunter M. Zieber 11/11/11 16 */ 17 #ifndef __USB_UAC_MIC__ 18 #define __USB_UAC_MIC__ 19 20 #ifdef __cplusplus 21 extern "C" { 22 #endif 23 24 #include <cafe/mem_res.h> 25 26 typedef short int usb_mic_pcm_sample_t; 27 typedef long int usb_mic_handle_t; 28 29 typedef enum { 30 usb_mic_state_sample_rate, 31 usb_mic_state_gain_db, 32 usb_mic_state_gain_min, 33 usb_mic_state_gain_max, 34 usb_mic_state_gain_step, 35 usb_mic_state_mute, 36 usb_mic_state_digital_gain_db, 37 usb_mic_state_queue_depth, 38 usb_mic_state_xfer_per_entry, 39 usb_mic_state_max_queue_depth, 40 usb_mic_state_max_xfer_per_entry, 41 usb_mic_state_core 42 } usb_mic_state_t; 43 44 typedef struct { 45 unsigned long int modulus; /* in sample size: num_chan * sizeof(s16) */ 46 usb_mic_pcm_sample_t* base; 47 } usb_mic_ringbuffer_t; 48 49 typedef struct { 50 unsigned long int flags; 51 unsigned long int available; 52 unsigned long int read_idx; 53 } usb_mic_status_t; 54 55 #define MIC_STATUS_FLAG_PCM16 (1 << 0) 56 57 typedef enum { 58 usb_uac_attach, 59 usb_uac_detach, 60 usb_uac_error 61 } usb_event_type_t; 62 63 typedef struct { 64 unsigned long int host; 65 unsigned long int port; 66 unsigned long int vid; 67 unsigned long int pid; 68 usb_mic_handle_t h_inst; 69 } usb_event_data_t; 70 71 typedef struct { 72 unsigned long int num_channels; 73 unsigned long int sample_rates; 74 } usb_dev_attr_t; 75 76 typedef struct { 77 usb_event_data_t evt_data; 78 unsigned long int cap_flags; 79 usb_dev_attr_t input_attr; 80 usb_dev_attr_t output_attr; 81 } usb_event_data_ex_t; 82 83 #define UAC_CAPS_INPUT (1 << 0) 84 #define UAC_CAPS_OUTPUT (1 << 1) 85 86 #define UAC_SAMPLE_RATE_32K (1 << 5) 87 #define UAC_SAMPLE_RATE_48K (1 << 7) 88 89 typedef void (*usb_event_handler_t)(void*, usb_event_type_t, usb_event_data_t*, int); 90 91 typedef struct OSEvent* p_os_event; 92 /* 93 * Error Codes 94 */ 95 #define USB_MIC_ERROR_NONE 0 96 #define USB_MIC_ERROR_NOT_SUP (-1) 97 #define USB_MIC_ERROR_INV_ARG (-2) 98 #define USB_MIC_ERROR_INV_STATE (-3) 99 #define USB_MIC_ERROR_NO_MEM (-4) 100 #define USB_MIC_ERROR_ALREADY_OPEN (-5) 101 #define USB_MIC_ERROR_NOT_OPEN (-6) 102 #define USB_MIC_ERROR_DEVICE (-7) 103 /* 104 * API Function Prototypes 105 */ 106 int USBMICInit(void* pv_cx, usb_event_handler_t pfn_event); 107 int USBMICUninit(void); 108 int USBMICOpenQuery(usb_mic_handle_t h_inst, mem_res_query_t* p_res_query); 109 int USBMICOpen(usb_mic_handle_t h_mic, mem_res_t* p_mem_res, usb_mic_ringbuffer_t* prb); 110 int USBMICClose(usb_mic_handle_t h_mic); 111 int USBMICStart(usb_mic_handle_t h_mic); 112 int USBMICStartExt(usb_mic_handle_t h_mic, p_os_event p_wait_event, unsigned int delay_us); 113 int USBMICStop(usb_mic_handle_t h_mic); 114 int USBMICGetStatus(usb_mic_handle_t h_mic, usb_mic_status_t* p_status); 115 int USBMICSetDataConsumed(usb_mic_handle_t h_mic, unsigned int c_samples); 116 int USBMICSetState(usb_mic_handle_t h_mic, usb_mic_state_t state, unsigned int value); 117 int USBMICGetState(usb_mic_handle_t h_mic, usb_mic_state_t state, unsigned int* p_value); 118 int UACOUTStart(usb_mic_handle_t h_mic, usb_mic_ringbuffer_t* p_rb, unsigned int sample_rate); 119 int UACOUTStop(usb_mic_handle_t h_mic); 120 int UACOUTGetStatus(usb_mic_handle_t h_mic, usb_mic_status_t* p_status); 121 int UACOUTSetDataConsumed(usb_mic_handle_t h_mic, unsigned int c_samples); 122 123 #ifdef __cplusplus 124 } 125 #endif 126 127 #endif // __USB_UAC_MIC__ 128