-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathhardware.h
108 lines (98 loc) · 2.42 KB
/
hardware.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
// Hardware-specific definitions
// (C) 2012 Nonolith Labs
// Authors:
// Kevin Mehall
// Ian Daniher
// Licensed under the terms of the GNU GPLv3+
// MCP4922 flags
#define DACFLAG_CHANNEL (1<<3)
#define DACFLAG_BUF (1<<2)
#define DACFLAG_NO_MULT_REF (1<<1)
#define DACFLAG_ENABLE (1<<0)
// DAC-specific pinmappings
#define DAC_SHDN (1 << 2)
#define LDAC (1 << 3)
#define CS (1 << 4)
#define SCK (1 << 5)
#define TXD1 (1 << 7)
// PORTC is mapped to VPORT0 for speed
inline void CS_LO(void) ATTR_ALWAYS_INLINE;
inline void CS_LO(void){VPORT0.OUT &= ~CS;}
inline void CS_HI(void) ATTR_ALWAYS_INLINE;
inline void CS_HI(void){VPORT0.OUT |= CS;}
// generic pinmappings
#define SHDN_INS_A (1 << 5)
#define SWMODE_A (1 << 3)
#define SWMODE_B (1 << 2)
#define SHDN_INS_B (1 << 1)
#define EN_OPA_A (1 << 0)
#define EN_OPA_B (1 << 0)
#define TFLAG_A (1 << 4)
#define TFLAG_B (1 << 1)
#define ISET_B (1 << 3)
#define ISET_A (1 << 2)
/* Configure the shutdown/enable pin states and set the SPDT switch states. */
inline void configChannelA(chan_mode state) ATTR_ALWAYS_INLINE;
inline void configChannelA(chan_mode state){
switch (state) {
case SVMI: // source voltage, measure current
PORTD.OUTSET = SWMODE_A;
PORTD.OUTCLR = SHDN_INS_A;
break;
case SIMV: // source current, measure voltage
PORTD.OUTCLR = SWMODE_A | SHDN_INS_A;
break;
case DISABLED: // high impedance
PORTD.OUTSET = SHDN_INS_A;
PORTD.OUTCLR = SWMODE_A;
break;
case CALIBRATE: // MAX9919F on, OPA567 off - used to characterize the '9919
PORTD.OUTCLR = SHDN_INS_A;
PORTD.OUTSET = SWMODE_A;
break;
}
}
inline void configChannelB(chan_mode state) ATTR_ALWAYS_INLINE;
inline void configChannelB(chan_mode state){
switch (state) {
case SVMI:
PORTC.OUTSET = SWMODE_B;
PORTD.OUTCLR = SHDN_INS_B;
break;
case SIMV:
PORTC.OUTCLR = SWMODE_B;
PORTD.OUTCLR = SHDN_INS_B;
break;
case DISABLED:
PORTC.OUTCLR = SWMODE_B;
PORTD.OUTSET = SHDN_INS_B;
break;
case CALIBRATE:
PORTD.OUTCLR = SHDN_INS_B;
PORTC.OUTSET = SWMODE_A;
}
}
inline void enableOutA(chan_mode state){
switch (state) {
case SVMI:
case SIMV:
PORTD.OUTSET = EN_OPA_A;
break;
case DISABLED:
case CALIBRATE:
PORTD.OUTCLR = EN_OPA_A;
break;
}
}
inline void enableOutB(chan_mode state){
switch (state) {
case SVMI:
case SIMV:
PORTC.OUTSET = EN_OPA_B;
break;
case DISABLED:
case CALIBRATE:
PORTC.OUTCLR = EN_OPA_B;
break;
}
}