Skip to content

Commit

Permalink
SPI now works but is currently no faster than bit banging...
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulZC committed Apr 7, 2020
1 parent 02e3091 commit 19db4df
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 33 deletions.
25 changes: 16 additions & 9 deletions platforms/apollo3/fastpin_apollo3.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ _FL_DEFPIN(15); _FL_DEFPIN(16); _FL_DEFPIN(17); _FL_DEFPIN(18); _FL_DEFPIN(19);
_FL_DEFPIN(20); _FL_DEFPIN(21); _FL_DEFPIN(22); _FL_DEFPIN(23); _FL_DEFPIN(24);
_FL_DEFPIN(25); _FL_DEFPIN(26); _FL_DEFPIN(27); _FL_DEFPIN(28); _FL_DEFPIN(29);
_FL_DEFPIN(30); _FL_DEFPIN(31);

#define SPI_DATA MOSI
#define SPI_CLOCK SCK
//These two lines are commented out as dedicates SPI support using fastShiftOut produces
//glitchy results that is slower than bit banging. TO DO: implement 'proper' SPI functionality
//#define SPI_DATA MOSI
//#define SPI_CLOCK SCK

#define HAS_HARDWARE_PIN_SUPPORT 1

Expand All @@ -97,8 +98,10 @@ _FL_DEFPIN(10); _FL_DEFPIN(11); _FL_DEFPIN(12); _FL_DEFPIN(13); _FL_DEFPIN(14);
_FL_DEFPIN(15); _FL_DEFPIN(16); _FL_DEFPIN(17); _FL_DEFPIN(18); _FL_DEFPIN(19);
_FL_DEFPIN(20); _FL_DEFPIN(21); _FL_DEFPIN(22); _FL_DEFPIN(23);

#define SPI_DATA MOSI
#define SPI_CLOCK SCK
//These two lines are commented out as dedicates SPI support using fastShiftOut produces
//glitchy results that is slower than bit banging. TO DO: implement 'proper' SPI functionality
//#define SPI_DATA MOSI
//#define SPI_CLOCK SCK

#define HAS_HARDWARE_PIN_SUPPORT 1

Expand All @@ -112,8 +115,10 @@ _FL_DEFPIN(15); _FL_DEFPIN(16); _FL_DEFPIN(17); _FL_DEFPIN(18); _FL_DEFPIN(19);
_FL_DEFPIN(20); _FL_DEFPIN(21); _FL_DEFPIN(22); _FL_DEFPIN(23); _FL_DEFPIN(24);
_FL_DEFPIN(25); _FL_DEFPIN(26); _FL_DEFPIN(27); _FL_DEFPIN(28);

#define SPI_DATA MOSI
#define SPI_CLOCK SCK
//These two lines are commented out as dedicates SPI support using fastShiftOut produces
//glitchy results that is slower than bit banging. TO DO: implement 'proper' SPI functionality
//#define SPI_DATA MOSI
//#define SPI_CLOCK SCK

#define HAS_HARDWARE_PIN_SUPPORT 1

Expand All @@ -133,8 +138,10 @@ _FL_DEFPIN(35); _FL_DEFPIN(36); _FL_DEFPIN(37); _FL_DEFPIN(38); _FL_DEFPIN(39);
_FL_DEFPIN(40); _FL_DEFPIN(41); _FL_DEFPIN(42); _FL_DEFPIN(43); _FL_DEFPIN(44);
_FL_DEFPIN(45); _FL_DEFPIN(47); _FL_DEFPIN(48); _FL_DEFPIN(49);

#define SPI_DATA MOSI
#define SPI_CLOCK SCK
//These two lines are commented out as dedicates SPI support using fastShiftOut produces
//glitchy results that is slower than bit banging. TO DO: implement 'proper' SPI functionality
//#define SPI_DATA MOSI
//#define SPI_CLOCK SCK

#define HAS_HARDWARE_PIN_SUPPORT 1

Expand Down
47 changes: 23 additions & 24 deletions platforms/apollo3/fastspi_apollo3.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef __INC_FASTSPI_APOLLO3_H
#define __INC_FASTSPI_APOLLO3_H

//#include "FastLED.h"
#include "FastLED.h"

