Motion Control Bus protocol implemented in Rust
Find a file
2024-08-06 10:45:01 +02:00
.github/workflows * Applied clippy recommendations 2024-07-03 23:07:28 +02:00
src added basic support for string transfers 2024-08-06 10:45:01 +02:00
tests added basic support for string transfers 2024-08-06 10:45:01 +02:00
.gitattributes Repository creation 2023-11-23 21:07:38 +01:00
.gitignore Repository creation 2023-11-23 21:07:38 +01:00
Cargo.toml Added support for basic float types 2024-07-07 13:31:07 +02:00
LICENSE Repository creation 2023-11-23 21:07:38 +01:00
README.md Added new features after integrate lib into an application 2024-07-15 21:32:48 +02:00

workflow

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