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
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
<> 149:156823d33999 1 /* mbed Microcontroller Library
<> 149:156823d33999 2 * Copyright (c) 2015-2016 Nuvoton
<> 149:156823d33999 3 *
<> 149:156823d33999 4 * Licensed under the Apache License, Version 2.0 (the "License");
<> 149:156823d33999 5 * you may not use this file except in compliance with the License.
<> 149:156823d33999 6 * You may obtain a copy of the License at
<> 149:156823d33999 7 *
<> 149:156823d33999 8 * http://www.apache.org/licenses/LICENSE-2.0
<> 149:156823d33999 9 *
<> 149:156823d33999 10 * Unless required by applicable law or agreed to in writing, software
<> 149:156823d33999 11 * distributed under the License is distributed on an "AS IS" BASIS,
<> 149:156823d33999 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<> 149:156823d33999 13 * See the License for the specific language governing permissions and
<> 149:156823d33999 14 * limitations under the License.
<> 149:156823d33999 15 */
<> 149:156823d33999 16
<> 149:156823d33999 17 #include "port_api.h"
<> 149:156823d33999 18 #include "gpio_api.h"
<> 149:156823d33999 19 #include "pinmap.h"
<> 149:156823d33999 20 #include "mbed_error.h"
<> 149:156823d33999 21
<> 149:156823d33999 22 #if DEVICE_PORTIN || DEVICE_PORTOUT || DEVICE_PORTINOUT
<> 149:156823d33999 23
<> 149:156823d33999 24 PinName port_pin(PortName port, int pin_n)
<> 149:156823d33999 25 {
<> 149:156823d33999 26 return (PinName) NU_PORT_N_PIN_TO_PINNAME(port, pin_n);
<> 149:156823d33999 27 }
<> 149:156823d33999 28
<> 149:156823d33999 29 void port_init(port_t *obj, PortName port, int mask, PinDirection dir)
<> 149:156823d33999 30 {
<> 149:156823d33999 31 obj->port = port;
<> 149:156823d33999 32 obj->mask = mask;
<> 149:156823d33999 33 obj->direction = dir;
<> 149:156823d33999 34
<> 149:156823d33999 35 uint32_t i;
<> 149:156823d33999 36 obj->direction = dir;
<> 149:156823d33999 37 for (i = 0; i < GPIO_PIN_MAX; i++) {
<> 149:156823d33999 38 if (obj->mask & (1 << i)) {
<> 149:156823d33999 39 gpio_set(port_pin(port, i));
<> 149:156823d33999 40 }
<> 149:156823d33999 41 }
<> 149:156823d33999 42
<> 149:156823d33999 43 port_dir(obj, dir);
<> 149:156823d33999 44 }
<> 149:156823d33999 45
<> 149:156823d33999 46 void port_dir(port_t *obj, PinDirection dir)
<> 149:156823d33999 47 {
<> 149:156823d33999 48 uint32_t i;
<> 149:156823d33999 49 obj->direction = dir;
<> 149:156823d33999 50 for (i = 0; i < GPIO_PIN_MAX; i++) {
<> 149:156823d33999 51 if (obj->mask & (1 << i)) {
<> 149:156823d33999 52 if (dir == PIN_OUTPUT) {
<> 149:156823d33999 53 GPIO_SetMode(NU_PORT_BASE(obj->port), 1 << i, GPIO_MODE_OUTPUT);
<> 149:156823d33999 54 } else { // PIN_INPUT
<> 149:156823d33999 55 GPIO_SetMode(NU_PORT_BASE(obj->port), 1 << i, GPIO_MODE_INPUT);
<> 149:156823d33999 56 }
<> 149:156823d33999 57 }
<> 149:156823d33999 58 }
<> 149:156823d33999 59 }
<> 149:156823d33999 60
<> 149:156823d33999 61 void port_mode(port_t *obj, PinMode mode)
<> 149:156823d33999 62 {
<> 149:156823d33999 63 uint32_t i;
<> 149:156823d33999 64
<> 149:156823d33999 65 for (i = 0; i < GPIO_PIN_MAX; i++) {
<> 149:156823d33999 66 if (obj->mask & (1 << i)) {
<> 149:156823d33999 67 pin_mode(port_pin(obj->port, i), mode);
<> 149:156823d33999 68 }
<> 149:156823d33999 69 }
<> 149:156823d33999 70 }
<> 149:156823d33999 71
<> 149:156823d33999 72 void port_write(port_t *obj, int value)
<> 149:156823d33999 73 {
<> 149:156823d33999 74 uint32_t i;
<> 149:156823d33999 75 uint32_t port_index = obj->port;
<> 149:156823d33999 76
<> 149:156823d33999 77 for (i = 0; i < GPIO_PIN_MAX; i++) {
<> 149:156823d33999 78 if (obj->mask & (1 << i)) {
<> 149:156823d33999 79 GPIO_PIN_DATA(port_index, i) = (value & obj->mask) ? 1 : 0;
<> 149:156823d33999 80 }
<> 149:156823d33999 81 }
<> 149:156823d33999 82 }
<> 149:156823d33999 83
<> 149:156823d33999 84 int port_read(port_t *obj)
<> 149:156823d33999 85 {
<> 149:156823d33999 86 uint32_t i;
<> 149:156823d33999 87 uint32_t port_index = obj->port;
<> 149:156823d33999 88 int value = 0;
<> 149:156823d33999 89
<> 149:156823d33999 90 for (i = 0; i < GPIO_PIN_MAX; i++) {
<> 149:156823d33999 91 if (obj->mask & (1 << i)) {
<> 149:156823d33999 92 value = value | (GPIO_PIN_DATA(port_index, i) << i);
<> 149:156823d33999 93 }
<> 149:156823d33999 94 }
<> 149:156823d33999 95
<> 149:156823d33999 96 return value;
<> 149:156823d33999 97 }
<> 149:156823d33999 98
<> 149:156823d33999 99 #endif