-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxpander.h
323 lines (238 loc) · 8.34 KB
/
xpander.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
/************************************************************************************************
* Äåôèíèöèè äëÿ ïåðåêëþ÷åíèÿ ýêñïàíäåðà (íà ðàçíûõ ïîðòàõ) ïðîòèâ ÷àñîâîé ñòðåëêè ïî ñõåìå
************************************************************************************************/
#ifndef _XPANDER_H
#define _XPANDER_H
#include "globdefs.h"
/****************************************************************************
* Äåôèíèöèè äëÿ ïîðòîâ èç ôàéëà <avr/iom165pa.h>,
* â ñëó÷àå êîíôëèêòîâ - ïåðåíåñòè âíóòðü c-ôàéëà
*****************************************************************************/
#define PINA 0x20
#define DDRA 0x21
#define PORTA 0x22
#define PINB 0x23
#define DDRB 0x24
#define PORTB 0x25
#define PINC 0x26
#define DDRC 0x27
#define PORTC 0x28
#define PIND 0x29
#define DDRD 0x2A
#define PORTD 0x2B
#define PINE 0x2C
#define DDRE 0x2D
#define PORTE 0x2E
#define PINF 0x2F
#define DDRF 0x30
#define PORTF 0x31
#define PING 0x32 /* Âñåãî øåñòü ïèíîâ!!! */
#define DDRG 0x33 /* Âñåãî ïÿòü íàïðàâëåíèé!!! */
#define PORTG 0x34 /* Âñåãî ïÿòü âûõîäîâ!!! */
#define PRR 0x64 /* Ðåãèñòð power reduction */
#define PRADC 0
#define PRUSART0 1
#define PRSPI 2
#define PRTIM1 3
/* ÀÖÏ */
#define ADMUX 0x7C
#define DIDR1 0x7F
#define DIDR0 0x7E
#define ADCSRA 0x7A
#define ADCSRB 0x7B
#define ADCH 0x79
#define ADCL 0x78
#define PIN0 0
#define PIN1 1
#define PIN2 2
#define PIN3 3
#define PIN4 4
#define PIN5 5
#define PIN6 6
#define PIN7 7
/************************************************************************************************
* Äåôèíèöèè äëÿ ïîðòîâ ïî àëôàâèòó
************************************************************************************************/
/* 1. --------------------- Ïîðòû A --------------------- */
#define MES_MUX_SELA_PIN PIN0 /* Íà âûõîä */
#define MES_MUX_SELA_PORT PORTA
#define MES_MUX_SELA_DIR DDRA
#define MES_MUX_SELB_PIN PIN3 /* Íà âûõîä */
#define MES_MUX_SELB_PORT PORTA
#define MES_MUX_SELB_DIR DDRA
#define FT232_RST_PIN PIN1
#define FT232_RST_PORT PORTA
#define FT232_RST_DIR DDRA
#define USB_IS_ENA_PIN PIN2
#define USB_IS_ENA_INPUT_PORT PINA // ÷òåíèå
#define USB_IS_ENA_DIR DDRA
#define SD_EN_PIN PIN4
#define SD_EN_PORT PORTA
#define SD_EN_DIR DDRA
#define AM_RST_PIN PIN5
#define AM_RST_PORT PORTA
#define AM_RST_DIR DDRA
#define GATEBURN_PIN PIN6
#define GATEBURN_PORT PORTA
#define GATEBURN_DIR DDRA
#define USB_VBUSDET_BUF_PIN PIN7
#define USB_VBUSDET_BUF_INPUT_PORT PINA // ÷òåíèå
#define USB_VBUSDET_BUF_DIR DDRA
/* 2. --------------------- Ïîðòû B --------------------- */
#define EXP_SS_PIN PIN0 /* ÷èïñåëåêò-ñëåéâñåëåêò SPI */
#define EXP_SS_INPUT_PORT PINB // âõîä
#define EXP_SS_DIR DDRB
#define EXP_SCK_PIN PIN1 /* êëîê SPI */
#define EXP_SCK_PORT PORTB
#define EXP_SCK_DIR DDRB
#define EXP_MOSI_PIN PIN2 /* MOSI */
#define EXP_MOSI_INPUT_PORT PINB // âõîä
#define EXP_MOSI_DIR DDRB
#define EXP_MISO_PIN PIN3 /* MISO */
#define EXP_MISO_PORT PORTB
#define EXP_MISO_DIR DDRB
#define HUB_RST_PIN PIN4
#define HUB_RST_PORT PORTB
#define HUB_RST_DIR DDRB
#define RTC_IRQ_PIN PIN6
#define RTC_IRQ_INPUT_PORT PINB // âõîä
#define RTC_IRQ_DIR DDRB
#define WUSB_EN_PIN PIN7
#define WUSB_EN_PORT PORTB
#define WUSB_EN_DIR DDRB
/* 3. --------------------- Ïîðòû C --------------------- */
#if defined GNS110_R2A_BOARD || defined GNS110_R2B_BOARD || defined GNS110_R2C_BOARD /* Âåðñèÿ ïëàòû R2a */
#define DAC4MHZ_CS_PIN PIN0
#define DAC4MHZ_CS_PORT PORTC
#define DAC4MHZ_CS_DIR DDRC
#else
#define DAC4MHZ_CS_PIN PIN2
#define DAC4MHZ_CS_PORT PORTG
#define DAC4MHZ_CS_DIR DDRG
#endif
#if defined GNS110_R2A_BOARD || defined GNS110_R2B_BOARD || defined GNS110_R2C_BOARD
#define APWR_EN_PIN PIN1 /* Analog POWER enable */
#define APWR_EN_PORT PORTC
#define APWR_EN_DIR DDRC
#else
#define APWR_EN_PIN PIN3 /* Analog POWER enable */
#define APWR_EN_PORT PORTG
#define APWR_EN_DIR DDRG
#endif
#if defined GNS110_R2A_BOARD || defined GNS110_R2B_BOARD || defined GNS110_R2C_BOARD
#define USBEXT33_EN_PIN PIN4
#define USBEXT33_EN_PORT PORTC
#define USBEXT33_EN_DIR DDRC
#else
#define USBEXT33_EN_PIN PIN2
#define USBEXT33_EN_PORT PORTC
#define USBEXT33_EN_DIR DDRC
#define ADXL_CS_PIN PIN4 /* PC4 - â "1" ïîêà */
#define ADXL_CS_PORT PORTC
#define ADXL_CS_DIR DDRC
#endif
#define DAC192MHZ_CS_PIN PIN5
#define DAC192MHZ_CS_PORT PORTC
#define DAC192MHZ_CS_DIR DDRC
#define DAC_TEST_CS_PIN PIN6
#define DAC_TEST_CS_PORT PORTC
#define DAC_TEST_CS_DIR DDRG
#define _1282_RESET_PIN PIN7
#define _1282_RESET_PORT PORTC
#define _1282_RESET_DIR DDRC
/* 4. --------------------- Ïîðòû D --------------------- */
#define GPS_EN_PIN PIN0
#define GPS_EN_PORT PORTD
#define GPS_EN_DIR DDRD
#define LSM_DRDY_PIN PIN1
#define LSM_DRDY_INPUT_PORT PIND // âõîä
#define LSM_DRDY_DIR DDRD
#define RELEBURN_CS_PIN PIN2
#define RELEBURN_CS_PORT PORTD
#define RELEBURN_CS_DIR DDRD
#define RELEAM_CS_PIN PIN3
#define RELEAM_CS_PORT PORTD
#define RELEAM_CS_DIR DDRD
#define RELEPOW_CS_PIN PIN4
#define RELEPOW_CS_PORT PORTD
#define RELEPOW_CS_DIR DDRD
#define USB_EN_PIN PIN5
#define USB_EN_PORT PORTD
#define USB_EN_DIR DDRD
#define RELE_CLR_PIN PIN6
#define RELE_CLR_PORT PORTD
#define RELE_CLR_DIR DDRD
#define RELE_SET_PIN PIN7
#define RELE_SET_PORT PORTD
#define RELE_SET_DIR DDRD
/* 5. --------------------- Ïîðòû E --------------------- */
#define UART_SELA_PIN PIN1
#define UART_SELA_PORT PORTE
#define UART_SELA_DIR DDRE
#define UART_SELB_PIN PIN2
#define UART_SELB_PORT PORTE
#define UART_SELB_DIR DDRE
#define SD_SRCSEL_PIN PIN3
#define SD_SRCSEL_PORT PORTE
#define SD_SRCSEL_DIR DDRE
#define AT_SD_WP_PIN PIN4
#define AT_SD_WP_PORT PORTE
#define AT_SD_WP_DIR DDRE
#define AT_SD_CD_PIN PIN5
#define AT_SD_CD_PORT PORTE
#define AT_SD_CD_DIR DDRE
/* 6. --------------------- Ïîðòû F --------------------- */
#if defined GNS110_R2A_BOARD || defined GNS110_R2B_BOARD || defined GNS110_R2C_BOARD
#define ADC_PORT_PIN (1 << PIN0) | (1 << PIN1) | (1 << PIN2) | (1 << PIN3) | (1 << PIN4)
#else
#define ADC_PORT_PIN (1 << PIN0) | (1 << PIN1) | (1 << PIN2) | (1 << PIN3)
#endif
#define ADC_PORT_INPUT_PORT PINF
#define ADC_PORT_DIR DDRF
/* 7. --------------------- Ïîðòû G --------------------- */
#define LED1_PIN PIN0
#define LED1_PORT PORTG
#define LED1_DIR DDRG
#define LED2_PIN PIN1
#define LED2_PORT PORTG
#define LED2_DIR DDRG
/* Âåðñèÿ ïëàòû R2a */
#if defined GNS110_R2A_BOARD || defined GNS110_R2B_BOARD || defined GNS110_R2C_BOARD
#define LED3_PIN PIN2
#define LED3_PORT PORTG
#define LED3_DIR DDRG
#define LED4_PIN PIN3
#define LED4_PORT PORTG
#define LED4_DIR DDRG
#else
#define RELEBURN2_PIN PIN3
#define RELEBURN2_PORT PORTC
#define RELEBURN2_DIR DDRC
#define LED3_PIN PIN0
#define LED3_PORT PORTC
#define LED3_DIR DDRC
#define LED4_PIN PIN1
#define LED4_PORT PORTC
#define LED4_DIR DDRC
#define AVR_RST_PIN PIN5
#define AVR_RST_INPUT_PORT PING // âõîä
#define AVR_RST_DIR DDRG
#define AUX_EN_PIN PIN4
#define AUX_EN_PORT PORTG
#define AUX_EN_DIR DDRG
#endif
/* Êîýôôèöèåíòû ïðåîáðàçîâàíèÿ íàïðÿæåíèÿ ÀÖÏ ïðè ðåôåðåíñå 3.3 Âîëüòà
* äëÿ ôîðìóëû:Umv = ADC * 3.3 / 1024 * 11 * 1000. Êîýôôèöèåíòû ÁÅÇ ÑÊÎÁÎÊ!!! */
#define ATMEGA_AMEND_COEF 1 /* Ïîïðàâî÷íûé êîýôôèöèåíò - ó÷èòûâàåò ïàäåíèå íà ñòàáèëèòðîíå - òîëüêî äëÿ U */
#define ATMEGA_VOLT_COEF 36300 >> 10 /* Äëÿ íàïðÿæåíèÿ U 3.3 * 11 * 1000 */
#define ATMEGA_AMPER_SUPPLY_COEF 330 >> 10 /* Äëÿ òîêà I 3.3 * 1000 */
#define ATMEGA_AMPER_BURN_COEF 3300 >> 10 /* Äëÿ òîêà I 3.3 * 1000 */
#define ATMEGA_AMPER_AM3_COEF 660 >> 10 /* Äëÿ òîêà I 3.3 * 1000 */
void adc_init(void); /* Íàñòðîèòü ÀÖÏ */
void pin_set(u8, u8);
void pin_clr(u8, u8);
void pin_hiz(u8, u8);
u8 pin_get(u8);
void adc_stop(void); /* Âûêëþ÷åíèå ÀÖÏ */
bool adc_get(void*);
#endif /* xpander.h */