Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-src by
targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/port_api.c@30:91c1d09ada54, 2013-09-25 (annotated)
- Committer:
- mbed_official
- Date:
- Wed Sep 25 10:30:04 2013 +0100
- Revision:
- 30:91c1d09ada54
Synchronized with git revision 8f57c1e84759991fa81ede0da2b4aabe8530fa09
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| mbed_official | 30:91c1d09ada54 | 1 | /* mbed Microcontroller Library |
| mbed_official | 30:91c1d09ada54 | 2 | * Copyright (c) 2006-2013 ARM Limited |
| mbed_official | 30:91c1d09ada54 | 3 | * |
| mbed_official | 30:91c1d09ada54 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| mbed_official | 30:91c1d09ada54 | 5 | * you may not use this file except in compliance with the License. |
| mbed_official | 30:91c1d09ada54 | 6 | * You may obtain a copy of the License at |
| mbed_official | 30:91c1d09ada54 | 7 | * |
| mbed_official | 30:91c1d09ada54 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| mbed_official | 30:91c1d09ada54 | 9 | * |
| mbed_official | 30:91c1d09ada54 | 10 | * Unless required by applicable law or agreed to in writing, software |
| mbed_official | 30:91c1d09ada54 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| mbed_official | 30:91c1d09ada54 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| mbed_official | 30:91c1d09ada54 | 13 | * See the License for the specific language governing permissions and |
| mbed_official | 30:91c1d09ada54 | 14 | * limitations under the License. |
| mbed_official | 30:91c1d09ada54 | 15 | */ |
| mbed_official | 30:91c1d09ada54 | 16 | |
| mbed_official | 30:91c1d09ada54 | 17 | #include "port_api.h" |
| mbed_official | 30:91c1d09ada54 | 18 | #include "pinmap.h" |
| mbed_official | 30:91c1d09ada54 | 19 | #include "gpio_api.h" |
| mbed_official | 30:91c1d09ada54 | 20 | |
| mbed_official | 30:91c1d09ada54 | 21 | // LPC114 IOCON offset table [port][pin] |
| mbed_official | 30:91c1d09ada54 | 22 | |
| mbed_official | 30:91c1d09ada54 | 23 | static uint8_t iocon_offset[4][12] = { |
| mbed_official | 30:91c1d09ada54 | 24 | {0x0c,0x10,0x1c,0x2c,0x30,0x34,0x4c,0x50,0x60,0x64,0x68,0x74}, // PORT 0 |
| mbed_official | 30:91c1d09ada54 | 25 | {0x78,0x7c,0x80,0x90,0x94,0xa0,0xa4,0xa8,0x14,0x38,0x6c,0x98}, // PORT 1 |
| mbed_official | 30:91c1d09ada54 | 26 | {0x08,0x28,0x5c,0x8c,0x40,0x44,0x00,0x20,0x24,0x54,0x58,0x70}, // PORT 2 |
| mbed_official | 30:91c1d09ada54 | 27 | {0x84,0x88,0x9c,0xac,0x3c,0x48} // PORT 3 |
| mbed_official | 30:91c1d09ada54 | 28 | }; |
| mbed_official | 30:91c1d09ada54 | 29 | |
| mbed_official | 30:91c1d09ada54 | 30 | PinName port_pin(PortName port, int pin) { |
| mbed_official | 30:91c1d09ada54 | 31 | return (PinName)((port << PORT_SHIFT) | (pin << PIN_SHIFT) | (uint32_t)iocon_offset[port][pin]); |
| mbed_official | 30:91c1d09ada54 | 32 | } |
| mbed_official | 30:91c1d09ada54 | 33 | |
| mbed_official | 30:91c1d09ada54 | 34 | void port_init(port_t *obj, PortName port, int mask, PinDirection dir) { |
| mbed_official | 30:91c1d09ada54 | 35 | obj->port = port; |
| mbed_official | 30:91c1d09ada54 | 36 | obj->mask = mask; |
| mbed_official | 30:91c1d09ada54 | 37 | |
| mbed_official | 30:91c1d09ada54 | 38 | LPC_GPIO_TypeDef *port_reg = ((LPC_GPIO_TypeDef *) (LPC_GPIO0_BASE + (port * 0x10000))); |
| mbed_official | 30:91c1d09ada54 | 39 | |
| mbed_official | 30:91c1d09ada54 | 40 | obj->reg_data = &port_reg->DATA; |
| mbed_official | 30:91c1d09ada54 | 41 | obj->reg_dir = &port_reg->DIR; |
| mbed_official | 30:91c1d09ada54 | 42 | |
| mbed_official | 30:91c1d09ada54 | 43 | uint32_t i; |
| mbed_official | 30:91c1d09ada54 | 44 | // The function is set per pin: reuse gpio logic |
| mbed_official | 30:91c1d09ada54 | 45 | for (i=0; i<12; i++) { |
| mbed_official | 30:91c1d09ada54 | 46 | if (obj->mask & (1<<i)) { |
| mbed_official | 30:91c1d09ada54 | 47 | gpio_set(port_pin(obj->port, i)); |
| mbed_official | 30:91c1d09ada54 | 48 | } |
| mbed_official | 30:91c1d09ada54 | 49 | } |
| mbed_official | 30:91c1d09ada54 | 50 | |
| mbed_official | 30:91c1d09ada54 | 51 | port_dir(obj, dir); |
| mbed_official | 30:91c1d09ada54 | 52 | } |
| mbed_official | 30:91c1d09ada54 | 53 | |
| mbed_official | 30:91c1d09ada54 | 54 | void port_mode(port_t *obj, PinMode mode) { |
| mbed_official | 30:91c1d09ada54 | 55 | uint32_t i; |
| mbed_official | 30:91c1d09ada54 | 56 | // The mode is set per pin: reuse pinmap logic |
| mbed_official | 30:91c1d09ada54 | 57 | for (i=0; i<12; i++) { |
| mbed_official | 30:91c1d09ada54 | 58 | if (obj->mask & (1<<i)) { |
| mbed_official | 30:91c1d09ada54 | 59 | pin_mode(port_pin(obj->port, i), mode); |
| mbed_official | 30:91c1d09ada54 | 60 | } |
| mbed_official | 30:91c1d09ada54 | 61 | } |
| mbed_official | 30:91c1d09ada54 | 62 | } |
| mbed_official | 30:91c1d09ada54 | 63 | |
| mbed_official | 30:91c1d09ada54 | 64 | void port_dir(port_t *obj, PinDirection dir) { |
| mbed_official | 30:91c1d09ada54 | 65 | switch (dir) { |
| mbed_official | 30:91c1d09ada54 | 66 | case PIN_INPUT : *obj->reg_dir &= ~obj->mask; break; |
| mbed_official | 30:91c1d09ada54 | 67 | case PIN_OUTPUT: *obj->reg_dir |= obj->mask; break; |
| mbed_official | 30:91c1d09ada54 | 68 | } |
| mbed_official | 30:91c1d09ada54 | 69 | } |
| mbed_official | 30:91c1d09ada54 | 70 | |
| mbed_official | 30:91c1d09ada54 | 71 | void port_write(port_t *obj, int value) { |
| mbed_official | 30:91c1d09ada54 | 72 | *obj->reg_data = (value & obj->mask); |
| mbed_official | 30:91c1d09ada54 | 73 | } |
| mbed_official | 30:91c1d09ada54 | 74 | |
| mbed_official | 30:91c1d09ada54 | 75 | int port_read(port_t *obj) { |
| mbed_official | 30:91c1d09ada54 | 76 | return (*obj->reg_data & obj->mask); |
| mbed_official | 30:91c1d09ada54 | 77 | } |
| mbed_official | 30:91c1d09ada54 | 78 |
