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:
Fri May 22 10:45:46 2015 +0100
Revision:
548:1abac31e188e
Parent:
525:c320967f86b9
Child:
627:4fa1328d9c60
Synchronized with git revision 88d158e43b54f97c5e94da305ea9a096889cc81b

Full URL: https://github.com/mbedmicro/mbed/commit/88d158e43b54f97c5e94da305ea9a096889cc81b/

Silicon Labs - Cosmetic: apply mbed coding style to HAL

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 525:c320967f86b9 1 /* mbed Microcontroller Library
mbed_official 525:c320967f86b9 2 * Copyright (c) 2006-2013 ARM Limited
mbed_official 525:c320967f86b9 3 *
mbed_official 525:c320967f86b9 4 * Licensed under the Apache License, Version 2.0 (the "License");
mbed_official 525:c320967f86b9 5 * you may not use this file except in compliance with the License.
mbed_official 525:c320967f86b9 6 * You may obtain a copy of the License at
mbed_official 525:c320967f86b9 7 *
mbed_official 525:c320967f86b9 8 * http://www.apache.org/licenses/LICENSE-2.0
mbed_official 525:c320967f86b9 9 *
mbed_official 525:c320967f86b9 10 * Unless required by applicable law or agreed to in writing, software
mbed_official 525:c320967f86b9 11 * distributed under the License is distributed on an "AS IS" BASIS,
mbed_official 525:c320967f86b9 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 525:c320967f86b9 13 * See the License for the specific language governing permissions and
mbed_official 525:c320967f86b9 14 * limitations under the License.
mbed_official 525:c320967f86b9 15 */
mbed_official 525:c320967f86b9 16
mbed_official 525:c320967f86b9 17 #include "device.h"
mbed_official 525:c320967f86b9 18 #if DEVICE_PORTOUT
mbed_official 525:c320967f86b9 19
mbed_official 525:c320967f86b9 20 #include "port_api.h"
mbed_official 525:c320967f86b9 21 #include "pinmap.h"
mbed_official 525:c320967f86b9 22 #include "gpio_api.h"
mbed_official 525:c320967f86b9 23 #include "em_gpio.h"
mbed_official 525:c320967f86b9 24 #include "em_cmu.h"
mbed_official 525:c320967f86b9 25
mbed_official 525:c320967f86b9 26 #define PORT_NUM_PINS 16
mbed_official 525:c320967f86b9 27
mbed_official 525:c320967f86b9 28 uint8_t port_get_index(port_t *obj)
mbed_official 525:c320967f86b9 29 {
mbed_official 525:c320967f86b9 30 return 0;
mbed_official 525:c320967f86b9 31 }
mbed_official 525:c320967f86b9 32
mbed_official 525:c320967f86b9 33 PinName port_pin(PortName port, int pin_n)
mbed_official 525:c320967f86b9 34 {
mbed_official 525:c320967f86b9 35 return (PinName) (pin_n | port << 4); // Encode pin and port number in one uint32
mbed_official 525:c320967f86b9 36 }
mbed_official 525:c320967f86b9 37
mbed_official 525:c320967f86b9 38 void port_preinit(port_t *obj, PortName port, int mask, PinDirection dir)
mbed_official 525:c320967f86b9 39 {
mbed_official 525:c320967f86b9 40 obj->mask = mask;
mbed_official 525:c320967f86b9 41 obj->port = port;
mbed_official 525:c320967f86b9 42 obj->dir = dir;
mbed_official 525:c320967f86b9 43 }
mbed_official 525:c320967f86b9 44
mbed_official 525:c320967f86b9 45 void port_init(port_t *obj, PortName port, int mask, PinDirection dir)
mbed_official 525:c320967f86b9 46 {
mbed_official 548:1abac31e188e 47 port_preinit(obj, port, mask, dir);
mbed_official 525:c320967f86b9 48 port_dir(obj, obj->dir);
mbed_official 525:c320967f86b9 49 }
mbed_official 525:c320967f86b9 50
mbed_official 525:c320967f86b9 51 void port_mode(port_t *obj, PinMode mode)
mbed_official 525:c320967f86b9 52 {
mbed_official 525:c320967f86b9 53 /* Set mode for pins given by mask */
mbed_official 525:c320967f86b9 54 uint32_t pin;
mbed_official 525:c320967f86b9 55 for (pin = 0; pin < PORT_NUM_PINS; pin++) {
mbed_official 525:c320967f86b9 56 if (obj->mask & (1 << pin)) {
mbed_official 525:c320967f86b9 57 pin_mode(port_pin(obj->port, pin), mode);
mbed_official 525:c320967f86b9 58 }
mbed_official 525:c320967f86b9 59 }
mbed_official 525:c320967f86b9 60 }
mbed_official 525:c320967f86b9 61
mbed_official 525:c320967f86b9 62 void port_dir(port_t *obj, PinDirection dir)
mbed_official 525:c320967f86b9 63 {
mbed_official 525:c320967f86b9 64 obj->dir = dir;
mbed_official 525:c320967f86b9 65
mbed_official 525:c320967f86b9 66 /* Set default pin mode for pins given by mask */
mbed_official 525:c320967f86b9 67 switch (dir) {
mbed_official 525:c320967f86b9 68 case PIN_INPUT:
mbed_official 525:c320967f86b9 69 port_mode(obj, PullDefault);
mbed_official 525:c320967f86b9 70 break;
mbed_official 525:c320967f86b9 71 case PIN_OUTPUT:
mbed_official 525:c320967f86b9 72 port_mode(obj, PullNone);
mbed_official 525:c320967f86b9 73 break;
mbed_official 525:c320967f86b9 74 }
mbed_official 525:c320967f86b9 75 }
mbed_official 525:c320967f86b9 76
mbed_official 525:c320967f86b9 77 void port_write(port_t *obj, int value)
mbed_official 525:c320967f86b9 78 {
mbed_official 525:c320967f86b9 79 if (value) {
mbed_official 525:c320967f86b9 80 GPIO_PortOutSet(obj->port, obj->mask);
mbed_official 525:c320967f86b9 81 } else {
mbed_official 525:c320967f86b9 82 GPIO_PortOutClear(obj->port, obj->mask);
mbed_official 525:c320967f86b9 83 }
mbed_official 525:c320967f86b9 84 }
mbed_official 525:c320967f86b9 85
mbed_official 525:c320967f86b9 86 int port_read(port_t *obj)
mbed_official 525:c320967f86b9 87 {
mbed_official 525:c320967f86b9 88 if (obj->dir == PIN_INPUT) {
mbed_official 525:c320967f86b9 89 return (int) (GPIO_PortInGet(obj->port) & obj->mask);
mbed_official 525:c320967f86b9 90 } else {
mbed_official 525:c320967f86b9 91 return (int) (GPIO_PortOutGet(obj->port) & obj->mask);
mbed_official 525:c320967f86b9 92 }
mbed_official 525:c320967f86b9 93 }
mbed_official 525:c320967f86b9 94
mbed_official 525:c320967f86b9 95 #endif