C++ convert uint8_t to unsigned long
I'm transferring some data with spidev using a struct like this
struct spi_ioc_transfer tr = {
.tx_buf = (unsigned long)tx, // transferred
.rx_buf = (unsigned long)rx, // received
.len = ARRAY_SIZE(tx),
.delay_usecs = delay,
.speed_hz = speed,
.bits_per_word = bits,
};
The data that I want to send is uint8_t tx[] = {0xAC, 0xDC} So I'm casting
the array like this: msg.tx_buf = (unsigned long)tx;
But this is not good for portability and it's endian dependent. Is there a
better and fast way to do this? I also need to compare the values of
msg.tx_buf and msg.rx_buf to make sure that the value was written
correctly.
Thanks
No comments:
Post a Comment