• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright (C) 2001-2012 Broadcom Corporation
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 /******************************************************************************
20  *
21  *  Definitions for UPIO driver
22  *
23  ******************************************************************************/
24 #ifndef UPIO_H
25 #define UPIO_H
26 
27 #include "bt_target.h"
28 
29 /* Enumeration of UPIO features                                         */
30 /* Not all features enumerated here are supported by the hardware.      */
31 /* Use UPIO_Feature() to determine support of a particular feature.     */
32 enum
33 {
34     /* LEDs */
35     UPIO_FEAT_LED1,
36     UPIO_FEAT_LED2,
37     UPIO_FEAT_LED3,
38     UPIO_FEAT_LED4,
39     UPIO_FEAT_LED5,
40     UPIO_FEAT_LED6,
41     UPIO_FEAT_LED7,
42     UPIO_FEAT_LED8,
43 
44     /* Switches */
45     UPIO_FEAT_SWITCH1,
46     UPIO_FEAT_SWITCH2,
47     UPIO_FEAT_SWITCH3,
48     UPIO_FEAT_SWITCH4,
49     UPIO_FEAT_SWITCH5,
50     UPIO_FEAT_SWITCH6,
51     UPIO_FEAT_SWITCH7,
52     UPIO_FEAT_SWITCH8,
53     UPIO_FEAT_SWITCH9,
54     UPIO_FEAT_SWITCH10,
55     UPIO_FEAT_SWITCH11,
56     UPIO_FEAT_SWITCH12,
57     UPIO_FEAT_SWITCH13,
58     UPIO_FEAT_SWITCH14,
59     UPIO_FEAT_SWITCH15,
60     UPIO_FEAT_SWITCH16,
61 
62     /* Jumpers */
63     UPIO_FEAT_JUMPER1,
64     UPIO_FEAT_JUMPER2,
65     UPIO_FEAT_JUMPER3,
66     UPIO_FEAT_JUMPER4,
67     UPIO_FEAT_JUMPER5,
68     UPIO_FEAT_JUMPER6,
69     UPIO_FEAT_JUMPER7,
70     UPIO_FEAT_JUMPER8,
71 
72     /* Push buttons */
73     UPIO_FEAT_BUTTON1,
74     UPIO_FEAT_BUTTON2,
75     UPIO_FEAT_BUTTON3,
76     UPIO_FEAT_BUTTON4,
77     UPIO_FEAT_BUTTON5,
78     UPIO_FEAT_BUTTON6,
79     UPIO_FEAT_BUTTON7,
80     UPIO_FEAT_BUTTON8,
81 
82     /* General purpose */
83     UPIO_FEAT_GENERAL1,
84     UPIO_FEAT_GENERAL2,
85     UPIO_FEAT_GENERAL3,
86     UPIO_FEAT_GENERAL4,
87     UPIO_FEAT_GENERAL5,
88     UPIO_FEAT_GENERAL6,
89     UPIO_FEAT_GENERAL7,
90     UPIO_FEAT_GENERAL8,
91     UPIO_FEAT_GENERAL9,
92     UPIO_FEAT_GENERAL10,
93     UPIO_FEAT_GENERAL11,
94     UPIO_FEAT_GENERAL12,
95     UPIO_FEAT_GENERAL13,
96     UPIO_FEAT_GENERAL14,
97     UPIO_FEAT_GENERAL15,
98     UPIO_FEAT_GENERAL16,
99     UPIO_FEAT_GENERAL17,
100     UPIO_FEAT_GENERAL18,
101     UPIO_FEAT_GENERAL19,
102     UPIO_FEAT_GENERAL20,
103     UPIO_FEAT_GENERAL21,
104     UPIO_FEAT_GENERAL22,
105     UPIO_FEAT_GENERAL23,
106     UPIO_FEAT_GENERAL24,
107     UPIO_FEAT_GENERAL25,
108     UPIO_FEAT_GENERAL26,
109     UPIO_FEAT_GENERAL27,
110     UPIO_FEAT_GENERAL28,
111     UPIO_FEAT_GENERAL29,
112     UPIO_FEAT_GENERAL30,
113     UPIO_FEAT_GENERAL31,
114     UPIO_FEAT_GENERAL32,
115 
116     UPIO_FEAT_IN_HIGH,          /* Support for input with interrupt on high signal level. */
117     UPIO_FEAT_IN_LOW,           /* Support for input with interrupt on low signal level. */
118     UPIO_FEAT_IN_RISE,          /* Support for input with interrupt on rising edge. */
119     UPIO_FEAT_IN_FALL           /* Support for input with interrupt on falling. */
120 
121 };
122 typedef UINT8 tUPIO_FEATURE;
123 
124 
125 /* Enumeration of UPIO configurations */
126 enum
127 {
128     UPIO_OUT,
129     UPIO_IN,
130     UPIO_IN_EDGE,
131     UPIO_IN_LEVEL,
132     UPIO_NONE
133 };
134 typedef UINT8 tUPIO_CONFIG;
135 
136 
137 /* Enumeration of UPIO types */
138 enum
139 {
140     UPIO_LED,                   /* LED */
141     UPIO_SWITCH,                /* Switch */
142     UPIO_JUMPER,                /* Jumper */
143     UPIO_BUTTON,                /* Push-button switch */
144     UPIO_GENERAL,               /* General purpose I/O */
145 
146     UPIO_NUMBER_OF_TYPES
147 };
148 typedef UINT8 tUPIO_TYPE;
149 
150 
151 /* Enumeration of UPIO states */
152 enum
153 {
154     UPIO_OFF,
155     UPIO_ON,
156     UPIO_TOGGLE
157 };
158 typedef UINT8 tUPIO_STATE;
159 
160 
161 enum
162 {
163     UPIO_SW_BANK2,
164     UPIO_SW_BANK3
165 };
166 typedef UINT8 tUPIO_SW_BANK;
167 
168 /* Jumper masks */
169 #define UPIO_JUMPER1    0x00000001
170 #define UPIO_JUMPER2    0x00000002
171 #define UPIO_JUMPER3    0x00000004
172 #define UPIO_JUMPER4    0x00000008
173 #define UPIO_JUMPER5    0x00000010
174 #define UPIO_JUMPER6    0x00000020
175 #define UPIO_JUMPER7    0x00000040
176 #define UPIO_JUMPER8    0x00000080
177 
178 /* General purpose i/o masks */
179 #define UPIO_GENERAL1   0x00000001
180 #define UPIO_GENERAL2   0x00000002
181 #define UPIO_GENERAL3   0x00000004
182 #define UPIO_GENERAL4   0x00000008
183 #define UPIO_GENERAL5   0x00000010
184 #define UPIO_GENERAL6   0x00000020
185 #define UPIO_GENERAL7   0x00000040
186 #define UPIO_GENERAL8   0x00000080
187 #define UPIO_GENERAL9   0x00000100
188 #define UPIO_GENERAL10  0x00000200
189 #define UPIO_GENERAL11  0x00000400
190 #define UPIO_GENERAL12  0x00000800
191 #define UPIO_GENERAL13  0x00001000
192 #define UPIO_GENERAL14  0x00002000
193 #define UPIO_GENERAL15  0x00004000
194 #define UPIO_GENERAL16  0x00008000
195 #define UPIO_GENERAL17  0x00010000
196 #define UPIO_GENERAL18  0x00020000
197 #define UPIO_GENERAL19  0x00040000
198 #define UPIO_GENERAL20  0x00080000
199 #define UPIO_GENERAL21  0x00100000
200 #define UPIO_GENERAL22  0x00200000
201 #define UPIO_GENERAL23  0x00400000
202 #define UPIO_GENERAL24  0x00800000
203 #define UPIO_GENERAL25  0x01000000
204 #define UPIO_GENERAL26  0x02000000
205 #define UPIO_GENERAL27  0x04000000
206 #define UPIO_GENERAL28  0x08000000
207 #define UPIO_GENERAL29  0x10000000
208 #define UPIO_GENERAL30  0x20000000
209 #define UPIO_GENERAL31  0x40000000
210 #define UPIO_GENERAL32  0x80000000
211 
212 typedef UINT32 tUPIO;
213 
214 /* LED masks */
215 #define UPIO_LED1       0x00000001
216 #define UPIO_LED2       0x00000002
217 #define UPIO_LED3       0x00000004
218 #define UPIO_LED4       0x00000008
219 #define UPIO_LED5       0x00000010
220 #define UPIO_LED6       0x00000020
221 #define UPIO_LED7       0x00000040
222 #define UPIO_LED8       0x00000080
223 
224 #define UPIO_LED_ALL    (UPIO_LED1 | UPIO_LED2 | UPIO_LED3 | UPIO_LED4 | \
225                         UPIO_LED5 | UPIO_LED6 | UPIO_LED7 | UPIO_LED8)
226 
227 
228 /* Switch masks */
229 #define UPIO_SWITCH1    0x00000001
230 #define UPIO_SWITCH2    0x00000002
231 #define UPIO_SWITCH3    0x00000004
232 #define UPIO_SWITCH4    0x00000008
233 #define UPIO_SWITCH5    0x00000010
234 #define UPIO_SWITCH6    0x00000020
235 #define UPIO_SWITCH7    0x00000040
236 #define UPIO_SWITCH8    0x00000080
237 #define UPIO_SWITCH9    0x00000100
238 #define UPIO_SWITCH10   0x00000200
239 #define UPIO_SWITCH11   0x00000400
240 #define UPIO_SWITCH12   0x00000800
241 #define UPIO_SWITCH13   0x00001000
242 #define UPIO_SWITCH14   0x00002000
243 #define UPIO_SWITCH15   0x00004000
244 #define UPIO_SWITCH16   0x00008000
245 
246 /* Push button masks */
247 #define UPIO_BUTTON1    0x00000001
248 #define UPIO_BUTTON2    0x00000002
249 #define UPIO_BUTTON3    0x00000004
250 #define UPIO_BUTTON4    0x00000008
251 #define UPIO_BUTTON5    0x00000010
252 #define UPIO_BUTTON6    0x00000020
253 #define UPIO_BUTTON7    0x00000040
254 #define UPIO_BUTTON8    0x00000080
255 
256 typedef void (tUPIO_CBACK)(tUPIO_TYPE type, tUPIO pio, tUPIO_STATE state);
257 
258 #ifdef __cplusplus
259 extern "C" {
260 #endif
261 
262 /* API functions for UPIO driver */
263 
264 /*****************************************************************************
265 **
266 ** Function         UPIO_Init
267 **
268 ** Description
269 **      Initialize the GPIO service.
270 **      This function is typically called once upon system startup.
271 **
272 ** Returns          nothing
273 **
274 *****************************************************************************/
275 UDRV_API void UPIO_Init(void *p_cfg);
276 
277 
278 /*****************************************************************************
279 **
280 ** Function         UPIO_Set
281 **
282 ** Description
283 **      This function sets one or more GPIO devices to the given state.
284 **      Multiple GPIOs of the same type can be masked together to set more
285 **      than one GPIO. This function can only be used on types UPIO_LED and
286 **      UPIO_GENERAL.
287 **
288 ** Input Parameters:
289 **      type    The type of device.
290 **      pio     Indicates the particular GPIOs.
291 **      state   The desired state.
292 **
293 ** Output Parameter:
294 **      None.
295 **
296 ** Returns:
297 **      None.
298 **
299 *****************************************************************************/
300 UDRV_API void UPIO_Set(tUPIO_TYPE type, tUPIO pio, tUPIO_STATE state);
301 
302 
303 /*****************************************************************************
304 **
305 ** Function         UPIO_Read
306 **
307 ** Description
308 **      Read the state of a GPIO. This function can be used for any type of
309 **      device. Parameter pio can only indicate a single GPIO; multiple GPIOs
310 **      cannot be masked together.
311 **
312 ** Input Parameters:
313 **      Type:	The type of device.
314 **      pio:    Indicates the particular GUPIO.
315 **
316 ** Output Parameter:
317 **      None.
318 **
319 ** Returns:
320 **      State of GPIO (UPIO_ON or UPIO_OFF).
321 **
322 *****************************************************************************/
323 UDRV_API tUPIO_STATE UPIO_Read(tUPIO_TYPE type, tUPIO pio);
324 
325 
326 /*****************************************************************************
327 **
328 ** Function         UPIO_Config
329 **
330 ** Description      - Configure GPIOs of type UPIO_GENERAL as inputs or outputs
331 **                  - Configure GPIOs to be polled or interrupt driven
332 **
333 **                  Currently only support polled GPIOs.
334 **
335 ** Input Parameters:
336 **      type    The type of device.
337 **      pio     Indicates the particular GPIOs.
338 **      config
339 **      cback
340 **
341 ** Output Parameter:
342 **      None.
343 **
344 ** Returns:
345 **      None.
346 **
347 *****************************************************************************/
348 UDRV_API void UPIO_Config(tUPIO_TYPE type, tUPIO pio, tUPIO_CONFIG config, tUPIO_CBACK *cback);
349 
350 
351 /*****************************************************************************
352 **
353 ** Function         UPIO_Feature
354 **
355 ** Description
356 **      Checks whether a feature of the pio API is supported
357 **
358 ** Input Parameter:
359 **      feature     The feature to check
360 **
361 ** Output Parameter:
362 **      None.
363 **
364 ** Returns:
365 **      TRUE if feature is supported, FALSE if it is not.
366 **
367 *****************************************************************************/
368 UDRV_API BOOLEAN UPIO_Feature(tUPIO_FEATURE feature);
369 
370 #ifdef __cplusplus
371 }
372 #endif
373 
374 #endif  /* ifdef UPIO_H */
375