PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

96 lines
3.2KB

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