Skip to content

Commit

Permalink
More compiler switches exposed to sketch
Browse files Browse the repository at this point in the history
  • Loading branch information
2dom committed Oct 26, 2019
1 parent 685e11d commit 4aa802a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 11 deletions.
37 changes: 27 additions & 10 deletions PxMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,36 @@ BSD license, check license.txt for more information
#define PxMATRIX_COLOR_DEPTH 8
#endif

// Defines the buffer height / the maximum height of the matrix
#ifndef PxMATRIX_MAX_HEIGHT
#define PxMATRIX_MAX_HEIGHT 64
#endif

// Defines the buffer width / the maximum width of the matrix
#ifndef PxMATRIX_MAX_WIDTH
#define PxMATRIX_MAX_WIDTH 64
#endif

// Defines how long we display things by default
#ifndef PxMATRIX_DEFAULT_SHOWTIME
#define PxMATRIX_DEFAULT_SHOWTIME 30
#endif

//#define double_buffer
// Defines the speed of the SPI bus (reducing this may help if you experience noisy images)
#ifndef PxMATRIX_SPI_FREQEUNCY
#define PxMATRIX_SPI_FREQEUNCY 20000000
#endif

// Creates a second buffer for backround drawing (doubles the required RAM)
#ifndef PxMATRIX_double_buffer
#define PxMATRIX_double_buffer false
#endif

// Legacy suppport
#ifndef double_buffer
#define PxMATRIX_double_buffer true
#endif


#include "Adafruit_GFX.h"
#include "Arduino.h"
Expand Down Expand Up @@ -182,7 +199,7 @@ class PxMATRIX : public Adafruit_GFX {

// the display buffer for the LED matrix
uint8_t PxMATRIX_buffer[PxMATRIX_COLOR_DEPTH][buffer_size];
#ifdef double_buffer
#ifdef PxMATRIX_double_buffer
uint8_t PxMATRIX_buffer2[PxMATRIX_COLOR_DEPTH][buffer_size];
#endif

Expand Down Expand Up @@ -341,7 +358,7 @@ inline void PxMATRIX::init(uint16_t width, uint16_t height,uint8_t LATCH, uint8_


clearDisplay(0);
#ifdef double_buffer
#ifdef PxMATRIX_double_buffer
clearDisplay(1);
#endif
}
Expand Down Expand Up @@ -708,7 +725,7 @@ inline void PxMATRIX::fillMatrixBuffer(int16_t x, int16_t y, uint8_t r, uint8_t

uint8_t (*PxMATRIX_bufferp)[PxMATRIX_COLOR_DEPTH][buffer_size] = &PxMATRIX_buffer;

#ifdef double_buffer
#ifdef PxMATRIX_double_buffer
PxMATRIX_bufferp = selected_buffer ? &PxMATRIX_buffer2 : &PxMATRIX_buffer;
#endif

Expand Down Expand Up @@ -738,15 +755,15 @@ inline void PxMATRIX::drawPixelRGB565(int16_t x, int16_t y, uint16_t color) {
uint8_t r = ((((color >> 11) & 0x1F) * 527) + 23) >> 6;
uint8_t g = ((((color >> 5) & 0x3F) * 259) + 33) >> 6;
uint8_t b = (((color & 0x1F) * 527) + 23) >> 6;
#ifdef double_buffer
#ifdef PxMATRIX_double_buffer
fillMatrixBuffer(x, y, r, g, b, !_active_buffer);
#else
fillMatrixBuffer(x, y, r, g, b, false);
#endif
}

inline void PxMATRIX::drawPixelRGB888(int16_t x, int16_t y, uint8_t r, uint8_t g,uint8_t b) {
#ifdef double_buffer
#ifdef PxMATRIX_double_buffer
fillMatrixBuffer(x, y, r, g, b, !_active_buffer);
#else
fillMatrixBuffer(x, y, r, g, b, false);
Expand Down Expand Up @@ -785,7 +802,7 @@ void PxMATRIX::spi_init(){

SPI.setDataMode(SPI_MODE0);
SPI.setBitOrder(MSBFIRST);
SPI.setFrequency(20000000);
SPI.setFrequency(PxMATRIX_SPI_FREQEUNCY);

}

Expand Down Expand Up @@ -966,7 +983,7 @@ void PxMATRIX::display(uint16_t show_time) {

uint8_t (*bufferp)[PxMATRIX_COLOR_DEPTH][buffer_size] = &PxMATRIX_buffer;

#ifdef double_buffer
#ifdef PxMATRIX_double_buffer
if(_active_buffer)
bufferp=&PxMATRIX_buffer2;
else
Expand Down Expand Up @@ -1186,7 +1203,7 @@ void PxMATRIX::displayTestPixel(uint16_t show_time) {
}

void PxMATRIX::clearDisplay(void) {
#ifdef double_buffer
#ifdef PxMATRIX_double_buffer
clearDisplay(!_active_buffer);
#else
clearDisplay(false);
Expand All @@ -1196,7 +1213,7 @@ void PxMATRIX::clearDisplay(void) {

// clear everything
void PxMATRIX::clearDisplay(bool selected_buffer) {
#ifdef double_buffer
#ifdef PxMATRIX_double_buffer
if(selected_buffer)
memset(PxMATRIX_buffer2, 0, PxMATRIX_COLOR_DEPTH*buffer_size);
else
Expand Down
20 changes: 19 additions & 1 deletion examples/pixeltime/pixeltime.ino
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
// This is how many color levels the display shows - the more the slower the update
//#define PxMATRIX_COLOR_DEPTH 8

// Defines the buffer height / the maximum height of the matrix
//#define PxMATRIX_MAX_HEIGHT 64

// Defines the buffer width / the maximum width of the matrix
//#define PxMATRIX_MAX_WIDTH 64

// Defines how long we display things by default
//#define PxMATRIX_DEFAULT_SHOWTIME 30

// Defines the speed of the SPI bus (reducing this may help if you experience noisy images)
//#define PxMATRIX_SPI_FREQEUNCY 20000000

// Creates a second buffer for backround drawing (doubles the required RAM)
//#define PxMATRIX_double_buffer true

#include <PxMatrix.h>

Expand Down Expand Up @@ -113,8 +130,9 @@ void display_update_enable(bool is_enable)

void setup() {
Serial.begin(9600);
// Define your display layout here, e.g. 1/8 step
// Define your display layout here, e.g. 1/8 step, and optional SPI pins begin(row_pattern, CLK, MOSI, MISO, SS)
display.begin(8);
//display.begin(8, 14, 13, 12, 4);

// Define multiplex implemention here {BINARY, STRAIGHT} (default is BINARY)
//display.setMuxPattern(BINARY);
Expand Down

0 comments on commit 4aa802a

Please sign in to comment.