From c6f1e1ac51def816e8d18e7410101fb87151af7d Mon Sep 17 00:00:00 2001 From: Andelf Date: Mon, 1 Jan 2024 15:29:19 +0800 Subject: [PATCH] fix: compile error --- Cargo.toml | 7 +++---- examples/adc_pin.rs | 18 ++---------------- examples/adc_temp.rs | 9 +-------- examples/blinky.rs | 2 +- examples/empty.rs | 2 +- examples/flashisp.rs | 2 +- examples/hardfault.rs | 2 +- examples/i2c-mpu6050.rs | 2 +- examples/serial.rs | 2 +- examples/spi-ssd1306.rs | 2 +- examples/yd-ch582m.rs | 2 +- src/adc.rs | 2 +- src/critical_section.rs | 21 --------------------- src/lib.rs | 3 +-- src/sysctl.rs | 1 + src/systick.rs | 2 +- 16 files changed, 18 insertions(+), 61 deletions(-) delete mode 100644 src/critical_section.rs diff --git a/Cargo.toml b/Cargo.toml index 0711af8..4113976 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,11 +23,10 @@ ble = [] #] } ch58x = { version = "0.2.0", features = ["ch58x"] } -riscv = "0.10.1" -qingke = "0.1.2" +critical-section = "1.1.2" +qingke = { version = "0.1.6", features = ["critical-section-impl"] } # ch32v-rt = { version = "0.0.2", path = "../ch32v-rt" } ch32v-rt = "0.0.2" -critical-section = { version = "1.1.2", features = ["restore-state-u8"] } fugit = "0.3.7" nb = "1.1.0" @@ -49,7 +48,7 @@ display-interface = "0.4.1" display-interface-spi = "0.4.1" embedded-graphics = "0.8.1" panic-halt = "0.2.0" -ssd1306 = "0.8.3" +ssd1306 = "0.8.4" embassy-futures = "0.1.1" embassy-executor = { version = "0.4.0", features = [ diff --git a/examples/adc_pin.rs b/examples/adc_pin.rs index 6d88068..b4dda09 100644 --- a/examples/adc_pin.rs +++ b/examples/adc_pin.rs @@ -5,7 +5,7 @@ use core::arch::{asm, global_asm}; use core::fmt::Write; use core::writeln; -use embedded_hal_1::delay::DelayUs; +use embedded_hal_1::delay::DelayNs; use hal::adc::{adc_to_temperature_celsius, Adc}; use hal::dma::NoDma; use hal::gpio::{AnyPin, Input, Level, Output, OutputDrive, Pull}; @@ -31,23 +31,12 @@ fn main() -> ! { let mut download_button = Input::new(p.PB22, Pull::Up); let mut reset_button = Input::new(p.PB23, Pull::Up); - let mut rtc = Rtc {}; serial.blocking_flush(); - // rtc.set_datatime(DateTime { - // year: 2023, - // month: 10, - // day: 16, - // hour: 15, - // minute: 42, - // second: 10, - // }); writeln!(serial, "\n\n\nHello World!").unwrap(); writeln!(serial, "Clocks: {}", hal::sysctl::clocks().hclk).unwrap(); writeln!(serial, "ChipID: {:02x}", hal::signature::get_chip_id()); - let now = rtc.now(); - writeln!(serial, "Boot time: {} weekday={}", now, now.isoweekday()).unwrap(); // ADC part let mut adc = Adc::new(p.ADC, hal::adc::Config::default()); @@ -60,8 +49,6 @@ fn main() -> ! { loop { blue_led.toggle(); - let now = rtc.now(); - let data = adc.read(&mut pin); writeln!(serial, "adc raw data: {}", data).unwrap(); let vi = adc.read_as_millivolts(&mut pin); @@ -69,8 +56,7 @@ fn main() -> ! { writeln!( serial, - "{}: download={} reset={}", - now, + "BUTTON state: download={} reset={}", // now.isoweekday(), download_button.is_low(), reset_button.is_low() diff --git a/examples/adc_temp.rs b/examples/adc_temp.rs index 7a9d594..f65cdc5 100644 --- a/examples/adc_temp.rs +++ b/examples/adc_temp.rs @@ -5,7 +5,7 @@ use core::arch::{asm, global_asm}; use core::fmt::Write; use core::writeln; -use embedded_hal_1::delay::DelayUs; +use embedded_hal_1::delay::DelayNs; use hal::adc::{adc_to_temperature_celsius, Adc}; use hal::dma::NoDma; use hal::gpio::{AnyPin, Input, Level, Output, OutputDrive, Pull}; @@ -21,7 +21,6 @@ use {ch58x_hal as hal, panic_halt as _}; fn main() -> ! { let mut config = hal::Config::default(); config.clock.use_pll_60mhz().enable_lse(); - let p = hal::init(config); // LED PA8 @@ -49,12 +48,6 @@ fn main() -> ! { let now = rtc.now(); writeln!(serial, "Boot time: {} weekday={}", now, now.isoweekday()).unwrap(); - // requires machine mode - // let marchid = riscv::register::marchid::read().unwrap(); - // writeln!(serial, "marchid: 0x{:08x?}", marchid.bits()); - // let mias = riscv::register::misa::read().unwrap(); - // writeln!(serial, "mias: 0x{:08x?}", mias.bits()); - // ADC part let adc_config = hal::adc::Config::for_temperature(); let mut adc = Adc::new(p.ADC, adc_config); diff --git a/examples/blinky.rs b/examples/blinky.rs index 7be706b..36a1ce9 100644 --- a/examples/blinky.rs +++ b/examples/blinky.rs @@ -5,7 +5,7 @@ use core::arch::{asm, global_asm}; use core::fmt::Write; use core::writeln; -use embedded_hal_1::delay::DelayUs; +use embedded_hal_1::delay::DelayNs; use hal::gpio::{AnyPin, Input, Level, Output, OutputDrive, Pull}; use hal::interrupt::Interrupt; use hal::isp::EEPROM_BLOCK_SIZE; diff --git a/examples/empty.rs b/examples/empty.rs index b333a41..e4c012f 100644 --- a/examples/empty.rs +++ b/examples/empty.rs @@ -1,7 +1,7 @@ #![no_std] #![no_main] -use embedded_hal_1::delay::DelayUs; +use embedded_hal_1::delay::DelayNs; use hal::gpio::{Input, Level, Output, OutputDrive, Pull}; use hal::peripherals; use hal::uart::UartTx; diff --git a/examples/flashisp.rs b/examples/flashisp.rs index a179cde..e3b1381 100644 --- a/examples/flashisp.rs +++ b/examples/flashisp.rs @@ -2,7 +2,7 @@ #![no_main] use ch32v_rt::highcode; -use embedded_hal_1::delay::DelayUs; +use embedded_hal_1::delay::DelayNs; use hal::gpio::{Input, Level, Output, OutputDrive, Pull}; // use hal::interrupt::Interrupt; use hal::rtc::{DateTime, Rtc}; diff --git a/examples/hardfault.rs b/examples/hardfault.rs index 94ae107..2dfd73f 100644 --- a/examples/hardfault.rs +++ b/examples/hardfault.rs @@ -5,7 +5,7 @@ use core::arch::{asm, global_asm}; use core::fmt::Write; use core::writeln; -use embedded_hal_1::delay::DelayUs; +use embedded_hal_1::delay::DelayNs; use hal::gpio::{AnyPin, Input, Level, Output, OutputDrive, Pull}; use hal::isp::EEPROM_BLOCK_SIZE; use hal::rtc::{DateTime, Rtc}; diff --git a/examples/i2c-mpu6050.rs b/examples/i2c-mpu6050.rs index 4e8549b..42df222 100644 --- a/examples/i2c-mpu6050.rs +++ b/examples/i2c-mpu6050.rs @@ -1,7 +1,7 @@ #![no_std] #![no_main] -use embedded_hal_1::delay::DelayUs; +use embedded_hal_1::delay::DelayNs; use hal::gpio::{Input, Level, Output, OutputDrive, Pull}; use hal::i2c::{self, I2c}; use hal::peripherals; diff --git a/examples/serial.rs b/examples/serial.rs index 6e0eb5b..1631680 100644 --- a/examples/serial.rs +++ b/examples/serial.rs @@ -5,7 +5,7 @@ use core::arch::{asm, global_asm}; use core::fmt::Write; use core::writeln; -use embedded_hal_1::delay::DelayUs; +use embedded_hal_1::delay::DelayNs; use hal::dma::NoDma; use hal::gpio::{AnyPin, Input, Level, Output, OutputDrive, Pull}; use hal::interrupt::Interrupt; diff --git a/examples/spi-ssd1306.rs b/examples/spi-ssd1306.rs index 37f3a8c..5fafdcb 100644 --- a/examples/spi-ssd1306.rs +++ b/examples/spi-ssd1306.rs @@ -13,7 +13,7 @@ use embedded_graphics::prelude::*; use embedded_graphics::primitives::Line; use embedded_graphics::text::{Baseline, Text}; use embedded_hal_02::spi::Polarity; -use embedded_hal_1::delay::DelayUs; +use embedded_hal_1::delay::DelayNs; use hal::adc::Adc; use hal::gpio::{Input, Level, Output, OutputDrive, Pull}; use hal::prelude::*; diff --git a/examples/yd-ch582m.rs b/examples/yd-ch582m.rs index fe20bd1..dce6df0 100644 --- a/examples/yd-ch582m.rs +++ b/examples/yd-ch582m.rs @@ -5,7 +5,7 @@ use ch32v_rt::highcode; use ch58x_hal as hal; -use embedded_hal_1::delay::DelayUs; +use embedded_hal_1::delay::DelayNs; use hal::gpio::{Input, Level, Output, OutputDrive, Pull}; use hal::peripherals; use hal::rtc::{DateTime, Rtc}; diff --git a/src/adc.rs b/src/adc.rs index 7c460b9..4757476 100644 --- a/src/adc.rs +++ b/src/adc.rs @@ -190,7 +190,7 @@ where .clk_div() .variant(config.clk as u8) .buf_en() - .bit(!config.buf_en) + .bit(config.buf_en) .pga_gain() .variant(config.pga_gain as u8) }); diff --git a/src/critical_section.rs b/src/critical_section.rs deleted file mode 100644 index 9ec1626..0000000 --- a/src/critical_section.rs +++ /dev/null @@ -1,21 +0,0 @@ -use critical_section::{set_impl, Impl, RawRestoreState}; -use qingke::register::gintenr; - -struct SingleHartCriticalSection; -set_impl!(SingleHartCriticalSection); - -unsafe impl Impl for SingleHartCriticalSection { - unsafe fn acquire() -> RawRestoreState { - let irq_state = gintenr::read(); - if irq_state & 0x08 != 0 { - gintenr::write(irq_state & (!0x08)); - } - irq_state as u8 // as the high bits are reserved 0x0. - } - - unsafe fn release(irq_state: RawRestoreState) { - // Only re-enable interrupts if they were enabled before the critical section. - let irq_state = irq_state as usize; - gintenr::write(gintenr::read() | (irq_state & 0x08)); - } -} diff --git a/src/lib.rs b/src/lib.rs index f3e1740..cea34de 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,6 +3,7 @@ use core::ptr; pub use ch58x::ch58x as pac; +use qingke::riscv; pub use self::peripheral::{Peripheral, PeripheralRef}; pub use self::peripherals::Peripherals; @@ -32,8 +33,6 @@ pub mod peripherals; mod peripheral; pub mod prelude; -mod critical_section; - #[cfg(feature = "embassy")] pub mod embassy; diff --git a/src/sysctl.rs b/src/sysctl.rs index 0e9ec00..fa56da9 100644 --- a/src/sysctl.rs +++ b/src/sysctl.rs @@ -1,4 +1,5 @@ use fugit::HertzU32 as Hertz; +use qingke::riscv; use crate::pac::SYS; use crate::with_safe_access; diff --git a/src/systick.rs b/src/systick.rs index 7122944..f1cd6cb 100644 --- a/src/systick.rs +++ b/src/systick.rs @@ -42,7 +42,7 @@ impl<'d> SysTick<'d> { } } -impl<'d> embedded_hal_1::delay::DelayUs for SysTick<'d> { +impl<'d> embedded_hal_1::delay::DelayNs for SysTick<'d> { fn delay_us(&mut self, us: u32) { let us = self.ticks_per_second * (us as u64) / 1_000_000;