-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrinityRackCV_HW.h
113 lines (77 loc) · 3.08 KB
/
trinityRackCV_HW.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
#include "trinityRackCV_HW_settings.h"
#ifndef TRINITYRACKCV_HW_H_
#define TRINITYRACKCV_HW_H_
#include <IHWLayer.h>
#include <Arduino.h>
#include <avr/pgmspace.h>
class trinityRackCV_HW : public IHWLayer {
public:
// sets up all the pins, timers and SPI interface
// call this before using any other method from this class
void init(void(*clockInCallback)());
/*** CV in***/
uint8_t getCVValue(uint8_t index);
uint8_t getLastCVValue(uint8_t index){return lastCVValues[index];}
bool CVMoved(uint8_t index);
/*** CV out ***/
void setDAC(uint8_t number, uint8_t value);
bool getClockState();
/**TIMING**/
// the number of bastl cycles elapsed since startup
// this number will overflow after some minutes; you have to deal with that in the layer above
// using a longer datatype would prevent this but at the cost of longer computation time
uint32_t getElapsedBastlCyclesLong() {return bastlCycles;}
uint16_t getElapsedBastlCycles() {return bastlCycles>>16;}
// returns the relation between bastl cycles and seconds
// this value is dependent on the hardware update frequency that you can set by a define
// use this to map real time processes (like BMP) to bastlCycles
uint16_t getBastlCyclesPerSecond();
// Buttons //
virtual ButtonState getButtonState(unsigned char index) {return UP;}
// LEDs //
virtual void setLED(unsigned char index, LedState state) {}
//virtual void setLED(unsigned char index, unsigned char brightness, unsigned char blinkTime = 0) = 0;
// Knobs //
virtual unsigned char getKnobValue(unsigned char index) {return 0;}
virtual void freezeKnob(uint8_t number, uint8_t value) {};
virtual void setKnobLED(uint8_t number, uint8_t value) {};
virtual void setKnobLEDTracking(uint8_t number, bool) {};
// RAM //
virtual unsigned char readSRAM(long address) {return 0;}
virtual void readSRAM(long address, unsigned char * data, unsigned int size) {};
virtual void writeSRAM(long address, unsigned char data) {};
virtual void writeSRAM(long address, unsigned char * data, unsigned int size) {};
// EEPROM //
virtual bool writeEEPROM(uint16_t address, uint8_t* byteArray, uint16_t numbBytes) {return false;}
virtual void readEEPROM(uint16_t address, uint8_t* byteArray, uint16_t numbBytes) {}
// general operation
virtual void giveSomeTime() {};
virtual void giveAllTime() {};
// only called by ISR routine.
// they would be declared private but this would prevent the ISR from accessing them
// there are workarounds for this but as they come at a cost I just left it like this
void isr_updateADC();
void isr_updateDAC();
void isr_updateClockIn();
inline void incrementBastlCycles() {bastlCycles++;}
private:
/**TIMING**/
uint32_t bastlCycles;
/** CLOCK IN **/
bool clockInState;
void (*clockInCallback)();
/** CV out */
static const uint8_t numbDACs = 8;
uint8_t dacCount;
uint8_t dacValues[numbDACs];
uint8_t dacValuesSent[numbDACs];
void DACInit();
void zeroDACs();
/** CV in */
static const uint8_t numbCVs = 6;
uint8_t CVValues[numbCVs];
uint8_t lastCVValues[numbCVs];
uint8_t CVCount;
uint8_t CVMovedHash;
};
#endif