mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Thu Mar 06 10:00:06 2014 +0000
Revision:
111:ae4891ca7084
Parent:
82:0b31dbcd4769
Child:
113:65a335a675de
Synchronized with git revision 955bd9a5c9e042f1cf30bbae2a99afaab8eb4cbf

Full URL: https://github.com/mbedmicro/mbed/commit/955bd9a5c9e042f1cf30bbae2a99afaab8eb4cbf/

Who changed what in which revision?

UserRevisionLine numberNew 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 82:0b31dbcd4769 24 void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
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 = &reg->PSOR;
mbed_official 82:0b31dbcd4769 34 obj->reg_clr = &reg->PCOR;
mbed_official 82:0b31dbcd4769 35 obj->reg_in = &reg->PDIR;
mbed_official 82:0b31dbcd4769 36 obj->reg_dir = &reg->PDDR;
mbed_official 82:0b31dbcd4769 37
mbed_official 82:0b31dbcd4769 38 gpio_dir(obj, direction);
mbed_official 82:0b31dbcd4769 39 switch (direction) {
mbed_official 82:0b31dbcd4769 40 case PIN_OUTPUT: pin_mode(pin, PullNone); break;
mbed_official 82:0b31dbcd4769 41 case PIN_INPUT : pin_mode(pin, PullUp); break;
mbed_official 82:0b31dbcd4769 42 }
mbed_official 82:0b31dbcd4769 43 }
mbed_official 82:0b31dbcd4769 44
mbed_official 82:0b31dbcd4769 45 void gpio_mode(gpio_t *obj, PinMode mode) {
mbed_official 82:0b31dbcd4769 46 pin_mode(obj->pin, mode);
mbed_official 82:0b31dbcd4769 47 }
mbed_official 82:0b31dbcd4769 48
mbed_official 82:0b31dbcd4769 49 void gpio_dir(gpio_t *obj, PinDirection direction) {
mbed_official 82:0b31dbcd4769 50 switch (direction) {
mbed_official 82:0b31dbcd4769 51 case PIN_INPUT : *obj->reg_dir &= ~obj->mask; break;
mbed_official 82:0b31dbcd4769 52 case PIN_OUTPUT: *obj->reg_dir |= obj->mask; break;
mbed_official 82:0b31dbcd4769 53 }
mbed_official 82:0b31dbcd4769 54 }