Permalink
Browse files

rename some macros

  • Loading branch information...
1 parent 92ca1e5 commit c4dc57779344d2d8e1d0d90fe97fb7d2ed74f26a @neophob committed Mar 25, 2012
Showing with 18 additions and 15 deletions.
  1. +18 −15 Neophob_LPD6803.cpp
View
@@ -9,9 +9,6 @@
#include "SPI.h"
#include "Neophob_LPD6803.h"
-#define SPI_A(data) SPDR=data; /*the SPI data register (SPDR) holds the byte which is about to be shifted out the MOSI line */
-#define SPI_B while(!(SPSR & (1<<SPIF))); /* Wait until last bytes is transmitted. */
-
//some local variables, ised in isr
static uint8_t isDirty;
static uint16_t prettyUglyCopyOfNumPixels;
@@ -33,38 +30,42 @@ Neophob_LPD6803::Neophob_LPD6803(uint16_t n) {
setPixelColor(i,0);
}
}
+/*the SPI data register (SPDR) holds the byte which is about to be shifted out the MOSI line */
+#define SPI_LOAD_BYTE(data) SPDR=data
+/* Wait until last bytes is transmitted. */
+#define SPI_WAIT_TILL_TRANSMITED while(!(SPSR & (1<<SPIF)))
+
//Interrupt routine.
//Frequency was set in setup(). Called once for every bit of data sent
//In your code, set global Sendmode to 0 to re-send the data to the pixels
//Otherwise it will just send clocks.
static void isr() {
- //static unsigned char nState=1;
- static unsigned char indx=0;
+ static uint16_t indx=0;
if(nState==1) {//send clock and check for color update (isDirty)
//SPI_A(0); //maybe, move at the end of the startSPI() method
if (isDirty==1) { //must we update the pixel value
nState = 0;
isDirty = 0;
- SPI_B;
- SPI_A(0);
+ SPI_LOAD_BYTE(0);
+ SPI_WAIT_TILL_TRANSMITED;
indx = 0;
pData = pDataStart; //reset index
return;
}
- SPI_B;
- SPI_A(0);
+ SPI_LOAD_BYTE(0);
+ SPI_WAIT_TILL_TRANSMITED;
return;
}
else { //feed out pixelbuffer
register uint16_t command;
command = *(pData++); //get current pixel
- SPI_B; //send 8bits
- SPI_A( (command>>8) & 0xFF);
+ SPI_LOAD_BYTE( (command>>8) & 0xFF);
+ SPI_WAIT_TILL_TRANSMITED; //send 8bits
- SPI_B; //send 8bits again
- SPI_A( command & 0xFF);
+ SPI_LOAD_BYTE( command & 0xFF);
+ SPI_WAIT_TILL_TRANSMITED; //send 8bits again
indx++; //are we done?
if(indx >= prettyUglyCopyOfNumPixels) {
@@ -101,14 +102,16 @@ void Neophob_LPD6803::startSPI(void) {
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
// SPI.setClockDivider(SPI_CLOCK_DIV8); // 2 MHz
- SPI.setClockDivider(SPI_CLOCK_DIV4); // 4 MHz
+ SPI.setClockDivider(SPI_CLOCK_DIV16); // 1 MHz
+// SPI.setClockDivider(SPI_CLOCK_DIV32); // 0.5 MHz
+// SPI.setClockDivider(SPI_CLOCK_DIV64); // 0.25 MHz
// LPD6803 can handle a data/PWM clock of up to 25 MHz, and 50 Ohm
// resistors on SPI lines for impedance matching. In practice and
// at short distances, 2 MHz seemed to work reliably enough without
// resistors, and 4 MHz was possible with a 220 Ohm resistor on the
// SPI clock line only. Your mileage may vary. Experiment!
- SPI_A(0); //maybe, move at the end of the startSPI() method
+ //SPI_A(0); //maybe, move at the end of the startSPI() method
}
uint16_t Neophob_LPD6803::numPixels(void) {

0 comments on commit c4dc577

Please sign in to comment.