Repository navigation
Expand file tree
/
Copy pathBoard.h
More file actions
93 lines (62 loc) · 1.74 KB
/
Copy pathBoard.h
File metadata and controls
93 lines (62 loc) · 1.74 KB
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
#include <inttypes.h>
// Declare buttons
// Call buttons
#define C1 5
#define C2 6
#define C3 7
#define C4 8
#define C5 9
// Channel select
#define CH0 A3
#define CH1 A4
// Station select
#define ST0 0
#define ST1 1
// Not used on current board due to lack of space for call buttons
#define ST2 4
#define MIC A0
#define SPKR 3
#define POWER_PIN A5
// Not connected, but we output signals on these pins for debugging
// bringing these out on a future board rev to tiny LEDs would be clever...
#define RX_LED A1
#define TX_LED A2
#define BUTTON_DEBOUNCE_TICKS 320
#define SAMPLE_RATE 8000
#define EVENT_BUTTON_UP 1
#define EVENT_BUTTON_DOWN 2
// Event handlers should return true if the want the event flag to be cleared
typedef bool (*ButtonEventHandler)(void);
class Board {
volatile bool bounce;
volatile int buttonState;
uint16_t bounceTicks;
int sampleRate;
int _nodeId();
ButtonEventHandler buttonDownEventHandler;
ButtonEventHandler buttonUpEventHandler;
public:
Board();
volatile uint16_t ticks;
int buttonEvents;
int buttons;
uint8_t boardId;
void initialise();
void setButtonDownHandler(ButtonEventHandler handler);
void setButtonUpHandler(ButtonEventHandler handler);
void handleButtonEvents();
// Debounce the buttons and return any events generated
uint8_t getButtonEvents();
int readButtons();
// Set the buttons up as inputs with pullups enabled
// Enable pin-change interrupts
void initialiseButtons();
void handleButtonInterrupt();
void showSource(int source);
void setAnalogEnabled(bool enabled);
void setADCEnabled(bool enabled);
void setDACEnabled(bool enabled);
// Start the timers which are used to drive the DAC and ADC
// Also used to count ticks for timeouts and button debounce
void startTimers();
};