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