Skip to content

Commit e77349b

Browse files
committed
Add GD32 GPIO & USB host headers, remove old HAL
Introduce GD32 GPIO and USB host interfaces and clean up legacy HAL/debug files. Added lib-gd32/include/gpio.h (inline GPIO helpers, enums and wrappers) and lib-gd32/include/device/host/host.h (usb::host enums and accessors). Adjusted lib-gd32/include/gd32_gpio.h by moving GPIO interrupt macros to the common GD32 section. Removed obsolete files in lib-hal: debug/emac/gd32/emac_debug.cpp, include/gd32/hal_gpio.h and include/hal_gpio.h as part of the HAL consolidation/refactor.
1 parent 85af451 commit e77349b

6 files changed

Lines changed: 133 additions & 146 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* host.h
3+
*/
4+
5+
#ifndef DEVICE_USB_HOSTMSC_H_
6+
#define DEVICE_USB_HOSTMSC_H_
7+
8+
9+
namespace usb::host {
10+
11+
enum class Status {
12+
NOT_AVAILABLE,
13+
DISCONNECTED,
14+
RESET,
15+
SPEED_AVAILALBE,
16+
ATTACHED,
17+
CONNECTED,
18+
ENUMERATION_COMPLETED,
19+
READY,
20+
DEVICE_NOT_SUPPORTED,
21+
UNRECOVERABLE_ERROR
22+
};
23+
24+
enum class Speed {
25+
FAULT,
26+
LOW,
27+
FULL,
28+
HIGH
29+
};
30+
31+
enum class Class {
32+
NOT_SUPPORTED,
33+
MSC,
34+
HID
35+
};
36+
37+
Status get_status();
38+
Speed get_speed();
39+
Class get_class();
40+
} // namespace usb::host
41+
42+
43+
#endif /* DEVICE_USB_HOSTMSC_H_ */

lib-gd32/include/gd32_gpio.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737
#define GPIO_PULL_UP GPIO_MODE_IPU
3838
#define GPIO_PULL_DOWN GPIO_MODE_IPD
3939
#define GPIO_PULL_DISABLE GPIO_MODE_IN_FLOATING
40-
#define GPIO_INT_CFG_NEG_EDGE EXTI_TRIG_FALLING
41-
#define GPIO_INT_CFG_BOTH EXTI_TRIG_BOTH
4240
#elif defined(GD32F4XX) || defined(GD32H7XX)
4341
#define GPIO_FSEL_OUTPUT GPIO_MODE_OUTPUT
4442
#define GPIO_FSEL_INPUT GPIO_MODE_INPUT
@@ -47,6 +45,9 @@
4745
#define GPIO_PULL_DISABLE GPIO_PUPD_NONE
4846
#endif
4947

48+
#define GPIO_INT_CFG_NEG_EDGE EXTI_TRIG_FALLING
49+
#define GPIO_INT_CFG_BOTH EXTI_TRIG_BOTH
50+
5051
#if defined(GD32F4XX)
5152
#define GPIOx_OCTL_OFFSET 0x14U;
5253
#define GPIOx_BOP_OFFSET 0x18U;

lib-gd32/include/gpio.h

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/**
2+
* @file gpio.h
3+
* @brief GD32
4+
*/
5+
/* Copyright (C) 2026 by Arjan van Vught mailto:info@gd32-dmx.org
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
26+
#ifndef GPIO_H_
27+
#define GPIO_H_
28+
29+
#include <cstdint>
30+
31+
#include "gd32_gpio.h"
32+
#include "gd32_board.h" // IWYU pragma: keep
33+
34+
namespace gpio {
35+
enum class Select {
36+
kInput = GPIO_FSEL_INPUT,
37+
kOutput = GPIO_FSEL_OUTPUT
38+
};
39+
40+
enum class Pull {
41+
kDisable = GPIO_PULL_DISABLE,
42+
kUp = GPIO_PULL_UP,
43+
kDown = GPIO_PULL_DOWN
44+
};
45+
46+
enum class IntConfig {
47+
// kPosEdge =
48+
// kNegEdge =
49+
kHighLev = GPIO_INT_CFG_NEG_EDGE,
50+
// kLowLev = GPIO_INT_CFG_LOW_LEV,
51+
kDoubleEdge = EXTI_TRIG_BOTH
52+
};
53+
54+
inline void Fsel(uint32_t gpio, Select fsel) {
55+
Gd32GpioFsel(gpio, static_cast<uint32_t>(fsel));
56+
}
57+
58+
inline void SetPud(uint32_t gpio, Pull pull) {
59+
Gd32GpioSetPud(gpio, static_cast<uint32_t>(pull));
60+
}
61+
62+
inline void IntCfg(uint32_t gpio, IntConfig int_cfg) {
63+
Gd32GpioIntCfg(gpio, static_cast<uint32_t>(int_cfg));
64+
}
65+
66+
inline void Set(uint32_t pin) {
67+
Gd32GpioSet(pin);
68+
}
69+
70+
inline void Clr(uint32_t pin) {
71+
Gd32GpioClr(pin);
72+
}
73+
74+
inline void Write(uint32_t pin, uint32_t value) {
75+
if (value != 0) {
76+
Set(pin);
77+
} else {
78+
Clr(pin);
79+
}
80+
}
81+
82+
inline uint8_t Lev(uint32_t pin) {
83+
return Gd32GpioLev(pin);
84+
}
85+
} // namespace gpio
86+
87+
#endif // GPIO_H_

lib-hal/debug/emac/gd32/emac_debug.cpp

Lines changed: 0 additions & 44 deletions
This file was deleted.

lib-hal/include/gd32/hal_gpio.h

Lines changed: 0 additions & 32 deletions
This file was deleted.

lib-hal/include/hal_gpio.h

Lines changed: 0 additions & 68 deletions
This file was deleted.

0 commit comments

Comments
 (0)