mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
targets/hal/TARGET_Silicon_Labs/TARGET_EFM32/port_api.c@50:a417edff4437, 2016-01-15 (annotated)
- Committer:
- mbed_official
- Date:
- Fri Jan 15 07:45:16 2016 +0000
- Revision:
- 50:a417edff4437
- Parent:
- 0:9b334a45a8ff
- Child:
- 144:ef7eb2e8f9f7
Synchronized with git revision 6010f32619bfcbb01cc73747d4ff9040863482d9
Full URL: https://github.com/mbedmicro/mbed/commit/6010f32619bfcbb01cc73747d4ff9040863482d9/
Remove doubling of buffer size in realiseEndpoint()
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bogdanm | 0:9b334a45a8ff | 1 | /***************************************************************************//** |
bogdanm | 0:9b334a45a8ff | 2 | * @file port_api.c |
bogdanm | 0:9b334a45a8ff | 3 | ******************************************************************************* |
bogdanm | 0:9b334a45a8ff | 4 | * @section License |
bogdanm | 0:9b334a45a8ff | 5 | * <b>(C) Copyright 2015 Silicon Labs, http://www.silabs.com</b> |
bogdanm | 0:9b334a45a8ff | 6 | ******************************************************************************* |
bogdanm | 0:9b334a45a8ff | 7 | * |
bogdanm | 0:9b334a45a8ff | 8 | * Permission is granted to anyone to use this software for any purpose, |
bogdanm | 0:9b334a45a8ff | 9 | * including commercial applications, and to alter it and redistribute it |
bogdanm | 0:9b334a45a8ff | 10 | * freely, subject to the following restrictions: |
bogdanm | 0:9b334a45a8ff | 11 | * |
bogdanm | 0:9b334a45a8ff | 12 | * 1. The origin of this software must not be misrepresented; you must not |
bogdanm | 0:9b334a45a8ff | 13 | * claim that you wrote the original software. |
bogdanm | 0:9b334a45a8ff | 14 | * 2. Altered source versions must be plainly marked as such, and must not be |
bogdanm | 0:9b334a45a8ff | 15 | * misrepresented as being the original software. |
bogdanm | 0:9b334a45a8ff | 16 | * 3. This notice may not be removed or altered from any source distribution. |
bogdanm | 0:9b334a45a8ff | 17 | * |
bogdanm | 0:9b334a45a8ff | 18 | * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Silicon Labs has no |
bogdanm | 0:9b334a45a8ff | 19 | * obligation to support this Software. Silicon Labs is providing the |
bogdanm | 0:9b334a45a8ff | 20 | * Software "AS IS", with no express or implied warranties of any kind, |
bogdanm | 0:9b334a45a8ff | 21 | * including, but not limited to, any implied warranties of merchantability |
bogdanm | 0:9b334a45a8ff | 22 | * or fitness for any particular purpose or warranties against infringement |
bogdanm | 0:9b334a45a8ff | 23 | * of any proprietary rights of a third party. |
bogdanm | 0:9b334a45a8ff | 24 | * |
bogdanm | 0:9b334a45a8ff | 25 | * Silicon Labs will not be liable for any consequential, incidental, or |
bogdanm | 0:9b334a45a8ff | 26 | * special damages, or any other relief, or for any claim by any third party, |
bogdanm | 0:9b334a45a8ff | 27 | * arising from your use of this Software. |
bogdanm | 0:9b334a45a8ff | 28 | * |
bogdanm | 0:9b334a45a8ff | 29 | ******************************************************************************/ |
bogdanm | 0:9b334a45a8ff | 30 | |
bogdanm | 0:9b334a45a8ff | 31 | #include "device.h" |
bogdanm | 0:9b334a45a8ff | 32 | #if DEVICE_PORTOUT |
bogdanm | 0:9b334a45a8ff | 33 | |
bogdanm | 0:9b334a45a8ff | 34 | #include "port_api.h" |
bogdanm | 0:9b334a45a8ff | 35 | #include "pinmap.h" |
bogdanm | 0:9b334a45a8ff | 36 | #include "gpio_api.h" |
bogdanm | 0:9b334a45a8ff | 37 | #include "em_gpio.h" |
bogdanm | 0:9b334a45a8ff | 38 | #include "em_cmu.h" |
bogdanm | 0:9b334a45a8ff | 39 | |
bogdanm | 0:9b334a45a8ff | 40 | #define PORT_NUM_PINS 16 |
bogdanm | 0:9b334a45a8ff | 41 | |
bogdanm | 0:9b334a45a8ff | 42 | PinName port_pin(PortName port, int pin_n) |
bogdanm | 0:9b334a45a8ff | 43 | { |
bogdanm | 0:9b334a45a8ff | 44 | return (PinName) (pin_n | port << 4); // Encode pin and port number in one uint32 |
bogdanm | 0:9b334a45a8ff | 45 | } |
bogdanm | 0:9b334a45a8ff | 46 | |
mbed_official | 50:a417edff4437 | 47 | void port_init(port_t *obj, PortName port, int mask, PinDirection dir) |
bogdanm | 0:9b334a45a8ff | 48 | { |
bogdanm | 0:9b334a45a8ff | 49 | obj->mask = mask; |
bogdanm | 0:9b334a45a8ff | 50 | obj->port = port; |
bogdanm | 0:9b334a45a8ff | 51 | obj->dir = dir; |
mbed_official | 50:a417edff4437 | 52 | |
bogdanm | 0:9b334a45a8ff | 53 | port_dir(obj, obj->dir); |
bogdanm | 0:9b334a45a8ff | 54 | } |
bogdanm | 0:9b334a45a8ff | 55 | |
bogdanm | 0:9b334a45a8ff | 56 | void port_mode(port_t *obj, PinMode mode) |
bogdanm | 0:9b334a45a8ff | 57 | { |
bogdanm | 0:9b334a45a8ff | 58 | /* Set mode for pins given by mask */ |
bogdanm | 0:9b334a45a8ff | 59 | uint32_t pin; |
bogdanm | 0:9b334a45a8ff | 60 | for (pin = 0; pin < PORT_NUM_PINS; pin++) { |
bogdanm | 0:9b334a45a8ff | 61 | if (obj->mask & (1 << pin)) { |
bogdanm | 0:9b334a45a8ff | 62 | pin_mode(port_pin(obj->port, pin), mode); |
bogdanm | 0:9b334a45a8ff | 63 | } |
bogdanm | 0:9b334a45a8ff | 64 | } |
bogdanm | 0:9b334a45a8ff | 65 | } |
bogdanm | 0:9b334a45a8ff | 66 | |
bogdanm | 0:9b334a45a8ff | 67 | void port_dir(port_t *obj, PinDirection dir) |
bogdanm | 0:9b334a45a8ff | 68 | { |
bogdanm | 0:9b334a45a8ff | 69 | obj->dir = dir; |
bogdanm | 0:9b334a45a8ff | 70 | |
bogdanm | 0:9b334a45a8ff | 71 | /* Set default pin mode for pins given by mask */ |
bogdanm | 0:9b334a45a8ff | 72 | switch (dir) { |
bogdanm | 0:9b334a45a8ff | 73 | case PIN_INPUT: |
mbed_official | 50:a417edff4437 | 74 | port_mode(obj, Input); |
bogdanm | 0:9b334a45a8ff | 75 | break; |
bogdanm | 0:9b334a45a8ff | 76 | case PIN_OUTPUT: |
mbed_official | 50:a417edff4437 | 77 | port_mode(obj, PushPull); |
bogdanm | 0:9b334a45a8ff | 78 | break; |
bogdanm | 0:9b334a45a8ff | 79 | } |
bogdanm | 0:9b334a45a8ff | 80 | } |
bogdanm | 0:9b334a45a8ff | 81 | |
bogdanm | 0:9b334a45a8ff | 82 | void port_write(port_t *obj, int value) |
bogdanm | 0:9b334a45a8ff | 83 | { |
mbed_official | 50:a417edff4437 | 84 | GPIO_PortOutSetVal(obj->port, value, obj->mask); |
bogdanm | 0:9b334a45a8ff | 85 | } |
bogdanm | 0:9b334a45a8ff | 86 | |
bogdanm | 0:9b334a45a8ff | 87 | int port_read(port_t *obj) |
bogdanm | 0:9b334a45a8ff | 88 | { |
bogdanm | 0:9b334a45a8ff | 89 | if (obj->dir == PIN_INPUT) { |
bogdanm | 0:9b334a45a8ff | 90 | return (int) (GPIO_PortInGet(obj->port) & obj->mask); |
bogdanm | 0:9b334a45a8ff | 91 | } else { |
bogdanm | 0:9b334a45a8ff | 92 | return (int) (GPIO_PortOutGet(obj->port) & obj->mask); |
bogdanm | 0:9b334a45a8ff | 93 | } |
bogdanm | 0:9b334a45a8ff | 94 | } |
bogdanm | 0:9b334a45a8ff | 95 | |
bogdanm | 0:9b334a45a8ff | 96 | #endif |