summaryrefslogtreecommitdiff
path: root/src/driver/resistive_load.cc
blob: 0c3009c06d1e42f30684ab88ed7d3da9a2ed2a01 (plain)
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
#include "driver/resistive_load.h"
#include "driver/gpio.h"
#include "arch.h"

#ifndef RESISTIVE_LOAD_PIN1
#error RESISTIVE_LOAD_PIN1 must be set
#endif

#ifndef RESISTIVE_LOAD_PIN2
#error RESISTIVE_LOAD_PIN2 must be set
#endif

#ifndef RESISTIVE_LOAD_PIN3
#error RESISTIVE_LOAD_PIN3 must be set
#endif

#ifndef RESISTIVE_LOAD_PIN4
#error RESISTIVE_LOAD_PIN4 must be set
#endif

#ifndef RESISTIVE_LOAD_PIN5
#error RESISTIVE_LOAD_PIN5 must be set
#endif

#ifndef RESISTIVE_LOAD_PIN6
#error RESISTIVE_LOAD_PIN6 must be set
#endif

void ResistiveLoad::setup()
{
	gpio.output(RESISTIVE_LOAD_PIN1, 0);
	gpio.output(RESISTIVE_LOAD_PIN2, 0);
	gpio.output(RESISTIVE_LOAD_PIN3, 0);
	gpio.output(RESISTIVE_LOAD_PIN4, 0);
    gpio.output(RESISTIVE_LOAD_PIN5, 0);
    gpio.output(RESISTIVE_LOAD_PIN6, 0);
}

void ResistiveLoad::switchToNone()
{
	gpio.write(RESISTIVE_LOAD_PIN1, 0);
	gpio.write(RESISTIVE_LOAD_PIN2, 0);
	gpio.write(RESISTIVE_LOAD_PIN3, 0);
	gpio.write(RESISTIVE_LOAD_PIN4, 0);
    gpio.write(RESISTIVE_LOAD_PIN5, 0);
    gpio.write(RESISTIVE_LOAD_PIN6, 0);
}

void ResistiveLoad::switchTo750()
{
	gpio.write(RESISTIVE_LOAD_PIN1, 1);
	gpio.write(RESISTIVE_LOAD_PIN2, 1);
	gpio.write(RESISTIVE_LOAD_PIN3, 0);
	gpio.write(RESISTIVE_LOAD_PIN4, 0);
    gpio.write(RESISTIVE_LOAD_PIN5, 0);
    gpio.write(RESISTIVE_LOAD_PIN6, 0);
}

void ResistiveLoad::switchTo1K0()
{
	gpio.write(RESISTIVE_LOAD_PIN1, 1);
	gpio.write(RESISTIVE_LOAD_PIN2, 0);
	gpio.write(RESISTIVE_LOAD_PIN3, 0);
	gpio.write(RESISTIVE_LOAD_PIN4, 0);
    gpio.write(RESISTIVE_LOAD_PIN5, 0);
    gpio.write(RESISTIVE_LOAD_PIN6, 0);
}

void ResistiveLoad::switchTo2K4()
{
	gpio.write(RESISTIVE_LOAD_PIN1, 0);
	gpio.write(RESISTIVE_LOAD_PIN2, 1);
	gpio.write(RESISTIVE_LOAD_PIN3, 0);
	gpio.write(RESISTIVE_LOAD_PIN4, 1);
    gpio.write(RESISTIVE_LOAD_PIN5, 0);
    gpio.write(RESISTIVE_LOAD_PIN6, 0);
}

void ResistiveLoad::switchTo3K3()
{
	gpio.write(RESISTIVE_LOAD_PIN1, 0);
	gpio.write(RESISTIVE_LOAD_PIN2, 1);
	gpio.write(RESISTIVE_LOAD_PIN3, 0);
	gpio.write(RESISTIVE_LOAD_PIN4, 0);
    gpio.write(RESISTIVE_LOAD_PIN5, 0);
    gpio.write(RESISTIVE_LOAD_PIN6, 0);
}

void ResistiveLoad::switchTo10K()
{
	gpio.write(RESISTIVE_LOAD_PIN1, 0);
	gpio.write(RESISTIVE_LOAD_PIN2, 0);
	gpio.write(RESISTIVE_LOAD_PIN3, 0);
	gpio.write(RESISTIVE_LOAD_PIN4, 1);
    gpio.write(RESISTIVE_LOAD_PIN5, 0);
    gpio.write(RESISTIVE_LOAD_PIN6, 0);
}

