test

Committer:
elijahsj
Date:
Mon Nov 09 00:33:19 2020 -0500
Revision:
2:4364577b5ad8
Parent:
1:8a094db1347f
copied mbed library

Who changed what in which revision?

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