FASTLED_NAMESPACE_BEGIN

Expand All @@ -11,15 +11,13 @@ class APOLLO3HardwareSPIOutput {

public:
APOLLO3HardwareSPIOutput() { m_pSelect = NULL; }
APOLLO3HArdwareSPIOutput(Selectable *pSelect) { m_pSelect = pSelect; }
APOLLO3HardwareSPIOutput(Selectable *pSelect) { m_pSelect = pSelect; }

// set the object representing the selectable
void setSelect(Selectable *pSelect) { /* TODO */ }
void setSelect(Selectable *pSelect) { m_pSelect = pSelect; }

// initialize the SPI subssytem
void init() {
pinMode(_DATA_PIN, OUTPUT); am_hal_gpio_fastgpio_enable(_DATA_PIN);
pinMode(_CLOCK_PIN, OUTPUT); am_hal_gpio_fastgpio_enable(_CLOCK_PIN);
//enableBurstMode(); //Optional. Go to 96MHz. Roughly doubles the speed of shiftOut and fastShiftOut
enableFastShift(_DATA_PIN, _CLOCK_PIN);
}
Expand All @@ -40,8 +38,8 @@ class APOLLO3HardwareSPIOutput {

// write a word out via SPI (returns immediately on writing register)
static void writeWord(uint16_t w) {
writeByte((uint8_t)((w >> 8) && 0xff));
writeByte((uint8_t)(w && 0xff));
writeByte((uint8_t)((w >> 8) & 0xff));
writeByte((uint8_t)(w & 0xff));
}

// A raw set of writing byte values, assumes setup/init/waiting done elsewhere
Expand All @@ -51,28 +49,30 @@ class APOLLO3HardwareSPIOutput {

// A full cycle of writing a value for len bytes, including select, release, and waiting
void writeBytesValue(uint8_t value, int len) {
select(); writeBytesValueRaw(value, len); release();
//select();
writeBytesValueRaw(value, len);
//release();
}

// A full cycle of writing a value for len bytes, including select, release, and waiting
template <class D> void writeBytes(register uint8_t *data, int len) {
uint8_t *end = data + len;
select();
//select();
// could be optimized to write 16bit words out instead of 8bit bytes
while(data != end) {
writeByte(D::adjust(*data++));
}
D::postBlock(len);
waitFully();
release();
//waitFully();
//release();
}

// A full cycle of writing a value for len bytes, including select, release, and waiting
void writeBytes(register uint8_t *data, int len) { writeBytes<DATA_NOP>(data, len); }

// write a single bit out, which bit from the passed in byte is determined by template parameter
template <uint8_t BIT> inline static void writeBit(uint8_t b) {
waitFully();
//waitFully();
if(b & (1 << BIT)) {
FastPin<_DATA_PIN>::hi();
} else {
Expand All @@ -86,30 +86,29 @@ class APOLLO3HardwareSPIOutput {
// write a block of uint8_ts out in groups of three. len is the total number of uint8_ts to write out. The template
// parameters indicate how many uint8_ts to skip at the beginning and/or end of each grouping
template <uint8_t FLAGS, class D, EOrder RGB_ORDER> void writePixels(PixelController<RGB_ORDER> pixels) {
select();
//select();

int len = pixels.mLen; // unused?
int len = pixels.mLen;

if(FLAGS & FLAG_START_BIT) {
while(pixels.has(1)) {
//select();
while(pixels.has(1)) {
if(FLAGS & FLAG_START_BIT) {
writeBit<0>(1);
writeByte(D::adjust(pixels.loadAndScale0()));
writeByte(D::adjust(pixels.loadAndScale1()));
writeByte(D::adjust(pixels.loadAndScale2()));
pixels.advanceData();
pixels.stepDithering();
}
} else {
while(pixels.has(1)) {
} else {
writeByte(D::adjust(pixels.loadAndScale0()));
writeByte(D::adjust(pixels.loadAndScale1()));
writeByte(D::adjust(pixels.loadAndScale2()));
pixels.advanceData();
pixels.stepDithering();
}

pixels.advanceData();
pixels.stepDithering();
}
D::postBlock(len);
release();
//waitFully();
//release();
}

};
Expand Down

0 comments on commit 19db4df

Please sign in to comment.