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