Skip to content

Commit d0b2650

Browse files
committed
enhance: add v2 and v4 feature gates
1 parent a8c5690 commit d0b2650

4 files changed

Lines changed: 19 additions & 17 deletions

File tree

Cargo.toml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ documentation = "https://docs.rs/qingke"
88
homepage = "https://github.com/ch32-rs/qingke"
99
categories = ["embedded", "no-std", "hardware-support"]
1010
license = "MIT/Apache-2.0"
11-
version = "0.5.0" # for rt and macros
12-
edition = "2021"
11+
version = "0.6.0" # for rt and macros
12+
edition = "2024"
1313

1414
[package]
1515
name = "qingke"
@@ -27,17 +27,19 @@ readme = "README.md"
2727

2828
[dependencies]
2929
bit_field = "0.10.2"
30-
riscv = "0.12.0"
30+
riscv = "0.15.0"
3131
cfg-if = "1.0"
3232
critical-section = { version = "1.2.0", features = [
3333
"restore-state-bool",
3434
], optional = true }
35-
defmt = { version = "0.3.8", optional = true }
35+
defmt = { version = "1.0.1", optional = true }
3636

3737
[features]
3838
critical-section-impl = ["dep:critical-section"]
3939
defmt = ["dep:defmt"]
40+
v2 = []
4041
v3 = []
42+
v4 = []
4143
unsafe-trust-wch-atomics = []
4244

4345
[package.metadata.docs.rs]

qingke-rt/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ readme = "README.md"
1414

1515

1616
[features]
17-
v2 = []
17+
v2 = ["qingke/v2"]
1818
v3 = ["qingke/v3"]
19-
v4 = []
19+
v4 = ["qingke/v4"]
2020

2121
u-mode = []
2222
# v5 is not released yet
@@ -25,8 +25,8 @@ u-mode = []
2525
highcode = []
2626

2727
[dependencies]
28-
qingke-rt-macros = { version = "0.5.0", path = "./macros" }
29-
qingke = { version = "0.5.0", path = "../", features = ["critical-section-impl"] }
28+
qingke-rt-macros = { version = "0.6.0", path = "./macros" }
29+
qingke = { version = "0.6.0", path = "../", features = ["critical-section-impl"] }
3030

3131
[package.metadata.docs.rs]
3232
targets = ["riscv32imc-unknown-none-elf"]

src/critical_section_impl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ set_impl!(SingleHartCriticalSection);
66
unsafe impl Impl for SingleHartCriticalSection {
77
unsafe fn acquire() -> RawRestoreState {
88
cfg_if::cfg_if! {
9-
if #[cfg(qingke_v2)] {
9+
if #[cfg(feature = "v2")] {
1010
// CH32V003 (qingke_v2) does not have gintenr register
1111
// Use standard RISC-V mstatus.MIE instead
1212
let mut mstatus: usize;
@@ -24,7 +24,7 @@ unsafe impl Impl for SingleHartCriticalSection {
2424
// Only re-enable interrupts if they were enabled before the critical section.
2525
if irq_state {
2626
cfg_if::cfg_if! {
27-
if #[cfg(qingke_v2)] {
27+
if #[cfg(feature = "v2")] {
2828
core::arch::asm!("csrsi mstatus, 0b1000");
2929
} else {
3030
use crate::register::gintenr;

src/register/gintenr.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,34 @@
66
//!
77
//! Write 0x08 to enable global interrupt
88
//!
9-
//! NOTE: This register is NOT available on qingke_v2 (CH32V003).
10-
//! Use mstatus.MIE instead for qingke_v2.
9+
//! NOTE: This register is NOT available on v2 (CH32V003).
10+
//! Use mstatus.MIE instead for v2.
1111
12-
#[cfg(not(qingke_v2))]
12+
#[cfg(not(feature = "v2"))]
1313
use core::arch::asm;
1414

15-
#[cfg(not(qingke_v2))]
15+
#[cfg(not(feature = "v2"))]
1616
#[inline]
1717
pub fn read() -> usize {
1818
let ans: usize;
1919
unsafe { asm!("csrr {}, 0x800", out(reg) ans) };
2020
ans
2121
}
2222

23-
#[cfg(not(qingke_v2))]
23+
#[cfg(not(feature = "v2"))]
2424
#[inline]
2525
pub unsafe fn write(bits: usize) {
2626
asm!("csrw 0x800, {}", in(reg) bits);
2727
}
2828

29-
#[cfg(not(qingke_v2))]
29+
#[cfg(not(feature = "v2"))]
3030
#[inline]
3131
pub unsafe fn set_enable() {
3232
let mask = 0x8;
3333
asm!("csrs 0x800, {}", in(reg) mask);
3434
}
3535

36-
#[cfg(not(qingke_v2))]
36+
#[cfg(not(feature = "v2"))]
3737
#[inline]
3838
/// Disable interrupt and return the old `GINTENR` value
3939
pub fn set_disable() -> usize {

0 commit comments

Comments
 (0)