1 /*---------------------------------------------------------------------------*
2   Project:  Revolution PMIC library
3   File:     pmic.h
4 
5   Copyright (C)2008-2009 Nintendo  All Rights Reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Log: pmic.h,v $
14   Revision 1.24  2009/04/17 06:32:02  ozeki_kohei
15   [Bug.531 fix] Removed PMICQuitAsync().
16 
17   Revision 1.23  2009/04/10 07:13:53  aka
18   Copied from SDK_3_2_DEV_BRANCH.
19 
20   Revision 1.22  2009/02/09 01:34:47  aka
21   Revised Copyright.
22 
23   Revision 1.21  2009/01/07 04:49:50  ozeki_kohei
24   Added PMICQuitAsync().
25 
26   Revision 1.20  2008/12/22 08:01:41  aka
27   Changed comments.
28 
29   Revision 1.19  2008/10/27 07:47:02  aka
30   Changed returns of PMICExecEs().
31 
32   Revision 1.18  2008/10/27 01:18:28  aka
33   Change PMICExecEs().
34   Added PMICEsConference3_1, _2, _3, _4 and _5.
35 
36   Revision 1.17  2008/10/22 02:43:20  aka
37   Removed some definitions for test.
38 
39   Revision 1.16  2008/10/15 02:16:52  aka
40   Added PMICInitEx().
41 
42   Revision 1.15  2008/09/13 04:30:44  aka
43   Changed PMICExecEs().
44   Added 5 ES modes for trial.
45 
46   Revision 1.14  2008/08/28 05:24:20  aka
47   Added PMICSet/GetEcReset(Async)().
48 
49   Revision 1.13  2008/08/25 04:16:15  aka
50   Removed PMIC_ERR_NOT_OPENED.
51 
52   Revision 1.12  2008/08/13 07:18:07  aka
53   Added PMICRegisterErrorCallback().
54   Added PMIC_ERR_INVALID_DATA.
55 
56   Revision 1.11  2008/07/30 00:00:50  aka
57   Added some debug funcs.
58 
59   Revision 1.10  2008/07/29 11:06:13  aka
60   Removed PMICResetEsParam().
61   Changed from PMICSetEsParam() to PMICSetEsMode().
62   Changed from PMICGetEsParam() to PMICGetEsMode().
63 
64   Revision 1.9  2008/07/21 06:17:20  aka
65   Added PMICSetEsParam().
66   Added PMICGetEsParam().
67   Added PMICResetEsParam().
68   Added PMICIsReadOverwritten().
69   Added PMICIsWriteOverwritten().
70   Added PMICIsWriteEmpty().
71 
72   Revision 1.8  2008/07/04 06:24:30  aka
73   Removed PMICSetFirm().
74 
75   Revision 1.7  2008/06/09 12:26:02  aka
76   Added PMICSet/GetGain(Async)().
77 
78   Revision 1.6  2008/04/25 02:43:30  aka
79   Added PMICExecEs().
80 
81   Revision 1.5  2008/04/23 06:47:42  aka
82   Removed gain funcs.
83 
84   Revision 1.4  2008/04/23 06:26:25  aka
85   Added Gain, SP and Level funcs.
86 
87   Revision 1.3  2008/04/16 08:05:13  aka
88   Added PMICSet/GetFreq(Async)().
89 
90   Revision 1.2  2008/01/22 04:59:34  aka
91   modified comments.
92 
93   Revision 1.1  2008/01/22 02:43:20  aka
94   initial check-in.
95 
96   $NoKeywords: $
97  *---------------------------------------------------------------------------*/
98 
99 #ifndef __PMIC_H__
100 #define __PMIC_H__
101 
102 #ifdef __cplusplus
103 extern "C" {
104 #endif
105 
106 #include <revolution.h>
107 
108 /*---------------------------------------------------------------------------*
109    definitions
110  *---------------------------------------------------------------------------*/
111 
112 // Working area size on MEM2 which P-MIC lib uses.
113 #define PMIC_MEM2_WORK               17408 // 17KB
114 
115 #define PMIC_READ_BUFFER_MSEC        (48)                                     // 48msec
116 #define PMIC_READ_BUFFER_SAMPLES     (PMIC_READ_BUFFER_MSEC    * 16)          // @16KHz, @mono
117 #define PMIC_READ_BUFFER_SIZE        (PMIC_READ_BUFFER_SAMPLES * sizeof(s16)) // @s16
118 
119 //
120 // Returns
121 //
122 
123 typedef enum
124 {
125     PMIC_ERR_OK                 =   0,    // OK / no error
126 
127     PMIC_ERR_INVALID_ARGUMENTS  =  -1,    // invalide arguments
128 
129     PMIC_ERR_NO_DEVICE          =  -2,    // P-MIC is not inserted.
130     PMIC_ERR_INVALID_DEVICE     =  -3,    // (no use, but keep for compatibility).
131 
132     PMIC_ERR_INVALID_STATE      =  -4,    // Can't execute on current state.
133     PMIC_ERR_BUSY               =  -5,    // Please re-call later.
134 
135     PMIC_ERR_USB_ERROR          =  -6,    // Error is occured during enqueueing a USB request.
136 
137     PMIC_ERR_INVALID_DATA       =  -7,    // Received data from P-MIC is invalid (may noise...).
138 
139     PMIC_ERR_FATAL              =  -100   // Unrecoverable error is occured.
140 
141 } PMIC_ERR;
142 
143 //
144 // Arguments
145 //
146 
147 // Sampling Frequency
148 #define PMIC_FREQ_8KHZ               0x0000
149 #define PMIC_FREQ_11KHZ              0x0001
150 #define PMIC_FREQ_RESERVED           0x0002
151 #define PMIC_FREQ_16KHZ              0x0003
152 
153 // Signal Processing State
154 #define PMIC_SP_ON                   0x0000
155 #define PMIC_SP_OFF                  0x0001
156 
157 // Echo Canceller Reset State
158 #define PMIC_EC_RESET_ON             0x0001
159 #define PMIC_EC_RESET_OFF            0x0000
160 
161 // Input Level
162 #define PMIC_LEVEL_SIN               0x0000
163 #define PMIC_LEVEL_SOUT              0x0001
164 #define PMIC_LEVEL_RIN               0x0002
165 
166 // Mic(ADC) Gain
167 #define PMIC_GAIN_00dB               0x0000
168 #define PMIC_GAIN_15dB               0x0001
169 #define PMIC_GAIN_30dB               0x0002
170 #define PMIC_GAIN_36dB               0x0003
171 
172 //
173 // Callbacks
174 //
175 
176 typedef void (*PMICCallback) ( PMIC_ERR result, void* arg );
177 
178 //
179 // Structures
180 //
181 
182 typedef struct
183 {
184     f32 erl;
185 
186     f32 recv_vd_level;
187 
188     f32 send_loss_max;
189     f32 send_loss_up;
190     f32 send_loss_down;
191 
192     f32 recv_loss_max;
193     f32 recv_loss_up;
194     f32 recv_loss_down;
195 
196 } PMICEsMode;
197 
198 /*---------------------------------------------------------------------------*
199    P-MIC fundamental functions
200  *---------------------------------------------------------------------------*/
201 
202 PMIC_ERR         PMICInit                   ( void* mem2 );
203 PMIC_ERR         PMICInitEx                 ( void* mem2, s32 size );
204 
205 PMIC_ERR         PMICQuit                   ( void );
206 
207 PMIC_ERR         PMICProbe                  ( void );
208 
209 PMIC_ERR         PMICOpenAsync              ( PMICCallback cb, void* arg );
210 PMIC_ERR         PMICOpen                   ( void );
211 
212 PMIC_ERR         PMICCloseAsync             ( PMICCallback cb, void* arg );
213 PMIC_ERR         PMICClose                  ( void );
214 
215 PMIC_ERR         PMICStartAsync             ( PMICCallback cb, void* arg );
216 PMIC_ERR         PMICStart                  ( void );
217 
218 PMIC_ERR         PMICStopAsync              ( PMICCallback cb, void* arg );
219 PMIC_ERR         PMICStop                   ( void );
220 
221 /*---------------------------------------------------------------------------*
222    P-MIC data transfer functions
223  *---------------------------------------------------------------------------*/
224 
225 s32              PMICGetReadableSamples     ( void );
226 s32              PMICRead                   ( s16* buffer, s32 samples );
227 BOOL             PMICIsReadOverwritten      ( void );
228 
229 s32              PMICGetWritableSamples     ( void );
230 s32              PMICWrite                  ( s16* buffer, s32 samples );
231 BOOL             PMICIsWriteOverwritten     ( void );
232 BOOL             PMICIsWriteEmpty           ( void );
233 
234 PMICCallback     PMICRegisterErrorCallback  ( PMICCallback cb, void* arg );
235 
236 /*---------------------------------------------------------------------------*
237    P-MIC data convert functions
238  *---------------------------------------------------------------------------*/
239 
240 s32              PMICChangeRate             ( s16*       input,
241                                               s32        samples,
242                                               u32        rate,
243                                               s16*       output,
244                                               BOOL       init );
245 
246 /*---------------------------------------------------------------------------*
247    P-MIC setting functions
248  *---------------------------------------------------------------------------*/
249 
250 ////////////////
251 // Freq : Sampling Frequency Funcs
252 ////////////////
253 
254 // SetFreq : Set Sampling Frequency
255 PMIC_ERR         PMICSetFreqAsync           ( u16  freq,  PMICCallback cb, void* arg );
256 PMIC_ERR         PMICSetFreq                ( u16  freq );
257 
258 // GetFreq : Get Sampling Frequency
259 PMIC_ERR         PMICGetFreqAsync           ( u16* freq,  PMICCallback cb, void* arg );
260 PMIC_ERR         PMICGetFreq                ( u16* freq );
261 
262 ////////////////
263 // SP : Signal Processing Funcs
264 ////////////////
265 
266 // SetSpState : Set Signal Processing State (ON or OFF)
267 PMIC_ERR         PMICSetSpStateAsync        ( u16  state, PMICCallback cb, void* arg );
268 PMIC_ERR         PMICSetSpState             ( u16  state );
269 
270 // GetSpState : Get Signal Processing State (ON or OFF)
271 PMIC_ERR         PMICGetSpStateAsync        ( u16* state, PMICCallback cb, void* arg );
272 PMIC_ERR         PMICGetSpState             ( u16* state );
273 
274 ////////////////
275 // EcReset : Echo Canceller Resetting Funcs.
276 ////////////////
277 
278 // SetEcReset : Set Echo Canceller Reset State (ON or OFF)
279 PMIC_ERR         PMICSetEcResetAsync        ( u16  state, PMICCallback cb, void* arg );
280 PMIC_ERR         PMICSetEcReset             ( u16  state );
281 
282 // GetEcReset : Get Echo Canceller Reset State (ON or OFF)
283 PMIC_ERR         PMICGetEcResetAsync        ( u16* state, PMICCallback cb, void* arg );
284 PMIC_ERR         PMICGetEcReset             ( u16* state );
285 
286 ////////////////
287 // Level : Input Level Funcs
288 ////////////////
289 
290 // GetLevel : Get Input Level
291 PMIC_ERR         PMICGetLevelAsync          ( u16 addr, u16* level, PMICCallback cb, void* arg );
292 PMIC_ERR         PMICGetLevel               ( u16 addr, u16* level );
293 
294 ////////////////
295 // Gain : Mic(ADC) Gain Funcs
296 ////////////////
297 
298 // SetGain : Set Mic(ADC) Gain
299 PMIC_ERR         PMICSetGainAsync           ( u16  gain,  PMICCallback cb, void* arg );
300 PMIC_ERR         PMICSetGain                ( u16  gain );
301 
302 // GetGain : Get Mic(ADC) Gain
303 PMIC_ERR         PMICGetGainAsync           ( u16* gain,  PMICCallback cb, void* arg );
304 PMIC_ERR         PMICGetGain                ( u16* gain );
305 
306 /*---------------------------------------------------------------------------*
307    P-MIC utility (for VOIP) functions
308  *---------------------------------------------------------------------------*/
309 
310 // Echo Suppressor on Wii
311 PMIC_ERR         PMICExecEs                 ( s16* send, s16* recv, s32 samples, BOOL init, BOOL *vflag );
312 void             PMICSetEsMode              ( PMICEsMode* mode );
313 void             PMICGetEsMode              ( PMICEsMode* mode );
314 
315 // pre-defined modes
316 extern PMICEsMode  PMICEsPhone;         // for phone-mode
317 extern PMICEsMode  PMICEsConference2;   // for conference-mode between 2 persons
318 extern PMICEsMode  PMICEsConference3;   // for conference-mode between 3 persons
319 extern PMICEsMode  PMICEsConference3_1; // for conference-mode between 3 persons (deep loss     than c3)
320 extern PMICEsMode  PMICEsConference3_2; // for conference-mode between 3 persons (deep loss     than c3_1)
321 extern PMICEsMode  PMICEsConference3_3; // for conference-mode between 3 persons (fast decrease than c3)
322 extern PMICEsMode  PMICEsConference3_4; // for conference-mode between 3 persons (fast decrease than c3_1)
323 extern PMICEsMode  PMICEsConference3_5; // for conference-mode between 3 persons (fast decrease than c3_2)
324 extern PMICEsMode  PMICEsConference4;   // for conference-mode between 4 persons
325 
326 #ifdef __cplusplus
327 }
328 #endif
329 
330 #endif // __PMIC_H__
331