Skip to content

Commit

Permalink
Merge pull request #37 from hramrach/master
Browse files Browse the repository at this point in the history
make pcdtest better testing utility
  • Loading branch information
drak7 authored Aug 5, 2019
2 parents 0587de2 + de4f487 commit e258105
Show file tree
Hide file tree
Showing 3 changed files with 214 additions and 149 deletions.
94 changes: 67 additions & 27 deletions Adafruit_PCD8544.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ static uint8_t xUpdateMin, xUpdateMax, yUpdateMin, yUpdateMax;
#endif



static void updateBoundingBox(uint8_t xmin, uint8_t ymin, uint8_t xmax, uint8_t ymax) {
#ifdef enablePartialUpdate
if (xmin < xUpdateMin) xUpdateMin = xmin;
Expand Down Expand Up @@ -175,6 +174,25 @@ uint8_t Adafruit_PCD8544::getPixel(int8_t x, int8_t y) {
return (pcd8544_buffer[x+ (y/8)*LCDWIDTH] >> (y%8)) & 0x1;
}

void Adafruit_PCD8544::initDisplay()
{

// toggle RST low to reset
if (_rst > 0) {
digitalWrite(_rst, LOW);
delay(500);
digitalWrite(_rst, HIGH);
}

setBias(_bias);
setContrast(_contrast);

// normal mode
command(PCD8544_FUNCTIONSET);

// Set display to Normal
command(PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYNORMAL);
}

void Adafruit_PCD8544::begin(uint8_t contrast, uint8_t bias) {
if (isHardwareSPI()) {
Expand Down Expand Up @@ -205,31 +223,11 @@ void Adafruit_PCD8544::begin(uint8_t contrast, uint8_t bias) {
if (_cs > 0)
pinMode(_cs, OUTPUT);

// toggle RST low to reset
if (_rst > 0) {
digitalWrite(_rst, LOW);
delay(500);
digitalWrite(_rst, HIGH);
}

// get into the EXTENDED mode!
command(PCD8544_FUNCTIONSET | PCD8544_EXTENDEDINSTRUCTION );

// LCD bias select (4 is optimal?)
command(PCD8544_SETBIAS | bias);

// set VOP
if (contrast > 0x7f)
contrast = 0x7f;

command( PCD8544_SETVOP | contrast); // Experimentally determined


// normal mode
command(PCD8544_FUNCTIONSET);

// Set display to Normal
command(PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYNORMAL);
_bias = bias;
_contrast = contrast;
_reinit_interval = 0;
_display_count = 0;
initDisplay();

// initial display line
// set page address
Expand Down Expand Up @@ -286,17 +284,59 @@ void Adafruit_PCD8544::setContrast(uint8_t val) {
if (val > 0x7f) {
val = 0x7f;
}
_contrast = val;
command(PCD8544_FUNCTIONSET | PCD8544_EXTENDEDINSTRUCTION );
command( PCD8544_SETVOP | val);
command(PCD8544_FUNCTIONSET);

}

void Adafruit_PCD8544::setBias(uint8_t val) {
if (val > 0x07) {
val = 0x07;
}
_bias = val;
command(PCD8544_FUNCTIONSET | PCD8544_EXTENDEDINSTRUCTION );
command(PCD8544_SETBIAS | val);
command(PCD8544_FUNCTIONSET);
}

uint8_t Adafruit_PCD8544::getBias()
{
return _bias;
}

uint8_t Adafruit_PCD8544::getContrast()
{
return _contrast;
}

void Adafruit_PCD8544::setReinitInterval(uint8_t val) {
_reinit_interval = val;
}
uint8_t Adafruit_PCD8544::getReinitInterval()
{
return _reinit_interval;
}

void Adafruit_PCD8544::display(void) {
uint8_t col, maxcol, p;


if(_reinit_interval) {
_display_count++;
if(_display_count >= _reinit_interval)
{
_display_count = 0;
initDisplay();
#ifdef enablePartialUpdate
yUpdateMin = 0;
yUpdateMax = LCDHEIGHT-1;
xUpdateMin = 0;
xUpdateMax = LCDWIDTH-1;
#endif
}
}

for(p = 0; p < 6; p++) {
#ifdef enablePartialUpdate
// check if this page is part of update
Expand Down
8 changes: 8 additions & 0 deletions Adafruit_PCD8544.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,25 @@ class Adafruit_PCD8544 : public Adafruit_GFX {
void data(uint8_t c);

void setContrast(uint8_t val);
void setBias(uint8_t val);
uint8_t getContrast(void);
uint8_t getBias(void);
void clearDisplay(void);
void display();
void setReinitInterval(uint8_t val);
uint8_t getReinitInterval(void);

void drawPixel(int16_t x, int16_t y, uint16_t color);
uint8_t getPixel(int8_t x, int8_t y);

private:
int8_t _din, _sclk, _dc, _rst, _cs;
uint8_t _contrast, _bias;
uint8_t _reinit_interval, _display_count;
volatile PortReg *mosiport, *clkport;
PortMask mosipinmask, clkpinmask;

void initDisplay();
void spiWrite(uint8_t c);
bool isHardwareSPI();
};
Expand Down
Loading

0 comments on commit e258105

Please sign in to comment.