mbed library sources

Dependents:   frdm_kl05z_gpio_test

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Mon Mar 10 11:30:07 2014 +0000
Revision:
113:65a335a675de
Parent:
68:41613245dfd7
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?

UserRevisionLine numberNew contents of line
mbed_official 68:41613245dfd7 1 /* mbed Microcontroller Library
mbed_official 68:41613245dfd7 2 * Copyright (c) 2006-2013 ARM Limited
mbed_official 68:41613245dfd7 3 *
mbed_official 68:41613245dfd7 4 * Licensed under the Apache License, Version 2.0 (the "License");
mbed_official 68:41613245dfd7 5 * you may not use this file except in compliance with the License.
mbed_official 68:41613245dfd7 6 * You may obtain a copy of the License at
mbed_official 68:41613245dfd7 7 *
mbed_official 68:41613245dfd7 8 * http://www.apache.org/licenses/LICENSE-2.0
mbed_official 68:41613245dfd7 9 *
mbed_official 68:41613245dfd7 10 * Unless required by applicable law or agreed to in writing, software
mbed_official 68:41613245dfd7 11 * distributed under the License is distributed on an "AS IS" BASIS,
mbed_official 68:41613245dfd7 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 68:41613245dfd7 13 * See the License for the specific language governing permissions and
mbed_official 68:41613245dfd7 14 * limitations under the License.
mbed_official 68:41613245dfd7 15 */
mbed_official 68:41613245dfd7 16 #include "gpio_api.h"
mbed_official 68:41613245dfd7 17 #include "pinmap.h"
mbed_official 68:41613245dfd7 18
mbed_official 68:41613245dfd7 19 uint32_t gpio_set(PinName pin) {
mbed_official 68:41613245dfd7 20 pin_function(pin, 1);
mbed_official 68:41613245dfd7 21 return 1 << ((pin & 0x7F) >> 2);
mbed_official 68:41613245dfd7 22 }
mbed_official 68:41613245dfd7 23
mbed_official 113:65a335a675de 24 void gpio_init(gpio_t *obj, PinName pin) {
mbed_official 68:41613245dfd7 25 if(pin == NC)
mbed_official 68:41613245dfd7 26 return;
mbed_official 68:41613245dfd7 27
mbed_official 68:41613245dfd7 28 obj->pin = pin;
mbed_official 68:41613245dfd7 29 obj->mask = gpio_set(pin);
mbed_official 68:41613245dfd7 30
mbed_official 68:41613245dfd7 31 unsigned int port = (unsigned int)pin >> PORT_SHIFT;
mbed_official 68:41613245dfd7 32
mbed_official 68:41613245dfd7 33 GPIO_Type *reg = (GPIO_Type *)(PTA_BASE + port * 0x40);
mbed_official 68:41613245dfd7 34 obj->reg_set = &reg->PSOR;
mbed_official 68:41613245dfd7 35 obj->reg_clr = &reg->PCOR;
mbed_official 68:41613245dfd7 36 obj->reg_in = &reg->PDIR;
mbed_official 68:41613245dfd7 37 obj->reg_dir = &reg->PDDR;
mbed_official 68:41613245dfd7 38 }
mbed_official 68:41613245dfd7 39
mbed_official 68:41613245dfd7 40 void gpio_mode(gpio_t *obj, PinMode mode) {
mbed_official 68:41613245dfd7 41 pin_mode(obj->pin, mode);
mbed_official 68:41613245dfd7 42 }
mbed_official 68:41613245dfd7 43
mbed_official 68:41613245dfd7 44 void gpio_dir(gpio_t *obj, PinDirection direction) {
mbed_official 68:41613245dfd7 45 switch (direction) {
mbed_official 68:41613245dfd7 46 case PIN_INPUT :
mbed_official 68:41613245dfd7 47 *obj->reg_dir &= ~obj->mask;
mbed_official 68:41613245dfd7 48 break;
mbed_official 68:41613245dfd7 49 case PIN_OUTPUT:
mbed_official 68:41613245dfd7 50 *obj->reg_dir |= obj->mask;
mbed_official 68:41613245dfd7 51 break;
mbed_official 68:41613245dfd7 52 }
mbed_official 68:41613245dfd7 53 }