Pratyush Mallick
/
nano_dac
this is testing
noos_mbed/include/gpio.h@0:e8a1ba50c46b, 2021-01-14 (annotated)
- Committer:
- pmallick
- Date:
- Thu Jan 14 19:12:57 2021 +0530
- Revision:
- 0:e8a1ba50c46b
this is testing
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pmallick | 0:e8a1ba50c46b | 1 | /***************************************************************************//** |
pmallick | 0:e8a1ba50c46b | 2 | * @file gpio.h |
pmallick | 0:e8a1ba50c46b | 3 | * @brief Header file of GPIO Interface |
pmallick | 0:e8a1ba50c46b | 4 | * @author DBogdan (dragos.bogdan@analog.com) |
pmallick | 0:e8a1ba50c46b | 5 | ******************************************************************************** |
pmallick | 0:e8a1ba50c46b | 6 | * Copyright 2019(c) Analog Devices, Inc. |
pmallick | 0:e8a1ba50c46b | 7 | * |
pmallick | 0:e8a1ba50c46b | 8 | * All rights reserved. |
pmallick | 0:e8a1ba50c46b | 9 | * |
pmallick | 0:e8a1ba50c46b | 10 | * Redistribution and use in source and binary forms, with or without |
pmallick | 0:e8a1ba50c46b | 11 | * modification, are permitted provided that the following conditions are met: |
pmallick | 0:e8a1ba50c46b | 12 | * - Redistributions of source code must retain the above copyright |
pmallick | 0:e8a1ba50c46b | 13 | * notice, this list of conditions and the following disclaimer. |
pmallick | 0:e8a1ba50c46b | 14 | * - Redistributions in binary form must reproduce the above copyright |
pmallick | 0:e8a1ba50c46b | 15 | * notice, this list of conditions and the following disclaimer in |
pmallick | 0:e8a1ba50c46b | 16 | * the documentation and/or other materials provided with the |
pmallick | 0:e8a1ba50c46b | 17 | * distribution. |
pmallick | 0:e8a1ba50c46b | 18 | * - Neither the name of Analog Devices, Inc. nor the names of its |
pmallick | 0:e8a1ba50c46b | 19 | * contributors may be used to endorse or promote products derived |
pmallick | 0:e8a1ba50c46b | 20 | * from this software without specific prior written permission. |
pmallick | 0:e8a1ba50c46b | 21 | * - The use of this software may or may not infringe the patent rights |
pmallick | 0:e8a1ba50c46b | 22 | * of one or more patent holders. This license does not release you |
pmallick | 0:e8a1ba50c46b | 23 | * from the requirement that you obtain separate licenses from these |
pmallick | 0:e8a1ba50c46b | 24 | * patent holders to use this software. |
pmallick | 0:e8a1ba50c46b | 25 | * - Use of the software either in source or binary form, must be run |
pmallick | 0:e8a1ba50c46b | 26 | * on or directly connected to an Analog Devices Inc. component. |
pmallick | 0:e8a1ba50c46b | 27 | * |
pmallick | 0:e8a1ba50c46b | 28 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR |
pmallick | 0:e8a1ba50c46b | 29 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, |
pmallick | 0:e8a1ba50c46b | 30 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
pmallick | 0:e8a1ba50c46b | 31 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, |
pmallick | 0:e8a1ba50c46b | 32 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
pmallick | 0:e8a1ba50c46b | 33 | * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR |
pmallick | 0:e8a1ba50c46b | 34 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
pmallick | 0:e8a1ba50c46b | 35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
pmallick | 0:e8a1ba50c46b | 36 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
pmallick | 0:e8a1ba50c46b | 37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
pmallick | 0:e8a1ba50c46b | 38 | *******************************************************************************/ |
pmallick | 0:e8a1ba50c46b | 39 | |
pmallick | 0:e8a1ba50c46b | 40 | #ifndef GPIO_H_ |
pmallick | 0:e8a1ba50c46b | 41 | #define GPIO_H_ |
pmallick | 0:e8a1ba50c46b | 42 | |
pmallick | 0:e8a1ba50c46b | 43 | /******************************************************************************/ |
pmallick | 0:e8a1ba50c46b | 44 | /***************************** Include Files **********************************/ |
pmallick | 0:e8a1ba50c46b | 45 | /******************************************************************************/ |
pmallick | 0:e8a1ba50c46b | 46 | |
pmallick | 0:e8a1ba50c46b | 47 | #include <stdint.h> |
pmallick | 0:e8a1ba50c46b | 48 | |
pmallick | 0:e8a1ba50c46b | 49 | /******************************************************************************/ |
pmallick | 0:e8a1ba50c46b | 50 | /********************** Macros and Constants Definitions **********************/ |
pmallick | 0:e8a1ba50c46b | 51 | /******************************************************************************/ |
pmallick | 0:e8a1ba50c46b | 52 | |
pmallick | 0:e8a1ba50c46b | 53 | #define GPIO_OUT 0x01 |
pmallick | 0:e8a1ba50c46b | 54 | #define GPIO_IN 0x00 |
pmallick | 0:e8a1ba50c46b | 55 | |
pmallick | 0:e8a1ba50c46b | 56 | /******************************************************************************/ |
pmallick | 0:e8a1ba50c46b | 57 | /*************************** Types Declarations *******************************/ |
pmallick | 0:e8a1ba50c46b | 58 | /******************************************************************************/ |
pmallick | 0:e8a1ba50c46b | 59 | |
pmallick | 0:e8a1ba50c46b | 60 | /** |
pmallick | 0:e8a1ba50c46b | 61 | * @struct gpio_platform_ops |
pmallick | 0:e8a1ba50c46b | 62 | * @brief Structure holding gpio function pointers that point to the platform |
pmallick | 0:e8a1ba50c46b | 63 | * specific function |
pmallick | 0:e8a1ba50c46b | 64 | */ |
pmallick | 0:e8a1ba50c46b | 65 | struct gpio_platform_ops ; |
pmallick | 0:e8a1ba50c46b | 66 | |
pmallick | 0:e8a1ba50c46b | 67 | /** |
pmallick | 0:e8a1ba50c46b | 68 | * @struct gpio_init_param |
pmallick | 0:e8a1ba50c46b | 69 | * @brief Structure holding the parameters for GPIO initialization. |
pmallick | 0:e8a1ba50c46b | 70 | */ |
pmallick | 0:e8a1ba50c46b | 71 | typedef struct gpio_init_param { |
pmallick | 0:e8a1ba50c46b | 72 | /** GPIO number */ |
pmallick | 0:e8a1ba50c46b | 73 | uint32_t number; |
pmallick | 0:e8a1ba50c46b | 74 | /** GPIO platform specific functions */ |
pmallick | 0:e8a1ba50c46b | 75 | const struct gpio_platform_ops *platform_ops; |
pmallick | 0:e8a1ba50c46b | 76 | /** GPIO extra parameters (device specific) */ |
pmallick | 0:e8a1ba50c46b | 77 | void *extra; |
pmallick | 0:e8a1ba50c46b | 78 | } gpio_init_param; |
pmallick | 0:e8a1ba50c46b | 79 | |
pmallick | 0:e8a1ba50c46b | 80 | /** |
pmallick | 0:e8a1ba50c46b | 81 | * @struct gpio_desc |
pmallick | 0:e8a1ba50c46b | 82 | * @brief Structure holding the GPIO descriptor. |
pmallick | 0:e8a1ba50c46b | 83 | */ |
pmallick | 0:e8a1ba50c46b | 84 | typedef struct gpio_desc { |
pmallick | 0:e8a1ba50c46b | 85 | /** GPIO number */ |
pmallick | 0:e8a1ba50c46b | 86 | uint32_t number; |
pmallick | 0:e8a1ba50c46b | 87 | /** GPIO platform specific functions */ |
pmallick | 0:e8a1ba50c46b | 88 | const struct gpio_platform_ops *platform_ops; |
pmallick | 0:e8a1ba50c46b | 89 | /** GPIO extra parameters (device specific) */ |
pmallick | 0:e8a1ba50c46b | 90 | void *extra; |
pmallick | 0:e8a1ba50c46b | 91 | } gpio_desc; |
pmallick | 0:e8a1ba50c46b | 92 | |
pmallick | 0:e8a1ba50c46b | 93 | /** |
pmallick | 0:e8a1ba50c46b | 94 | * @enum gpio_values |
pmallick | 0:e8a1ba50c46b | 95 | * @brief Enum that holds the possible output states of a GPIO. |
pmallick | 0:e8a1ba50c46b | 96 | */ |
pmallick | 0:e8a1ba50c46b | 97 | enum gpio_values { |
pmallick | 0:e8a1ba50c46b | 98 | /** GPIO logic low */ |
pmallick | 0:e8a1ba50c46b | 99 | GPIO_LOW, |
pmallick | 0:e8a1ba50c46b | 100 | /** GPIO logic high */ |
pmallick | 0:e8a1ba50c46b | 101 | GPIO_HIGH, |
pmallick | 0:e8a1ba50c46b | 102 | /** GPIO high impedance */ |
pmallick | 0:e8a1ba50c46b | 103 | GPIO_HIGH_Z |
pmallick | 0:e8a1ba50c46b | 104 | }; |
pmallick | 0:e8a1ba50c46b | 105 | |
pmallick | 0:e8a1ba50c46b | 106 | /** |
pmallick | 0:e8a1ba50c46b | 107 | * @struct gpio_platform_ops |
pmallick | 0:e8a1ba50c46b | 108 | * @brief Structure holding gpio function pointers that point to the platform |
pmallick | 0:e8a1ba50c46b | 109 | * specific function |
pmallick | 0:e8a1ba50c46b | 110 | */ |
pmallick | 0:e8a1ba50c46b | 111 | struct gpio_platform_ops { |
pmallick | 0:e8a1ba50c46b | 112 | /** gpio initialization function pointer */ |
pmallick | 0:e8a1ba50c46b | 113 | int32_t (*gpio_ops_get)(struct gpio_desc **, const struct gpio_init_param *); |
pmallick | 0:e8a1ba50c46b | 114 | /** gpio optional descriptor function pointer */ |
pmallick | 0:e8a1ba50c46b | 115 | int32_t (*gpio_ops_get_optional)(struct gpio_desc **, |
pmallick | 0:e8a1ba50c46b | 116 | const struct gpio_init_param *); |
pmallick | 0:e8a1ba50c46b | 117 | /** gpio remove function pointer */ |
pmallick | 0:e8a1ba50c46b | 118 | int32_t (*gpio_ops_remove)(struct gpio_desc *); |
pmallick | 0:e8a1ba50c46b | 119 | /** gpio direction input function pointer */ |
pmallick | 0:e8a1ba50c46b | 120 | int32_t (*gpio_ops_direction_input)(struct gpio_desc *); |
pmallick | 0:e8a1ba50c46b | 121 | /** gpio direction output function pointer */ |
pmallick | 0:e8a1ba50c46b | 122 | int32_t (*gpio_ops_direction_output)(struct gpio_desc *, uint8_t); |
pmallick | 0:e8a1ba50c46b | 123 | /** gpio get direction function pointer */ |
pmallick | 0:e8a1ba50c46b | 124 | int32_t (*gpio_ops_get_direction)(struct gpio_desc *, uint8_t *); |
pmallick | 0:e8a1ba50c46b | 125 | /** gpio set value function pointer */ |
pmallick | 0:e8a1ba50c46b | 126 | int32_t (*gpio_ops_set_value)(struct gpio_desc *, uint8_t); |
pmallick | 0:e8a1ba50c46b | 127 | /** gpio get value function pointer */ |
pmallick | 0:e8a1ba50c46b | 128 | int32_t (*gpio_ops_get_value)(struct gpio_desc *, uint8_t *); |
pmallick | 0:e8a1ba50c46b | 129 | }; |
pmallick | 0:e8a1ba50c46b | 130 | |
pmallick | 0:e8a1ba50c46b | 131 | /******************************************************************************/ |
pmallick | 0:e8a1ba50c46b | 132 | /************************ Functions Declarations ******************************/ |
pmallick | 0:e8a1ba50c46b | 133 | /******************************************************************************/ |
pmallick | 0:e8a1ba50c46b | 134 | |
pmallick | 0:e8a1ba50c46b | 135 | /* Obtain the GPIO decriptor. */ |
pmallick | 0:e8a1ba50c46b | 136 | int32_t gpio_get(struct gpio_desc **desc, |
pmallick | 0:e8a1ba50c46b | 137 | const struct gpio_init_param *param); |
pmallick | 0:e8a1ba50c46b | 138 | |
pmallick | 0:e8a1ba50c46b | 139 | /* Obtain optional GPIO descriptor. */ |
pmallick | 0:e8a1ba50c46b | 140 | int32_t gpio_get_optional(struct gpio_desc **desc, |
pmallick | 0:e8a1ba50c46b | 141 | const struct gpio_init_param *param); |
pmallick | 0:e8a1ba50c46b | 142 | |
pmallick | 0:e8a1ba50c46b | 143 | /* Free the resources allocated by gpio_get() */ |
pmallick | 0:e8a1ba50c46b | 144 | int32_t gpio_remove(struct gpio_desc *desc); |
pmallick | 0:e8a1ba50c46b | 145 | |
pmallick | 0:e8a1ba50c46b | 146 | /* Enable the input direction of the specified GPIO. */ |
pmallick | 0:e8a1ba50c46b | 147 | int32_t gpio_direction_input(struct gpio_desc *desc); |
pmallick | 0:e8a1ba50c46b | 148 | |
pmallick | 0:e8a1ba50c46b | 149 | /* Enable the output direction of the specified GPIO. */ |
pmallick | 0:e8a1ba50c46b | 150 | int32_t gpio_direction_output(struct gpio_desc *desc, |
pmallick | 0:e8a1ba50c46b | 151 | uint8_t value); |
pmallick | 0:e8a1ba50c46b | 152 | |
pmallick | 0:e8a1ba50c46b | 153 | /* Get the direction of the specified GPIO. */ |
pmallick | 0:e8a1ba50c46b | 154 | int32_t gpio_get_direction(struct gpio_desc *desc, |
pmallick | 0:e8a1ba50c46b | 155 | uint8_t *direction); |
pmallick | 0:e8a1ba50c46b | 156 | |
pmallick | 0:e8a1ba50c46b | 157 | /* Set the value of the specified GPIO. */ |
pmallick | 0:e8a1ba50c46b | 158 | int32_t gpio_set_value(struct gpio_desc *desc, |
pmallick | 0:e8a1ba50c46b | 159 | uint8_t value); |
pmallick | 0:e8a1ba50c46b | 160 | |
pmallick | 0:e8a1ba50c46b | 161 | /* Get the value of the specified GPIO. */ |
pmallick | 0:e8a1ba50c46b | 162 | int32_t gpio_get_value(struct gpio_desc *desc, |
pmallick | 0:e8a1ba50c46b | 163 | uint8_t *value); |
pmallick | 0:e8a1ba50c46b | 164 | |
pmallick | 0:e8a1ba50c46b | 165 | #endif // GPIO_H_ |