diff --git a/rfm69.c b/rfm69.c index 4a60b51..70b66f4 100644 --- a/rfm69.c +++ b/rfm69.c @@ -157,8 +157,8 @@ setMode(MODE_STDBY); - size_t len = fmin(regRead(FIFO), FIFO_SIZE) - 1; - len = fmin(len, size); + size_t len = min(regRead(FIFO), FIFO_SIZE) - 1; + len = min(len, size); // TODO assume and ignore address for now regRead(FIFO); @@ -175,7 +175,7 @@ size_t transmitPayload(uint8_t *payload, size_t size) { // payload + address byte - size_t len = fmin(size, FIFO_SIZE) + 1; + size_t len = min(size, FIFO_SIZE) + 1; spiSel(); transmit(FIFO | 0x80); diff --git a/rfm69.h b/rfm69.h index 48d0e0b..8b1308f 100644 --- a/rfm69.h +++ b/rfm69.h @@ -9,7 +9,6 @@ #define RFM69_H #include -#include #include #include "rfm69.h" diff --git a/utils.h b/utils.h index c2c880e..3d9a00b 100644 --- a/utils.h +++ b/utils.h @@ -2,7 +2,7 @@ * File: utils.h * Author: torsten.roemer@luniks.net * - * Created on 14. April 2023, 00:14 + * Created on 07. February 2025, 00:25 */ #ifndef UTILS_H @@ -11,7 +11,30 @@ /** * Computes the length of the given array. */ -#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0])) +#define array_length(array) (sizeof(array) / sizeof(array[0])) + +/** + * Returns the greater of both given numbers. + * https://stackoverflow.com/questions/3437404/min-and-max-in-c + */ +#define max(a, b) \ +({ \ + __typeof__ (a) _a = (a); \ + __typeof__ (b) _b = (b); \ + _a > _b ? _a : _b; \ +}) + +/** + * Returns the smaller of both given numbers. + * https://stackoverflow.com/questions/3437404/min-and-max-in-c + */ +#define min(a, b) \ +({ \ + __typeof__ (a) _a = (a); \ + __typeof__ (b) _b = (b); \ + _a < _b ? _a : _b; \ +}) + #endif /* UTILS_H */