From f5cb899413f08bb37d84f94c260060ee1a8f6e3f Mon Sep 17 00:00:00 2001 From: Chun-Chieh Li Date: Thu, 12 Mar 2020 17:09:11 +0800 Subject: [PATCH] M263: Re-organize PinNames.h This is to support custom boards based on M261 series chips. --- .../TARGET_M261/PinNamesCommon.h | 79 +++++++++++++++++++ .../{ => TARGET_NUMAKER_IOT_M263A}/PinNames.h | 49 +----------- 2 files changed, 80 insertions(+), 48 deletions(-) create mode 100644 targets/TARGET_NUVOTON/TARGET_M261/PinNamesCommon.h rename targets/TARGET_NUVOTON/TARGET_M261/{ => TARGET_NUMAKER_IOT_M263A}/PinNames.h (59%) diff --git a/targets/TARGET_NUVOTON/TARGET_M261/PinNamesCommon.h b/targets/TARGET_NUVOTON/TARGET_M261/PinNamesCommon.h new file mode 100644 index 0000000000..ffa9ae6306 --- /dev/null +++ b/targets/TARGET_NUVOTON/TARGET_M261/PinNamesCommon.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2020, Nuvoton Technology Corporation + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef __PIN_NAMES_COMMON_H__ +#define __PIN_NAMES_COMMON_H__ + +#include "cmsis.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define NU_PININDEX_Pos 0 +#define NU_PININDEX_Msk (0xFFul << NU_PININDEX_Pos) +#define NU_PINPORT_Pos 8 +#define NU_PINPORT_Msk (0xFul << NU_PINPORT_Pos) +#define NU_PIN_MODINDEX_Pos 12 +#define NU_PIN_MODINDEX_Msk (0xFul << NU_PIN_MODINDEX_Pos) +#define NU_PIN_BIND_Pos 16 +#define NU_PIN_BIND_Msk (0x1ul << NU_PIN_BIND_Pos) + +#define NU_PININDEX(PINNAME) (((unsigned int)(PINNAME) & NU_PININDEX_Msk) >> NU_PININDEX_Pos) +#define NU_PINPORT(PINNAME) (((unsigned int)(PINNAME) & NU_PINPORT_Msk) >> NU_PINPORT_Pos) +#define NU_PIN_BIND(PINNAME) (((unsigned int)(PINNAME) & NU_PIN_BIND_Msk) >> NU_PIN_BIND_Pos) +#define NU_PIN_MODINDEX(PINNAME) (((unsigned int)(PINNAME) & NU_PIN_MODINDEX_Msk) >> NU_PIN_MODINDEX_Pos) +#define NU_PINNAME(PORT, PIN) ((((unsigned int) (PORT)) << (NU_PINPORT_Pos)) | (((unsigned int) (PIN)) << NU_PININDEX_Pos)) +#define NU_PINNAME_BIND(PINNAME, modname) ((PinName) NU_PINNAME_BIND_(NU_PINPORT(PINNAME), NU_PININDEX(PINNAME), modname)) +#define NU_PINNAME_BIND_(PORT, PIN, modname) ((((unsigned int)(PORT)) << NU_PINPORT_Pos) | (((unsigned int)(PIN)) << NU_PININDEX_Pos) | (NU_MODINDEX(modname) << NU_PIN_MODINDEX_Pos) | NU_PIN_BIND_Msk) + +#define NU_PORT_BASE(PORT) ((GPIO_T *)(((uint32_t) GPIOA_BASE) + 0x40 * PORT)) +#define NU_MFP_POS(PIN) ((PIN % 8) * 4) +#define NU_MFP_MSK(PIN) (0xful << NU_MFP_POS(PIN)) + +// LEGACY +#define NU_PINNAME_TO_PIN(PINNAME) NU_PININDEX(PINNAME) +#define NU_PINNAME_TO_PORT(PINNAME) NU_PINPORT(PINNAME) +#define NU_PINNAME_TO_MODSUBINDEX(PINNAME) NU_PIN_MODINDEX(PINNAME) +#define NU_PORT_N_PIN_TO_PINNAME(PORT, PIN) NU_PINNAME((PORT), (PIN)) + +typedef enum { + PIN_INPUT, + PIN_OUTPUT +} PinDirection; + +typedef enum { + /* Input pull mode */ + PullNone = 0, + PullDown, + PullUp, + + /* I/O mode */ + InputOnly, + PushPullOutput, + OpenDrain, + QuasiBidirectional, + + /* Default input pull mode */ + PullDefault = PullUp +} PinMode; + +#ifdef __cplusplus +} +#endif + +#endif // __PIN_NAMES_COMMON_H__ diff --git a/targets/TARGET_NUVOTON/TARGET_M261/PinNames.h b/targets/TARGET_NUVOTON/TARGET_M261/TARGET_NUMAKER_IOT_M263A/PinNames.h similarity index 59% rename from targets/TARGET_NUVOTON/TARGET_M261/PinNames.h rename to targets/TARGET_NUVOTON/TARGET_M261/TARGET_NUMAKER_IOT_M263A/PinNames.h index c094ff9473..cd77ed9193 100644 --- a/targets/TARGET_NUVOTON/TARGET_M261/PinNames.h +++ b/targets/TARGET_NUVOTON/TARGET_M261/TARGET_NUMAKER_IOT_M263A/PinNames.h @@ -18,59 +18,12 @@ #define MBED_PINNAMES_H #include "cmsis.h" +#include "PinNamesCommon.h" #ifdef __cplusplus extern "C" { #endif -#define NU_PININDEX_Pos 0 -#define NU_PININDEX_Msk (0xFFul << NU_PININDEX_Pos) -#define NU_PINPORT_Pos 8 -#define NU_PINPORT_Msk (0xFul << NU_PINPORT_Pos) -#define NU_PIN_MODINDEX_Pos 12 -#define NU_PIN_MODINDEX_Msk (0xFul << NU_PIN_MODINDEX_Pos) -#define NU_PIN_BIND_Pos 16 -#define NU_PIN_BIND_Msk (0x1ul << NU_PIN_BIND_Pos) - -#define NU_PININDEX(PINNAME) (((unsigned int)(PINNAME) & NU_PININDEX_Msk) >> NU_PININDEX_Pos) -#define NU_PINPORT(PINNAME) (((unsigned int)(PINNAME) & NU_PINPORT_Msk) >> NU_PINPORT_Pos) -#define NU_PIN_BIND(PINNAME) (((unsigned int)(PINNAME) & NU_PIN_BIND_Msk) >> NU_PIN_BIND_Pos) -#define NU_PIN_MODINDEX(PINNAME) (((unsigned int)(PINNAME) & NU_PIN_MODINDEX_Msk) >> NU_PIN_MODINDEX_Pos) -#define NU_PINNAME(PORT, PIN) ((((unsigned int) (PORT)) << (NU_PINPORT_Pos)) | (((unsigned int) (PIN)) << NU_PININDEX_Pos)) -#define NU_PINNAME_BIND(PINNAME, modname) ((PinName) NU_PINNAME_BIND_(NU_PINPORT(PINNAME), NU_PININDEX(PINNAME), modname)) -#define NU_PINNAME_BIND_(PORT, PIN, modname) ((((unsigned int)(PORT)) << NU_PINPORT_Pos) | (((unsigned int)(PIN)) << NU_PININDEX_Pos) | (NU_MODINDEX(modname) << NU_PIN_MODINDEX_Pos) | NU_PIN_BIND_Msk) - -#define NU_PORT_BASE(PORT) ((GPIO_T *)(((uint32_t) GPIOA_BASE) + 0x40 * PORT)) -#define NU_MFP_POS(PIN) ((PIN % 8) * 4) -#define NU_MFP_MSK(PIN) (0xful << NU_MFP_POS(PIN)) - -// LEGACY -#define NU_PINNAME_TO_PIN(PINNAME) NU_PININDEX(PINNAME) -#define NU_PINNAME_TO_PORT(PINNAME) NU_PINPORT(PINNAME) -#define NU_PINNAME_TO_MODSUBINDEX(PINNAME) NU_PIN_MODINDEX(PINNAME) -#define NU_PORT_N_PIN_TO_PINNAME(PORT, PIN) NU_PINNAME((PORT), (PIN)) - -typedef enum { - PIN_INPUT, - PIN_OUTPUT -} PinDirection; - -typedef enum { - /* Input pull mode */ - PullNone = 0, - PullDown, - PullUp, - - /* I/O mode */ - InputOnly, - PushPullOutput, - OpenDrain, - QuasiBidirectional, - - /* Default input pull mode */ - PullDefault = PullUp -} PinMode; - typedef enum { // Not connected NC = (int)0xFFFFFFFF,