microzig icon indicating copy to clipboard operation
microzig copied to clipboard

Generic Read-Write descriptor for driver framework/SPI

Open ikskuh opened this issue 10 months ago • 0 comments

Just dumping this so it isn't lost in the Discord:

An idea we could use for an abstract SPI transfer system:

fn transceivev(actions: []const Transaction) !usize;

const Transaction = struct {
  /// buffer to receive
  input: []u8 = &.{},
  /// index of first received byte
  input_offset: usize = 0,
  /// buffer to send
  output: []const u8 = &.{},
  /// index of first sent byte
  output_offset: usize = 0,
  /// transceive at least this amount of items
  min_len: usize = 0,
  /// output when total len bigger than output.len
  pad: u8 = 0x00,

  pub fn length(t: @This()) usize {
    return @max(
      t.min_length,
      t.input_offset + t.input.len,
      t.output_offset + t.output.len,
    );
  }
};

ikskuh avatar Apr 21 '25 07:04 ikskuh