Cylinder is an embedded rust library for type-safe inter MCU/MPU communication
that supports #![no_std]. I created it because handling
complex inter-MCU communication without type-safety
is extremely difficult, but with Cylinder you don't have
to worry about defining unique u8 values for
commands and conflicts and other issues with non type-safe communication.
Cylinder allows for type-safe communication by providing a procedural macro that runs at build time that you can apply to enum types. e.g: ```rust use cylinder::CylinerBuildU8;
enum Test {
MyEnum1,
MyEnum2,
MyEnum3,
MyEnum4
}
At build time this enum get's converted to a hash map where each enum type
gets mapped to a unique `u8` value that can be sent over I2C, SPI, CAN or any other protocol.
You can use that hashmap by doing the below:
rust
let hash : HashMap<&Test, u8> = Test::describe();
And then you can use it like this:
rust
let val : u8 = hash.get(&Test::MyEnum1);
``
Note that to allow the usage of#![nostd]instead of using thestd:hashmapimplementation Cylinder uses
hashbrown which is a hasmap library that supports#![nostd]so you will need to importhashbrowninto your code to use the hashmap.
Note that hashbrown when used in a#![no_std]enviroment requires that you configure a
global allocator with theallocpackage for example with theembedded-alloc` package.
You can install it with:
shell
cargo add embedded_cylinder
If you have any ideas to improve the library create a PR or issue and i will be happy to review it!