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:
Fri May 23 08:45:06 2014 +0100
Revision:
207:05668db47a72
Parent:
174:8bb9f3a33240
Child:
227:7bd0639b8911
Synchronized with git revision 10e3a9cea1c4a29a2df1152d715558ad48b085ad

Full URL: https://github.com/mbedmicro/mbed/commit/10e3a9cea1c4a29a2df1152d715558ad48b085ad/

[STM32F103RB] Support for GCC_ARM toolchain

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 174:8bb9f3a33240 1 /* mbed Microcontroller Library
mbed_official 174:8bb9f3a33240 2 * Copyright (c) 2006-2014 ARM Limited
mbed_official 174:8bb9f3a33240 3 *
mbed_official 174:8bb9f3a33240 4 * Licensed under the Apache License, Version 2.0 (the "License");
mbed_official 174:8bb9f3a33240 5 * you may not use this file except in compliance with the License.
mbed_official 174:8bb9f3a33240 6 * You may obtain a copy of the License at
mbed_official 174:8bb9f3a33240 7 *
mbed_official 174:8bb9f3a33240 8 * http://www.apache.org/licenses/LICENSE-2.0
mbed_official 174:8bb9f3a33240 9 *
mbed_official 174:8bb9f3a33240 10 * Unless required by applicable law or agreed to in writing, software
mbed_official 174:8bb9f3a33240 11 * distributed under the License is distributed on an "AS IS" BASIS,
mbed_official 174:8bb9f3a33240 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 174:8bb9f3a33240 13 * See the License for the specific language governing permissions and
mbed_official 174:8bb9f3a33240 14 * limitations under the License.
mbed_official 174:8bb9f3a33240 15 */
mbed_official 174:8bb9f3a33240 16 #include "gpio_api.h"
mbed_official 174:8bb9f3a33240 17 #include "pinmap.h"
mbed_official 174:8bb9f3a33240 18
mbed_official 174:8bb9f3a33240 19 static int gpio_enabled = 0;
mbed_official 174:8bb9f3a33240 20
mbed_official 174:8bb9f3a33240 21 static void gpio_enable(void) {
mbed_official 174:8bb9f3a33240 22 gpio_enabled = 1;
mbed_official 174:8bb9f3a33240 23
mbed_official 174:8bb9f3a33240 24 /* Enable AHB clock to the GPIO and IOCON domain. */
mbed_official 174:8bb9f3a33240 25 LPC_SYSCON->SYSAHBCLKCTRL |= ((1 << 16) | (1 << 6));
mbed_official 174:8bb9f3a33240 26 }
mbed_official 174:8bb9f3a33240 27
mbed_official 174:8bb9f3a33240 28 uint32_t gpio_set(PinName pin) {
mbed_official 174:8bb9f3a33240 29 if (!gpio_enabled)
mbed_official 174:8bb9f3a33240 30 gpio_enable();
mbed_official 174:8bb9f3a33240 31
mbed_official 207:05668db47a72 32 int f = ((pin == P0_0) ||
mbed_official 207:05668db47a72 33 (pin == P0_10) ||
mbed_official 207:05668db47a72 34 (pin == P0_15)) ? (1) : (0);
mbed_official 207:05668db47a72 35
mbed_official 207:05668db47a72 36 pin_function(pin, f);
mbed_official 207:05668db47a72 37
mbed_official 174:8bb9f3a33240 38 return (1UL << ((int)pin >> PIN_SHIFT & 0x1F));
mbed_official 174:8bb9f3a33240 39 }
mbed_official 174:8bb9f3a33240 40
mbed_official 174:8bb9f3a33240 41 void gpio_init(gpio_t *obj, PinName pin) {
mbed_official 174:8bb9f3a33240 42 if(pin == NC) return;
mbed_official 174:8bb9f3a33240 43
mbed_official 174:8bb9f3a33240 44 obj->pin = pin;
mbed_official 174:8bb9f3a33240 45 obj->mask = gpio_set(pin);
mbed_official 174:8bb9f3a33240 46
mbed_official 174:8bb9f3a33240 47 unsigned int port = (unsigned int)(pin >> PORT_SHIFT);
mbed_official 174:8bb9f3a33240 48
mbed_official 174:8bb9f3a33240 49 obj->reg_set = &LPC_GPIO_PORT->SET[port];
mbed_official 174:8bb9f3a33240 50 obj->reg_clr = &LPC_GPIO_PORT->CLR[port];
mbed_official 174:8bb9f3a33240 51 obj->reg_in = &LPC_GPIO_PORT->PIN[port];
mbed_official 174:8bb9f3a33240 52 obj->reg_dir = &LPC_GPIO_PORT->DIR[port];
mbed_official 174:8bb9f3a33240 53 }
mbed_official 174:8bb9f3a33240 54
mbed_official 174:8bb9f3a33240 55 void gpio_mode(gpio_t *obj, PinMode mode) {
mbed_official 174:8bb9f3a33240 56 pin_mode(obj->pin, mode);
mbed_official 174:8bb9f3a33240 57 }
mbed_official 174:8bb9f3a33240 58
mbed_official 174:8bb9f3a33240 59 void gpio_dir(gpio_t *obj, PinDirection direction) {
mbed_official 174:8bb9f3a33240 60 switch (direction) {
mbed_official 174:8bb9f3a33240 61 case PIN_INPUT : *obj->reg_dir &= ~obj->mask; break;
mbed_official 174:8bb9f3a33240 62 case PIN_OUTPUT: *obj->reg_dir |= obj->mask; break;
mbed_official 174:8bb9f3a33240 63 }
mbed_official 174:8bb9f3a33240 64 }