mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
AnnaBridge
Date:
Thu Nov 08 11:46:34 2018 +0000
Revision:
188:bcfe06ba3d64
Parent:
149:156823d33999
mbed-dev library. Release version 164

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;
AnnaBridge 188:bcfe06ba3d64 58
<> 144:ef7eb2e8f9f7 59 switch (mode) {
AnnaBridge 188:bcfe06ba3d64 60 case InputOnly:
<> 144:ef7eb2e8f9f7 61 mode_intern = GPIO_MODE_INPUT;
<> 144:ef7eb2e8f9f7 62 break;
AnnaBridge 188:bcfe06ba3d64 63
AnnaBridge 188:bcfe06ba3d64 64 case PushPullOutput:
<> 144:ef7eb2e8f9f7 65 mode_intern = GPIO_MODE_OUTPUT;
<> 144:ef7eb2e8f9f7 66 break;
AnnaBridge 188:bcfe06ba3d64 67
<> 144:ef7eb2e8f9f7 68 case OpenDrain:
<> 144:ef7eb2e8f9f7 69 mode_intern = GPIO_MODE_OPEN_DRAIN;
<> 144:ef7eb2e8f9f7 70 break;
AnnaBridge 188:bcfe06ba3d64 71
AnnaBridge 188:bcfe06ba3d64 72 case QuasiBidirectional:
<> 144:ef7eb2e8f9f7 73 mode_intern = GPIO_MODE_QUASI;
<> 144:ef7eb2e8f9f7 74 break;
AnnaBridge 188:bcfe06ba3d64 75
AnnaBridge 188:bcfe06ba3d64 76 default:
AnnaBridge 188:bcfe06ba3d64 77 /* H/W doesn't support separate configuration for input pull mode/direction.
AnnaBridge 188:bcfe06ba3d64 78 * We expect upper layer would have translated input pull mode/direction
AnnaBridge 188:bcfe06ba3d64 79 * to I/O mode */
AnnaBridge 188:bcfe06ba3d64 80 return;
<> 144:ef7eb2e8f9f7 81 }
AnnaBridge 188:bcfe06ba3d64 82
<> 144:ef7eb2e8f9f7 83 GPIO_SetMode(gpio_base, 1 << pin_index, mode_intern);
AnnaBridge 188:bcfe06ba3d64 84
AnnaBridge 188:bcfe06ba3d64 85 /* Invalid combinations of PinMode/PinDirection
AnnaBridge 188:bcfe06ba3d64 86 *
AnnaBridge 188:bcfe06ba3d64 87 * We assume developer would avoid the following combinations of PinMode/PinDirection
AnnaBridge 188:bcfe06ba3d64 88 * which are invalid:
AnnaBridge 188:bcfe06ba3d64 89 * 1. InputOnly/PIN_OUTPUT
AnnaBridge 188:bcfe06ba3d64 90 * 2. PushPullOutput/PIN_INPUT
AnnaBridge 188:bcfe06ba3d64 91 */
<> 144:ef7eb2e8f9f7 92 }