libsigrok-internal.h: add helper macro to read floats from unaligend memory.
This commit is contained in:
parent
7a0b98b544
commit
a2632bcafc
|
@ -113,6 +113,20 @@
|
||||||
((unsigned)((const uint8_t*)(x))[1] << 8) | \
|
((unsigned)((const uint8_t*)(x))[1] << 8) | \
|
||||||
(unsigned)((const uint8_t*)(x))[0]))
|
(unsigned)((const uint8_t*)(x))[0]))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read a 32 bits big endian float out of memory.
|
||||||
|
* @param x a pointer to the input memory
|
||||||
|
* @return the corresponding float
|
||||||
|
*/
|
||||||
|
#define RBFL(x) ((union { uint32_t u; float f; }) { .u = RB32(x) }.f)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read a 32 bits little endian float out of memory.
|
||||||
|
* @param x a pointer to the input memory
|
||||||
|
* @return the corresponding float
|
||||||
|
*/
|
||||||
|
#define RLFL(x) ((union { uint32_t u; float f; }) { .u = RL32(x) }.f)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write a 8 bits unsigned integer to memory.
|
* Write a 8 bits unsigned integer to memory.
|
||||||
* @param p a pointer to the output memory
|
* @param p a pointer to the output memory
|
||||||
|
@ -156,6 +170,20 @@
|
||||||
((uint8_t*)(p))[2] = (uint8_t)((x)>>16); \
|
((uint8_t*)(p))[2] = (uint8_t)((x)>>16); \
|
||||||
((uint8_t*)(p))[3] = (uint8_t)((x)>>24); } while (0)
|
((uint8_t*)(p))[3] = (uint8_t)((x)>>24); } while (0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write a 32 bits float to memory stored as big endian.
|
||||||
|
* @param p a pointer to the output memory
|
||||||
|
* @param x the input float
|
||||||
|
*/
|
||||||
|
#define WBFL(p, x) WB32(p, (union { uint32_t u; float f; }) { .f = x }.u)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write a 32 bits float to memory stored as little endian.
|
||||||
|
* @param p a pointer to the output memory
|
||||||
|
* @param x the input float
|
||||||
|
*/
|
||||||
|
#define WLFL(p, x) WL32(p, (union { uint32_t u; float f; }) { .f = x }.u)
|
||||||
|
|
||||||
/* Portability fixes for FreeBSD. */
|
/* Portability fixes for FreeBSD. */
|
||||||
#ifdef __FreeBSD__
|
#ifdef __FreeBSD__
|
||||||
#define LIBUSB_CLASS_APPLICATION 0xfe
|
#define LIBUSB_CLASS_APPLICATION 0xfe
|
||||||
|
|
Loading…
Reference in New Issue