Welcome to mirror list, hosted at ThFree Co, Russian Federation.

FastSPI_LED2.h - github.com/FastLED/FastLED.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4cb6048b37ed9cd98bb91bbf33d08973cf3273b6 (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
#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, uint8_t SPI_SPEED = 0 >
class LPD8806Controller : public CLEDController {
	typedef AVRSPIOutput<DATA_PIN, CLOCK_PIN, LATCH_PIN, SPI_SPEED> 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, uint8_t SPI_SPEED = 1>
class WS2801Controller : public CLEDController {
	typedef AVRSPIOutput<DATA_PIN, CLOCK_PIN, LATCH_PIN, SPI_SPEED> 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, NS(500), NS(1500), NS(500)> {};
#if NO_TIME(500, 1500, 500) 
#pragma message "No enough clock cycles available for the UCS103"
#endif

// 312.5ns, 312.5ns, 325ns
template <uint8_t DATA_PIN>
class TM1809Controller800Mhz : public ClocklessController<DATA_PIN, NS(350), NS(350), NS(550)> {};
#if NO_TIME(350, 350, 550) 
#pragma message "No enough clock cycles available for the UCS103"
#endif

// 380s, 380ns, 725ns
template <uint8_t DATA_PIN>
class WS2811Controller800Mhz : public ClocklessController<DATA_PIN, NS(350), NS(350), NS(550)> {};
#if NO_TIME(350, 350, 550) 
#pragma message "No enough clock cycles available for the UCS103"
#endif

// 750NS, 750NS, 750NS
template <uint8_t DATA_PIN>
class TM1803Controller400Mhz : public ClocklessController<DATA_PIN, NS(750), NS(750), NS(750)> {};
#if NO_TIME(750, 750, 750) 
#pragma message "No enough clock cycles available for the UCS103"
#endif

#endif