initial reoder of folders and library crate creation
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
#![feature(impl_trait_in_assoc_type)]
|
||||
|
||||
use ch32_hal::println;
|
||||
use ch32_hal::time::Hertz;
|
||||
use embassy_executor::Spawner;
|
||||
//use embassy_time::{Duration, Timer};
|
||||
use hal::bind_interrupts;
|
||||
use hal::i2c::{Config, I2c, SlaveAddress, SlaveConfig};
|
||||
use {ch32_hal as hal, panic_halt as _};
|
||||
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
I2C1_EV => ch32_hal::i2c::EventInterruptHandler<ch32_hal::peripherals::I2C1>;
|
||||
I2C1_ER => ch32_hal::i2c::ErrorInterruptHandler<ch32_hal::peripherals::I2C1>;
|
||||
});
|
||||
|
||||
#[embassy_executor::main(entry = "qingke_rt::entry")]
|
||||
async fn main(_spawner: Spawner) -> ! {
|
||||
let p = hal::init(Default::default());
|
||||
|
||||
let config = Config::default();
|
||||
let mut i2c_slave = I2c::new_blocking(p.I2C1, p.PB6, p.PB7, Hertz::khz(100), config)
|
||||
.into_slave(SlaveConfig {
|
||||
address: SlaveAddress::SevenBit(0x55),
|
||||
general_call: false,
|
||||
});
|
||||
|
||||
loop {
|
||||
match i2c_slave.listen_blocking() {
|
||||
Ok(command) => {
|
||||
match command {
|
||||
ch32_hal::i2c::SlaveCommand::GeneralCall => { /* will not be triggered because we disabled it */
|
||||
}
|
||||
ch32_hal::i2c::SlaveCommand::ReadCommand => {
|
||||
// send empty response
|
||||
let _ = i2c_slave.blocking_write_timeout(&[0x05, 0x01]);
|
||||
}
|
||||
ch32_hal::i2c::SlaveCommand::WriteCommand => {
|
||||
let mut buf: [u8; 3] = [0x0, 0x0, 0x0];
|
||||
let _ = i2c_slave.blocking_read_timeout(&mut buf);
|
||||
println!("received byte 0x{buf:x?}");
|
||||
}
|
||||
}
|
||||
},
|
||||
Err(err) => {
|
||||
println!("{:?}", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user