Merge branch 'i2c-slave-testing'
This commit is contained in:
@@ -2,6 +2,6 @@ target extended-remote :3333
|
||||
set remotetimeout 2000
|
||||
|
||||
#symbol-file target/riscv32imc-unknown-none-elf/release/ch32v203-examples
|
||||
file target/riscv32imc-unknown-none-elf/release/bms
|
||||
file target/riscv32imc-unknown-none-elf/debug/bms
|
||||
|
||||
monitor reset halt
|
||||
|
||||
Generated
+143
-23
@@ -32,6 +32,12 @@ version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2d7e60934ceec538daadb9d8432424ed043a904d8e0243f3c6446bce549a46ac"
|
||||
|
||||
[[package]]
|
||||
name = "bitmaps"
|
||||
version = "3.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1d084b0137aaa901caf9f1e8b21daa6aa24d41cd806e111335541eff9683bd6"
|
||||
|
||||
[[package]]
|
||||
name = "bms"
|
||||
version = "0.1.0"
|
||||
@@ -40,14 +46,14 @@ dependencies = [
|
||||
"ch32-metapac 0.0.6",
|
||||
"embassy-executor",
|
||||
"embassy-futures",
|
||||
"embassy-time",
|
||||
"embassy-time 0.4.0",
|
||||
"embassy-usb",
|
||||
"embedded-hal 1.0.0",
|
||||
"heapless",
|
||||
"micromath",
|
||||
"panic-halt",
|
||||
"qingke",
|
||||
"qingke-rt",
|
||||
"qingke 0.5.0",
|
||||
"qingke-rt 0.5.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -65,17 +71,19 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
[[package]]
|
||||
name = "ch32-hal"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/ch32-rs/ch32-hal#2b8e1c864ba5545ee65b1c77dcb17c86a471b70c"
|
||||
source = "git+https://github.com/ju6ge/ch32-hal?branch=feature%2Fi2c-slave-api#9b1df89f5e8de21c7daad0f22fa7186dcfcbecdf"
|
||||
dependencies = [
|
||||
"bitmaps",
|
||||
"ch32-metapac 0.1.0",
|
||||
"critical-section",
|
||||
"embassy-futures",
|
||||
"embassy-hal-internal",
|
||||
"embassy-sync",
|
||||
"embassy-time",
|
||||
"embassy-sync 0.7.2",
|
||||
"embassy-time 0.5.0",
|
||||
"embassy-time-driver",
|
||||
"embassy-time-queue-utils",
|
||||
"embassy-usb-driver",
|
||||
"embassy-usb-driver 0.2.0",
|
||||
"embedded-can",
|
||||
"embedded-hal 0.2.7",
|
||||
"embedded-hal 1.0.0",
|
||||
"embedded-hal-async",
|
||||
@@ -83,8 +91,8 @@ dependencies = [
|
||||
"futures",
|
||||
"nb 1.1.0",
|
||||
"proc-macro2",
|
||||
"qingke",
|
||||
"qingke-rt",
|
||||
"qingke 0.6.1",
|
||||
"qingke-rt 0.6.1",
|
||||
"quote",
|
||||
"rand_core",
|
||||
"sdio-host",
|
||||
@@ -182,6 +190,12 @@ dependencies = [
|
||||
"syn 2.0.101",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "embassy-executor-timer-queue"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2fc328bf943af66b80b98755db9106bf7e7471b0cf47dc8559cd9a6be504cc9c"
|
||||
|
||||
[[package]]
|
||||
name = "embassy-futures"
|
||||
version = "0.1.1"
|
||||
@@ -190,9 +204,9 @@ checksum = "1f878075b9794c1e4ac788c95b728f26aa6366d32eeb10c7051389f898f7d067"
|
||||
|
||||
[[package]]
|
||||
name = "embassy-hal-internal"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0ef3bac31ec146321248a169e9c7b5799f1e0b3829c7a9b324cb4600a7438f59"
|
||||
checksum = "95285007a91b619dc9f26ea8f55452aa6c60f7115a4edc05085cd2bd3127cd7a"
|
||||
dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
@@ -211,7 +225,7 @@ checksum = "4818c32afec43e3cae234f324bad9a976c9aa7501022d26ff60a4017a1a006b7"
|
||||
dependencies = [
|
||||
"embassy-futures",
|
||||
"embassy-net-driver",
|
||||
"embassy-sync",
|
||||
"embassy-sync 0.6.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -228,6 +242,20 @@ dependencies = [
|
||||
"heapless",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "embassy-sync"
|
||||
version = "0.7.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "73974a3edbd0bd286759b3d483540f0ebef705919a5f56f4fc7709066f71689b"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"critical-section",
|
||||
"embedded-io-async",
|
||||
"futures-core",
|
||||
"futures-sink",
|
||||
"heapless",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "embassy-time"
|
||||
version = "0.4.0"
|
||||
@@ -245,21 +273,37 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "embassy-time-driver"
|
||||
version = "0.2.0"
|
||||
name = "embassy-time"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8d45f5d833b6d98bd2aab0c2de70b18bfaa10faf661a1578fd8e5dfb15eb7eba"
|
||||
checksum = "f4fa65b9284d974dad7a23bb72835c4ec85c0b540d86af7fc4098c88cff51d65"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"critical-section",
|
||||
"document-features",
|
||||
"embassy-time-driver",
|
||||
"embedded-hal 0.2.7",
|
||||
"embedded-hal 1.0.0",
|
||||
"embedded-hal-async",
|
||||
"futures-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "embassy-time-driver"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a0a244c7dc22c8d0289379c8d8830cae06bb93d8f990194d0de5efb3b5ae7ba6"
|
||||
dependencies = [
|
||||
"document-features",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "embassy-time-queue-utils"
|
||||
version = "0.1.0"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc55c748d16908a65b166d09ce976575fb8852cf60ccd06174092b41064d8f83"
|
||||
checksum = "80e2ee86063bd028a420a5fb5898c18c87a8898026da1d4c852af2c443d0a454"
|
||||
dependencies = [
|
||||
"embassy-executor",
|
||||
"embassy-executor-timer-queue",
|
||||
"heapless",
|
||||
]
|
||||
|
||||
@@ -271,8 +315,8 @@ checksum = "8d0b882133fa684b9d4652351cd7aac5afe8a2c2bf4a7da59f442ff61087cda2"
|
||||
dependencies = [
|
||||
"embassy-futures",
|
||||
"embassy-net-driver-channel",
|
||||
"embassy-sync",
|
||||
"embassy-usb-driver",
|
||||
"embassy-sync 0.6.2",
|
||||
"embassy-usb-driver 0.1.0",
|
||||
"heapless",
|
||||
"ssmarshal",
|
||||
"usbd-hid",
|
||||
@@ -284,6 +328,24 @@ version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4fc247028eae04174b6635104a35b1ed336aabef4654f5e87a8f32327d231970"
|
||||
|
||||
[[package]]
|
||||
name = "embassy-usb-driver"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "17119855ccc2d1f7470a39756b12068454ae27a3eabb037d940b5c03d9c77b7a"
|
||||
dependencies = [
|
||||
"embedded-io-async",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "embedded-can"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e9d2e857f87ac832df68fa498d18ddc679175cf3d2e4aa893988e5601baf9438"
|
||||
dependencies = [
|
||||
"nb 1.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "embedded-hal"
|
||||
version = "0.2.7"
|
||||
@@ -578,14 +640,36 @@ dependencies = [
|
||||
"riscv 0.12.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "qingke"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "10318bf64fc0befbcd09d7a9a62d8b99972ba3dfdd4a94695f63fd892f47e14e"
|
||||
dependencies = [
|
||||
"bit_field",
|
||||
"cfg-if",
|
||||
"critical-section",
|
||||
"riscv 0.15.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "qingke-rt"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b955c60adac70c6d40205b1dbe9f57e1151d06aa842069cdbaef7bc07ad283fd"
|
||||
dependencies = [
|
||||
"qingke",
|
||||
"qingke-rt-macros",
|
||||
"qingke 0.5.0",
|
||||
"qingke-rt-macros 0.5.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "qingke-rt"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a8ba56c91dd9a044bd519778bcf70644d1d936fee4ea20fdc2d0e3bac8f75fb9"
|
||||
dependencies = [
|
||||
"qingke 0.6.1",
|
||||
"qingke-rt-macros 0.6.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -600,6 +684,18 @@ dependencies = [
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "qingke-rt-macros"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "54edcd0e9b8b5c3c83d313c93869325bfcd969d30d9cef1a1015b0970b21be81"
|
||||
dependencies = [
|
||||
"proc-macro-error",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.40"
|
||||
@@ -634,7 +730,20 @@ dependencies = [
|
||||
"critical-section",
|
||||
"embedded-hal 1.0.0",
|
||||
"paste",
|
||||
"riscv-macros",
|
||||
"riscv-macros 0.1.0",
|
||||
"riscv-pac",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "riscv"
|
||||
version = "0.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b05cfa3f7b30c84536a9025150d44d26b8e1cc20ddf436448d74cd9591eefb25"
|
||||
dependencies = [
|
||||
"critical-section",
|
||||
"embedded-hal 1.0.0",
|
||||
"paste",
|
||||
"riscv-macros 0.3.0",
|
||||
"riscv-pac",
|
||||
]
|
||||
|
||||
@@ -649,6 +758,17 @@ dependencies = [
|
||||
"syn 2.0.101",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "riscv-macros"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7d323d13972c1b104aa036bc692cd08b822c8bbf23d79a27c526095856499799"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.101",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "riscv-pac"
|
||||
version = "0.2.0"
|
||||
|
||||
+2
-1
@@ -4,7 +4,8 @@ version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
ch32-hal = { git = "https://github.com/ch32-rs/ch32-hal", features = [
|
||||
#ch32-hal = { git = "https://github.com/ch32-rs/ch32-hal", features = [
|
||||
ch32-hal = { git = "https://github.com/ju6ge/ch32-hal", branch = "feature/i2c-slave-api", features = [
|
||||
"ch32v203c8t6",
|
||||
"memory-x",
|
||||
"embassy",
|
||||
|
||||
+1
-1
@@ -12,6 +12,6 @@ target create $_TARGETNAME.0 wch_riscv -chain-position $_TARGETNAME
|
||||
$_TARGETNAME.0 configure -work-area-phys 0x20000000 -work-area-size 10000 -work-area-backup 1
|
||||
set _FLASHNAME $_CHIPNAME.flash
|
||||
|
||||
flash bank $_FLASHNAME wch_rsicv 0x00000000 0 0 0 $_TARGETNAME.0
|
||||
flash bank $_FLASHNAME wch_riscv 0x00000000 0 0 0 $_TARGETNAME.0
|
||||
|
||||
init
|
||||
|
||||
+33
-13
@@ -3,31 +3,51 @@
|
||||
#![feature(type_alias_impl_trait)]
|
||||
#![feature(impl_trait_in_assoc_type)]
|
||||
|
||||
mod i2c_slave;
|
||||
|
||||
use ch32_hal::println;
|
||||
use ch32_hal::time::Hertz;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_time::Timer;
|
||||
//use embassy_time::{Duration, Timer};
|
||||
use hal::bind_interrupts;
|
||||
use hal::gpio::{Level, Output};
|
||||
use hal::peripherals::USBD;
|
||||
use hal::usbd::InterruptHandler;
|
||||
use hal::i2c::{Config, I2c, SlaveAddress, SlaveConfig};
|
||||
use {ch32_hal as hal, panic_halt as _};
|
||||
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
USB_LP_CAN1_RX0 => InterruptHandler<USBD>;
|
||||
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 mut led = Output::new(p.PB2, Level::Low, 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 {
|
||||
Timer::after_millis(1000).await;
|
||||
|
||||
//class.write_packet(b"hello world from embassy main\r\n").await;
|
||||
|
||||
led.toggle();
|
||||
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