mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
<>
Date:
Fri Oct 28 11:17:30 2016 +0100
Revision:
149:156823d33999
Parent:
targets/hal/TARGET_NXP/TARGET_LPC11UXX/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?

UserRevisionLine numberNew 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)((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->MASK[port] = ~mask;
<> 144:ef7eb2e8f9f7 29
<> 144:ef7eb2e8f9f7 30 obj->reg_mpin = &LPC_GPIO->MPIN[port];
<> 144:ef7eb2e8f9f7 31 obj->reg_dir = &LPC_GPIO->DIR[port];
<> 144:ef7eb2e8f9f7 32
<> 144:ef7eb2e8f9f7 33 uint32_t i;
<> 144:ef7eb2e8f9f7 34 // The function is set per pin: reuse gpio logic
<> 144:ef7eb2e8f9f7 35 for (i=0; i<32; i++) {
<> 144:ef7eb2e8f9f7 36 if (obj->mask & (1<<i)) {
<> 144:ef7eb2e8f9f7 37 gpio_set(port_pin(obj->port, i));
<> 144:ef7eb2e8f9f7 38 }
<> 144:ef7eb2e8f9f7 39 }
<> 144:ef7eb2e8f9f7 40
<> 144:ef7eb2e8f9f7 41 port_dir(obj, dir);
<> 144:ef7eb2e8f9f7 42 }
<> 144:ef7eb2e8f9f7 43
<> 144:ef7eb2e8f9f7 44 void port_mode(port_t *obj, PinMode mode) {
<> 144:ef7eb2e8f9f7 45 uint32_t i;
<> 144:ef7eb2e8f9f7 46 // The mode is set per pin: reuse pinmap logic
<> 144:ef7eb2e8f9f7 47 for (i=0; i<32; i++) {
<> 144:ef7eb2e8f9f7 48 if (obj->mask & (1<<i)) {
<> 144:ef7eb2e8f9f7 49 pin_mode(port_pin(obj->port, i), mode);
<> 144:ef7eb2e8f9f7 50 }
<> 144:ef7eb2e8f9f7 51 }
<> 144:ef7eb2e8f9f7 52 }
<> 144:ef7eb2e8f9f7 53
<> 144:ef7eb2e8f9f7 54 void port_dir(port_t *obj, PinDirection dir) {
<> 144:ef7eb2e8f9f7 55 switch (dir) {
<> 144:ef7eb2e8f9f7 56 case PIN_INPUT : *obj->reg_dir &= ~obj->mask; break;
<> 144:ef7eb2e8f9f7 57 case PIN_OUTPUT: *obj->reg_dir |= obj->mask; break;
<> 144:ef7eb2e8f9f7 58 }
<> 144:ef7eb2e8f9f7 59 }
<> 144:ef7eb2e8f9f7 60
<> 144:ef7eb2e8f9f7 61 void port_write(port_t *obj, int value) {
<> 144:ef7eb2e8f9f7 62 *obj->reg_mpin = value;
<> 144:ef7eb2e8f9f7 63 }
<> 144:ef7eb2e8f9f7 64
<> 144:ef7eb2e8f9f7 65 int port_read(port_t *obj) {
<> 144:ef7eb2e8f9f7 66 return (*obj->reg_mpin);
<> 144:ef7eb2e8f9f7 67 }