- Notifications
You must be signed in to change notification settings - Fork 62
/
Copy patheeplib.h
135 lines (113 loc) · 2.81 KB
/
eeplib.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#ifndef_EEPLIB_H
#define_EEPLIB_H
#include<stdarg.h>
#include<stdbool.h>
#include<stdint.h>
#include<stdio.h>
#include<endian.h>
// minimal sizes of data structures
#defineHEADER_SIZE 12
#defineATOM_SIZE 10
#defineATOM_HDR_SIZE 8
#defineVENDOR_SIZE 22
#defineGPIO_SIZE 30
#defineGPIO_BANK1_SIZE 20
#definePOWER_SUPPLY_SIZE 4
#defineCRC_SIZE 2
#defineGPIO_MIN 2
#defineGPIO_COUNT 28
#defineGPIO_COUNT_BANK1 18
#defineGPIO_COUNT_TOTAL (GPIO_COUNT + GPIO_COUNT_BANK1)
#defineCRC16 0x8005
// Signature is "R-Pi" in ASCII. It is required to reversed (little endian) on disk.
#defineHEADER_SIGN (uint32_t)be32toh((((char)'R' << 24) | ((char)'-' << 16) | ((char)'P' << 8) | ((char)'i')))
#definecount_of(x) ((sizeof(x) / sizeof(x[0])))
#definemax(x, y) ((x) > (y) ? (x) : (y))
typedefvoid (*log_callback_t)(constchar*, va_list);
/* Atom types */
enumatom_type_t
{
ATOM_INVALID_TYPE=0x0000,
ATOM_VENDOR_TYPE=0x0001,
ATOM_GPIO_TYPE=0x0002,
ATOM_DT_TYPE=0x0003,
ATOM_CUSTOM_TYPE=0x0004,
ATOM_GPIO_BANK1_TYPE=0x0005,
ATOM_POWER_SUPPLY_TYPE=0x0006,
ATOM_HINVALID_TYPE=0xffff
};
enumfile_ver_t
{
EEP_VERSION_HATV1=0x01,
EEP_VERSION_HATPLUS=0x02,
EEP_VERSION=EEP_VERSION_HATPLUS,
};
enumeepio_dir_t
{
EEPIO_READ,
EEPIO_WRITE,
};
/* EEPROM header structure */
structheader_t
{
uint32_tsignature;
unsigned charver;
unsigned charres;
uint16_tnumatoms;
uint32_teeplen;
};
/* Atom structure */
structatom_t
{
uint16_ttype;
uint16_tcount;
uint32_tdlen;
char*data;
};
structvar_blob_t
{
uint8_t*data;
uint32_tdlen;
};
/* Vendor info atom data */
structvendor_info_d
{
uint32_tserial[4]; // 0 = least significant, 3 = most significant
uint16_tpid;
uint16_tpver;
unsigned charvslen;
unsigned charpslen;
char*vstr;
char*pstr;
};
/* GPIO map atom data */
structgpio_map_d
{
unsigned charflags;
unsigned charpower;
unsigned charpins[GPIO_COUNT];
};
/* Power supply atom data */
structpower_supply_d
{
uint32_tcurrent_supply; /* In milliamps */
};
externstructheader_teep_header;
externstructatom_teep_atom_header;
externuint16_teep_atom_crc;
voideepio_start(enumfile_ver_t*pver, int*pnumatoms, enumeepio_dir_tdir, FILE*fp);
booleepio_end(void);
booleepio_atom_start(enumatom_type_t*ptype, uint32_t*pdlen);
booleepio_atom_vinf(structvendor_info_d*vinf);
booleepio_atom_gpio(structgpio_map_d*map);
booleepio_atom_gpio_bank1(structgpio_map_d*map);
booleepio_atom_power_supply(structpower_supply_d*power);
booleepio_atom_var(structvar_blob_t*var);
voideepio_atom_end(void);
voideepio_clear_error(void);
booleepio_error(constchar*msg, ...);
voideepio_warning(constchar*msg, ...);
booleepio_got_error(void);
voideepio_set_error_callback(log_callback_tcallback);
voideepio_set_warning_callback(log_callback_tcallback);
#endif