license: update source file and licensing files
[libsi24] / libsi24.h
1 /* Copyright (C) 
2  * 2023 - Robin Krens
3  * This program is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU General Public License
5  * as published by the Free Software Foundation; either version 2
6  * of the License, or (at your option) any later version.
7  * 
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  * 
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16  * 
17  */
18 #include <stddef.h>
19
20 #if defined(__cplusplus)
21 extern "C" {
22 #endif
23
24 enum si24_status_t {
25     SHUTDOWN = 0,
26     STANDBY,
27     IDLETX,
28     TX,
29     RX
30 };
31
32 typedef enum si24_status_t si24_status_t;
33
34 enum si24_mode_t {
35     RECV_MODE = 0,
36     SEND_MODE
37 };
38
39 typedef enum si24_mode_t si24_mode_t;
40
41 enum si24_crc_t {
42     ONE_BYTE = 0,
43     TWO_BYTE = 1
44 };
45
46 typedef enum si24_crc_t si24_crc_t;
47
48 enum si24_speed_t {
49         MBPS1 = 0,
50         MBPS2 = 1,
51         KBPS250 = 2
52 };
53
54 typedef enum si24_speed_t si24_speed_t;
55
56 enum si24_txpower_t {
57         MINUS12DB = 0,
58         MINUS6DB,
59         MINUS4DB,
60         ZERODB,
61         PLUS1DB,
62         PLUS3DB,
63         PLUS4DB,
64         PLUS7DB
65 };
66
67 typedef enum si24_txpower_t si24_txpower_t;
68
69 enum si24_event_type_t {
70     EV_RX_COMPLETE = 0,
71     EV_TX_COMPLETE,
72     EV_TX_FULL,
73     EV_RX_EMPTY,
74     EV_ERR_TIMEOUT,
75     EV_ERR_BUS,
76     EV_ERR_MAX_RETRIES,
77     EV_ERR_CRC,
78     EV_ERR_CONFIG
79 };
80
81 typedef enum si24_event_type_t si24_event_type_t;
82
83 union si24_event_t {
84         enum si24_event_type_t type;
85         struct error_t {
86                 enum si24_event_type_t _type;
87                 const char *file;
88                 const char *func;
89                 const char *msg;
90                 int line;
91         } error;
92 };
93
94 typedef union si24_event_t si24_event_t;
95
96 /* low level IO control */
97 typedef struct {
98     int (*write_and_read)(unsigned char *data, size_t sz);
99     void (*chip_enable)(unsigned val);
100 } si24_ioctl_t;
101
102 typedef struct {
103     si24_mode_t mode;
104     unsigned enable_ack;
105     unsigned non_blocking;
106     unsigned enable_crc;
107     unsigned enable_dynpd;
108     si24_crc_t crc;
109     si24_ioctl_t *ioctl;
110     si24_speed_t speed;
111     si24_txpower_t txpwr;
112     unsigned payload;
113     unsigned timeout; /* 1: 250 us, 15: 4000 us */
114     unsigned retries; /* 1 to 15 */
115     unsigned char mac_addr[5];
116 } si24_opts_t;
117
118 /* private data structure */
119 typedef struct si24_t si24_t;
120
121 typedef void (*si24_event_handler_t)(si24_t* si24, si24_event_t* event);
122
123 extern si24_t* si24_init(const si24_opts_t* si24opts, si24_event_handler_t eh);
124 extern void si24_free(si24_t* si24);
125 extern size_t si24_send(si24_t* si24, const unsigned char * buf, size_t size);
126 extern size_t si24_recv(si24_t* si24, unsigned char * buf, size_t size);
127 extern void si24_reset(si24_t* si24);
128
129 #if defined(__cplusplus)
130 }
131 #endif