Skip to main content

build_command_frame

Function build_command_frame 

Source
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 the OP_* constants from crate::opcodes.
  • param1: First single-byte parameter (command-specific meaning).
  • param2: Two-byte parameter, written in little-endian.
  • data : Optional command-specific payload, up to MAX_COMMAND_DATA_LEN bytes.
  • out : Buffer that receives the encoded frame. Must hold at least COMMAND_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.