lzbp li / mbed-src

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Mon Oct 06 10:00:08 2014 +0100
Revision:
337:6ed01c00b962
Synchronized with git revision b30176a071a49d95914b97d2ab98240f3a1e2cae

Full URL: https://github.com/mbedmicro/mbed/commit/b30176a071a49d95914b97d2ab98240f3a1e2cae/

Platform: LPC824 - new platform addition

Who changed what in which revision?

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