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