FastLED 3.9.15
Loading...
Searching...
No Matches
fastspi_ref.h
Go to the documentation of this file.
1#pragma once
2
6
7#ifndef __INC_FASTSPI_ARM_SAM_H
8#define __INC_FASTSPI_ARM_SAM_H
9
10#if FASTLED_DOXYGEN // guard against the arduino ide idiotically including every header file
11#include "fl/system/fastled.h"
12#include "fl/stl/int.h"
14
17
20template <fl::u8 _DATA_PIN, fl::u8 _CLOCK_PIN, fl::u32 _SPI_CLOCK_DIVIDER>
22 Selectable *mPSelect;
23
24public:
27
29 SAMHArdwareSPIOutput(Selectable *pSelect) { mPSelect = pSelect; }
30
32 void setSelect(Selectable *pSelect) { /* TODO */ }
33
35 void init() { /* TODO */ }
36
38 void inline select() __attribute__((always_inline)) { if(mPSelect != nullptr) { mPSelect->select(); } }
39
41 void inline release() __attribute__((always_inline)) { if(mPSelect != nullptr) { mPSelect->release(); } }
42
44 waitFully();
45 release();
46 }
47
49 static void waitFully() { /* TODO */ }
50
52 static void writeByte(fl::u8 b) { /* TODO */ }
53
55 static void writeWord(fl::u16 w) { /* TODO */ }
56
58 static void writeBytesValueRaw(fl::u8 value, int len) {
59 while(len--) { writeByte(value); }
60 }
61
63 void writeBytesValue(fl::u8 value, int len) {
64 select(); writeBytesValueRaw(value, len); release();
65 }
66
68 template <class D> void writeBytes(FASTLED_REGISTER fl::u8 *data, int len) {
69 fl::u8 *end = data + len;
70 select();
71 // could be optimized to write 16bit words out instead of 8bit bytes
72 while(data != end) {
73 writeByte(D::adjust(*data++));
74 }
75 D::postBlock(len);
76 waitFully();
77 release();
78 }
79
81 void writeBytes(FASTLED_REGISTER fl::u8 *data, int len) { writeBytes<DATA_NOP>(data, len); }
82
84 template <fl::u8 BIT> inline static void writeBit(fl::u8 b) { /* TODO */ }
85
88 template <fl::u8 FLAGS, class D, EOrder RGB_ORDER> void writePixels(PixelController<RGB_ORDER> pixels, void* context = nullptr) {
89 select();
90 while(data != end) {
91 if(FLAGS & FLAG_START_BIT) {
92 writeBit<0>(1);
93 }
94 writeByte(D::adjust(pixels.loadAndScale0()));
95 writeByte(D::adjust(pixels.loadAndScale1()));
96 writeByte(D::adjust(pixels.loadAndScale2()));
97
98 pixels.advanceData();
99 pixels.stepDithering();
100 data += (3+skip);
101 }
102 D::postBlock(len);
103 release();
104 }
105
106};
107
108
109#endif
110
111#endif
112
void writeBytes(FASTLED_REGISTER fl::u8 *data, int len)
A full cycle of writing a value for len bytes, including select, release, and waiting.
Definition fastspi_ref.h:81
static void writeBit(fl::u8 b)
write a single bit out, which bit from the passed in byte is determined by template parameter
Definition fastspi_ref.h:84
static void writeByte(fl::u8 b)
write a byte out via SPI (returns immediately on writing register)
Definition fastspi_ref.h:52
SAMHArdwareSPIOutput(Selectable *pSelect)
Constructor with selectable.
Definition fastspi_ref.h:29
static void writeWord(fl::u16 w)
write a word out via SPI (returns immediately on writing register)
Definition fastspi_ref.h:55
SAMHardwareSPIOutput()
Default Constructor.
Definition fastspi_ref.h:26
void release()
release the CS select
Definition fastspi_ref.h:41
void setSelect(Selectable *pSelect)
set the object representing the selectable
Definition fastspi_ref.h:32
void select()
latch the CS select
Definition fastspi_ref.h:38
static void writeBytesValueRaw(fl::u8 value, int len)
A raw set of writing byte values, assumes setup/init/waiting done elsewhere.
Definition fastspi_ref.h:58
void init()
initialize the SPI subssytem
Definition fastspi_ref.h:35
void writePixels(PixelController< RGB_ORDER > pixels, void *context=nullptr)
write a block of uint8_ts out in groups of three.
Definition fastspi_ref.h:88
static void waitFully()
wait until all queued up data has been written
Definition fastspi_ref.h:49
void writeBytesValue(fl::u8 value, int len)
A full cycle of writing a value for len bytes, including select, release, and waiting.
Definition fastspi_ref.h:63
Selectable * mPSelect
Definition fastspi_ref.h:22
void writeBytes(FASTLED_REGISTER fl::u8 *data, int len)
A full cycle of writing a value for len bytes, including select, release, and waiting.
Definition fastspi_ref.h:68
A skeletal implementation of hardware SPI support.
Definition fastspi_ref.h:21
#define FLAG_START_BIT
Flag for the start of an SPI transaction.
Internal FastLED header for implementation files.
unsigned char u8
Definition stdint.h:131
#define FASTLED_REGISTER
#define FL_DISABLE_WARNING_PUSH
#define FL_DISABLE_WARNING_POP
#define FL_DISABLE_WARNING_DEPRECATED_REGISTER
FASTLED_FORCE_INLINE fl::u8 loadAndScale0(int lane, fl::u8 scale)
non-template alias of loadAndScale<0>()
FASTLED_FORCE_INLINE void advanceData()
Advance the data pointer forward, adjust position counter.
FASTLED_FORCE_INLINE fl::u8 loadAndScale1(int lane, fl::u8 scale)
non-template alias of loadAndScale<1>()
FASTLED_FORCE_INLINE void stepDithering()
Step the dithering forward - creates triangular wave that toggles between pixels.
FASTLED_FORCE_INLINE fl::u8 loadAndScale2(int lane, fl::u8 scale)
non-template alias of loadAndScale<2>()
Pixel controller class.