Skip to content

Commit 6901277

Browse files
committed
M263: Re-organize PinNames.h
This is to support custom boards based on M261 series chips.
1 parent 2cdb05e commit 6901277

File tree

2 files changed

+80
-48
lines changed

2 files changed

+80
-48
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright (c) 2020, Nuvoton Technology Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
#ifndef __PIN_NAMES_COMMON_H__
19+
#define __PIN_NAMES_COMMON_H__
20+
21+
#include "cmsis.h"
22+
23+
#ifdef __cplusplus
24+
extern "C" {
25+
#endif
26+
27+
#define NU_PININDEX_Pos 0
28+
#define NU_PININDEX_Msk (0xFFul << NU_PININDEX_Pos)
29+
#define NU_PINPORT_Pos 8
30+
#define NU_PINPORT_Msk (0xFul << NU_PINPORT_Pos)
31+
#define NU_PIN_MODINDEX_Pos 12
32+
#define NU_PIN_MODINDEX_Msk (0xFul << NU_PIN_MODINDEX_Pos)
33+
#define NU_PIN_BIND_Pos 16
34+
#define NU_PIN_BIND_Msk (0x1ul << NU_PIN_BIND_Pos)
35+
36+
#define NU_PININDEX(PINNAME) (((unsigned int)(PINNAME) & NU_PININDEX_Msk) >> NU_PININDEX_Pos)
37+
#define NU_PINPORT(PINNAME) (((unsigned int)(PINNAME) & NU_PINPORT_Msk) >> NU_PINPORT_Pos)
38+
#define NU_PIN_BIND(PINNAME) (((unsigned int)(PINNAME) & NU_PIN_BIND_Msk) >> NU_PIN_BIND_Pos)
39+
#define NU_PIN_MODINDEX(PINNAME) (((unsigned int)(PINNAME) & NU_PIN_MODINDEX_Msk) >> NU_PIN_MODINDEX_Pos)
40+
#define NU_PINNAME(PORT, PIN) ((((unsigned int) (PORT)) << (NU_PINPORT_Pos)) | (((unsigned int) (PIN)) << NU_PININDEX_Pos))
41+
#define NU_PINNAME_BIND(PINNAME, modname) ((PinName) NU_PINNAME_BIND_(NU_PINPORT(PINNAME), NU_PININDEX(PINNAME), modname))
42+
#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)
43+
44+
#define NU_PORT_BASE(PORT) ((GPIO_T *)(((uint32_t) GPIOA_BASE) + 0x40 * PORT))
45+
#define NU_MFP_POS(PIN) ((PIN % 8) * 4)
46+
#define NU_MFP_MSK(PIN) (0xful << NU_MFP_POS(PIN))
47+
48+
// LEGACY
49+
#define NU_PINNAME_TO_PIN(PINNAME) NU_PININDEX(PINNAME)
50+
#define NU_PINNAME_TO_PORT(PINNAME) NU_PINPORT(PINNAME)
51+
#define NU_PINNAME_TO_MODSUBINDEX(PINNAME) NU_PIN_MODINDEX(PINNAME)
52+
#define NU_PORT_N_PIN_TO_PINNAME(PORT, PIN) NU_PINNAME((PORT), (PIN))
53+
54+
typedef enum {
55+
PIN_INPUT,
56+
PIN_OUTPUT
57+
} PinDirection;
58+
59+
typedef enum {
60+
/* Input pull mode */
61+
PullNone = 0,
62+
PullDown,
63+
PullUp,
64+
65+
/* I/O mode */
66+
InputOnly,
67+
PushPullOutput,
68+
OpenDrain,
69+
QuasiBidirectional,
70+
71+
/* Default input pull mode */
72+
PullDefault = PullUp
73+
} PinMode;
74+
75+
#ifdef __cplusplus
76+
}
77+
#endif
78+
79+
#endif // __PIN_NAMES_COMMON_H__

targets/TARGET_NUVOTON/TARGET_M261/PinNames.h renamed to targets/TARGET_NUVOTON/TARGET_M261/TARGET_NUMAKER_IOT_M263A/PinNames.h

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -18,59 +18,12 @@
1818
#define MBED_PINNAMES_H
1919

2020
#include "cmsis.h"
21+
#include "PinNamesCommon.h"
2122

2223
#ifdef __cplusplus
2324
extern "C" {
2425
#endif
2526

26-
#define NU_PININDEX_Pos 0
27-
#define NU_PININDEX_Msk (0xFFul << NU_PININDEX_Pos)
28-
#define NU_PINPORT_Pos 8
29-
#define NU_PINPORT_Msk (0xFul << NU_PINPORT_Pos)
30-
#define NU_PIN_MODINDEX_Pos 12
31-
#define NU_PIN_MODINDEX_Msk (0xFul << NU_PIN_MODINDEX_Pos)
32-
#define NU_PIN_BIND_Pos 16
33-
#define NU_PIN_BIND_Msk (0x1ul << NU_PIN_BIND_Pos)
34-
35-
#define NU_PININDEX(PINNAME) (((unsigned int)(PINNAME) & NU_PININDEX_Msk) >> NU_PININDEX_Pos)
36-
#define NU_PINPORT(PINNAME) (((unsigned int)(PINNAME) & NU_PINPORT_Msk) >> NU_PINPORT_Pos)
37-
#define NU_PIN_BIND(PINNAME) (((unsigned int)(PINNAME) & NU_PIN_BIND_Msk) >> NU_PIN_BIND_Pos)
38-
#define NU_PIN_MODINDEX(PINNAME) (((unsigned int)(PINNAME) & NU_PIN_MODINDEX_Msk) >> NU_PIN_MODINDEX_Pos)
39-
#define NU_PINNAME(PORT, PIN) ((((unsigned int) (PORT)) << (NU_PINPORT_Pos)) | (((unsigned int) (PIN)) << NU_PININDEX_Pos))
40-
#define NU_PINNAME_BIND(PINNAME, modname) ((PinName) NU_PINNAME_BIND_(NU_PINPORT(PINNAME), NU_PININDEX(PINNAME), modname))
41-
#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)
42-
43-
#define NU_PORT_BASE(PORT) ((GPIO_T *)(((uint32_t) GPIOA_BASE) + 0x40 * PORT))
44-
#define NU_MFP_POS(PIN) ((PIN % 8) * 4)
45-
#define NU_MFP_MSK(PIN) (0xful << NU_MFP_POS(PIN))
46-
47-
// LEGACY
48-
#define NU_PINNAME_TO_PIN(PINNAME) NU_PININDEX(PINNAME)
49-
#define NU_PINNAME_TO_PORT(PINNAME) NU_PINPORT(PINNAME)
50-
#define NU_PINNAME_TO_MODSUBINDEX(PINNAME) NU_PIN_MODINDEX(PINNAME)
51-
#define NU_PORT_N_PIN_TO_PINNAME(PORT, PIN) NU_PINNAME((PORT), (PIN))
52-
53-
typedef enum {
54-
PIN_INPUT,
55-
PIN_OUTPUT
56-
} PinDirection;
57-
58-
typedef enum {
59-
/* Input pull mode */
60-
PullNone = 0,
61-
PullDown,
62-
PullUp,
63-
64-
/* I/O mode */
65-
InputOnly,
66-
PushPullOutput,
67-
OpenDrain,
68-
QuasiBidirectional,
69-
70-
/* Default input pull mode */
71-
PullDefault = PullUp
72-
} PinMode;
73-
7427
typedef enum {
7528
// Not connected
7629
NC = (int)0xFFFFFFFF,

0 commit comments

Comments
 (0)