Skip to content

Commit dde8f6f

Browse files
committed
M252: Re-organize PinNames.h
This is to support M251 series based targets.
1 parent a76f5dc commit dde8f6f

File tree

2 files changed

+74
-42
lines changed

2 files changed

+74
-42
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
typedef enum {
49+
PIN_INPUT,
50+
PIN_OUTPUT
51+
} PinDirection;
52+
53+
typedef enum {
54+
/* Input pull mode */
55+
PullNone = 0,
56+
PullDown,
57+
PullUp,
58+
59+
/* I/O mode */
60+
InputOnly,
61+
PushPullOutput,
62+
OpenDrain,
63+
QuasiBidirectional,
64+
65+
/* Default input pull mode */
66+
PullDefault = PullUp
67+
} PinMode;
68+
69+
#ifdef __cplusplus
70+
}
71+
#endif
72+
73+
#endif // __PIN_NAMES_COMMON_H__

targets/TARGET_NUVOTON/TARGET_M251/PinNames.h renamed to targets/TARGET_NUVOTON/TARGET_M251/TARGET_NUMAKER_IOT_M252/PinNames.h

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -20,53 +20,12 @@
2020
#define MBED_PINNAMES_H
2121

2222
#include "cmsis.h"
23+
#include "PinNamesCommon.h"
2324

2425
#ifdef __cplusplus
2526
extern "C" {
2627
#endif
2728

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

0 commit comments

Comments
 (0)