-
Notifications
You must be signed in to change notification settings - Fork 92
/
mode_config.h
185 lines (161 loc) · 3.87 KB
/
mode_config.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
* HydraBus/HydraNFC
*
* Copyright (C) 2014-2015 Benjamin VERNOUX
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _MODE_CONFIG_H_
#define _MODE_CONFIG_H_
typedef enum {
DEV_NUM = 0,
DEV_GPIO_PULL,
DEV_MODE,
DEV_SPEED,
DEV_CPOL_CPHA,
DEV_NUMBITS,
DEV_BIT_LSB_MSB,
DEV_PARITY,
DEV_STOP_BIT
} mode_config_dev_t;
typedef enum {
MODE_CONFIG_PROTO_INVALID = -1,
MODE_CONFIG_PROTO_VALID = 1
} mode_config_proto_valid_t;
typedef enum {
MODE_CONFIG_DEV_GPIO_NOPULL = 0,
MODE_CONFIG_DEV_GPIO_PULLUP = 1,
MODE_CONFIG_DEV_GPIO_PULLDOWN = 2
} mode_dev_gpio_pull_t;
typedef enum {
MODE_CONFIG_DEV_GPIO_IN = 0,
MODE_CONFIG_DEV_GPIO_OUT_PUSHPULL = 1,
MODE_CONFIG_DEV_GPIO_OUT_OPENDRAIN = 2
} mode_dev_gpio_mode_t;
/* dev_mode */
enum {
DEV_MASTER = 1,
DEV_SLAVE,
};
/* dev_bit_lsb_msb */
enum {
DEV_FIRSTBIT_MSB = 1,
DEV_FIRSTBIT_LSB,
};
typedef struct {
uint32_t dev_speed;
uint8_t dev_parity;
uint8_t dev_stop_bit;
} uart_config_t;
typedef struct {
mode_dev_gpio_pull_t dev_gpio_pull;
uint32_t dev_speed;
uint8_t ack_pending : 1;
} i2c_config_t;
typedef struct {
mode_dev_gpio_pull_t dev_gpio_pull;
uint32_t dev_speed;
uint8_t dev_mode;
uint8_t dev_polarity;
uint8_t dev_phase;
uint8_t dev_bit_lsb_msb;
} spi_config_t;
typedef struct {
mode_dev_gpio_mode_t dev_gpio_mode;
mode_dev_gpio_pull_t dev_gpio_pull;
uint8_t dev_bit_lsb_msb;
uint8_t divider;
uint8_t tdi_pin;
uint8_t tdo_pin;
uint8_t tms_pin;
uint8_t tck_pin;
uint8_t trst_pin;
} jtag_config_t;
typedef struct {
uint32_t dev_speed;
uint8_t dev_mode;
uint32_t dev_timing;
uint32_t can_id;
uint32_t filter_id_low;
uint32_t filter_id_high;
} can_config_t;
typedef struct {
mode_dev_gpio_mode_t dev_gpio_mode;
mode_dev_gpio_pull_t dev_gpio_pull;
uint8_t dev_bit_lsb_msb;
uint8_t dev_numbits;
} flash_config_t;
typedef struct {
mode_dev_gpio_mode_t dev_gpio_mode;
mode_dev_gpio_pull_t dev_gpio_pull;
uint8_t dev_bit_lsb_msb;
} onewire_config_t;
typedef struct {
mode_dev_gpio_mode_t dev_gpio_mode;
mode_dev_gpio_pull_t dev_gpio_pull;
uint8_t dev_bit_lsb_msb;
uint32_t dev_pulse_width;
uint32_t dev_pulse_gap;
} wiegand_config_t;
typedef struct {
uint32_t dev_speed;
mode_dev_gpio_mode_t dev_gpio_mode;
mode_dev_gpio_pull_t dev_gpio_pull;
uint8_t dev_bit_lsb_msb;
uint8_t clk_pin;
uint8_t sdi_pin;
uint8_t sdo_pin;
} rawwire_config_t;
typedef struct {
uint32_t trigger_masks[4];
uint32_t trigger_values[4];
uint32_t read_count;
uint32_t delay_count;
uint32_t divider;
uint8_t state;
uint8_t channels;
} sump_config_t;
typedef struct {
uint8_t dev_function;
} hydranfc_config_t;
#define MODE_CONFIG_PROTO_BUFFER_SIZE (256)
typedef struct {
uint8_t dev_num;
union {
uart_config_t uart;
i2c_config_t i2c;
spi_config_t spi;
jtag_config_t jtag;
can_config_t can;
flash_config_t flash;
onewire_config_t onewire;
rawwire_config_t rawwire;
wiegand_config_t wiegand;
sump_config_t sump;
hydranfc_config_t hydranfc;
} config;
uint8_t wwr : 1; // write with read
uint8_t buffer_tx[MODE_CONFIG_PROTO_BUFFER_SIZE];
uint8_t buffer_rx[MODE_CONFIG_PROTO_BUFFER_SIZE];
} mode_config_proto_t;
typedef struct {
uint32_t num;
uint32_t repeat;
uint32_t cmd; /* command defined in hydrabus_mode_cmd() */
} mode_config_command_t;
typedef struct t_mode_config {
mode_config_proto_t proto;
const struct mode_exec_t *exec;
mode_config_command_t cmd;
} t_mode_config;
#endif /* _MODE_CONFIG_H_ */