|
| 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__ |
0 commit comments