summaryrefslogtreecommitdiff
path: root/src/driver/resistive_load.cc
blob: 460e0f739fd28bc0acb372b4ea4c94860fa03ebc (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
/*
 * Copyright 2020 Birte Kristina Friesel
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */
#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

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);
}

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);
}

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);
}

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);
}

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);
}

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);
}

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);
}

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);
}

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;