mbed library sources modified for open wear
Dependents: openwear-lifelogger-example
Fork of mbed-src by
targets/hal/TARGET_NXP/TARGET_LPC43XX/port_api.c@20:4263a77256ae, 2013-09-10 (annotated)
- Committer:
- bogdanm
- Date:
- Tue Sep 10 15:14:19 2013 +0300
- Revision:
- 20:4263a77256ae
- Child:
- 295:78f9587bb26d
Sync with git revision 171dda705c947bf910926a0b73d6a4797802554d
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bogdanm | 20:4263a77256ae | 1 | /* mbed Microcontroller Library |
bogdanm | 20:4263a77256ae | 2 | * Copyright (c) 2006-2013 ARM Limited |
bogdanm | 20:4263a77256ae | 3 | * |
bogdanm | 20:4263a77256ae | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
bogdanm | 20:4263a77256ae | 5 | * you may not use this file except in compliance with the License. |
bogdanm | 20:4263a77256ae | 6 | * You may obtain a copy of the License at |
bogdanm | 20:4263a77256ae | 7 | * |
bogdanm | 20:4263a77256ae | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
bogdanm | 20:4263a77256ae | 9 | * |
bogdanm | 20:4263a77256ae | 10 | * Unless required by applicable law or agreed to in writing, software |
bogdanm | 20:4263a77256ae | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
bogdanm | 20:4263a77256ae | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
bogdanm | 20:4263a77256ae | 13 | * See the License for the specific language governing permissions and |
bogdanm | 20:4263a77256ae | 14 | * limitations under the License. |
bogdanm | 20:4263a77256ae | 15 | * |
bogdanm | 20:4263a77256ae | 16 | * Ported to NXP LPC43XX by Micromint USA <support@micromint.com> |
bogdanm | 20:4263a77256ae | 17 | */ |
bogdanm | 20:4263a77256ae | 18 | #include "port_api.h" |
bogdanm | 20:4263a77256ae | 19 | #include "pinmap.h" |
bogdanm | 20:4263a77256ae | 20 | #include "gpio_api.h" |
bogdanm | 20:4263a77256ae | 21 | |
bogdanm | 20:4263a77256ae | 22 | PinName port_pin(PortName port, int pin_n) { |
bogdanm | 20:4263a77256ae | 23 | return (PinName)(LPC_GPIO_PORT_BASE + ((port << PORT_SHIFT) | pin_n)); |
bogdanm | 20:4263a77256ae | 24 | } |
bogdanm | 20:4263a77256ae | 25 | |
bogdanm | 20:4263a77256ae | 26 | void port_init(port_t *obj, PortName port, int mask, PinDirection dir) { |
bogdanm | 20:4263a77256ae | 27 | obj->port = port; |
bogdanm | 20:4263a77256ae | 28 | obj->mask = mask; |
bogdanm | 20:4263a77256ae | 29 | |
bogdanm | 20:4263a77256ae | 30 | LPC_GPIO_T *port_reg = (LPC_GPIO_T *)(LPC_GPIO_PORT_BASE + ((int)port << PORT_SHIFT)); |
bogdanm | 20:4263a77256ae | 31 | |
bogdanm | 20:4263a77256ae | 32 | port_reg->MASK[port] = ~mask; |
bogdanm | 20:4263a77256ae | 33 | |
bogdanm | 20:4263a77256ae | 34 | obj->reg_out = &port_reg->PIN[port]; |
bogdanm | 20:4263a77256ae | 35 | obj->reg_in = &port_reg->PIN[port]; |
bogdanm | 20:4263a77256ae | 36 | obj->reg_dir = &port_reg->DIR[port]; |
bogdanm | 20:4263a77256ae | 37 | |
bogdanm | 20:4263a77256ae | 38 | uint32_t i; |
bogdanm | 20:4263a77256ae | 39 | // The function is set per pin: reuse gpio logic |
bogdanm | 20:4263a77256ae | 40 | for (i=0; i<32; i++) { |
bogdanm | 20:4263a77256ae | 41 | if (obj->mask & (1<<i)) { |
bogdanm | 20:4263a77256ae | 42 | gpio_set(port_pin(obj->port, i)); |
bogdanm | 20:4263a77256ae | 43 | } |
bogdanm | 20:4263a77256ae | 44 | } |
bogdanm | 20:4263a77256ae | 45 | |
bogdanm | 20:4263a77256ae | 46 | port_dir(obj, dir); |
bogdanm | 20:4263a77256ae | 47 | } |
bogdanm | 20:4263a77256ae | 48 | |
bogdanm | 20:4263a77256ae | 49 | void port_mode(port_t *obj, PinMode mode) { |
bogdanm | 20:4263a77256ae | 50 | uint32_t i; |
bogdanm | 20:4263a77256ae | 51 | // The mode is set per pin: reuse pinmap logic |
bogdanm | 20:4263a77256ae | 52 | for (i=0; i<32; i++) { |
bogdanm | 20:4263a77256ae | 53 | if (obj->mask & (1<<i)) { |
bogdanm | 20:4263a77256ae | 54 | pin_mode(port_pin(obj->port, i), mode); |
bogdanm | 20:4263a77256ae | 55 | } |
bogdanm | 20:4263a77256ae | 56 | } |
bogdanm | 20:4263a77256ae | 57 | } |
bogdanm | 20:4263a77256ae | 58 | |
bogdanm | 20:4263a77256ae | 59 | void port_dir(port_t *obj, PinDirection dir) { |
bogdanm | 20:4263a77256ae | 60 | switch (dir) { |
bogdanm | 20:4263a77256ae | 61 | case PIN_INPUT : *obj->reg_dir &= ~obj->mask; break; |
bogdanm | 20:4263a77256ae | 62 | case PIN_OUTPUT: *obj->reg_dir |= obj->mask; break; |
bogdanm | 20:4263a77256ae | 63 | } |
bogdanm | 20:4263a77256ae | 64 | } |
bogdanm | 20:4263a77256ae | 65 | |
bogdanm | 20:4263a77256ae | 66 | void port_write(port_t *obj, int value) { |
bogdanm | 20:4263a77256ae | 67 | *obj->reg_out = (*obj->reg_in & ~obj->mask) | (value & obj->mask); |
bogdanm | 20:4263a77256ae | 68 | } |
bogdanm | 20:4263a77256ae | 69 | |
bogdanm | 20:4263a77256ae | 70 | int port_read(port_t *obj) { |
bogdanm | 20:4263a77256ae | 71 | return (*obj->reg_in & obj->mask); |
bogdanm | 20:4263a77256ae | 72 | } |