microzig
microzig copied to clipboard
Generic Read-Write descriptor for driver framework/SPI
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,
);
}
};