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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// Copyright 2021 The gd32f1x0-hal authors.
//
// SPDX-License-Identifier: MIT OR Apache-2.0

//! # HAL for the GD32F1x0 family of microcontrollers
//!
//! This is an implementation of the [`embedded-hal`] traits for the GD32F1x0 family of
//! microcontrollers.
//!
//! [`embedded-hal`]: https://crates.io/crates/embedded-hal
//!
//! # Usage
//!
//! ## Building an application (binary crate)
//!
//! A detailed usage guide can be found in the [README]
//!
//! ## Variants
//!
//! This crate supports multiple microcontrollers in the GD32F1x0 family. Which specific
//! microcontroller you want to build for has to be specified with a feature, for example
//! `gd32f130x8`.
//!
//! If no microcontroller is specified, the crate will not compile.
//!
//! The currently supported variants are
//!
//! - `gd32f130x4` (e.g. GD32F130F4, GD32F130G4, ...)
//! - `gd32f130x6` (e.g. GD32F130F6, GD32F130G6, ...)
//! - `gd32f130x8` (e.g. GD32F130F8, GD32F130G8, ...)
//! - `gd32f150x4` (e.g. GD32F150G4, GD32F150K4, ...)
//! - `gd32f150x6` (e.g. GD32F150G6, GD32F150K6, ...)
//! - `gd32f150x8` (e.g. GD32F150G8, GD32F150K8, ...)
//! - `gd32f170x4` (e.g. GD32F170T4, GD32F170C4, ...)
//! - `gd32f170x6` (e.g. GD32F170T6, GD32F170C6, ...)
//! - `gd32f170x8` (e.g. GD32F170T8, GD32F170C8, ...)
//! - `gd32f190x4` (e.g. GD32F190T4, GD32F190C4, ...)
//! - `gd32f190x6` (e.g. GD32F190T6, GD32F190C6, ...)
//! - `gd32f190x8` (e.g. GD32F190T8, GD32F190C8, ...)
//!
//! ## Commonly used setup
//! Almost all peripherals require references to some registers in `RCU`. The following
//! code shows how to set up those registers
//!
//! ```rust
//! // Get access to the device specific peripherals from the peripheral access crate
//! let dp = pac::Peripherals::take().unwrap();
//!
//! // Take ownership over the raw RCU and FMC devices and convert tem into the corresponding HAL
//! //  structs.
//! let mut rcu = dp.rcu.constrain();
//! let mut flash = p.fmc.constrain();
//!
//! // Freeze the configuration of all the clocks in the system and store the frozen frequencies in
//! // `clocks`
//! let clocks = rcu.cfgr.freeze(&mut flash.ws);
//! ```
//!
//! ## Usage examples
//!
//! See the [examples] folder.
//!
//! Most of the examples require the following additional dependencies
//! ```toml
//! [dependencies]
//! embedded-hal = "1.0.0"
//! nb = "1.1.0"
//! cortex-m = { version = "0.7.7", features = ["critical-section-single-core"] }
//! cortex-m-rt = "0.7.3"
//! # Panic behaviour, see https://crates.io/keywords/panic-impl for alternatives
//! panic-halt = "0.2.0"
//! ```
//!
//! [examples]: https://github.com/gd32-rust/gd32f1x0-hal/tree/main/examples
//! [README]: https://github.com/gd32-rust/gd32f1x0-hal

#![no_std]
#![deny(broken_intra_doc_links)]

// If no target specified, print error message.
#[cfg(not(any(
    feature = "gd32f130x4",
    feature = "gd32f130x6",
    feature = "gd32f130x8",
    feature = "gd32f150x4",
    feature = "gd32f150x6",
    feature = "gd32f150x8",
    feature = "gd32f170x4",
    feature = "gd32f170x6",
    feature = "gd32f170x8",
    feature = "gd32f190x4",
    feature = "gd32f190x6",
    feature = "gd32f190x8",
)))]
compile_error!("Target not found. A `--features <target-name>` is required.");

// If any two or more targets are specified, print error message.
#[cfg(any(
    all(feature = "gd32f130", feature = "gd32f150"),
    all(feature = "gd32f130", feature = "gd32f170"),
    all(feature = "gd32f130", feature = "gd32f190"),
    all(feature = "gd32f150", feature = "gd32f170"),
    all(feature = "gd32f150", feature = "gd32f190"),
    all(feature = "gd32f170", feature = "gd32f190"),
    all(feature = "gd32f130x4", feature = "gd32f130x6"),
    all(feature = "gd32f130x4", feature = "gd32f130x8"),
    all(feature = "gd32f130x6", feature = "gd32f130x8"),
    all(feature = "gd32f150x4", feature = "gd32f150x6"),
    all(feature = "gd32f150x4", feature = "gd32f150x8"),
    all(feature = "gd32f150x6", feature = "gd32f150x8"),
    all(feature = "gd32f170x4", feature = "gd32f170x6"),
    all(feature = "gd32f170x4", feature = "gd32f170x8"),
    all(feature = "gd32f170x6", feature = "gd32f170x8"),
    all(feature = "gd32f190x4", feature = "gd32f190x6"),
    all(feature = "gd32f190x4", feature = "gd32f190x8"),
    all(feature = "gd32f190x6", feature = "gd32f190x8"),
))]
compile_error!(
    "Multiple targets specified. Only a single `--features <target-name>` can be specified."
);

#[cfg(feature = "gd32f130")]
pub use gd32f1::gd32f130 as pac;
#[cfg(feature = "gd32f150")]
pub use gd32f1::gd32f150 as pac;
#[cfg(feature = "gd32f170")]
pub use gd32f1::gd32f170 as pac;
#[cfg(feature = "gd32f190")]
pub use gd32f1::gd32f190 as pac;

#[cfg(feature = "device-selected")]
pub mod adc;
/*#[cfg(feature = "device-selected")]
pub mod backup_domain;
#[cfg(all(feature = "device-selected", feature = "has-can"))]
pub mod can;*/
#[cfg(feature = "device-selected")]
pub mod crc;
#[cfg(feature = "device-selected")]
pub mod delay;
#[cfg(feature = "device-selected")]
pub mod dma;
#[cfg(feature = "device-selected")]
pub mod flash;
#[cfg(feature = "device-selected")]
pub mod gpio;
#[cfg(feature = "device-selected")]
pub mod i2c;
#[cfg(feature = "device-selected")]
pub mod prelude;
#[cfg(feature = "device-selected")]
pub mod pwm;
/*#[cfg(feature = "device-selected")]
pub mod pwm_input;
#[cfg(feature = "device-selected")]
pub mod qei;*/
#[cfg(feature = "device-selected")]
pub mod rcu;
/*#[cfg(feature = "device-selected")]
pub mod rtc;*/
#[cfg(feature = "device-selected")]
pub mod serial;
/*#[cfg(feature = "device-selected")]
pub mod spi;*/
#[cfg(feature = "device-selected")]
pub mod time;
#[cfg(feature = "device-selected")]
pub mod timer;
/*#[cfg(all(
    feature = "stm32-usbd",
    any(feature = "stm32f102", feature = "stm32f103")
))]
pub mod usb;*/
#[cfg(feature = "device-selected")]
pub mod watchdog;