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