t
Fork of mbed-dev by
targets/TARGET_NXP/TARGET_LPC23XX/port_api.c@149:156823d33999, 2016-10-28 (annotated)
- Committer:
- <>
- Date:
- Fri Oct 28 11:17:30 2016 +0100
- Revision:
- 149:156823d33999
- Parent:
- targets/hal/TARGET_NXP/TARGET_LPC23XX/port_api.c@144:ef7eb2e8f9f7
This updates the lib to the mbed lib v128
NOTE: This release includes a restructuring of the file and directory locations and thus some
include paths in your code may need updating accordingly.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
<> | 144:ef7eb2e8f9f7 | 1 | /* mbed Microcontroller Library |
<> | 144:ef7eb2e8f9f7 | 2 | * Copyright (c) 2006-2013 ARM Limited |
<> | 144:ef7eb2e8f9f7 | 3 | * |
<> | 144:ef7eb2e8f9f7 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
<> | 144:ef7eb2e8f9f7 | 5 | * you may not use this file except in compliance with the License. |
<> | 144:ef7eb2e8f9f7 | 6 | * You may obtain a copy of the License at |
<> | 144:ef7eb2e8f9f7 | 7 | * |
<> | 144:ef7eb2e8f9f7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
<> | 144:ef7eb2e8f9f7 | 9 | * |
<> | 144:ef7eb2e8f9f7 | 10 | * Unless required by applicable law or agreed to in writing, software |
<> | 144:ef7eb2e8f9f7 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
<> | 144:ef7eb2e8f9f7 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
<> | 144:ef7eb2e8f9f7 | 13 | * See the License for the specific language governing permissions and |
<> | 144:ef7eb2e8f9f7 | 14 | * limitations under the License. |
<> | 144:ef7eb2e8f9f7 | 15 | */ |
<> | 144:ef7eb2e8f9f7 | 16 | #include "port_api.h" |
<> | 144:ef7eb2e8f9f7 | 17 | #include "pinmap.h" |
<> | 144:ef7eb2e8f9f7 | 18 | #include "gpio_api.h" |
<> | 144:ef7eb2e8f9f7 | 19 | |
<> | 144:ef7eb2e8f9f7 | 20 | PinName port_pin(PortName port, int pin_n) { |
<> | 144:ef7eb2e8f9f7 | 21 | return (PinName)(LPC_GPIO0_BASE + ((port << PORT_SHIFT) | pin_n)); |
<> | 144:ef7eb2e8f9f7 | 22 | } |
<> | 144:ef7eb2e8f9f7 | 23 | |
<> | 144:ef7eb2e8f9f7 | 24 | void port_init(port_t *obj, PortName port, int mask, PinDirection dir) { |
<> | 144:ef7eb2e8f9f7 | 25 | obj->port = port; |
<> | 144:ef7eb2e8f9f7 | 26 | obj->mask = mask; |
<> | 144:ef7eb2e8f9f7 | 27 | |
<> | 144:ef7eb2e8f9f7 | 28 | LPC_GPIO_TypeDef *port_reg = (LPC_GPIO_TypeDef *)(LPC_GPIO0_BASE + ((int)port * 0x20)); |
<> | 144:ef7eb2e8f9f7 | 29 | |
<> | 144:ef7eb2e8f9f7 | 30 | // Do not use masking, because it prevents the use of the unmasked pins |
<> | 144:ef7eb2e8f9f7 | 31 | // port_reg->FIOMASK = ~mask; |
<> | 144:ef7eb2e8f9f7 | 32 | |
<> | 144:ef7eb2e8f9f7 | 33 | obj->reg_out = &port_reg->FIOPIN; |
<> | 144:ef7eb2e8f9f7 | 34 | obj->reg_in = &port_reg->FIOPIN; |
<> | 144:ef7eb2e8f9f7 | 35 | obj->reg_dir = &port_reg->FIODIR; |
<> | 144:ef7eb2e8f9f7 | 36 | |
<> | 144:ef7eb2e8f9f7 | 37 | uint32_t i; |
<> | 144:ef7eb2e8f9f7 | 38 | // The function is set per pin: reuse gpio logic |
<> | 144:ef7eb2e8f9f7 | 39 | for (i=0; i<32; i++) { |
<> | 144:ef7eb2e8f9f7 | 40 | if (obj->mask & (1<<i)) { |
<> | 144:ef7eb2e8f9f7 | 41 | gpio_set(port_pin(obj->port, i)); |
<> | 144:ef7eb2e8f9f7 | 42 | } |
<> | 144:ef7eb2e8f9f7 | 43 | } |
<> | 144:ef7eb2e8f9f7 | 44 | |
<> | 144:ef7eb2e8f9f7 | 45 | port_dir(obj, dir); |
<> | 144:ef7eb2e8f9f7 | 46 | } |
<> | 144:ef7eb2e8f9f7 | 47 | |
<> | 144:ef7eb2e8f9f7 | 48 | void port_mode(port_t *obj, PinMode mode) { |
<> | 144:ef7eb2e8f9f7 | 49 | uint32_t i; |
<> | 144:ef7eb2e8f9f7 | 50 | // The mode is set per pin: reuse pinmap logic |
<> | 144:ef7eb2e8f9f7 | 51 | for (i=0; i<32; i++) { |
<> | 144:ef7eb2e8f9f7 | 52 | if (obj->mask & (1<<i)) { |
<> | 144:ef7eb2e8f9f7 | 53 | pin_mode(port_pin(obj->port, i), mode); |
<> | 144:ef7eb2e8f9f7 | 54 | } |
<> | 144:ef7eb2e8f9f7 | 55 | } |
<> | 144:ef7eb2e8f9f7 | 56 | } |
<> | 144:ef7eb2e8f9f7 | 57 | |
<> | 144:ef7eb2e8f9f7 | 58 | void port_dir(port_t *obj, PinDirection dir) { |
<> | 144:ef7eb2e8f9f7 | 59 | switch (dir) { |
<> | 144:ef7eb2e8f9f7 | 60 | case PIN_INPUT : *obj->reg_dir &= ~obj->mask; break; |
<> | 144:ef7eb2e8f9f7 | 61 | case PIN_OUTPUT: *obj->reg_dir |= obj->mask; break; |
<> | 144:ef7eb2e8f9f7 | 62 | } |
<> | 144:ef7eb2e8f9f7 | 63 | } |
<> | 144:ef7eb2e8f9f7 | 64 | |
<> | 144:ef7eb2e8f9f7 | 65 | void port_write(port_t *obj, int value) { |
<> | 144:ef7eb2e8f9f7 | 66 | *obj->reg_out = (*obj->reg_in & ~obj->mask) | (value & obj->mask); |
<> | 144:ef7eb2e8f9f7 | 67 | } |
<> | 144:ef7eb2e8f9f7 | 68 | |
<> | 144:ef7eb2e8f9f7 | 69 | int port_read(port_t *obj) { |
<> | 144:ef7eb2e8f9f7 | 70 | return (*obj->reg_in & obj->mask); |
<> | 144:ef7eb2e8f9f7 | 71 | } |