1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//! A `no-std`, hardware-agnostic library for serializing Monome II protocol commands.
//!
//! This crate provides type-safe structures for II-protocol commands for various
//! Eurorack modules. Its sole purpose is to serialize these high-level commands
//! into the correct byte sequences. It does not handle I2C communication itself.
//!
//! ## Usage
//!
//! 1. Choose a module from the library, like `er301`.
//! 2. Instantiate a command enum, e.g., `er301::Commands::SetCv { ... }`.
//! 3. Create a buffer to hold the serialized message. The `Command::MAX_LENGTH`
//! associated constant can help you size this appropriately.
//! 4. Call the `.to_bytes()` method on your command object.
//! 5. If successful, you get a byte slice ready to be sent over I2C.
//!
//! ### Example
//!
//! ```
//! use mii::{Command, devices::ansible};
//!
//! let mut buffer = [0u8; ansible::Commands::MAX_LENGTH];
//!
//! // Set CV output
//! let cv_cmd = ansible::Commands::SetCv { port: 0, value: 4096 };
//! let message = cv_cmd.to_bytes(&mut buffer).unwrap();
//! // Send message over I2C to ansible::ADDRESS (0x20)
//!
//! // Trigger pulse
//! let pulse_cmd = ansible::Commands::SetTrPulse { port: 1 };
//! let message = pulse_cmd.to_bytes(&mut buffer).unwrap();
//! // Send message over I2C to ansible::ADDRESS (0x20)
//! ```
/// Represents errors that can occur during command serialization.
/// The core trait for any object that can be serialized into an II-compatible byte message.