1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
/*
* Copyright (c) 2006-2026, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2026-04-20 rcitach first version
*/
#include "drv_pinmux.h"
#define S100_PIN_MUX_REG_BASE 0x234C0060U
#define S100_PIN_CONFIG_REG_BASE 0x234D0010U
#define S100_PORT_IP_NUM 2
#define S100_PORT_LLD_IP_NUM 6
#define S100_PORT_PIN_NUM (uint8_t)124U
#define S100_PORT_MCU_PIN_NUM (uint8_t)88U
#define S100_PORT_AON_PIN_NUM (uint8_t)18U
#define AON_PIN_NUM(aon_gpio_idx) ((aon_gpio_idx) + (S100_PORT_MCU_PIN_NUM))
/*
* Keep the same MCU GPIO blacklist as the SDK Port subsystem.
* These pins are reserved for power/debug or other board-critical uses
* and must not be reconfigured as generic GPIO from RT-Thread.
*
* Note:
* The SDK also blacklists a few AON pins. The current cpu1_rtthread BSP
* driver only manages MCU GPIO pins, so only the MCU-side blacklist is
* enforced here.
*/
static const s100_pin_t s100_gpio_blacklist[] =
{
0, /* S100 Power related pins */
5, /* S100 debug uart tx */
38, /* S100 Power related pins */
15, /* S100 Power related pins */
68, /* S100 Power related pins */
69, /* S100 Power related pins */
71, /* S100 Power related pins */
80, /* S100 Power related pins */
81, /* S100 Power related pins */
82, /* S100 Power related pins */
83, /* S100 Power related pins */
AON_PIN_NUM(0), /* S100 debug uart rx */
AON_PIN_NUM(12), /* S100 Power related pins */
};
typedef struct
{
volatile rt_uint32_t reg_pin_mux_func;
} s100_pin_mux_reg_t;
typedef union
{
struct
{
volatile rt_uint32_t ds : 4;
volatile rt_uint32_t ie : 1;
volatile rt_uint32_t pd : 1;
volatile rt_uint32_t pu : 1;
volatile rt_uint32_t st : 1;
volatile rt_uint32_t rsvd: 24;
} type0;
volatile rt_uint32_t value;
} s100_pin_cfg_reg_t;
static s100_pin_mux_reg_t *const s100_pin_mux_regs =
(s100_pin_mux_reg_t *)S100_PIN_MUX_REG_BASE;
static s100_pin_cfg_reg_t *const s100_pin_cfg_regs =
(s100_pin_cfg_reg_t *)S100_PIN_CONFIG_REG_BASE;
static rt_bool_t s100_pin_is_blacklisted(s100_pin_t pin)
{
rt_size_t i;
for (i = 0; i < sizeof(s100_gpio_blacklist) / sizeof(s100_gpio_blacklist[0]); i++)
{
if (pin == s100_gpio_blacklist[i])
{
return RT_TRUE;
}
}
return RT_FALSE;
}
rt_bool_t s100_pin_is_valid(s100_pin_t pin)
{
if (pin >= S100_GPIO_PIN_COUNT)
{
return RT_FALSE;
}
/* Pin 79 is a hole in the MCU GPIO numbering and must be skipped. */
if (pin == 79U)
{
return RT_FALSE;
}
if (s100_pin_is_blacklisted(pin) == RT_TRUE)
{
return RT_FALSE;
}
return RT_TRUE;
}
rt_err_t s100_pin_set_function(s100_pin_t pin, s100_pin_function_t function)
{
if (!s100_pin_is_valid(pin))
{
return -RT_EINVAL;
}
s100_pin_mux_regs[pin].reg_pin_mux_func = (rt_uint32_t)function & 0x3U;
return RT_EOK;
}
rt_err_t s100_pin_set_pull(s100_pin_t pin, s100_pin_pull_t pull)
{
s100_pin_cfg_reg_t cfg;
if (!s100_pin_is_valid(pin))
{
return -RT_EINVAL;
}
cfg = s100_pin_cfg_regs[pin];
cfg.type0.ie = 1U;
cfg.type0.st = 1U;
cfg.type0.pu = 0U;
cfg.type0.pd = 0U;
if (pull == S100_PIN_PULL_UP)
{
cfg.type0.pu = 1U;
}
else if (pull == S100_PIN_PULL_DOWN)
{
cfg.type0.pd = 1U;
}
s100_pin_cfg_regs[pin].value = cfg.value;
return RT_EOK;
}
|