Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

32 migrate to hal 10 #33

Merged
merged 5 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/qa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ jobs:
matrix:
target:
- thumbv7m-none-eabi
- thumbv8m.main-none-eabihf
- riscv32imac-unknown-none-elf
rust:
- stable
- beta
Expand Down
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ documentation = "https://docs.rs/mcp2517"
byteorder = { version = "^1.3.0", default-features = false }
bytes = { version = "1.6.0", default-features = false }
embedded-can = "0.4.1"
embedded-hal = { version = "0.2.7", features = ["unproven"] }
embedded-hal = { version = "1.0.0" }
embedded-time = "0.12.1"
log = "0.4.17"
modular-bitfield-msb = "0.11.2"
serde = { version = "1.0.197", features = ["derive"], default-features = false }


[dev-dependencies]
Expand Down
1 change: 1 addition & 0 deletions example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mcp2517 = { path = "..", version = "*" }

# Embedded crates
embedded-hal = "1.0.0"
embedded-hal-bus = "0.2.0"
embedded-time = "0.12.1"
embedded-alloc = "0.5.1"
critical-section = "1.1.2"
Expand Down
21 changes: 13 additions & 8 deletions example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub mod mutex;
use crate::clock::SystemClock;
use crate::heap::Heap;
use bytes::Bytes;
use core::cell::RefCell;
use core::fmt::Write;
use embedded_can::{Id, StandardId};
use embedded_hal::delay::DelayNs;
Expand All @@ -36,6 +37,7 @@ use bsp::{
Spi, Timer,
},
};
use embedded_hal_bus::spi::{NoDelay, RefCellDevice};

const XTAL_FREQ_HZ: u32 = 12_000_000u32;

Expand Down Expand Up @@ -94,7 +96,11 @@ fn main() -> ! {
)
.unwrap();

let mut can_controller: MCP2517<_, _, SystemClock> = MCP2517::new(spi, pin_cs);
let spi_bus = RefCell::new(spi);

let device = RefCellDevice::new(&spi_bus, pin_cs, NoDelay).unwrap();

let mut can_controller: MCP2517<_, _> = MCP2517::new(device);

// Setup clk config
let clk_config = ClockConfiguration {
Expand All @@ -115,6 +121,7 @@ fn main() -> ! {
bit_rate: BitRateConfig::default(),
};

let _ = can_controller.reset();
if let Err(_) = can_controller.configure(&config, &sys_clk) {
panic!()
}
Expand All @@ -126,17 +133,15 @@ fn main() -> ! {
// Set mask to match if only 2 LSB of ID match with filter
filter.set_mask_standard_id(0xFF);
let _ = can_controller.set_filter_object(filter);

// Create message frame
let payload_8 = [0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8];
let message_type = Can20::<8> {};
let payload = [0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8];
let pl_bytes = Bytes::copy_from_slice(&payload);
let can_message = TxMessage::new(message_type, pl_bytes, can_id).unwrap();
let pl_8bytes = Bytes::copy_from_slice(&payload_8);
let can_message = TxMessage::new(message_type, pl_8bytes, can_id).unwrap();

let mut receive_buffer = [0u8; 8];

loop {
can_controller.transmit(&can_message, true).unwrap();
let _ = can_controller.transmit(&can_message, true);
uart.write_raw(b"can message sent\n\r").unwrap();

timer.delay_ms(500);
Expand All @@ -149,7 +154,7 @@ fn main() -> ! {
uart.write_fmt(format_args!("{val}\n\r")).unwrap();
}
}
Err(e) => uart.write_fmt(format_args!("error reading message {:?}\n\r", e)).unwrap(),
Err(_) => uart.write_fmt(format_args!("error reading message")).unwrap(),
}

timer.delay_ms(500);
Expand Down
Loading
Loading