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.
targets/hal/TARGET_Silicon_Labs/TARGET_EFM32/gpio_api.c@627:4fa1328d9c60, 2015-09-25 (annotated)
- Committer:
- mbed_official
- Date:
- Fri Sep 25 14:15:10 2015 +0100
- Revision:
- 627:4fa1328d9c60
- Parent:
- 593:78ee8643776a
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 gpio_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 | 627:4fa1328d9c60 | 30 | |
mbed_official | 525:c320967f86b9 | 31 | #include "gpio_api.h" |
mbed_official | 525:c320967f86b9 | 32 | #include "pinmap.h" |
mbed_official | 525:c320967f86b9 | 33 | #include "em_cmu.h" |
mbed_official | 525:c320967f86b9 | 34 | #include "mbed_assert.h" |
mbed_official | 526:7c4bdfe6a168 | 35 | #include "sleepmodes.h" |
mbed_official | 525:c320967f86b9 | 36 | |
mbed_official | 593:78ee8643776a | 37 | |
mbed_official | 593:78ee8643776a | 38 | void gpio_write(gpio_t *obj, int value) |
mbed_official | 525:c320967f86b9 | 39 | { |
mbed_official | 593:78ee8643776a | 40 | if (value) { |
mbed_official | 593:78ee8643776a | 41 | GPIO_PinOutSet((GPIO_Port_TypeDef)(obj->pin >> 4 & 0xF), obj->pin & 0xF); // Pin number encoded in first four bits of obj->pin |
mbed_official | 593:78ee8643776a | 42 | } else { |
mbed_official | 593:78ee8643776a | 43 | GPIO_PinOutClear((GPIO_Port_TypeDef)(obj->pin >> 4 & 0xF), obj->pin & 0xF); |
mbed_official | 593:78ee8643776a | 44 | } |
mbed_official | 593:78ee8643776a | 45 | } |
mbed_official | 593:78ee8643776a | 46 | |
mbed_official | 593:78ee8643776a | 47 | int gpio_read(gpio_t *obj) |
mbed_official | 593:78ee8643776a | 48 | { |
mbed_official | 593:78ee8643776a | 49 | if (obj->dir == PIN_INPUT) { |
mbed_official | 593:78ee8643776a | 50 | return GPIO_PinInGet((GPIO_Port_TypeDef)(obj->pin >> 4 & 0xF), obj->pin & 0xF); // Pin number encoded in first four bits of obj->pin |
mbed_official | 593:78ee8643776a | 51 | } else { |
mbed_official | 593:78ee8643776a | 52 | return GPIO_PinOutGet((GPIO_Port_TypeDef)(obj->pin >> 4 & 0xF), obj->pin & 0xF); |
mbed_official | 593:78ee8643776a | 53 | } |
mbed_official | 593:78ee8643776a | 54 | } |
mbed_official | 593:78ee8643776a | 55 | |
mbed_official | 593:78ee8643776a | 56 | int gpio_is_connected(const gpio_t *obj) |
mbed_official | 593:78ee8643776a | 57 | { |
mbed_official | 593:78ee8643776a | 58 | return (obj->pin | 0xFFFFFF00 )!= (PinName)NC; |
mbed_official | 525:c320967f86b9 | 59 | } |
mbed_official | 525:c320967f86b9 | 60 | |
mbed_official | 525:c320967f86b9 | 61 | /* |
mbed_official | 525:c320967f86b9 | 62 | * @return the GPIO port mask for this pin |
mbed_official | 525:c320967f86b9 | 63 | * Pin and port index encoded in one uint32. |
mbed_official | 525:c320967f86b9 | 64 | * First four bits represent the pin number |
mbed_official | 525:c320967f86b9 | 65 | * The remaining bits represent the pin mode |
mbed_official | 525:c320967f86b9 | 66 | */ |
mbed_official | 525:c320967f86b9 | 67 | uint32_t gpio_set(PinName pin) |
mbed_official | 525:c320967f86b9 | 68 | { |
mbed_official | 525:c320967f86b9 | 69 | return 1 << ((uint32_t) pin & 0xF); |
mbed_official | 525:c320967f86b9 | 70 | } |
mbed_official | 525:c320967f86b9 | 71 | |
mbed_official | 525:c320967f86b9 | 72 | void gpio_init(gpio_t *obj, PinName pin) |
mbed_official | 525:c320967f86b9 | 73 | { |
mbed_official | 525:c320967f86b9 | 74 | MBED_ASSERT(pin != NC); |
mbed_official | 525:c320967f86b9 | 75 | |
mbed_official | 525:c320967f86b9 | 76 | CMU_ClockEnable(cmuClock_HFPER, true); |
mbed_official | 525:c320967f86b9 | 77 | CMU_ClockEnable(cmuClock_GPIO, true); |
mbed_official | 525:c320967f86b9 | 78 | obj->pin = pin; |
mbed_official | 525:c320967f86b9 | 79 | } |
mbed_official | 525:c320967f86b9 | 80 | |
mbed_official | 525:c320967f86b9 | 81 | void gpio_mode(gpio_t *obj, PinMode mode) |
mbed_official | 525:c320967f86b9 | 82 | { |
mbed_official | 593:78ee8643776a | 83 | if(obj->dir == PIN_INPUT) { |
mbed_official | 593:78ee8643776a | 84 | switch(mode) { |
mbed_official | 593:78ee8643776a | 85 | case PullDefault: |
mbed_official | 593:78ee8643776a | 86 | mode = Input; |
mbed_official | 593:78ee8643776a | 87 | break; |
mbed_official | 593:78ee8643776a | 88 | case PullUp: |
mbed_official | 593:78ee8643776a | 89 | mode = InputPullUp; |
mbed_official | 593:78ee8643776a | 90 | break; |
mbed_official | 593:78ee8643776a | 91 | case PullDown: |
mbed_official | 593:78ee8643776a | 92 | mode = InputPullDown; |
mbed_official | 593:78ee8643776a | 93 | break; |
mbed_official | 593:78ee8643776a | 94 | default: |
mbed_official | 593:78ee8643776a | 95 | break; |
mbed_official | 593:78ee8643776a | 96 | } |
mbed_official | 593:78ee8643776a | 97 | |
mbed_official | 593:78ee8643776a | 98 | //Handle DOUT setting |
mbed_official | 593:78ee8643776a | 99 | if((mode & 0x10) != 0) { |
mbed_official | 593:78ee8643776a | 100 | //Set DOUT |
mbed_official | 593:78ee8643776a | 101 | GPIO->P[(obj->pin >> 4) & 0xF].DOUTSET = 1 << (obj->pin & 0xF); |
mbed_official | 593:78ee8643776a | 102 | } else { |
mbed_official | 593:78ee8643776a | 103 | //Clear DOUT |
mbed_official | 593:78ee8643776a | 104 | GPIO->P[(obj->pin >> 4) & 0xF].DOUTCLR = 1 << (obj->pin & 0xF); |
mbed_official | 593:78ee8643776a | 105 | } |
mbed_official | 593:78ee8643776a | 106 | } else { |
mbed_official | 593:78ee8643776a | 107 | switch(mode) { |
mbed_official | 593:78ee8643776a | 108 | case PullDefault: |
mbed_official | 593:78ee8643776a | 109 | mode = PushPull; |
mbed_official | 593:78ee8643776a | 110 | break; |
mbed_official | 593:78ee8643776a | 111 | case PullUp: |
mbed_official | 593:78ee8643776a | 112 | mode = WiredAndPullUp; |
mbed_official | 593:78ee8643776a | 113 | break; |
mbed_official | 593:78ee8643776a | 114 | case PullDown: |
mbed_official | 593:78ee8643776a | 115 | mode = WiredOrPullDown; |
mbed_official | 593:78ee8643776a | 116 | break; |
mbed_official | 593:78ee8643776a | 117 | default: |
mbed_official | 593:78ee8643776a | 118 | break; |
mbed_official | 593:78ee8643776a | 119 | } |
mbed_official | 593:78ee8643776a | 120 | } |
mbed_official | 593:78ee8643776a | 121 | |
mbed_official | 525:c320967f86b9 | 122 | obj->mode = mode; // Update object |
mbed_official | 525:c320967f86b9 | 123 | pin_mode(obj->pin, mode); // Update register |
mbed_official | 525:c320967f86b9 | 124 | } |
mbed_official | 525:c320967f86b9 | 125 | |
mbed_official | 525:c320967f86b9 | 126 | // Used by DigitalInOut to set correct mode when direction is set |
mbed_official | 525:c320967f86b9 | 127 | void gpio_dir(gpio_t *obj, PinDirection direction) |
mbed_official | 525:c320967f86b9 | 128 | { |
mbed_official | 525:c320967f86b9 | 129 | obj->dir = direction; |
mbed_official | 525:c320967f86b9 | 130 | switch (direction) { |
mbed_official | 525:c320967f86b9 | 131 | case PIN_INPUT: |
mbed_official | 525:c320967f86b9 | 132 | gpio_mode(obj, PullDefault); |
mbed_official | 525:c320967f86b9 | 133 | break; |
mbed_official | 525:c320967f86b9 | 134 | case PIN_OUTPUT: |
mbed_official | 525:c320967f86b9 | 135 | gpio_mode(obj, PullNone); |
mbed_official | 525:c320967f86b9 | 136 | break; |
mbed_official | 525:c320967f86b9 | 137 | } |
mbed_official | 525:c320967f86b9 | 138 | } |