mbed library sources. Supersedes mbed-src.

Fork of mbed-dev by mbed official

Committer:
<>
Date:
Fri Sep 02 15:07:44 2016 +0100
Revision:
144:ef7eb2e8f9f7
This updates the lib to the mbed lib v125

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 144:ef7eb2e8f9f7 1 /* mbed Microcontroller Library
<> 144:ef7eb2e8f9f7 2 * Copyright (c) 2015-2016 Nuvoton
<> 144:ef7eb2e8f9f7 3 *
<> 144:ef7eb2e8f9f7 4 * Licensed under the Apache License, Version 2.0 (the "License");
<> 144:ef7eb2e8f9f7 5 * you may not use this file except in compliance with the License.
<> 144:ef7eb2e8f9f7 6 * You may obtain a copy of the License at
<> 144:ef7eb2e8f9f7 7 *
<> 144:ef7eb2e8f9f7 8 * http://www.apache.org/licenses/LICENSE-2.0
<> 144:ef7eb2e8f9f7 9 *
<> 144:ef7eb2e8f9f7 10 * Unless required by applicable law or agreed to in writing, software
<> 144:ef7eb2e8f9f7 11 * distributed under the License is distributed on an "AS IS" BASIS,
<> 144:ef7eb2e8f9f7 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<> 144:ef7eb2e8f9f7 13 * See the License for the specific language governing permissions and
<> 144:ef7eb2e8f9f7 14 * limitations under the License.
<> 144:ef7eb2e8f9f7 15 */
<> 144:ef7eb2e8f9f7 16
<> 144:ef7eb2e8f9f7 17 #include "mbed_assert.h"
<> 144:ef7eb2e8f9f7 18 #include "pinmap.h"
<> 144:ef7eb2e8f9f7 19 #include "PortNames.h"
<> 144:ef7eb2e8f9f7 20 #include "mbed_error.h"
<> 144:ef7eb2e8f9f7 21
<> 144:ef7eb2e8f9f7 22 /**
<> 144:ef7eb2e8f9f7 23 * Configure pin multi-function
<> 144:ef7eb2e8f9f7 24 */
<> 144:ef7eb2e8f9f7 25 void pin_function(PinName pin, int data)
<> 144:ef7eb2e8f9f7 26 {
<> 144:ef7eb2e8f9f7 27 MBED_ASSERT(pin != (PinName)NC);
<> 144:ef7eb2e8f9f7 28 uint32_t pin_index = NU_PINNAME_TO_PIN(pin);
<> 144:ef7eb2e8f9f7 29 uint32_t port_index = NU_PINNAME_TO_PORT(pin);
<> 144:ef7eb2e8f9f7 30 __IO uint32_t *GPx_MFPx = ((__IO uint32_t *) &SYS->GPA_MFPL) + port_index * 2 + (pin_index / 8);
<> 144:ef7eb2e8f9f7 31 //uint32_t MFP_Pos = NU_MFP_POS(pin_index);
<> 144:ef7eb2e8f9f7 32 uint32_t MFP_Msk = NU_MFP_MSK(pin_index);
<> 144:ef7eb2e8f9f7 33
<> 144:ef7eb2e8f9f7 34 // E.g.: SYS->GPA_MFPL = (SYS->GPA_MFPL & (~SYS_GPA_MFPL_PA0MFP_Msk) ) | SYS_GPA_MFPL_PA0MFP_SC0_CD ;
<> 144:ef7eb2e8f9f7 35 *GPx_MFPx = (*GPx_MFPx & (~MFP_Msk)) | data;
<> 144:ef7eb2e8f9f7 36
<> 144:ef7eb2e8f9f7 37 // [TODO] Disconnect JTAG-DP + SW-DP signals.
<> 144:ef7eb2e8f9f7 38 // Warning: Need to reconnect under reset
<> 144:ef7eb2e8f9f7 39 //if ((pin == PA_13) || (pin == PA_14)) {
<> 144:ef7eb2e8f9f7 40 //
<> 144:ef7eb2e8f9f7 41 //}
<> 144:ef7eb2e8f9f7 42 //if ((pin == PA_15) || (pin == PB_3) || (pin == PB_4)) {
<> 144:ef7eb2e8f9f7 43 //
<> 144:ef7eb2e8f9f7 44 //}
<> 144:ef7eb2e8f9f7 45 }
<> 144:ef7eb2e8f9f7 46
<> 144:ef7eb2e8f9f7 47 /**
<> 144:ef7eb2e8f9f7 48 * Configure pin pull-up/pull-down
<> 144:ef7eb2e8f9f7 49 */
<> 144:ef7eb2e8f9f7 50 void pin_mode(PinName pin, PinMode mode)
<> 144:ef7eb2e8f9f7 51 {
<> 144:ef7eb2e8f9f7 52 MBED_ASSERT(pin != (PinName)NC);
<> 144:ef7eb2e8f9f7 53 uint32_t pin_index = NU_PINNAME_TO_PIN(pin);
<> 144:ef7eb2e8f9f7 54 uint32_t port_index = NU_PINNAME_TO_PORT(pin);
<> 144:ef7eb2e8f9f7 55 GPIO_T *gpio_base = NU_PORT_BASE(port_index);
<> 144:ef7eb2e8f9f7 56
<> 144:ef7eb2e8f9f7 57 uint32_t mode_intern = GPIO_MODE_INPUT;
<> 144:ef7eb2e8f9f7 58
<> 144:ef7eb2e8f9f7 59 switch (mode) {
<> 144:ef7eb2e8f9f7 60 case PullUp:
<> 144:ef7eb2e8f9f7 61 mode_intern = GPIO_MODE_INPUT;
<> 144:ef7eb2e8f9f7 62 break;
<> 144:ef7eb2e8f9f7 63
<> 144:ef7eb2e8f9f7 64 case PullDown:
<> 144:ef7eb2e8f9f7 65 case PullNone:
<> 144:ef7eb2e8f9f7 66 // NOTE: Not support
<> 144:ef7eb2e8f9f7 67 return;
<> 144:ef7eb2e8f9f7 68
<> 144:ef7eb2e8f9f7 69 case PushPull:
<> 144:ef7eb2e8f9f7 70 mode_intern = GPIO_MODE_OUTPUT;
<> 144:ef7eb2e8f9f7 71 break;
<> 144:ef7eb2e8f9f7 72
<> 144:ef7eb2e8f9f7 73 case OpenDrain:
<> 144:ef7eb2e8f9f7 74 mode_intern = GPIO_MODE_OPEN_DRAIN;
<> 144:ef7eb2e8f9f7 75 break;
<> 144:ef7eb2e8f9f7 76
<> 144:ef7eb2e8f9f7 77 case Quasi:
<> 144:ef7eb2e8f9f7 78 mode_intern = GPIO_MODE_QUASI;
<> 144:ef7eb2e8f9f7 79 break;
<> 144:ef7eb2e8f9f7 80 }
<> 144:ef7eb2e8f9f7 81
<> 144:ef7eb2e8f9f7 82 GPIO_SetMode(gpio_base, 1 << pin_index, mode_intern);
<> 144:ef7eb2e8f9f7 83 }