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
|
#ifndef __INC_FASTSPI_LED2_H
#define __INC_FASTSPI_LED2_H
#include "controller.h"
#include "fastpin.h"
#include "fastspi.h"
#include "clockless.h"
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// LPD8806 controller class - takes data/clock/latch pin values (N.B. should take an SPI definition)
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class LPD8806_ADJUST {
public:
static uint8_t adjust(register uint8_t data) { return (data>>1) | 0x80; }
};
template <uint8_t DATA_PIN, uint8_t CLOCK_PIN, uint8_t LATCH_PIN>
class LPD8806Controller : public CLEDController {
typedef AVRSPIOutput<DATA_PIN, CLOCK_PIN, LATCH_PIN, 0> SPI;
void clearLine(int nLeds) {
int n = ((nLeds + 63) >> 6);
SPI::writeBytesValue(0, n);
}
public:
virtual void init() {
SPI::init();
SPI::writeBytesValue(0x80, 1000);
clearLine(1000);
}
virtual void showRGB(uint8_t *data, int nLeds) {
SPI::template writeBytes3<LPD8806_ADJUST>(data, nLeds * 3);
clearLine(nLeds);
}
virtual void showARGB(uint8_t *data, int nLeds) {
SPI::template writeBytes3<1, LPD8806_ADJUST>(data, nLeds * 4);
clearLine(nLeds);
}
};
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// WS2801 definition
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <uint8_t DATA_PIN, uint8_t CLOCK_PIN, uint8_t LATCH_PIN>
class WS2801Controller : public CLEDController {
typedef AVRSPIOutput<DATA_PIN, CLOCK_PIN, LATCH_PIN, 0> SPI;
public:
virtual void init() {
SPI::init();
}
virtual void showRGB(uint8_t *data, int nLeds) {
SPI::template writeBytes3(data, nLeds * 3);
}
virtual void showARGB(uint8_t *data, int nLeds) {
SPI::template writeBytes3<1>(data, nLeds * 4);
}
};
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Clockless template instantiations
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 500ns, 1500ns, 500ns
template <uint8_t DATA_PIN>
class UCS1903Controller400Mhz : public ClocklessController<DATA_PIN, 8, 24, 8> {};
// 312.5ns, 312.5ns, 325ns
template <uint8_t DATA_PIN>
class TM1809Controller800Mhz : public ClocklessController<DATA_PIN, 5, 5, 10> {};
// 312.5ns, 312.5ns, 325ns
template <uint8_t DATA_PIN>
class WS2811Controller800Mhz : public ClocklessController<DATA_PIN, 5, 5, 10> {};
// 750NS, 750NS, 750NS
template <uint8_t DATA_PIN>
class TM1803Controller400Mhz : public ClocklessController<DATA_PIN, 12, 12, 12> {};
#endif
|