Toying around with a 4.2 in. e-Paper module from Waveshare and the Raspberry Pi Pico. Maybe it'll become a library some day.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

51 lines
1.3 KiB

/*
* util.h
*
* Created on: Feb 26, 2023
* Author: Daniel Peter Chokola
*/
#ifndef UTIL_H_
#define UTIL_H_
/* Definitions */
#ifdef __GNUC__
# define UNUSED __attribute__((unused))
#else
# define UNUSED
#endif
#define return_if_fail(cond) \
if(!(cond)) { return; }
#define return_val_if_fail(cond, val) \
if(!(cond)) { return (val); }
#define return_null_if_fail(cond) return_val_if_fail((cond), NULL)
/* MIN() and MAX() */
#ifdef __GNUC__
# if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 9))
/* prevent double evaluation */
# define MIN(a,b) \
__extension__({ __auto_type _a = (a); \
__auto_type _b = (b); \
_a < _b ? _a : _b; })
# define MAX(a,b) \
__extension__({ __auto_type _a = (a); \
__auto_type _b = (b); \
_a > _b ? _a : _b; })
# else
/* typesafety but double evaluation is possible */
# define MIN(a,b) \
__extension__({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a < _b ? _a : _b; })
# define MAX(a,b) \
__extension__({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a > _b ? _a : _b; })
# endif
#else
/* no typesafety and double evaluation is possible */
# define MIN(a,b) ((a) < (b) ? (a) : (b))
# define MAX(a,b) ((a) > (b) ? (a) : (b))
#endif
#endif /* UTIL_H_ */