1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

drivers/periph_spi: Add spi_transfer_u16_be()

This adds a helper function to exchange a 16 bit number that is to
be transferred in big endian order on the wire.
This commit is contained in:
Marian Buschsieweke 2024-01-30 11:13:09 +01:00
parent 22dbbf4a07
commit 87abafb13f
No known key found for this signature in database
GPG Key ID: 77AA882EC78084E6

View File

@ -66,8 +66,8 @@
#ifndef PERIPH_SPI_H
#define PERIPH_SPI_H
#include <endian.h>
#include <errno.h>
#include <limits.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
@ -430,6 +430,25 @@ uint8_t spi_transfer_reg(spi_t bus, spi_cs_t cs, uint8_t reg, uint8_t out);
void spi_transfer_regs(spi_t bus, spi_cs_t cs, uint8_t reg,
const void *out, void *in, size_t len);
/**
* @brief Transfer a 16 bit number in big endian byte order
*
* @param[in] bus SPI device to use
* @param[in] cs chip select pin/line to use, set to
* SPI_CS_UNDEF if chip select should not be
* handled by the SPI driver
* @param[in] cont if true, keep device selected after transfer
* @param[in] host_number number to transfer in host byte order
* @return The 16 bit number received in host byte order
*/
static inline uint16_t spi_transfer_u16_be(spi_t bus, spi_cs_t cs, bool cont, uint16_t host_number)
{
const uint16_t send = htobe16(host_number);
uint16_t receive;
spi_transfer_bytes(bus, cs, cont, &send, &receive, sizeof(receive));
return be16toh(receive);
}
#ifdef __cplusplus
}
#endif