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