mbed library sources modified for open wear
Dependents: openwear-lifelogger-example
Fork of mbed-src by
targets/hal/TARGET_NXP/TARGET_LPC408X/port_api.c@259:da299e454ce7, 2014-07-18 (annotated)
- Committer:
- mbed_official
- Date:
- Fri Jul 18 14:15:09 2014 +0100
- Revision:
- 259:da299e454ce7
- Parent:
- 34:a3c7023e45de
Synchronized with git revision df84f2b3e967624878b8b54e093a8a3a675f3ca7
Full URL: https://github.com/mbedmicro/mbed/commit/df84f2b3e967624878b8b54e093a8a3a675f3ca7/
New ARCH_GPRS target
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 | */ |
bogdanm | 15:4892fe388435 | 16 | #include "port_api.h" |
bogdanm | 15:4892fe388435 | 17 | #include "pinmap.h" |
bogdanm | 15:4892fe388435 | 18 | #include "gpio_api.h" |
bogdanm | 15:4892fe388435 | 19 | |
mbed_official | 34:a3c7023e45de | 20 | |
bogdanm | 15:4892fe388435 | 21 | PinName port_pin(PortName port, int pin_n) { |
mbed_official | 34:a3c7023e45de | 22 | return (PinName)(((port << PORT_SHIFT) | pin_n)); |
bogdanm | 15:4892fe388435 | 23 | } |
bogdanm | 15:4892fe388435 | 24 | |
bogdanm | 15:4892fe388435 | 25 | void port_init(port_t *obj, PortName port, int mask, PinDirection dir) { |
bogdanm | 15:4892fe388435 | 26 | obj->port = port; |
bogdanm | 15:4892fe388435 | 27 | obj->mask = mask; |
bogdanm | 15:4892fe388435 | 28 | |
bogdanm | 15:4892fe388435 | 29 | LPC_GPIO_TypeDef *port_reg = (LPC_GPIO_TypeDef *)(LPC_GPIO0_BASE + ((int)port * 0x20)); |
bogdanm | 15:4892fe388435 | 30 | |
bogdanm | 15:4892fe388435 | 31 | port_reg->MASK = ~mask; |
bogdanm | 15:4892fe388435 | 32 | |
bogdanm | 15:4892fe388435 | 33 | obj->reg_out = &port_reg->PIN; |
bogdanm | 15:4892fe388435 | 34 | obj->reg_in = &port_reg->PIN; |
bogdanm | 15:4892fe388435 | 35 | obj->reg_dir = &port_reg->DIR; |
bogdanm | 15:4892fe388435 | 36 | |
bogdanm | 15:4892fe388435 | 37 | uint32_t i; |
bogdanm | 15:4892fe388435 | 38 | // The function is set per pin: reuse gpio logic |
bogdanm | 15:4892fe388435 | 39 | for (i=0; i<32; i++) { |
bogdanm | 15:4892fe388435 | 40 | if (obj->mask & (1<<i)) { |
bogdanm | 15:4892fe388435 | 41 | gpio_set(port_pin(obj->port, i)); |
bogdanm | 15:4892fe388435 | 42 | } |
bogdanm | 15:4892fe388435 | 43 | } |
bogdanm | 15:4892fe388435 | 44 | |
bogdanm | 15:4892fe388435 | 45 | port_dir(obj, dir); |
bogdanm | 15:4892fe388435 | 46 | } |
bogdanm | 15:4892fe388435 | 47 | |
bogdanm | 15:4892fe388435 | 48 | void port_mode(port_t *obj, PinMode mode) { |
bogdanm | 15:4892fe388435 | 49 | uint32_t i; |
bogdanm | 15:4892fe388435 | 50 | // The mode is set per pin: reuse pinmap logic |
bogdanm | 15:4892fe388435 | 51 | for (i=0; i<32; i++) { |
bogdanm | 15:4892fe388435 | 52 | if (obj->mask & (1<<i)) { |
bogdanm | 15:4892fe388435 | 53 | pin_mode(port_pin(obj->port, i), mode); |
bogdanm | 15:4892fe388435 | 54 | } |
bogdanm | 15:4892fe388435 | 55 | } |
bogdanm | 15:4892fe388435 | 56 | } |
bogdanm | 15:4892fe388435 | 57 | |
bogdanm | 15:4892fe388435 | 58 | void port_dir(port_t *obj, PinDirection dir) { |
bogdanm | 15:4892fe388435 | 59 | switch (dir) { |
bogdanm | 15:4892fe388435 | 60 | case PIN_INPUT : *obj->reg_dir &= ~obj->mask; break; |
bogdanm | 15:4892fe388435 | 61 | case PIN_OUTPUT: *obj->reg_dir |= obj->mask; break; |
bogdanm | 15:4892fe388435 | 62 | } |
bogdanm | 15:4892fe388435 | 63 | } |
bogdanm | 15:4892fe388435 | 64 | |
bogdanm | 15:4892fe388435 | 65 | void port_write(port_t *obj, int value) { |
bogdanm | 15:4892fe388435 | 66 | *obj->reg_out = (*obj->reg_in & ~obj->mask) | (value & obj->mask); |
bogdanm | 15:4892fe388435 | 67 | } |
bogdanm | 15:4892fe388435 | 68 | |
bogdanm | 15:4892fe388435 | 69 | int port_read(port_t *obj) { |
bogdanm | 15:4892fe388435 | 70 | return (*obj->reg_in & obj->mask); |
bogdanm | 15:4892fe388435 | 71 | } |