Marco Zecchini
/
Example_RTOS
Rtos API example
mbed-os/hal/gpio_api.h@0:9fca2b23d0ba, 2019-02-23 (annotated)
- Committer:
- marcozecchini
- Date:
- Sat Feb 23 12:13:36 2019 +0000
- Revision:
- 0:9fca2b23d0ba
final commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
marcozecchini | 0:9fca2b23d0ba | 1 | |
marcozecchini | 0:9fca2b23d0ba | 2 | /** \addtogroup hal */ |
marcozecchini | 0:9fca2b23d0ba | 3 | /** @{*/ |
marcozecchini | 0:9fca2b23d0ba | 4 | /* mbed Microcontroller Library |
marcozecchini | 0:9fca2b23d0ba | 5 | * Copyright (c) 2006-2013 ARM Limited |
marcozecchini | 0:9fca2b23d0ba | 6 | * |
marcozecchini | 0:9fca2b23d0ba | 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
marcozecchini | 0:9fca2b23d0ba | 8 | * you may not use this file except in compliance with the License. |
marcozecchini | 0:9fca2b23d0ba | 9 | * You may obtain a copy of the License at |
marcozecchini | 0:9fca2b23d0ba | 10 | * |
marcozecchini | 0:9fca2b23d0ba | 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
marcozecchini | 0:9fca2b23d0ba | 12 | * |
marcozecchini | 0:9fca2b23d0ba | 13 | * Unless required by applicable law or agreed to in writing, software |
marcozecchini | 0:9fca2b23d0ba | 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
marcozecchini | 0:9fca2b23d0ba | 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
marcozecchini | 0:9fca2b23d0ba | 16 | * See the License for the specific language governing permissions and |
marcozecchini | 0:9fca2b23d0ba | 17 | * limitations under the License. |
marcozecchini | 0:9fca2b23d0ba | 18 | */ |
marcozecchini | 0:9fca2b23d0ba | 19 | #ifndef MBED_GPIO_API_H |
marcozecchini | 0:9fca2b23d0ba | 20 | #define MBED_GPIO_API_H |
marcozecchini | 0:9fca2b23d0ba | 21 | |
marcozecchini | 0:9fca2b23d0ba | 22 | #include <stdint.h> |
marcozecchini | 0:9fca2b23d0ba | 23 | #include "device.h" |
marcozecchini | 0:9fca2b23d0ba | 24 | |
marcozecchini | 0:9fca2b23d0ba | 25 | #ifdef __cplusplus |
marcozecchini | 0:9fca2b23d0ba | 26 | extern "C" { |
marcozecchini | 0:9fca2b23d0ba | 27 | #endif |
marcozecchini | 0:9fca2b23d0ba | 28 | |
marcozecchini | 0:9fca2b23d0ba | 29 | /** |
marcozecchini | 0:9fca2b23d0ba | 30 | * \defgroup hal_gpio GPIO HAL functions |
marcozecchini | 0:9fca2b23d0ba | 31 | * @{ |
marcozecchini | 0:9fca2b23d0ba | 32 | */ |
marcozecchini | 0:9fca2b23d0ba | 33 | |
marcozecchini | 0:9fca2b23d0ba | 34 | /** Set the given pin as GPIO |
marcozecchini | 0:9fca2b23d0ba | 35 | * |
marcozecchini | 0:9fca2b23d0ba | 36 | * @param pin The pin to be set as GPIO |
marcozecchini | 0:9fca2b23d0ba | 37 | * @return The GPIO port mask for this pin |
marcozecchini | 0:9fca2b23d0ba | 38 | **/ |
marcozecchini | 0:9fca2b23d0ba | 39 | uint32_t gpio_set(PinName pin); |
marcozecchini | 0:9fca2b23d0ba | 40 | /* Checks if gpio object is connected (pin was not initialized with NC) |
marcozecchini | 0:9fca2b23d0ba | 41 | * @param pin The pin to be set as GPIO |
marcozecchini | 0:9fca2b23d0ba | 42 | * @return 0 if port is initialized with NC |
marcozecchini | 0:9fca2b23d0ba | 43 | **/ |
marcozecchini | 0:9fca2b23d0ba | 44 | int gpio_is_connected(const gpio_t *obj); |
marcozecchini | 0:9fca2b23d0ba | 45 | |
marcozecchini | 0:9fca2b23d0ba | 46 | /** Initialize the GPIO pin |
marcozecchini | 0:9fca2b23d0ba | 47 | * |
marcozecchini | 0:9fca2b23d0ba | 48 | * @param obj The GPIO object to initialize |
marcozecchini | 0:9fca2b23d0ba | 49 | * @param pin The GPIO pin to initialize |
marcozecchini | 0:9fca2b23d0ba | 50 | */ |
marcozecchini | 0:9fca2b23d0ba | 51 | void gpio_init(gpio_t *obj, PinName pin); |
marcozecchini | 0:9fca2b23d0ba | 52 | |
marcozecchini | 0:9fca2b23d0ba | 53 | /** Set the input pin mode |
marcozecchini | 0:9fca2b23d0ba | 54 | * |
marcozecchini | 0:9fca2b23d0ba | 55 | * @param obj The GPIO object |
marcozecchini | 0:9fca2b23d0ba | 56 | * @param mode The pin mode to be set |
marcozecchini | 0:9fca2b23d0ba | 57 | */ |
marcozecchini | 0:9fca2b23d0ba | 58 | void gpio_mode(gpio_t *obj, PinMode mode); |
marcozecchini | 0:9fca2b23d0ba | 59 | |
marcozecchini | 0:9fca2b23d0ba | 60 | /** Set the pin direction |
marcozecchini | 0:9fca2b23d0ba | 61 | * |
marcozecchini | 0:9fca2b23d0ba | 62 | * @param obj The GPIO object |
marcozecchini | 0:9fca2b23d0ba | 63 | * @param direction The pin direction to be set |
marcozecchini | 0:9fca2b23d0ba | 64 | */ |
marcozecchini | 0:9fca2b23d0ba | 65 | void gpio_dir(gpio_t *obj, PinDirection direction); |
marcozecchini | 0:9fca2b23d0ba | 66 | |
marcozecchini | 0:9fca2b23d0ba | 67 | /** Set the output value |
marcozecchini | 0:9fca2b23d0ba | 68 | * |
marcozecchini | 0:9fca2b23d0ba | 69 | * @param obj The GPIO object |
marcozecchini | 0:9fca2b23d0ba | 70 | * @param value The value to be set |
marcozecchini | 0:9fca2b23d0ba | 71 | */ |
marcozecchini | 0:9fca2b23d0ba | 72 | void gpio_write(gpio_t *obj, int value); |
marcozecchini | 0:9fca2b23d0ba | 73 | |
marcozecchini | 0:9fca2b23d0ba | 74 | /** Read the input value |
marcozecchini | 0:9fca2b23d0ba | 75 | * |
marcozecchini | 0:9fca2b23d0ba | 76 | * @param obj The GPIO object |
marcozecchini | 0:9fca2b23d0ba | 77 | * @return An integer value 1 or 0 |
marcozecchini | 0:9fca2b23d0ba | 78 | */ |
marcozecchini | 0:9fca2b23d0ba | 79 | int gpio_read(gpio_t *obj); |
marcozecchini | 0:9fca2b23d0ba | 80 | |
marcozecchini | 0:9fca2b23d0ba | 81 | // the following functions are generic and implemented in the common gpio.c file |
marcozecchini | 0:9fca2b23d0ba | 82 | // TODO: fix, will be moved to the common gpio header file |
marcozecchini | 0:9fca2b23d0ba | 83 | |
marcozecchini | 0:9fca2b23d0ba | 84 | /** Init the input pin and set mode to PullDefault |
marcozecchini | 0:9fca2b23d0ba | 85 | * |
marcozecchini | 0:9fca2b23d0ba | 86 | * @param gpio The GPIO object |
marcozecchini | 0:9fca2b23d0ba | 87 | * @param pin The pin name |
marcozecchini | 0:9fca2b23d0ba | 88 | */ |
marcozecchini | 0:9fca2b23d0ba | 89 | void gpio_init_in(gpio_t* gpio, PinName pin); |
marcozecchini | 0:9fca2b23d0ba | 90 | |
marcozecchini | 0:9fca2b23d0ba | 91 | /** Init the input pin and set the mode |
marcozecchini | 0:9fca2b23d0ba | 92 | * |
marcozecchini | 0:9fca2b23d0ba | 93 | * @param gpio The GPIO object |
marcozecchini | 0:9fca2b23d0ba | 94 | * @param pin The pin name |
marcozecchini | 0:9fca2b23d0ba | 95 | * @param mode The pin mode to be set |
marcozecchini | 0:9fca2b23d0ba | 96 | */ |
marcozecchini | 0:9fca2b23d0ba | 97 | void gpio_init_in_ex(gpio_t* gpio, PinName pin, PinMode mode); |
marcozecchini | 0:9fca2b23d0ba | 98 | |
marcozecchini | 0:9fca2b23d0ba | 99 | /** Init the output pin as an output, with predefined output value 0 |
marcozecchini | 0:9fca2b23d0ba | 100 | * |
marcozecchini | 0:9fca2b23d0ba | 101 | * @param gpio The GPIO object |
marcozecchini | 0:9fca2b23d0ba | 102 | * @param pin The pin name |
marcozecchini | 0:9fca2b23d0ba | 103 | * @return An integer value 1 or 0 |
marcozecchini | 0:9fca2b23d0ba | 104 | */ |
marcozecchini | 0:9fca2b23d0ba | 105 | void gpio_init_out(gpio_t* gpio, PinName pin); |
marcozecchini | 0:9fca2b23d0ba | 106 | |
marcozecchini | 0:9fca2b23d0ba | 107 | /** Init the pin as an output and set the output value |
marcozecchini | 0:9fca2b23d0ba | 108 | * |
marcozecchini | 0:9fca2b23d0ba | 109 | * @param gpio The GPIO object |
marcozecchini | 0:9fca2b23d0ba | 110 | * @param pin The pin name |
marcozecchini | 0:9fca2b23d0ba | 111 | * @param value The value to be set |
marcozecchini | 0:9fca2b23d0ba | 112 | */ |
marcozecchini | 0:9fca2b23d0ba | 113 | void gpio_init_out_ex(gpio_t* gpio, PinName pin, int value); |
marcozecchini | 0:9fca2b23d0ba | 114 | |
marcozecchini | 0:9fca2b23d0ba | 115 | /** Init the pin to be in/out |
marcozecchini | 0:9fca2b23d0ba | 116 | * |
marcozecchini | 0:9fca2b23d0ba | 117 | * @param gpio The GPIO object |
marcozecchini | 0:9fca2b23d0ba | 118 | * @param pin The pin name |
marcozecchini | 0:9fca2b23d0ba | 119 | * @param direction The pin direction to be set |
marcozecchini | 0:9fca2b23d0ba | 120 | * @param mode The pin mode to be set |
marcozecchini | 0:9fca2b23d0ba | 121 | * @param value The value to be set for an output pin |
marcozecchini | 0:9fca2b23d0ba | 122 | */ |
marcozecchini | 0:9fca2b23d0ba | 123 | void gpio_init_inout(gpio_t* gpio, PinName pin, PinDirection direction, PinMode mode, int value); |
marcozecchini | 0:9fca2b23d0ba | 124 | |
marcozecchini | 0:9fca2b23d0ba | 125 | /**@}*/ |
marcozecchini | 0:9fca2b23d0ba | 126 | |
marcozecchini | 0:9fca2b23d0ba | 127 | #ifdef __cplusplus |
marcozecchini | 0:9fca2b23d0ba | 128 | } |
marcozecchini | 0:9fca2b23d0ba | 129 | #endif |
marcozecchini | 0:9fca2b23d0ba | 130 | |
marcozecchini | 0:9fca2b23d0ba | 131 | #endif |
marcozecchini | 0:9fca2b23d0ba | 132 | |
marcozecchini | 0:9fca2b23d0ba | 133 | /** @}*/ |