-
Notifications
You must be signed in to change notification settings - Fork 2
/
util.h
executable file
·83 lines (65 loc) · 1.42 KB
/
util.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/** \file
* Utility functions.
*/
#ifndef _util_h_
#define _util_h_
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <inttypes.h>
#include <errno.h>
#include <unistd.h>
#define warn(fmt, ...) \
do { \
fprintf(stderr, "%s:%d: " fmt, \
__func__, __LINE__, ## __VA_ARGS__); \
} while (0)
#define warn_once(fmt, ...) \
do { \
static unsigned __warned__; \
if (__warned__) \
break; \
__warned__ = 1; \
warn(fmt, ## __VA_ARGS__ ); \
} while (0)
#define die(fmt, ...) \
do { \
warn(fmt, ## __VA_ARGS__ ); \
exit(EXIT_FAILURE); \
} while(0)
extern void
hexdump(
FILE * const outfile,
const void * const buf,
const size_t len
);
extern int
serial_open(
const char * const dev
);
/** Write all the bytes to a fd, even if there is a brief interruption.
* \return number of bytes written or -1 on any fatal error.
*/
extern ssize_t
write_all(
const int fd,
const void * const buf_ptr,
const size_t len
);
extern size_t strlcpy(char *dst, const char *src, size_t size);
extern size_t strlcat(char *dst, const char *src, size_t size);
typedef enum {
COLOR_ORDER_RGB,
COLOR_ORDER_RBG,
COLOR_ORDER_GRB,
COLOR_ORDER_GBR,
COLOR_ORDER_BGR,
COLOR_ORDER_BRG // Old LedSPI default
} color_channel_order_t;
extern const char* color_channel_order_to_string(
color_channel_order_t color_channel_order
);
extern color_channel_order_t color_channel_order_from_string(
const char* str
);
#endif