-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHardwareConfig.h
134 lines (111 loc) · 3.2 KB
/
HardwareConfig.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
/*
* HardwareConfig.h
*
* Created on: 09.02.2017
* Author: cybaer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef HARDWARECONFIG_H_
#define HARDWARECONFIG_H_
//#define ATMEGA328P
#undef HIGH
#undef LOW
#include "avrlib/base.h"
#include "avrlib/gpio.h"
#include "avrlib/devices/switch.h"
#include "avrlib/adc.h"
//#include "avrlib/i2c/i2c.h"
#include "MCP23017.h"
#include "analogSwitch.h"
using namespace avrlib;
template<typename Input, uint8_t ActiveLevel=0>
class EdgeTrigger
{
public:
static inline void init(void)
{
Input::set_mode(DIGITAL_INPUT);
if(ActiveLevel == 0) Input::High();
}
static inline bool isTriggered(void)
{
uint8_t in = Input::value();
bool ret = in != OldValue && in == ActiveLevel;
OldValue = in;
return ret;
}
private:
static uint8_t OldValue;
};
template<typename Input, uint8_t ActiveLevel>
uint8_t EdgeTrigger<Input, ActiveLevel>::OldValue;
typedef Inverter<Gpio<PortD, 2> > ClockIn; // 2
typedef EdgeTrigger<Gpio<PortD, 3>, 0> StartIn; // 3
typedef EdgeTrigger<Gpio<PortD, 4>, 0> ResetIn; // 4
typedef Gpio<PortB, 3> Input_A; // 11
typedef Gpio<PortB, 2> Input_B; // 10
typedef Gpio<PortB, 5> debug; // 13
typedef Gpio<PortB, 0> Start_; // 8
typedef Gpio<PortB, 1> Reset_; // 9
typedef DebouncedSwitch< Start_> StartButton;
typedef DebouncedSwitch< Reset_> ResetButton;
typedef Inverter<Gpio<PortD, 6> > Output_A; // 6
typedef Inverter<Gpio<PortD, 7> > Output_B; // 7
typedef Inverter<Gpio<PortD, 5> > ClockOut; // 5
//typedef I2cMaster<8, 4, 100000> I2C_bus;
typedef AnalogSwitch<Adc, 2, 8> SwitchMultivider;
typedef AnalogSwitch<Adc, 3, 8> SwitchMode;
typedef AnalogSwitch<Adc, 1, 3> SwitchLink; // 1x16; 2x8; ...
typedef AnalogSwitch<Adc, 7, 3> SwitchAction_A;
typedef AnalogSwitch<Adc, 0, 3> SwitchAction_B;
extern MCP23017 Extender;
extern Adc adc;
inline void initInputs(void)
{
ClockIn::set_mode(DIGITAL_INPUT);
ClockIn::High();
StartIn::init();
ResetIn::init();
Input_A::set_mode(DIGITAL_INPUT);
Input_A::Low();
Input_B::set_mode(DIGITAL_INPUT);
Input_B::Low();
StartButton::Init();
ResetButton::Init();
}
inline void initOutputs(void)
{
Output_A::set_mode(DIGITAL_OUTPUT);
Output_A::set_value(true);
Output_B::set_mode(DIGITAL_OUTPUT);
Output_B::set_value(true);
ClockOut::set_mode(DIGITAL_OUTPUT);
ClockOut::set_value(true);
debug::set_mode(DIGITAL_OUTPUT);
debug::Low();
}
inline void initAnalogIn(void)
{
adc.Init();
}
inline void initHW(void)
{
initInputs();
initOutputs();
initAnalogIn();
Extender.init(0);
Extender.writeGPIOA(0);
Extender.writeGPIOB(0);
}
#endif /* HARDWARECONFIG_H_ */