void ResistiveLoad::switchTo47K()
{
	gpio.write(RESISTIVE_LOAD_PIN1, 0);
	gpio.write(RESISTIVE_LOAD_PIN2, 0);
	gpio.write(RESISTIVE_LOAD_PIN3, 1);
	gpio.write(RESISTIVE_LOAD_PIN4, 0);
    gpio.write(RESISTIVE_LOAD_PIN5, 0);
    gpio.write(RESISTIVE_LOAD_PIN6, 0);
}

void ResistiveLoad::switchTo2K2()
{
    gpio.write(RESISTIVE_LOAD_PIN1, 0);
    gpio.write(RESISTIVE_LOAD_PIN2, 0);
    gpio.write(RESISTIVE_LOAD_PIN3, 0);
    gpio.write(RESISTIVE_LOAD_PIN4, 0);
    gpio.write(RESISTIVE_LOAD_PIN5, 1);
    gpio.write(RESISTIVE_LOAD_PIN6, 0);
}

void ResistiveLoad::switchTo4K7()
{
    gpio.write(RESISTIVE_LOAD_PIN1, 0);
    gpio.write(RESISTIVE_LOAD_PIN2, 0);
    gpio.write(RESISTIVE_LOAD_PIN3, 0);
    gpio.write(RESISTIVE_LOAD_PIN4, 0);
    gpio.write(RESISTIVE_LOAD_PIN5, 0);
    gpio.write(RESISTIVE_LOAD_PIN6, 1);
}

void ResistiveLoad::switchTo680()
{
    gpio.write(RESISTIVE_LOAD_PIN1, 1);
    gpio.write(RESISTIVE_LOAD_PIN2, 0);
    gpio.write(RESISTIVE_LOAD_PIN3, 0);
    gpio.write(RESISTIVE_LOAD_PIN4, 0);
    gpio.write(RESISTIVE_LOAD_PIN5, 1);
    gpio.write(RESISTIVE_LOAD_PIN6, 0);
}

void ResistiveLoad::switchTo2K()
{
    gpio.write(RESISTIVE_LOAD_PIN1, 0);
    gpio.write(RESISTIVE_LOAD_PIN2, 0);
    gpio.write(RESISTIVE_LOAD_PIN3, 1);
    gpio.write(RESISTIVE_LOAD_PIN4, 0);
    gpio.write(RESISTIVE_LOAD_PIN5, 1);
    gpio.write(RESISTIVE_LOAD_PIN6, 0);
}

void ResistiveLoad::switchTo1K8()
{
    gpio.write(RESISTIVE_LOAD_PIN1, 0);
    gpio.write(RESISTIVE_LOAD_PIN2, 0);
    gpio.write(RESISTIVE_LOAD_PIN3, 0);
    gpio.write(RESISTIVE_LOAD_PIN4, 1);
    gpio.write(RESISTIVE_LOAD_PIN5, 1);
    gpio.write(RESISTIVE_LOAD_PIN6, 0);
}

void ResistiveLoad::switchTo1K3()
{
    gpio.write(RESISTIVE_LOAD_PIN1, 0);
    gpio.write(RESISTIVE_LOAD_PIN2, 1);
    gpio.write(RESISTIVE_LOAD_PIN3, 0);
    gpio.write(RESISTIVE_LOAD_PIN4, 0);
    gpio.write(RESISTIVE_LOAD_PIN5, 1);
    gpio.write(RESISTIVE_LOAD_PIN6, 0);
}

void ResistiveLoad::nop1K0(unsigned int duration_ms)
{
	switchTo1K0();
	arch.delay_ms(duration_ms);
	switchToNone();
}

void ResistiveLoad::nop2K4(unsigned int duration_ms)
{
	switchTo2K4();
	arch.delay_ms(duration_ms);
	switchToNone();
}

void ResistiveLoad::nop3K3(unsigned int duration_ms)
{
	switchTo3K3();
	arch.delay_ms(duration_ms);
	switchToNone();
}

void ResistiveLoad::nop10K(unsigned int duration_ms)
{
	switchTo10K();
	arch.delay_ms(duration_ms);
	switchToNone();
}

void ResistiveLoad::nop47K(unsigned int duration_ms)
{
	switchTo47K();
	arch.delay_ms(duration_ms);
	switchToNone();
}

ResistiveLoad resistiveLoad;