mirror of
https://github.com/javifercep/mcb-rs.git
synced 2026-09-09 18:38:07 +02:00
Motion Control Bus protocol implemented in Rust
- Rust 100%
| .github/workflows | ||
| src | ||
| tests | ||
| .gitattributes | ||
| .gitignore | ||
| Cargo.toml | ||
| LICENSE | ||
| README.md | ||
Motion Control Bus - Rust
This is a personal project for learning the basics of Rust.
Motivation
Learning how to use Rust in embedded systems and learn about the "safe" features the language offers by default.
What does it do?
mcb-rs implements the Motion Control Bus protocol:
This library works over other protocols such as Ethernet,
SPI or USB. It is designed for embedded system where the
hardware abstraction needs to be created. This means that
this library requires the implementation of a struct implementing
the [PhysicalInterface] trait.
Examples
use mcb::mcb_main::{create_main_mcb, Main};
use mcb::{Config, Init, IntfError, IntfResult, ExtMode, PhysicalInterface, MAX_FRAME_SIZE};
use mcb::IntfResult::*;
struct NewInterface;
impl PhysicalInterface for NewInterface {
fn raw_write(&mut self, frame: &[u16]) -> Result<IntfResult, IntfError> {
// your implementation
Ok(Success)
}
fn raw_read(&mut self) -> Result<IntfResult, IntfError> {
// ignore this block. Created to pass cargo test --doc
let mut msg = [0u16; MAX_FRAME_SIZE];
msg[1] = 166;
msg[2] = 1;
msg[6] = 17282;
// end of ignore block
// your implementation
Ok(Data(Box::new(msg)))
}
fn is_data2read(&mut self) -> Result<IntfResult, IntfError> {
// your implementation
Ok(Success)
}
}
fn main() {
let interface: NewInterface = NewInterface;
let mcb_main = create_main_mcb(Some(interface), ExtMode::Extended);
let mut mcb_main_cfg = mcb_main.init();
let result = mcb_main_cfg.writeu8(0x0Au16, 1u8);
assert!(matches!(result, Ok(IntfResult::Success)));
}
This crate contains both modules
- Main
- Node
The main module is the expected to be used over SPI with the drives implementing these protocols:
The node module is expected to be used for bridge applications such as Turonet