mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
targets/hal/TARGET_NXP/TARGET_LPC11UXX/port_api.c@0:9b334a45a8ff, 2015-10-01 (annotated)
- Committer:
- bogdanm
- Date:
- Thu Oct 01 15:25:22 2015 +0300
- Revision:
- 0:9b334a45a8ff
- Child:
- 144:ef7eb2e8f9f7
Initial commit on mbed-dev
Replaces mbed-src (now inactive)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bogdanm | 0:9b334a45a8ff | 1 | /* mbed Microcontroller Library |
bogdanm | 0:9b334a45a8ff | 2 | * Copyright (c) 2006-2013 ARM Limited |
bogdanm | 0:9b334a45a8ff | 3 | * |
bogdanm | 0:9b334a45a8ff | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
bogdanm | 0:9b334a45a8ff | 5 | * you may not use this file except in compliance with the License. |
bogdanm | 0:9b334a45a8ff | 6 | * You may obtain a copy of the License at |
bogdanm | 0:9b334a45a8ff | 7 | * |
bogdanm | 0:9b334a45a8ff | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
bogdanm | 0:9b334a45a8ff | 9 | * |
bogdanm | 0:9b334a45a8ff | 10 | * Unless required by applicable law or agreed to in writing, software |
bogdanm | 0:9b334a45a8ff | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
bogdanm | 0:9b334a45a8ff | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
bogdanm | 0:9b334a45a8ff | 13 | * See the License for the specific language governing permissions and |
bogdanm | 0:9b334a45a8ff | 14 | * limitations under the License. |
bogdanm | 0:9b334a45a8ff | 15 | */ |
bogdanm | 0:9b334a45a8ff | 16 | #include "port_api.h" |
bogdanm | 0:9b334a45a8ff | 17 | #include "pinmap.h" |
bogdanm | 0:9b334a45a8ff | 18 | #include "gpio_api.h" |
bogdanm | 0:9b334a45a8ff | 19 | |
bogdanm | 0:9b334a45a8ff | 20 | PinName port_pin(PortName port, int pin_n) { |
bogdanm | 0:9b334a45a8ff | 21 | return (PinName)((port << PORT_SHIFT) | pin_n); |
bogdanm | 0:9b334a45a8ff | 22 | } |
bogdanm | 0:9b334a45a8ff | 23 | |
bogdanm | 0:9b334a45a8ff | 24 | void port_init(port_t *obj, PortName port, int mask, PinDirection dir) { |
bogdanm | 0:9b334a45a8ff | 25 | obj->port = port; |
bogdanm | 0:9b334a45a8ff | 26 | obj->mask = mask; |
bogdanm | 0:9b334a45a8ff | 27 | |
bogdanm | 0:9b334a45a8ff | 28 | LPC_GPIO->MASK[port] = ~mask; |
bogdanm | 0:9b334a45a8ff | 29 | |
bogdanm | 0:9b334a45a8ff | 30 | obj->reg_mpin = &LPC_GPIO->MPIN[port]; |
bogdanm | 0:9b334a45a8ff | 31 | obj->reg_dir = &LPC_GPIO->DIR[port]; |
bogdanm | 0:9b334a45a8ff | 32 | |
bogdanm | 0:9b334a45a8ff | 33 | uint32_t i; |
bogdanm | 0:9b334a45a8ff | 34 | // The function is set per pin: reuse gpio logic |
bogdanm | 0:9b334a45a8ff | 35 | for (i=0; i<32; i++) { |
bogdanm | 0:9b334a45a8ff | 36 | if (obj->mask & (1<<i)) { |
bogdanm | 0:9b334a45a8ff | 37 | gpio_set(port_pin(obj->port, i)); |
bogdanm | 0:9b334a45a8ff | 38 | } |
bogdanm | 0:9b334a45a8ff | 39 | } |
bogdanm | 0:9b334a45a8ff | 40 | |
bogdanm | 0:9b334a45a8ff | 41 | port_dir(obj, dir); |
bogdanm | 0:9b334a45a8ff | 42 | } |
bogdanm | 0:9b334a45a8ff | 43 | |
bogdanm | 0:9b334a45a8ff | 44 | void port_mode(port_t *obj, PinMode mode) { |
bogdanm | 0:9b334a45a8ff | 45 | uint32_t i; |
bogdanm | 0:9b334a45a8ff | 46 | // The mode is set per pin: reuse pinmap logic |
bogdanm | 0:9b334a45a8ff | 47 | for (i=0; i<32; i++) { |
bogdanm | 0:9b334a45a8ff | 48 | if (obj->mask & (1<<i)) { |
bogdanm | 0:9b334a45a8ff | 49 | pin_mode(port_pin(obj->port, i), mode); |
bogdanm | 0:9b334a45a8ff | 50 | } |
bogdanm | 0:9b334a45a8ff | 51 | } |
bogdanm | 0:9b334a45a8ff | 52 | } |
bogdanm | 0:9b334a45a8ff | 53 | |
bogdanm | 0:9b334a45a8ff | 54 | void port_dir(port_t *obj, PinDirection dir) { |
bogdanm | 0:9b334a45a8ff | 55 | switch (dir) { |
bogdanm | 0:9b334a45a8ff | 56 | case PIN_INPUT : *obj->reg_dir &= ~obj->mask; break; |
bogdanm | 0:9b334a45a8ff | 57 | case PIN_OUTPUT: *obj->reg_dir |= obj->mask; break; |
bogdanm | 0:9b334a45a8ff | 58 | } |
bogdanm | 0:9b334a45a8ff | 59 | } |
bogdanm | 0:9b334a45a8ff | 60 | |
bogdanm | 0:9b334a45a8ff | 61 | void port_write(port_t *obj, int value) { |
bogdanm | 0:9b334a45a8ff | 62 | *obj->reg_mpin = value; |
bogdanm | 0:9b334a45a8ff | 63 | } |
bogdanm | 0:9b334a45a8ff | 64 | |
bogdanm | 0:9b334a45a8ff | 65 | int port_read(port_t *obj) { |
bogdanm | 0:9b334a45a8ff | 66 | return (*obj->reg_mpin); |
bogdanm | 0:9b334a45a8ff | 67 | } |