gd32f1x0_hal/lib.rs
1// Copyright 2021 The gd32f1x0-hal authors.
2//
3// SPDX-License-Identifier: MIT OR Apache-2.0
4
5//! # HAL for the GD32F1x0 family of microcontrollers
6//!
7//! This is an implementation of the [`embedded-hal`] traits for the GD32F1x0 family of
8//! microcontrollers.
9//!
10//! [`embedded-hal`]: https://crates.io/crates/embedded-hal
11//!
12//! # Usage
13//!
14//! ## Building an application (binary crate)
15//!
16//! A detailed usage guide can be found in the [README]
17//!
18//! ## Variants
19//!
20//! This crate supports multiple microcontrollers in the GD32F1x0 family. Which specific
21//! microcontroller you want to build for has to be specified with a feature, for example
22//! `gd32f130x8`.
23//!
24//! If no microcontroller is specified, the crate will not compile.
25//!
26//! The currently supported variants are
27//!
28//! - `gd32f130x4` (e.g. GD32F130F4, GD32F130G4, ...)
29//! - `gd32f130x6` (e.g. GD32F130F6, GD32F130G6, ...)
30//! - `gd32f130x8` (e.g. GD32F130F8, GD32F130G8, ...)
31//! - `gd32f150x4` (e.g. GD32F150G4, GD32F150K4, ...)
32//! - `gd32f150x6` (e.g. GD32F150G6, GD32F150K6, ...)
33//! - `gd32f150x8` (e.g. GD32F150G8, GD32F150K8, ...)
34//! - `gd32f170x4` (e.g. GD32F170T4, GD32F170C4, ...)
35//! - `gd32f170x6` (e.g. GD32F170T6, GD32F170C6, ...)
36//! - `gd32f170x8` (e.g. GD32F170T8, GD32F170C8, ...)
37//! - `gd32f190x4` (e.g. GD32F190T4, GD32F190C4, ...)
38//! - `gd32f190x6` (e.g. GD32F190T6, GD32F190C6, ...)
39//! - `gd32f190x8` (e.g. GD32F190T8, GD32F190C8, ...)
40//!
41//! ## Commonly used setup
42//! Almost all peripherals require references to some registers in `RCU`. The following
43//! code shows how to set up those registers
44//!
45//! ```rust
46//! // Get access to the device specific peripherals from the peripheral access crate
47//! let dp = pac::Peripherals::take().unwrap();
48//!
49//! // Take ownership over the raw RCU and FMC devices and convert tem into the corresponding HAL
50//! // structs.
51//! let mut rcu = dp.rcu.constrain();
52//! let mut flash = p.fmc.constrain();
53//!
54//! // Freeze the configuration of all the clocks in the system and store the frozen frequencies in
55//! // `clocks`
56//! let clocks = rcu.cfgr.freeze(&mut flash.ws);
57//! ```
58//!
59//! ## Usage examples
60//!
61//! See the [examples] folder.
62//!
63//! Most of the examples require the following additional dependencies
64//! ```toml
65//! [dependencies]
66//! embedded-hal = "1.0.0"
67//! nb = "1.1.0"
68//! cortex-m = { version = "0.7.7", features = ["critical-section-single-core"] }
69//! cortex-m-rt = "0.7.3"
70//! # Panic behaviour, see https://crates.io/keywords/panic-impl for alternatives
71//! panic-halt = "0.2.0"
72//! ```
73//!
74//! [examples]: https://github.com/gd32-rust/gd32f1x0-hal/tree/main/examples
75//! [README]: https://github.com/gd32-rust/gd32f1x0-hal
76
77#![no_std]
78#![deny(broken_intra_doc_links)]
79
80// If no target specified, print error message.
81#[cfg(not(any(
82 feature = "gd32f130x4",
83 feature = "gd32f130x6",
84 feature = "gd32f130x8",
85 feature = "gd32f150x4",
86 feature = "gd32f150x6",
87 feature = "gd32f150x8",
88 feature = "gd32f170x4",
89 feature = "gd32f170x6",
90 feature = "gd32f170x8",
91 feature = "gd32f190x4",
92 feature = "gd32f190x6",
93 feature = "gd32f190x8",
94)))]
95compile_error!("Target not found. A `--features <target-name>` is required.");
96
97// If any two or more targets are specified, print error message.
98#[cfg(any(
99 all(feature = "gd32f130", feature = "gd32f150"),
100 all(feature = "gd32f130", feature = "gd32f170"),
101 all(feature = "gd32f130", feature = "gd32f190"),
102 all(feature = "gd32f150", feature = "gd32f170"),
103 all(feature = "gd32f150", feature = "gd32f190"),
104 all(feature = "gd32f170", feature = "gd32f190"),
105 all(feature = "gd32f130x4", feature = "gd32f130x6"),
106 all(feature = "gd32f130x4", feature = "gd32f130x8"),
107 all(feature = "gd32f130x6", feature = "gd32f130x8"),
108 all(feature = "gd32f150x4", feature = "gd32f150x6"),
109 all(feature = "gd32f150x4", feature = "gd32f150x8"),
110 all(feature = "gd32f150x6", feature = "gd32f150x8"),
111 all(feature = "gd32f170x4", feature = "gd32f170x6"),
112 all(feature = "gd32f170x4", feature = "gd32f170x8"),
113 all(feature = "gd32f170x6", feature = "gd32f170x8"),
114 all(feature = "gd32f190x4", feature = "gd32f190x6"),
115 all(feature = "gd32f190x4", feature = "gd32f190x8"),
116 all(feature = "gd32f190x6", feature = "gd32f190x8"),
117))]
118compile_error!(
119 "Multiple targets specified. Only a single `--features <target-name>` can be specified."
120);
121
122#[cfg(feature = "gd32f130")]
123pub use gd32f1::gd32f130 as pac;
124#[cfg(feature = "gd32f150")]
125pub use gd32f1::gd32f150 as pac;
126#[cfg(feature = "gd32f170")]
127pub use gd32f1::gd32f170 as pac;
128#[cfg(feature = "gd32f190")]
129pub use gd32f1::gd32f190 as pac;
130
131#[cfg(feature = "device-selected")]
132pub mod adc;
133/*#[cfg(feature = "device-selected")]
134pub mod backup_domain;
135#[cfg(all(feature = "device-selected", feature = "has-can"))]
136pub mod can;*/
137#[cfg(feature = "device-selected")]
138pub mod crc;
139#[cfg(feature = "device-selected")]
140pub mod delay;
141#[cfg(feature = "device-selected")]
142pub mod dma;
143#[cfg(feature = "device-selected")]
144pub mod flash;
145#[cfg(feature = "device-selected")]
146pub mod gpio;
147#[cfg(feature = "device-selected")]
148pub mod i2c;
149#[cfg(feature = "device-selected")]
150pub mod prelude;
151#[cfg(feature = "device-selected")]
152pub mod pwm;
153/*#[cfg(feature = "device-selected")]
154pub mod pwm_input;
155#[cfg(feature = "device-selected")]
156pub mod qei;*/
157#[cfg(feature = "device-selected")]
158pub mod rcu;
159/*#[cfg(feature = "device-selected")]
160pub mod rtc;*/
161#[cfg(feature = "device-selected")]
162pub mod serial;
163/*#[cfg(feature = "device-selected")]
164pub mod spi;*/
165#[cfg(feature = "device-selected")]
166pub mod time;
167#[cfg(feature = "device-selected")]
168pub mod timer;
169/*#[cfg(all(
170 feature = "stm32-usbd",
171 any(feature = "stm32f102", feature = "stm32f103")
172))]
173pub mod usb;*/
174#[cfg(feature = "device-selected")]
175pub mod watchdog;