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