Hello, in one C lib I must give to struct [*]u64
buffers for read and write. I have *[]u8
buffers. So, can I do transform it somehow?
C example code:
uint8_t tx[] = {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x40, 0x00, 0x00, 0x00, 0x00, 0x95,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xDE, 0xAD, 0xBE, 0xEF, 0xBA, 0xAD,
0xF0, 0x0D,
};
uint8_t rx[ARRAY_SIZE(tx)] = {0, };
struct spi_ioc_transfer tr = {
.tx_buf = (unsigned long)tx,
.rx_buf = (unsigned long)rx,
.len = ARRAY_SIZE(tx),
.delay_usecs = delay,
.speed_hz = speed,
.bits_per_word = bits,
};
My function in Zig:
const c_ioctl = @cImport({
@cInclude("sys/ioctl.h");
});
pub fn writeAndRead(self: *Spi, write_buf: *[]u8, read_buf: *[]u8,) !?[]const u8 {
const len = write_buf.*.len;
var tr = spidev.struct_spi_ioc_transfer {
.tx_buf = write_buf,
.rx_buf = read_buf,
.len = len,
.delay_usecs = 0,
.speed_hz = self.speed,
.bits_per_word = self.bits,
};
if (c_ioctl.ioctl(self.fd, spidev.SPI_IOC_MESSAGE(1), &tr) == -1) {
if (get_ioctl_err()) |err| {
std.log.err("Ioctl Error: {s}\n", .{err});
}
return error.SpiTransferFailed;
}
return read_buf.*;
}
So may be you can give me an advice and some examples, it’ll be great