FastLED  3.1
fastspi_ref.h
1 #ifndef __INC_FASTSPI_ARM_SAM_H
2 #define __INC_FASTSPI_ARM_SAM_H
3 
4 #if 0 // guard against the arduino ide idiotically including every header file
5 #include "FastLED.h"
6 
7 FASTLED_NAMESPACE_BEGIN
8 
9 // A skeletal implementation of hardware SPI support. Fill in the necessary code for init, waiting, and writing. The rest of
10 // the method implementations should provide a starting point, even if not hte most efficient to start with
11 template <uint8_t _DATA_PIN, uint8_t _CLOCK_PIN, uint8_t _SPI_CLOCK_DIVIDER>
13  Selectable *m_pSelect;
14 public:
15  SAMHardwareSPIOutput() { m_pSelect = NULL; }
16  SAMHArdwareSPIOutput(Selectable *pSelect) { m_pSelect = pSelect; }
17 
18  // set the object representing the selectable
19  void setSelect(Selectable *pSelect) { /* TODO */ }
20 
21  // initialize the SPI subssytem
22  void init() { /* TODO */ }
23 
24  // latch the CS select
25  void inline select() __attribute__((always_inline)) { if(m_pSelect != NULL) { m_pSelect->select(); } }
26 
27  // release the CS select
28  void inline release() __attribute__((always_inline)) { if(m_pSelect != NULL) { m_pSelect->release(); } }
29 
30  // wait until all queued up data has been written
31  static void waitFully() { /* TODO */ }
32 
33  // write a byte out via SPI (returns immediately on writing register)
34  static void writeByte(uint8_t b) { /* TODO */ }
35 
36  // write a word out via SPI (returns immediately on writing register)
37  static void writeWord(uint16_t w) { /* TODO */ }
38 
39  // A raw set of writing byte values, assumes setup/init/waiting done elsewhere
40  static void writeBytesValueRaw(uint8_t value, int len) {
41  while(len--) { writeByte(value); }
42  }
43 
44  // A full cycle of writing a value for len bytes, including select, release, and waiting
45  void writeBytesValue(uint8_t value, int len) {
46  select(); writeBytesValueRaw(value, len); release();
47  }
48 
49  // A full cycle of writing a value for len bytes, including select, release, and waiting
50  template <class D> void writeBytes(register uint8_t *data, int len) {
51  uint8_t *end = data + len;
52  select();
53  // could be optimized to write 16bit words out instead of 8bit bytes
54  while(data != end) {
55  writeByte(D::adjust(*data++));
56  }
57  D::postBlock(len);
58  waitFully();
59  release();
60  }
61 
62  // A full cycle of writing a value for len bytes, including select, release, and waiting
63  void writeBytes(register uint8_t *data, int len) { writeBytes<DATA_NOP>(data, len); }
64 
65  // write a single bit out, which bit from the passed in byte is determined by template parameter
66  template <uint8_t BIT> inline static void writeBit(uint8_t b) { /* TODO */ }
67 
68  // write a block of uint8_ts out in groups of three. len is the total number of uint8_ts to write out. The template
69  // parameters indicate how many uint8_ts to skip at the beginning and/or end of each grouping
70  template <uint8_t FLAGS, class D, EOrder RGB_ORDER> void writePixels(PixelController<RGB_ORDER> pixels) {
71  select();
72  while(data != end) {
73  if(FLAGS & FLAG_START_BIT) {
74  writeBit<0>(1);
75  }
76  writeByte(D::adjust(pixels.loadAndScale0()));
77  writeByte(D::adjust(pixels.loadAndScale1()));
78  writeByte(D::adjust(pixels.loadAndScale2()));
79 
80  pixels.advanceData();
81  pixels.stepDithering();
82  data += (3+skip);
83  }
84  D::postBlock(len);
85  release();
86  }
87 
88 };
89 
90 FASTLED_NAMESPACE_END
91 
92 #endif
93 
94 #endif
95 
central include file for FastLED, defines the CFastLED class/object
__attribute__((always_inline)) inline void swapbits8(bitswap_type in
Do an 8byte by 8bit rotation.
Definition: fastled_delay.h:92