Skip to content

Commit

Permalink
fix: compile errors
Browse files Browse the repository at this point in the history
  • Loading branch information
andelf committed Jan 1, 2024
1 parent e98a051 commit 5d00f65
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ch58x-hal"
version = "0.0.1"
version = "0.0.2"
edition = "2021"
authors = ["Andelf <andelf@gmail.com>"]
repository = "https://github.com/ch32-rs/ch58x-hal"
Expand Down
4 changes: 2 additions & 2 deletions examples/adc_pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
4 changes: 2 additions & 2 deletions examples/adc_temp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
2 changes: 0 additions & 2 deletions examples/ble-broadcaster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions examples/ble-scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
11 changes: 5 additions & 6 deletions examples/hardfault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ macro_rules! println {
}
}

#[qingke_rt::interrupt]
fn RTC() {
extern "C" fn RTC() {
let mut rtc = Rtc;

rtc.ack_timing();
Expand All @@ -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);

Expand Down Expand Up @@ -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();
Expand Down
22 changes: 11 additions & 11 deletions examples/i2c-mpu6050.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down

0 comments on commit 5d00f65

Please sign in to comment.