sending can messages works
This commit is contained in:
parent
5912a547ba
commit
57f213a5f0
3 changed files with 16 additions and 119 deletions
81
Cargo.lock
generated
81
Cargo.lock
generated
|
|
@ -31,8 +31,7 @@ name = "ch32-dimmer-node"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"ch32-hal",
|
||||
"embassy-executor",
|
||||
"embassy-time",
|
||||
"embedded-can",
|
||||
"embedded-hal 1.0.0",
|
||||
"fugit",
|
||||
"panic-halt",
|
||||
|
|
@ -83,41 +82,6 @@ version = "1.2.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b"
|
||||
|
||||
[[package]]
|
||||
name = "darling"
|
||||
version = "0.20.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc7f46116c46ff9ab3eb1597a45688b6715c6e628b5c133e288e709a29bcb4ee"
|
||||
dependencies = [
|
||||
"darling_core",
|
||||
"darling_macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling_core"
|
||||
version = "0.20.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0d00b9596d185e565c2207a0b01f8bd1a135483d02d9b7b0a54b11da8d53412e"
|
||||
dependencies = [
|
||||
"fnv",
|
||||
"ident_case",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"strsim",
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling_macro"
|
||||
version = "0.20.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead"
|
||||
dependencies = [
|
||||
"darling_core",
|
||||
"quote",
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "document-features"
|
||||
version = "0.2.11"
|
||||
|
|
@ -127,31 +91,6 @@ dependencies = [
|
|||
"litrs",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "embassy-executor"
|
||||
version = "0.6.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f64f84599b0f4296b92a4b6ac2109bc02340094bda47b9766c5f9ec6a318ebf8"
|
||||
dependencies = [
|
||||
"critical-section",
|
||||
"document-features",
|
||||
"embassy-executor-macros",
|
||||
"embassy-time-driver",
|
||||
"embassy-time-queue-driver",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "embassy-executor-macros"
|
||||
version = "0.6.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3577b1e9446f61381179a330fc5324b01d511624c55f25e3c66c9e3c626dbecf"
|
||||
dependencies = [
|
||||
"darling",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "embassy-futures"
|
||||
version = "0.1.1"
|
||||
|
|
@ -279,12 +218,6 @@ dependencies = [
|
|||
"embedded-io",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fnv"
|
||||
version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||
|
||||
[[package]]
|
||||
name = "fugit"
|
||||
version = "0.3.7"
|
||||
|
|
@ -392,12 +325,6 @@ dependencies = [
|
|||
"stable_deref_trait",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ident_case"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
|
||||
|
||||
[[package]]
|
||||
name = "litrs"
|
||||
version = "0.4.1"
|
||||
|
|
@ -585,12 +512,6 @@ version = "1.2.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.109"
|
||||
|
|
|
|||
14
Cargo.toml
14
Cargo.toml
|
|
@ -14,27 +14,15 @@ panic-halt = "1.0.0"
|
|||
# https://github.com/ch32-rs/ch32-hal/pull/75
|
||||
ch32-hal = {git = "https://github.com/paval-shlyk/ch32-hal", rev="ace32859924ab0d5e411521a8f392df01ce262ff", features = [
|
||||
"ch32v203f6p6",
|
||||
"embassy",
|
||||
"time-driver-tim1",
|
||||
]}
|
||||
qingke-rt = { version = "0.5.0", features = ["highcode"] }
|
||||
qingke = "0.5.0"
|
||||
embedded-hal = "1.0.0"
|
||||
|
||||
embassy-executor = {version = "0.6.0", features = [
|
||||
"integrated-timers",
|
||||
"arch-spin",
|
||||
"executor-thread",
|
||||
|
||||
# see https://docs.embassy.dev/embassy-executor/git/cortex-m/index.html#task-arena-size
|
||||
#"task-arena-size-64",
|
||||
"task-arena-size-128"
|
||||
#"task-arena-size-192",
|
||||
#"task-arena-size-256",
|
||||
]}
|
||||
fugit = "0.3.7"
|
||||
|
||||
embassy-time = { version = "0.3.0" }
|
||||
embedded-can = "0.4.1"
|
||||
|
||||
[profile.release]
|
||||
strip = true
|
||||
|
|
|
|||
40
src/main.rs
40
src/main.rs
|
|
@ -9,24 +9,16 @@ use hal::time::Hertz;
|
|||
use hal::timer::low_level::CountingMode;
|
||||
use hal::timer::simple_pwm::{PwmPin, SimplePwm};
|
||||
use hal::can::{Can, CanFifo, CanFilter, CanFrame, CanMode, StandardId};
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_time::{Duration, Ticker};
|
||||
use qingke::riscv;
|
||||
use embedded_can::nb::Can as _;
|
||||
|
||||
#[embassy_executor::main(entry = "qingke_rt::entry")]
|
||||
async fn main(_spawner: Spawner) -> ! {
|
||||
#[qingke_rt::entry]
|
||||
fn main() -> ! {
|
||||
hal::debug::SDIPrint::enable();
|
||||
let p = hal::init(hal::Config::default());
|
||||
|
||||
println!("setting up can");
|
||||
let can = Can::new(p.CAN1, p.PA11, p.PA12, CanFifo::Fifo1, CanMode::Normal, 500_000).expect("Valid");
|
||||
println!("setting up can filter");
|
||||
let mut filter = CanFilter::new_id_list();
|
||||
filter
|
||||
.get(0)
|
||||
.unwrap()
|
||||
.set(StandardId::new(0x580 | 0x42).unwrap().into(), Default::default());
|
||||
|
||||
println!("adding can filter");
|
||||
let mut can = Can::new(p.CAN1, p.PA11, p.PA12, CanFifo::Fifo1, CanMode::Normal, 500_000).expect("Valid");
|
||||
can.add_filter(CanFilter::accept_all());
|
||||
|
||||
println!("setting up pwm");
|
||||
|
|
@ -73,12 +65,11 @@ async fn main(_spawner: Spawner) -> ! {
|
|||
pwm_w.set_duty(ch_cw, 0);
|
||||
pwm_w.enable(ch_cw);
|
||||
|
||||
let mut ticker = Ticker::every(Duration::from_millis(25));
|
||||
//let mut ticker = Ticker::every(Duration::from_millis(250));
|
||||
println!("entering main loop");
|
||||
let msg: [u8; 8] = [0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF];
|
||||
let msg: [u8; 3] = [0xAB, 0xCD, 0xEF];
|
||||
|
||||
let delay = 100_000;
|
||||
loop {
|
||||
/*
|
||||
let frame = CanFrame::new(StandardId::new(0x42).unwrap(), &msg).unwrap();
|
||||
match can.transmit(&frame) {
|
||||
Ok(_) => println!("Sent CAN message {:?}", msg),
|
||||
|
|
@ -87,32 +78,29 @@ async fn main(_spawner: Spawner) -> ! {
|
|||
let _ = can.transmit(&frame);
|
||||
|
||||
println!("-");
|
||||
match can.try_recv() {
|
||||
Err(_) => println!("Receive error"),
|
||||
match can.receive() {
|
||||
Err(err) => println!("Receive error: {:?}", err),
|
||||
Ok(recv_msg) => println!("Received: {:?}", recv_msg),
|
||||
}
|
||||
|
||||
println!(".");
|
||||
*/
|
||||
|
||||
for x in 0..100 {
|
||||
pwm_w.set_duty(ch_cw, x*8);
|
||||
ticker.next().await;
|
||||
riscv::asm::delay(delay);
|
||||
}
|
||||
for x in 0..100 {
|
||||
pwm_w.set_duty(ch_cw, (100-x)*8);
|
||||
ticker.next().await;
|
||||
riscv::asm::delay(delay);
|
||||
}
|
||||
for x in 0..100 {
|
||||
pwm_w.set_duty(ch_ww, x*8);
|
||||
ticker.next().await;
|
||||
riscv::asm::delay(delay);
|
||||
}
|
||||
for x in 0..100 {
|
||||
pwm_w.set_duty(ch_ww, (100-x)*8);
|
||||
ticker.next().await;
|
||||
riscv::asm::delay(delay);
|
||||
}
|
||||
|
||||
ticker.next().await;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue