mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
bogdanm
Date:
Mon Aug 19 18:17:02 2013 +0300
Revision:
19:398f4c622e1b
Sync with official mbed library release 66

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bogdanm 19:398f4c622e1b 1 /* mbed Microcontroller Library
bogdanm 19:398f4c622e1b 2 * Copyright (c) 2006-2013 ARM Limited
bogdanm 19:398f4c622e1b 3 *
bogdanm 19:398f4c622e1b 4 * Licensed under the Apache License, Version 2.0 (the "License");
bogdanm 19:398f4c622e1b 5 * you may not use this file except in compliance with the License.
bogdanm 19:398f4c622e1b 6 * You may obtain a copy of the License at
bogdanm 19:398f4c622e1b 7 *
bogdanm 19:398f4c622e1b 8 * http://www.apache.org/licenses/LICENSE-2.0
bogdanm 19:398f4c622e1b 9 *
bogdanm 19:398f4c622e1b 10 * Unless required by applicable law or agreed to in writing, software
bogdanm 19:398f4c622e1b 11 * distributed under the License is distributed on an "AS IS" BASIS,
bogdanm 19:398f4c622e1b 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
bogdanm 19:398f4c622e1b 13 * See the License for the specific language governing permissions and
bogdanm 19:398f4c622e1b 14 * limitations under the License.
bogdanm 19:398f4c622e1b 15 */
bogdanm 19:398f4c622e1b 16
bogdanm 19:398f4c622e1b 17 #include "port_api.h"
bogdanm 19:398f4c622e1b 18 #include "pinmap.h"
bogdanm 19:398f4c622e1b 19 #include "gpio_api.h"
bogdanm 19:398f4c622e1b 20
bogdanm 19:398f4c622e1b 21 // LPC114 IOCON offset table [port][pin]
bogdanm 19:398f4c622e1b 22
bogdanm 19:398f4c622e1b 23 static uint8_t iocon_offset[4][12] = {
bogdanm 19:398f4c622e1b 24 {0x0c,0x10,0x1c,0x2c,0x30,0x34,0x4c,0x50,0x60,0x64,0x68,0x74}, // PORT 0
bogdanm 19:398f4c622e1b 25 {0x78,0x7c,0x80,0x90,0x94,0xa0,0xa4,0xa8,0x14,0x38,0x6c,0x98}, // PORT 1
bogdanm 19:398f4c622e1b 26 {0x08,0x28,0x5c,0x8c,0x40,0x44,0x00,0x20,0x24,0x54,0x58,0x70}, // PORT 2
bogdanm 19:398f4c622e1b 27 {0x84,0x88,0x9c,0xac,0x3c,0x48} // PORT 3
bogdanm 19:398f4c622e1b 28 };
bogdanm 19:398f4c622e1b 29
bogdanm 19:398f4c622e1b 30 PinName port_pin(PortName port, int pin) {
bogdanm 19:398f4c622e1b 31 return (PinName)((port << PORT_SHIFT) | (pin << PIN_SHIFT) | (uint32_t)iocon_offset[port][pin]);
bogdanm 19:398f4c622e1b 32 }
bogdanm 19:398f4c622e1b 33
bogdanm 19:398f4c622e1b 34 void port_init(port_t *obj, PortName port, int mask, PinDirection dir) {
bogdanm 19:398f4c622e1b 35 obj->port = port;
bogdanm 19:398f4c622e1b 36 obj->mask = mask;
bogdanm 19:398f4c622e1b 37
bogdanm 19:398f4c622e1b 38 LPC_GPIO_TypeDef *port_reg = ((LPC_GPIO_TypeDef *) (LPC_GPIO0_BASE + (port * 0x10000)));
bogdanm 19:398f4c622e1b 39
bogdanm 19:398f4c622e1b 40 obj->reg_data = &port_reg->DATA;
bogdanm 19:398f4c622e1b 41 obj->reg_dir = &port_reg->DIR;
bogdanm 19:398f4c622e1b 42
bogdanm 19:398f4c622e1b 43 uint32_t i;
bogdanm 19:398f4c622e1b 44 // The function is set per pin: reuse gpio logic
bogdanm 19:398f4c622e1b 45 for (i=0; i<12; i++) {
bogdanm 19:398f4c622e1b 46 if (obj->mask & (1<<i)) {
bogdanm 19:398f4c622e1b 47 gpio_set(port_pin(obj->port, i));
bogdanm 19:398f4c622e1b 48 }
bogdanm 19:398f4c622e1b 49 }
bogdanm 19:398f4c622e1b 50
bogdanm 19:398f4c622e1b 51 port_dir(obj, dir);
bogdanm 19:398f4c622e1b 52 }
bogdanm 19:398f4c622e1b 53
bogdanm 19:398f4c622e1b 54 void port_mode(port_t *obj, PinMode mode) {
bogdanm 19:398f4c622e1b 55 uint32_t i;
bogdanm 19:398f4c622e1b 56 // The mode is set per pin: reuse pinmap logic
bogdanm 19:398f4c622e1b 57 for (i=0; i<12; i++) {
bogdanm 19:398f4c622e1b 58 if (obj->mask & (1<<i)) {
bogdanm 19:398f4c622e1b 59 pin_mode(port_pin(obj->port, i), mode);
bogdanm 19:398f4c622e1b 60 }
bogdanm 19:398f4c622e1b 61 }
bogdanm 19:398f4c622e1b 62 }
bogdanm 19:398f4c622e1b 63
bogdanm 19:398f4c622e1b 64 void port_dir(port_t *obj, PinDirection dir) {
bogdanm 19:398f4c622e1b 65 switch (dir) {
bogdanm 19:398f4c622e1b 66 case PIN_INPUT : *obj->reg_dir &= ~obj->mask; break;
bogdanm 19:398f4c622e1b 67 case PIN_OUTPUT: *obj->reg_dir |= obj->mask; break;
bogdanm 19:398f4c622e1b 68 }
bogdanm 19:398f4c622e1b 69 }
bogdanm 19:398f4c622e1b 70
bogdanm 19:398f4c622e1b 71 void port_write(port_t *obj, int value) {
bogdanm 19:398f4c622e1b 72 *obj->reg_data = (value & obj->mask);
bogdanm 19:398f4c622e1b 73 }
bogdanm 19:398f4c622e1b 74
bogdanm 19:398f4c622e1b 75 int port_read(port_t *obj) {
bogdanm 19:398f4c622e1b 76 return (*obj->reg_data & obj->mask);
bogdanm 19:398f4c622e1b 77 }
bogdanm 19:398f4c622e1b 78