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:
mbed_official
Date:
Thu Sep 18 14:00:17 2014 +0100
Revision:
324:406fd2029f23
Synchronized with git revision a73f28e6fbca9559fbed2726410eeb4c0534a4a5

Full URL: https://github.com/mbedmicro/mbed/commit/a73f28e6fbca9559fbed2726410eeb4c0534a4a5/

Extended #476, which does not break ethernet for K64F

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 324:406fd2029f23 1 /* mbed Microcontroller Library
mbed_official 324:406fd2029f23 2 * Copyright (c) 2006-2013 ARM Limited
mbed_official 324:406fd2029f23 3 *
mbed_official 324:406fd2029f23 4 * Licensed under the Apache License, Version 2.0 (the "License");
mbed_official 324:406fd2029f23 5 * you may not use this file except in compliance with the License.
mbed_official 324:406fd2029f23 6 * You may obtain a copy of the License at
mbed_official 324:406fd2029f23 7 *
mbed_official 324:406fd2029f23 8 * http://www.apache.org/licenses/LICENSE-2.0
mbed_official 324:406fd2029f23 9 *
mbed_official 324:406fd2029f23 10 * Unless required by applicable law or agreed to in writing, software
mbed_official 324:406fd2029f23 11 * distributed under the License is distributed on an "AS IS" BASIS,
mbed_official 324:406fd2029f23 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 324:406fd2029f23 13 * See the License for the specific language governing permissions and
mbed_official 324:406fd2029f23 14 * limitations under the License.
mbed_official 324:406fd2029f23 15 */
mbed_official 324:406fd2029f23 16 #include "port_api.h"
mbed_official 324:406fd2029f23 17
mbed_official 324:406fd2029f23 18 #if DEVICE_PORTIN || DEVICE_PORTOUT
mbed_official 324:406fd2029f23 19
mbed_official 324:406fd2029f23 20 #include "pinmap.h"
mbed_official 324:406fd2029f23 21 #include "gpio_api.h"
mbed_official 324:406fd2029f23 22
mbed_official 324:406fd2029f23 23 PinName port_pin(PortName port, int pin_n) {
mbed_official 324:406fd2029f23 24 return (PinName)((port << GPIO_PORT_SHIFT) | pin_n);
mbed_official 324:406fd2029f23 25 }
mbed_official 324:406fd2029f23 26
mbed_official 324:406fd2029f23 27 void port_init(port_t *obj, PortName port, int mask, PinDirection dir) {
mbed_official 324:406fd2029f23 28 obj->port = port;
mbed_official 324:406fd2029f23 29 obj->mask = mask;
mbed_official 324:406fd2029f23 30
mbed_official 324:406fd2029f23 31 // The function is set per pin: reuse gpio logic
mbed_official 324:406fd2029f23 32 for (uint32_t i = 0; i < 32; i++) {
mbed_official 324:406fd2029f23 33 if (obj->mask & (1 << i)) {
mbed_official 324:406fd2029f23 34 gpio_set(port_pin(obj->port, i));
mbed_official 324:406fd2029f23 35 }
mbed_official 324:406fd2029f23 36 }
mbed_official 324:406fd2029f23 37
mbed_official 324:406fd2029f23 38 port_dir(obj, dir);
mbed_official 324:406fd2029f23 39 }
mbed_official 324:406fd2029f23 40
mbed_official 324:406fd2029f23 41 void port_mode(port_t *obj, PinMode mode) {
mbed_official 324:406fd2029f23 42
mbed_official 324:406fd2029f23 43 // The mode is set per pin: reuse pinmap logic
mbed_official 324:406fd2029f23 44 for (uint32_t i = 0; i < 32; i++) {
mbed_official 324:406fd2029f23 45 if (obj->mask & (1 << i)) {
mbed_official 324:406fd2029f23 46 pin_mode(port_pin(obj->port, i), mode);
mbed_official 324:406fd2029f23 47 }
mbed_official 324:406fd2029f23 48 }
mbed_official 324:406fd2029f23 49 }
mbed_official 324:406fd2029f23 50
mbed_official 324:406fd2029f23 51 void port_dir(port_t *obj, PinDirection dir) {
mbed_official 324:406fd2029f23 52 uint32_t port_addrs[] = PORT_BASE_ADDRS;
mbed_official 324:406fd2029f23 53 uint32_t direction = GPIO_HAL_GetPortDir(port_addrs[obj->port]);
mbed_official 324:406fd2029f23 54 switch (dir) {
mbed_official 324:406fd2029f23 55 case PIN_INPUT :
mbed_official 324:406fd2029f23 56 direction &= ~obj->mask;
mbed_official 324:406fd2029f23 57 GPIO_HAL_SetPortDir(port_addrs[obj->port], direction);
mbed_official 324:406fd2029f23 58 break;
mbed_official 324:406fd2029f23 59 case PIN_OUTPUT:
mbed_official 324:406fd2029f23 60 direction |= obj->mask;
mbed_official 324:406fd2029f23 61 GPIO_HAL_SetPortDir(port_addrs[obj->port], direction);
mbed_official 324:406fd2029f23 62 break;
mbed_official 324:406fd2029f23 63 }
mbed_official 324:406fd2029f23 64 }
mbed_official 324:406fd2029f23 65
mbed_official 324:406fd2029f23 66 void port_write(port_t *obj, int value) {
mbed_official 324:406fd2029f23 67 uint32_t port_addrs[] = PORT_BASE_ADDRS;
mbed_official 324:406fd2029f23 68 uint32_t input = GPIO_HAL_ReadPortInput(port_addrs[obj->port]) & ~obj->mask;
mbed_official 324:406fd2029f23 69 GPIO_HAL_WritePortOutput(port_addrs[obj->port], input | (uint32_t)(value & obj->mask));
mbed_official 324:406fd2029f23 70 }
mbed_official 324:406fd2029f23 71
mbed_official 324:406fd2029f23 72 int port_read(port_t *obj) {
mbed_official 324:406fd2029f23 73 uint32_t port_addrs[] = PORT_BASE_ADDRS;
mbed_official 324:406fd2029f23 74 return (int)(GPIO_HAL_ReadPortInput(port_addrs[obj->port]) & obj->mask);
mbed_official 324:406fd2029f23 75 }
mbed_official 324:406fd2029f23 76
mbed_official 324:406fd2029f23 77 #endif