device-register
A no_std, zero cost toolkit to describe the registers of a device to ease driver development.
no_stdsupport- Zero cost, no use of dyn
- No dsl, just a derive macro and impl a trait.
- Error passthrough
Usage
Simply derive using XXRegister, where XX is the premission.
The following permissions are supported
RORegister, read only permissionWORegister, write only permissionEORegister, edit only permission, when a register need to be read-modify-writeRERegister, Read and edit permissionRWRegister, Read, write and edit permission.
To define a register, simply derive using the desired permission.
Then use the register attribute to define it's address, type for the address and the error type.
;
The your driver only need to implement the RegisterInterface
Complete example
Here is a complete example.
See the tests folder for more, or checkout the tmp117 driver for actual usage.
use HashMap;
use *;
// The type of the address used by the driver
;
// The type of the error, lets have none for now
type DeviceError = ;
// We define the register with Read/Write permission
// Then we pass the address type, value and error type of the driveer
;
// Mock of the device driver
// We implement the required interface
let mut device = DeviceDriver;
// We can the Read/Write/Edit the registers that uses the Address and DeviceError types.
let write = Register0;
device.write.unwrap;
let read: Register0 = device.read.unwrap;
assert_eq!;
device.edit.unwrap;
let read: Register0 = device.read.unwrap;
assert_eq!;
License
Licensed under either of
-
Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
-
MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
License: MIT OR Apache-2.0