mbed library sources
Dependents: frdm_kl05z_gpio_test
Fork of mbed-src by
targets/hal/TARGET_Freescale/TARGET_KLXX/gpio_api.c@113:65a335a675de, 2014-03-10 (annotated)
- Committer:
- mbed_official
- Date:
- Mon Mar 10 11:30:07 2014 +0000
- Revision:
- 113:65a335a675de
- Parent:
- 82:0b31dbcd4769
- Child:
- 227:7bd0639b8911
Synchronized with git revision 423ddcb86e83e2e0d599ca7106d436eb3c47e6dd
Full URL: https://github.com/mbedmicro/mbed/commit/423ddcb86e83e2e0d599ca7106d436eb3c47e6dd/
proposed change of gpio_api (new update pull request)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 82:0b31dbcd4769 | 1 | /* mbed Microcontroller Library |
mbed_official | 82:0b31dbcd4769 | 2 | * Copyright (c) 2006-2013 ARM Limited |
mbed_official | 82:0b31dbcd4769 | 3 | * |
mbed_official | 82:0b31dbcd4769 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
mbed_official | 82:0b31dbcd4769 | 5 | * you may not use this file except in compliance with the License. |
mbed_official | 82:0b31dbcd4769 | 6 | * You may obtain a copy of the License at |
mbed_official | 82:0b31dbcd4769 | 7 | * |
mbed_official | 82:0b31dbcd4769 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
mbed_official | 82:0b31dbcd4769 | 9 | * |
mbed_official | 82:0b31dbcd4769 | 10 | * Unless required by applicable law or agreed to in writing, software |
mbed_official | 82:0b31dbcd4769 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
mbed_official | 82:0b31dbcd4769 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mbed_official | 82:0b31dbcd4769 | 13 | * See the License for the specific language governing permissions and |
mbed_official | 82:0b31dbcd4769 | 14 | * limitations under the License. |
mbed_official | 82:0b31dbcd4769 | 15 | */ |
mbed_official | 82:0b31dbcd4769 | 16 | #include "gpio_api.h" |
mbed_official | 82:0b31dbcd4769 | 17 | #include "pinmap.h" |
mbed_official | 82:0b31dbcd4769 | 18 | |
mbed_official | 82:0b31dbcd4769 | 19 | uint32_t gpio_set(PinName pin) { |
mbed_official | 82:0b31dbcd4769 | 20 | pin_function(pin, 1); |
mbed_official | 82:0b31dbcd4769 | 21 | return 1 << ((pin & 0x7F) >> 2); |
mbed_official | 82:0b31dbcd4769 | 22 | } |
mbed_official | 82:0b31dbcd4769 | 23 | |
mbed_official | 113:65a335a675de | 24 | void gpio_init(gpio_t *obj, PinName pin) { |
mbed_official | 82:0b31dbcd4769 | 25 | if(pin == (PinName)NC) return; |
mbed_official | 82:0b31dbcd4769 | 26 | |
mbed_official | 82:0b31dbcd4769 | 27 | obj->pin = pin; |
mbed_official | 82:0b31dbcd4769 | 28 | obj->mask = gpio_set(pin); |
mbed_official | 82:0b31dbcd4769 | 29 | |
mbed_official | 82:0b31dbcd4769 | 30 | unsigned int port = (unsigned int)pin >> PORT_SHIFT; |
mbed_official | 82:0b31dbcd4769 | 31 | |
mbed_official | 82:0b31dbcd4769 | 32 | FGPIO_Type *reg = (FGPIO_Type *)(FPTA_BASE + port * 0x40); |
mbed_official | 82:0b31dbcd4769 | 33 | obj->reg_set = ®->PSOR; |
mbed_official | 82:0b31dbcd4769 | 34 | obj->reg_clr = ®->PCOR; |
mbed_official | 82:0b31dbcd4769 | 35 | obj->reg_in = ®->PDIR; |
mbed_official | 82:0b31dbcd4769 | 36 | obj->reg_dir = ®->PDDR; |
mbed_official | 82:0b31dbcd4769 | 37 | } |
mbed_official | 82:0b31dbcd4769 | 38 | |
mbed_official | 82:0b31dbcd4769 | 39 | void gpio_mode(gpio_t *obj, PinMode mode) { |
mbed_official | 82:0b31dbcd4769 | 40 | pin_mode(obj->pin, mode); |
mbed_official | 82:0b31dbcd4769 | 41 | } |
mbed_official | 82:0b31dbcd4769 | 42 | |
mbed_official | 82:0b31dbcd4769 | 43 | void gpio_dir(gpio_t *obj, PinDirection direction) { |
mbed_official | 82:0b31dbcd4769 | 44 | switch (direction) { |
mbed_official | 82:0b31dbcd4769 | 45 | case PIN_INPUT : *obj->reg_dir &= ~obj->mask; break; |
mbed_official | 82:0b31dbcd4769 | 46 | case PIN_OUTPUT: *obj->reg_dir |= obj->mask; break; |
mbed_official | 82:0b31dbcd4769 | 47 | } |
mbed_official | 82:0b31dbcd4769 | 48 | } |