From 5d00f65e3edc63b356776df1f574fb811839d4e4 Mon Sep 17 00:00:00 2001 From: Andelf Date: Tue, 2 Jan 2024 00:17:18 +0800 Subject: [PATCH] fix: compile errors --- Cargo.toml | 2 +- examples/adc_pin.rs | 4 ++-- examples/adc_temp.rs | 4 ++-- examples/ble-broadcaster.rs | 2 -- examples/ble-scanner.rs | 2 -- examples/hardfault.rs | 11 +++++------ examples/i2c-mpu6050.rs | 22 +++++++++++----------- 7 files changed, 21 insertions(+), 26 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 34704e5..c759158 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ch58x-hal" -version = "0.0.1" +version = "0.0.2" edition = "2021" authors = ["Andelf "] repository = "https://github.com/ch32-rs/ch58x-hal" diff --git a/examples/adc_pin.rs b/examples/adc_pin.rs index cdb82eb..edf21f1 100644 --- a/examples/adc_pin.rs +++ b/examples/adc_pin.rs @@ -49,9 +49,9 @@ fn main() -> ! { loop { blue_led.toggle(); - let data = adc().read(&mut pin); + let data = adc.read(&mut pin); writeln!(serial, "adc raw data: {}", data).unwrap(); - let vi = adc().read_as_millivolts(&mut pin); + let vi = adc.read_as_millivolts(&mut pin); writeln!(serial, "Vbat voltage: {}mV", vi).unwrap(); writeln!( diff --git a/examples/adc_temp.rs b/examples/adc_temp.rs index 56759ad..2e44ca4 100644 --- a/examples/adc_temp.rs +++ b/examples/adc_temp.rs @@ -59,12 +59,12 @@ fn main() -> ! { let now = rtc.now(); - let raw_temp = adc().read(&mut temp_sensor); + let raw_temp = adc.read(&mut temp_sensor); writeln!(serial, "ADC raw data: {}", raw_temp).unwrap(); let temp = adc_to_temperature_celsius(raw_temp); writeln!(serial, "sensor temp: {}C", temp).unwrap(); - let vi = adc().read_as_millivolts(&mut temp_sensor); + let vi = adc.read_as_millivolts(&mut temp_sensor); writeln!(serial, "ADC voltage: {}mV", vi).unwrap(); writeln!( diff --git a/examples/ble-broadcaster.rs b/examples/ble-broadcaster.rs index 1aaf51d..5e07611 100644 --- a/examples/ble-broadcaster.rs +++ b/examples/ble-broadcaster.rs @@ -119,9 +119,7 @@ async fn mainloop() -> ! { loop { Timer::after(Duration::from_micros(300)).await; unsafe { - hal::interrupt::SysTick::pend(); TMOS_SystemProcess(); - hal::interrupt::SysTick::unpend(); } } } diff --git a/examples/ble-scanner.rs b/examples/ble-scanner.rs index 0bc94d9..ce8e1e5 100644 --- a/examples/ble-scanner.rs +++ b/examples/ble-scanner.rs @@ -142,9 +142,7 @@ async fn main(spawner: Spawner) -> ! { loop { Timer::after(Duration::from_micros(300)).await; unsafe { - hal::interrupt::SysTick::pend(); TMOS_SystemProcess(); - hal::interrupt::SysTick::unpend(); } // println!("tick"); diff --git a/examples/hardfault.rs b/examples/hardfault.rs index 8af24a8..8b0664f 100644 --- a/examples/hardfault.rs +++ b/examples/hardfault.rs @@ -29,8 +29,7 @@ macro_rules! println { } } -#[qingke_rt::interrupt] -fn RTC() { +extern "C" fn RTC() { let mut rtc = Rtc; rtc.ack_timing(); @@ -39,8 +38,7 @@ fn RTC() { println!("Current time: {} weekday={}", now, now.isoweekday()); // writeln!(uart, "mepc: {:08x}", riscv::register::mepc::read()).unwrap(); } -#[qingke_rt::interrupt] -fn HardFault() { +extern "C" fn HardFault() { let pa8 = unsafe { hal::peripherals::PA8::steal() }; let mut led = Output::new(pa8, Level::Low, OutputDrive::_20mA); @@ -89,8 +87,9 @@ fn main() -> ! { let pfic = unsafe { &*pac::PFIC::PTR }; rtc.enable_timing(hal::rtc::TimingMode::_2S); - unsafe { pfic.ienr1.write(|w| w.bits(1 << 28)) }; // enable rtc irq - + unsafe { + qingke::pfic::enable_interrupt(pac::Interrupt::RTC as u8); + } loop { unsafe { pa8.toggle(); diff --git a/examples/i2c-mpu6050.rs b/examples/i2c-mpu6050.rs index eebfbb3..304b98e 100644 --- a/examples/i2c-mpu6050.rs +++ b/examples/i2c-mpu6050.rs @@ -268,35 +268,35 @@ impl<'d> MPU6050<'d> { } // get stable time source - self().write_byte(regs::PWR_MGMT_1, 0x01)?; // Set clock source to be PLL with x-axis gyroscope reference, bits 2:0 = 001 + self.write_byte(regs::PWR_MGMT_1, 0x01)?; // Set clock source to be PLL with x-axis gyroscope reference, bits 2:0 = 001 // Configure Gyro and Accelerometer // Disable FSYNC and set accelerometer and gyro bandwidth to 44 and 42 Hz, respectively; // DLPF_CFG = bits 2:0 = 010; this sets the sample rate at 1 kHz for both // Maximum delay time is 4.9 ms corresponding to just over 200 Hz sample rate - self().write_byte(regs::CONFIG, 0x03)?; + self.write_byte(regs::CONFIG, 0x03)?; // Set sample rate = gyroscope output rate/(1 + SMPLRT_DIV) - self().write_byte(regs::SMPLRT_DIV, 0x04)?; // Use a 200 Hz rate; the same rate set in CONFIG above + self.write_byte(regs::SMPLRT_DIV, 0x04)?; // Use a 200 Hz rate; the same rate set in CONFIG above // Set gyroscope full scale range // Range selects FS_SEL and AFS_SEL are 0 - 3, so 2-bit values are left-shifted into positions 4:3 let c = self.read_byte(regs::GYRO_CONFIG)?; - self().write_byte(regs::GYRO_CONFIG, c & !0xE0)?; // Clear self-test bits [7:5] - self().write_byte(regs::GYRO_CONFIG, c & !0x18)?; // Clear AFS bits [4:3] - self().write_byte(regs::GYRO_CONFIG, c | (config.gyro_scale as u8) << 3)?; // Set full scale range for the gyro + self.write_byte(regs::GYRO_CONFIG, c & !0xE0)?; // Clear self-test bits [7:5] + self.write_byte(regs::GYRO_CONFIG, c & !0x18)?; // Clear AFS bits [4:3] + self.write_byte(regs::GYRO_CONFIG, c | (config.gyro_scale as u8) << 3)?; // Set full scale range for the gyro // Set accelerometer configuration let c = self.read_byte(regs::ACCEL_CONFIG)?; - self().write_byte(regs::ACCEL_CONFIG, c & !0xE0)?; // Clear self-test bits [7:5] - self().write_byte(regs::ACCEL_CONFIG, c & !0x18)?; // Clear AFS bits [4:3] - self().write_byte(regs::ACCEL_CONFIG, c | (config.accel_scale as u8) << 3)?; // Set full scale range for the accelerometer + self.write_byte(regs::ACCEL_CONFIG, c & !0xE0)?; // Clear self-test bits [7:5] + self.write_byte(regs::ACCEL_CONFIG, c & !0x18)?; // Clear AFS bits [4:3] + self.write_byte(regs::ACCEL_CONFIG, c | (config.accel_scale as u8) << 3)?; // Set full scale range for the accelerometer // Configure Interrupts and Bypass Enable // Set interrupt pin active high, push-pull, and clear on read of INT_STATUS, enable I2C_BYPASS_EN so additional chips // can join the I2C bus and all can be controlled by the Arduino as master - self().write_byte(regs::INT_PIN_CFG, 0x22)?; - self().write_byte(regs::INT_ENABLE, 0x01)?; // Enable data ready (bit 0) interrupt + self.write_byte(regs::INT_PIN_CFG, 0x22)?; + self.write_byte(regs::INT_ENABLE, 0x01)?; // Enable data ready (bit 0) interrupt Ok(()) }