mbed library sources modified for open wear
Dependents: openwear-lifelogger-example
Fork of mbed-src by
targets/hal/TARGET_NXP/TARGET_LPC408X/gpio_api.c@310:6188e0254baa, 2014-09-16 (annotated)
- Committer:
- janekm
- Date:
- Tue Sep 16 22:42:01 2014 +0000
- Revision:
- 310:6188e0254baa
- Parent:
- 227:7bd0639b8911
N/A
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bogdanm | 15:4892fe388435 | 1 | /* mbed Microcontroller Library |
bogdanm | 15:4892fe388435 | 2 | * Copyright (c) 2006-2013 ARM Limited |
bogdanm | 15:4892fe388435 | 3 | * |
bogdanm | 15:4892fe388435 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
bogdanm | 15:4892fe388435 | 5 | * you may not use this file except in compliance with the License. |
bogdanm | 15:4892fe388435 | 6 | * You may obtain a copy of the License at |
bogdanm | 15:4892fe388435 | 7 | * |
bogdanm | 15:4892fe388435 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
bogdanm | 15:4892fe388435 | 9 | * |
bogdanm | 15:4892fe388435 | 10 | * Unless required by applicable law or agreed to in writing, software |
bogdanm | 15:4892fe388435 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
bogdanm | 15:4892fe388435 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
bogdanm | 15:4892fe388435 | 13 | * See the License for the specific language governing permissions and |
bogdanm | 15:4892fe388435 | 14 | * limitations under the License. |
bogdanm | 15:4892fe388435 | 15 | */ |
mbed_official | 227:7bd0639b8911 | 16 | #include "mbed_assert.h" |
bogdanm | 15:4892fe388435 | 17 | #include "gpio_api.h" |
bogdanm | 15:4892fe388435 | 18 | #include "pinmap.h" |
bogdanm | 15:4892fe388435 | 19 | |
bogdanm | 15:4892fe388435 | 20 | uint32_t gpio_set(PinName pin) { |
mbed_official | 227:7bd0639b8911 | 21 | MBED_ASSERT(pin != (PinName)NC); |
bogdanm | 15:4892fe388435 | 22 | pin_function(pin, 0); |
bogdanm | 15:4892fe388435 | 23 | return (1 << ((int)pin & 0x1F)); |
bogdanm | 15:4892fe388435 | 24 | } |
bogdanm | 15:4892fe388435 | 25 | |
mbed_official | 113:65a335a675de | 26 | void gpio_init(gpio_t *obj, PinName pin) { |
bogdanm | 15:4892fe388435 | 27 | obj->pin = pin; |
mbed_official | 227:7bd0639b8911 | 28 | if (pin == (PinName)NC) |
mbed_official | 227:7bd0639b8911 | 29 | return; |
mbed_official | 227:7bd0639b8911 | 30 | |
bogdanm | 15:4892fe388435 | 31 | obj->mask = gpio_set(pin); |
bogdanm | 15:4892fe388435 | 32 | |
bogdanm | 15:4892fe388435 | 33 | LPC_GPIO_TypeDef *port_reg = (LPC_GPIO_TypeDef *) ((int)(LPC_GPIO0_BASE+pin) & ~0x1F); |
bogdanm | 15:4892fe388435 | 34 | |
bogdanm | 15:4892fe388435 | 35 | obj->reg_set = &port_reg->SET; |
bogdanm | 15:4892fe388435 | 36 | obj->reg_clr = &port_reg->CLR; |
bogdanm | 15:4892fe388435 | 37 | obj->reg_in = &port_reg->PIN; |
bogdanm | 15:4892fe388435 | 38 | obj->reg_dir = &port_reg->DIR; |
bogdanm | 15:4892fe388435 | 39 | } |
bogdanm | 15:4892fe388435 | 40 | |
bogdanm | 15:4892fe388435 | 41 | void gpio_mode(gpio_t *obj, PinMode mode) { |
bogdanm | 15:4892fe388435 | 42 | pin_mode(obj->pin, mode); |
bogdanm | 15:4892fe388435 | 43 | } |
bogdanm | 15:4892fe388435 | 44 | |
bogdanm | 15:4892fe388435 | 45 | void gpio_dir(gpio_t *obj, PinDirection direction) { |
mbed_official | 227:7bd0639b8911 | 46 | MBED_ASSERT(obj->pin != (PinName)NC); |
mbed_official | 227:7bd0639b8911 | 47 | |
bogdanm | 15:4892fe388435 | 48 | switch (direction) { |
mbed_official | 227:7bd0639b8911 | 49 | case PIN_INPUT : |
mbed_official | 227:7bd0639b8911 | 50 | *obj->reg_dir &= ~obj->mask; |
mbed_official | 227:7bd0639b8911 | 51 | break; |
mbed_official | 227:7bd0639b8911 | 52 | case PIN_OUTPUT: |
mbed_official | 227:7bd0639b8911 | 53 | *obj->reg_dir |= obj->mask; |
mbed_official | 227:7bd0639b8911 | 54 | break; |
bogdanm | 15:4892fe388435 | 55 | } |
bogdanm | 15:4892fe388435 | 56 | } |