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