logi loader fork from jpiat
Fork of mbed-src by
common/gpio.c@160:6870f452afa4, 2014-04-14 (annotated)
- Committer:
- mbed_official
- Date:
- Mon Apr 14 11:30:06 2014 +0100
- Revision:
- 160:6870f452afa4
- Parent:
- 127:ce7cebc0511f
- Child:
- 221:8276e3a4886f
Synchronized with git revision 65be1ee4a1e5212e696a4d8cab05bfc0522bb81f
Full URL: https://github.com/mbedmicro/mbed/commit/65be1ee4a1e5212e696a4d8cab05bfc0522bb81f/
Mode added to BusIn + allow creation of NC pins
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 113:65a335a675de | 1 | /* mbed Microcontroller Library |
mbed_official | 113:65a335a675de | 2 | * Copyright (c) 2006-2013 ARM Limited |
mbed_official | 113:65a335a675de | 3 | * |
mbed_official | 113:65a335a675de | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
mbed_official | 113:65a335a675de | 5 | * you may not use this file except in compliance with the License. |
mbed_official | 113:65a335a675de | 6 | * You may obtain a copy of the License at |
mbed_official | 113:65a335a675de | 7 | * |
mbed_official | 113:65a335a675de | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
mbed_official | 113:65a335a675de | 9 | * |
mbed_official | 113:65a335a675de | 10 | * Unless required by applicable law or agreed to in writing, software |
mbed_official | 113:65a335a675de | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
mbed_official | 113:65a335a675de | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mbed_official | 113:65a335a675de | 13 | * See the License for the specific language governing permissions and |
mbed_official | 113:65a335a675de | 14 | * limitations under the License. |
mbed_official | 113:65a335a675de | 15 | */ |
mbed_official | 113:65a335a675de | 16 | #include "gpio_api.h" |
mbed_official | 113:65a335a675de | 17 | |
mbed_official | 113:65a335a675de | 18 | static inline void _gpio_init_in(gpio_t* gpio, PinName pin, PinMode mode) |
mbed_official | 113:65a335a675de | 19 | { |
mbed_official | 127:ce7cebc0511f | 20 | gpio_init(gpio, pin); |
mbed_official | 160:6870f452afa4 | 21 | if (pin != NC) { |
mbed_official | 160:6870f452afa4 | 22 | gpio_dir(gpio, PIN_INPUT); |
mbed_official | 160:6870f452afa4 | 23 | gpio_mode(gpio, mode); |
mbed_official | 160:6870f452afa4 | 24 | } |
mbed_official | 113:65a335a675de | 25 | } |
mbed_official | 113:65a335a675de | 26 | |
mbed_official | 113:65a335a675de | 27 | static inline void _gpio_init_out(gpio_t* gpio, PinName pin, PinMode mode, int value) |
mbed_official | 113:65a335a675de | 28 | { |
mbed_official | 113:65a335a675de | 29 | gpio_init(gpio, pin); |
mbed_official | 160:6870f452afa4 | 30 | if (pin != NC) { |
mbed_official | 160:6870f452afa4 | 31 | gpio_write(gpio, value); |
mbed_official | 160:6870f452afa4 | 32 | gpio_dir(gpio, PIN_OUTPUT); |
mbed_official | 160:6870f452afa4 | 33 | gpio_mode(gpio, mode); |
mbed_official | 160:6870f452afa4 | 34 | } |
mbed_official | 113:65a335a675de | 35 | } |
mbed_official | 113:65a335a675de | 36 | |
mbed_official | 113:65a335a675de | 37 | void gpio_init_in(gpio_t* gpio, PinName pin) { |
mbed_official | 113:65a335a675de | 38 | gpio_init_in_ex(gpio, pin, PullDefault); |
mbed_official | 113:65a335a675de | 39 | } |
mbed_official | 113:65a335a675de | 40 | |
mbed_official | 113:65a335a675de | 41 | void gpio_init_in_ex(gpio_t* gpio, PinName pin, PinMode mode) { |
mbed_official | 113:65a335a675de | 42 | _gpio_init_in(gpio, pin, mode); |
mbed_official | 113:65a335a675de | 43 | } |
mbed_official | 113:65a335a675de | 44 | |
mbed_official | 113:65a335a675de | 45 | void gpio_init_out(gpio_t* gpio, PinName pin) { |
mbed_official | 113:65a335a675de | 46 | gpio_init_out_ex(gpio, pin, 0); |
mbed_official | 113:65a335a675de | 47 | } |
mbed_official | 113:65a335a675de | 48 | |
mbed_official | 113:65a335a675de | 49 | void gpio_init_out_ex(gpio_t* gpio, PinName pin, int value) { |
mbed_official | 113:65a335a675de | 50 | _gpio_init_out(gpio, pin, PullNone, value); |
mbed_official | 113:65a335a675de | 51 | } |
mbed_official | 113:65a335a675de | 52 | |
mbed_official | 113:65a335a675de | 53 | void gpio_init_inout(gpio_t* gpio, PinName pin, PinDirection direction, PinMode mode, int value) { |
mbed_official | 113:65a335a675de | 54 | if (direction == PIN_INPUT) { |
mbed_official | 113:65a335a675de | 55 | _gpio_init_in(gpio, pin, mode); |
mbed_official | 160:6870f452afa4 | 56 | if (pin != NC) |
mbed_official | 160:6870f452afa4 | 57 | gpio_write(gpio, value); // we prepare the value in case it is switched later |
mbed_official | 113:65a335a675de | 58 | } else { |
mbed_official | 113:65a335a675de | 59 | _gpio_init_out(gpio, pin, mode, value); |
mbed_official | 113:65a335a675de | 60 | } |
mbed_official | 113:65a335a675de | 61 | } |