1 /*
2  * Copyright (c) 2015-2019, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * *  Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  * *  Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * *  Neither the name of Texas Instruments Incorporated nor the names of
17  *    its contributors may be used to endorse or promote products derived
18  *    from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 /*! ============================================================================
33  *  @file       GPIOCC32XX.h
34  *
35  *  @brief      GPIO driver implementation for CC32xx devices
36  *
37  *  The GPIO header file should be included in an application as follows:
38  *  @code
39  *  #include <ti/drivers/GPIO.h>
40  *  #include <ti/drivers/gpio/GPIOCC32XX.h>
41  *  @endcode
42  *
43  *  Refer to @ref GPIO.h for a complete description of the GPIO
44  *  driver APIs provided and examples of their use.
45  *
46  *  ### CC32xx GPIO Driver Configuration #
47  *
48  *  In order to use the GPIO APIs, the application is required
49  *  to provide 3 structures in the ti_drivers_config.c file:
50  *
51  *  1.  An array of @ref GPIO_PinConfig elements that defines the
52  *  initial configuration of each pin used by the application. A
53  *  pin is referenced in the application by its corresponding index in this
54  *  array. The pin type (that is, INPUT/OUTPUT), its initial state (that is
55  *  OUTPUT_HIGH or LOW), interrupt behavior (RISING/FALLING edge, etc.)
56  *  (see @ref GPIO_PinConfigSettings), and
57  *  device specific pin identification (see @ref GPIOCC32XX_PinConfigIds)
58  *  are configured in each element of this array.
59  *  Below is an CC32XX device specific example of the GPIO_PinConfig array:
60  *  @code
61  *  //
62  *  // Array of Pin configurations
63  *  // NOTE: The order of the pin configurations must coincide with what was
64  *  //       defined in CC3220SF_LAUNCHXL.h
65  *  // NOTE: Pins not used for interrupts should be placed at the end of the
66  *  //       array.  Callback entries can be omitted from callbacks array to
67  *  //       reduce memory usage.
68  *  //
69  *  GPIO_PinConfig gpioPinConfigs[] = {
70  *      // input pins with callbacks
71  *      // CC3220SF_LAUNCHXL_GPIO_SW2
72  *      GPIOCC32XX_GPIO_22 | GPIO_CFG_INPUT | GPIO_CFG_IN_INT_RISING,
73  *      // CC3220SF_LAUNCHXL_GPIO_SW3
74  *      GPIOCC32XX_GPIO_13 | GPIO_CFG_INPUT | GPIO_CFG_IN_INT_RISING,
75  *
76  *      // output pins
77  *      // CC3220SF_LAUNCHXL_GPIO_LED_D7
78  *      GPIOCC32XX_GPIO_09 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW,
79  *  };
80  *  @endcode
81  *
82  *  2.  An array of @ref GPIO_CallbackFxn elements that is used to store
83  *  callback function pointers for GPIO pins configured with interrupts.
84  *  The indexes for these array elements correspond to the pins defined
85  *  in the @ref GPIO_PinConfig array. These function pointers can be defined
86  *  statically by referencing the callback function name in the array
87  *  element, or dynamically, by setting the array element to NULL and using
88  *  GPIO_setCallback() at runtime to plug the callback entry.
89  *  Pins not used for interrupts can be omitted from the callback array to
90  *  reduce memory usage (if they are placed at the end of the @ref
91  *  GPIO_PinConfig array). The callback function syntax should match the
92  *  following:
93  *  @code
94  *  void (*GPIO_CallbackFxn)(unsigned int index);
95  *  @endcode
96  *  The index parameter is the same index that was passed to
97  *  GPIO_setCallback(). This allows the same callback function to be used
98  *  for multiple GPIO interrupts, by using the index to identify the GPIO
99  *  that caused the interrupt.
100  *  Below is a CC32XX device specific example of the @ref GPIO_CallbackFxn
101  *  array:
102  *  @code
103  *  //
104  *  // Array of callback function pointers
105  *  // NOTE: The order of the pin configurations must coincide with what was
106  *  //       defined in CC3220SF_LAUNCHXL.h
107  *  // NOTE: Pins not used for interrupts can be omitted from callbacks array to
108  *  //       reduce memory usage (if placed at end of gpioPinConfigs array).
109  *  //
110  *  GPIO_CallbackFxn gpioCallbackFunctions[] = {
111  *      NULL,  // CC3220SF_LAUNCHXL_GPIO_SW2
112  *      NULL   // CC3220SF_LAUNCHXL_GPIO_SW3
113  *  };
114  *  @endcode
115  *
116  *  3.  The device specific GPIOCC32XX_Config structure that tells the GPIO
117  *  driver where the two aforementioned arrays are and the number of elements
118  *  in each. The interrupt priority of all pins configured to generate
119  *  interrupts is also specified here. Values for the interrupt priority are
120  *  device-specific. You should be well-acquainted with the interrupt
121  *  controller used in your device before setting this parameter to a
122  *  non-default value. The sentinel value of (~0) (the default value) is
123  *  used to indicate that the lowest possible priority should be used.
124  *  Below is an example of an initialized GPIOCC32XX_Config
125  *  structure:
126  *  @code
127  *  const GPIOCC32XX_Config GPIOCC32XX_config = {
128  *      .pinConfigs = (GPIO_PinConfig *)gpioPinConfigs,
129  *      .callbacks = (GPIO_CallbackFxn *)gpioCallbackFunctions,
130  *      .numberOfPinConfigs = sizeof(gpioPinConfigs)/sizeof(GPIO_PinConfig),
131  *      .numberOfCallbacks = sizeof(gpioCallbackFunctions)/sizeof(GPIO_CallbackFxn),
132  *      .intPriority = (~0)
133  *  };
134  *  @endcode
135  *
136  * \note GPIOCC32XX_GPIO_26 & GPIOCC32XX_GPIO_27 can only be used as output
137  * pins.
138  *
139  *  ============================================================================
140  */
141 
142 #ifndef ti_drivers_GPIOCC32XX__include
143 #define ti_drivers_GPIOCC32XX__include
144 
145 #include <stdint.h>
146 #include <ti/drivers/GPIO.h>
147 
148 #ifdef __cplusplus
149 extern "C" {
150 #endif
151 
152 /*!
153  *  @brief  GPIO device specific driver configuration structure
154  *
155  *  The device specific GPIOCC32XX_Config structure that tells the GPIO
156  *  driver where the two aforementioned arrays are and the number of elements
157  *  in each. The interrupt priority of all pins configured to generate
158  *  interrupts is also specified here. Values for the interrupt priority are
159  *  device-specific. You should be well-acquainted with the interrupt
160  *  controller used in your device before setting this parameter to a
161  *  non-default value. The sentinel value of (~0) (the default value) is
162  *  used to indicate that the lowest possible priority should be used.
163  *
164  *  Below is an example of an initialized GPIOCC32XX_Config
165  *  structure:
166  *  @code
167  *  const GPIOCC32XX_Config GPIOCC32XX_config = {
168  *      .pinConfigs = (GPIO_PinConfig *)gpioPinConfigs,
169  *      .callbacks = (GPIO_CallbackFxn *)gpioCallbackFunctions,
170  *      .numberOfPinConfigs = sizeof(gpioPinConfigs)/sizeof(GPIO_PinConfig),
171  *      .numberOfCallbacks = sizeof(gpioCallbackFunctions)/sizeof(GPIO_CallbackFxn),
172  *      .intPriority = (~0)
173  *  };
174  *  @endcode
175  */
176 typedef struct {
177     /*! Pointer to the board's GPIO_PinConfig array */
178     GPIO_PinConfig  *pinConfigs;
179 
180     /*! Pointer to the board's GPIO_CallbackFxn array */
181     GPIO_CallbackFxn  *callbacks;
182 
183     /*! Number of GPIO_PinConfigs defined */
184     uint32_t numberOfPinConfigs;
185 
186     /*! Number of GPIO_Callbacks defined */
187     uint32_t numberOfCallbacks;
188 
189     /*!
190      *  Interrupt priority used for call back interrupts.
191      *
192      *  intPriority is the interrupt priority, as defined by the
193      *  underlying OS.  It is passed unmodified to the underlying OS's
194      *  interrupt handler creation code, so you need to refer to the OS
195      *  documentation for usage.  If the driver uses the ti.dpl
196      *  interface instead of making OS calls directly, then the HwiP port
197      *  handles the interrupt priority in an OS specific way.  In the case
198      *  of the SYS/BIOS port, intPriority is passed unmodified to Hwi_create().
199      *
200      *  Setting ~0 will configure the lowest possible priority
201      */
202     uint32_t intPriority;
203 } GPIOCC32XX_Config;
204 
205 /*!
206  *  \defgroup GPIOCC32XX_PinConfigIds GPIO pin identification macros used to configure GPIO pins
207  *  @{
208  */
209 /**
210  *  @name Device specific GPIO port/pin identifiers to be used within the board's GPIO_PinConfig table.
211  *  @{
212 */
213 #define GPIOCC32XX_EMPTY_PIN  0x0000    /*!< @hideinitializer */
214 
215 #define GPIOCC32XX_GPIO_00    0x0001    /*!< PIN 50 */
216 #define GPIOCC32XX_GPIO_01    0x0002    /*!< PIN 55 */
217 #define GPIOCC32XX_GPIO_02    0x0004    /*!< PIN 57 */
218 #define GPIOCC32XX_GPIO_03    0x0008    /*!< PIN 58 */
219 #define GPIOCC32XX_GPIO_04    0x0010    /*!< PIN 59 */
220 #define GPIOCC32XX_GPIO_05    0x0020    /*!< PIN 60 */
221 #define GPIOCC32XX_GPIO_06    0x0040    /*!< PIN 61 */
222 #define GPIOCC32XX_GPIO_07    0x0080    /*!< PIN 62 */
223 
224 #define GPIOCC32XX_GPIO_08    0x0101    /*!< PIN 63 */
225 #define GPIOCC32XX_GPIO_09    0x0102    /*!< PIN 64 */
226 #define GPIOCC32XX_GPIO_10    0x0104    /*!< PIN 1  */
227 #define GPIOCC32XX_GPIO_11    0x0108    /*!< PIN 2  */
228 #define GPIOCC32XX_GPIO_12    0x0110    /*!< PIN 3  */
229 #define GPIOCC32XX_GPIO_13    0x0120    /*!< PIN 4  */
230 #define GPIOCC32XX_GPIO_14    0x0140    /*!< PIN 5  */
231 #define GPIOCC32XX_GPIO_15    0x0180    /*!< PIN 6  */
232 
233 #define GPIOCC32XX_GPIO_16    0x0201    /*!< PIN 7  */
234 #define GPIOCC32XX_GPIO_17    0x0202    /*!< PIN 8  */
235 #define GPIOCC32XX_GPIO_22    0x0240    /*!< PIN 15 */
236 #define GPIOCC32XX_GPIO_23    0x0280    /*!< PIN 16 */
237 
238 #define GPIOCC32XX_GPIO_24    0x0301    /*!< PIN 17 */
239 #define GPIOCC32XX_GPIO_25    0x0302    /*!< PIN 21 */
240 #define GPIOCC32XX_GPIO_26    0x0304    /*!< PIN 29 */
241 #define GPIOCC32XX_GPIO_27    0x0308    /*!< PIN 30 */
242 #define GPIOCC32XX_GPIO_28    0x0310    /*!< PIN 18 */
243 #define GPIOCC32XX_GPIO_29    0x0320    /*!< PIN 20 */
244 #define GPIOCC32XX_GPIO_30    0x0340    /*!< PIN 53 */
245 #define GPIOCC32XX_GPIO_31    0x0380    /*!< PIN 45 */
246 
247 #define GPIOCC32XX_GPIO_32    0x0401    /*!< PIN 52 */
248 /** @} */
249 
250 /**
251  *  @name CC32xx device specific GPIO_PinConfig macros
252  *  @{
253  */
254 #define GPIOCC32XX_USE_STATIC 0x8000    /*!< @hideinitializer use statically-defined parking state */
255 /** @} */
256 
257 /** @} end of GPIOCC32XX_PinConfigIds group */
258 
259 #ifdef __cplusplus
260 }
261 #endif
262 
263 #endif /* ti_drivers_GPIOCC32XX__include */
264