
Entrega 3er corte - sistemas embebidos
mbed-os/hal/mbed_gpio.c@1:fcdb45ee95b9, 2018-05-30 (annotated)
- Committer:
- Bethory
- Date:
- Wed May 30 04:46:28 2018 +0000
- Revision:
- 1:fcdb45ee95b9
- Parent:
- 0:6ad07c9019fd
Entrega Final
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Bethory | 0:6ad07c9019fd | 1 | /* mbed Microcontroller Library |
Bethory | 0:6ad07c9019fd | 2 | * Copyright (c) 2006-2013 ARM Limited |
Bethory | 0:6ad07c9019fd | 3 | * |
Bethory | 0:6ad07c9019fd | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Bethory | 0:6ad07c9019fd | 5 | * you may not use this file except in compliance with the License. |
Bethory | 0:6ad07c9019fd | 6 | * You may obtain a copy of the License at |
Bethory | 0:6ad07c9019fd | 7 | * |
Bethory | 0:6ad07c9019fd | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Bethory | 0:6ad07c9019fd | 9 | * |
Bethory | 0:6ad07c9019fd | 10 | * Unless required by applicable law or agreed to in writing, software |
Bethory | 0:6ad07c9019fd | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Bethory | 0:6ad07c9019fd | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Bethory | 0:6ad07c9019fd | 13 | * See the License for the specific language governing permissions and |
Bethory | 0:6ad07c9019fd | 14 | * limitations under the License. |
Bethory | 0:6ad07c9019fd | 15 | */ |
Bethory | 0:6ad07c9019fd | 16 | #include "hal/gpio_api.h" |
Bethory | 0:6ad07c9019fd | 17 | |
Bethory | 0:6ad07c9019fd | 18 | static inline void _gpio_init_in(gpio_t* gpio, PinName pin, PinMode mode) |
Bethory | 0:6ad07c9019fd | 19 | { |
Bethory | 0:6ad07c9019fd | 20 | gpio_init(gpio, pin); |
Bethory | 0:6ad07c9019fd | 21 | if (pin != NC) { |
Bethory | 0:6ad07c9019fd | 22 | gpio_dir(gpio, PIN_INPUT); |
Bethory | 0:6ad07c9019fd | 23 | gpio_mode(gpio, mode); |
Bethory | 0:6ad07c9019fd | 24 | } |
Bethory | 0:6ad07c9019fd | 25 | } |
Bethory | 0:6ad07c9019fd | 26 | |
Bethory | 0:6ad07c9019fd | 27 | static inline void _gpio_init_out(gpio_t* gpio, PinName pin, PinMode mode, int value) |
Bethory | 0:6ad07c9019fd | 28 | { |
Bethory | 0:6ad07c9019fd | 29 | gpio_init(gpio, pin); |
Bethory | 0:6ad07c9019fd | 30 | if (pin != NC) { |
Bethory | 0:6ad07c9019fd | 31 | gpio_write(gpio, value); |
Bethory | 0:6ad07c9019fd | 32 | gpio_dir(gpio, PIN_OUTPUT); |
Bethory | 0:6ad07c9019fd | 33 | gpio_mode(gpio, mode); |
Bethory | 0:6ad07c9019fd | 34 | } |
Bethory | 0:6ad07c9019fd | 35 | } |
Bethory | 0:6ad07c9019fd | 36 | |
Bethory | 0:6ad07c9019fd | 37 | void gpio_init_in(gpio_t* gpio, PinName pin) { |
Bethory | 0:6ad07c9019fd | 38 | gpio_init_in_ex(gpio, pin, PullDefault); |
Bethory | 0:6ad07c9019fd | 39 | } |
Bethory | 0:6ad07c9019fd | 40 | |
Bethory | 0:6ad07c9019fd | 41 | void gpio_init_in_ex(gpio_t* gpio, PinName pin, PinMode mode) { |
Bethory | 0:6ad07c9019fd | 42 | _gpio_init_in(gpio, pin, mode); |
Bethory | 0:6ad07c9019fd | 43 | } |
Bethory | 0:6ad07c9019fd | 44 | |
Bethory | 0:6ad07c9019fd | 45 | void gpio_init_out(gpio_t* gpio, PinName pin) { |
Bethory | 0:6ad07c9019fd | 46 | gpio_init_out_ex(gpio, pin, 0); |
Bethory | 0:6ad07c9019fd | 47 | } |
Bethory | 0:6ad07c9019fd | 48 | |
Bethory | 0:6ad07c9019fd | 49 | void gpio_init_out_ex(gpio_t* gpio, PinName pin, int value) { |
Bethory | 0:6ad07c9019fd | 50 | _gpio_init_out(gpio, pin, PullNone, value); |
Bethory | 0:6ad07c9019fd | 51 | } |
Bethory | 0:6ad07c9019fd | 52 | |
Bethory | 0:6ad07c9019fd | 53 | void gpio_init_inout(gpio_t* gpio, PinName pin, PinDirection direction, PinMode mode, int value) { |
Bethory | 0:6ad07c9019fd | 54 | if (direction == PIN_INPUT) { |
Bethory | 0:6ad07c9019fd | 55 | _gpio_init_in(gpio, pin, mode); |
Bethory | 0:6ad07c9019fd | 56 | if (pin != NC) |
Bethory | 0:6ad07c9019fd | 57 | gpio_write(gpio, value); // we prepare the value in case it is switched later |
Bethory | 0:6ad07c9019fd | 58 | } else { |
Bethory | 0:6ad07c9019fd | 59 | _gpio_init_out(gpio, pin, mode, value); |
Bethory | 0:6ad07c9019fd | 60 | } |
Bethory | 0:6ad07c9019fd | 61 | } |