pub(crate) fn build_command_frame(
opcode: u8,
param1: u8,
param2: u16,
data: &[u8],
out: &mut [u8],
) -> Result<usize, PacketBuildError>Expand description
Build a command frame into out and return the number of bytes written.
The frame is laid out exactly as the chip expects to receive it, starting with the count byte. The caller is responsible for prepending the word address byte at the I2C transmission layer.
§Arguments
opcode: One of theOP_*constants fromcrate::opcodes.param1: First single-byte parameter (command-specific meaning).param2: Two-byte parameter, written in little-endian.data: Optional command-specific payload, up toMAX_COMMAND_DATA_LENbytes.out: Buffer that receives the encoded frame. Must hold at leastCOMMAND_FRAME_OVERHEAD + data.len()bytes.
§Errors
Returns PacketBuildError::DataTooLong if data exceeds the protocol
maximum, or PacketBuildError::OutputBufferTooSmall if out is too
small to hold the result.