Skip to content

Commit

Permalink
Use typedefs instead of unsigned types
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosefr committed Dec 17, 2017
1 parent 92167e6 commit 981d66d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 55 deletions.
54 changes: 26 additions & 28 deletions PCD8544.cpp
Expand Up @@ -45,9 +45,7 @@
#include "charset.cpp"


PCD8544::PCD8544(unsigned char sclk, unsigned char sdin,
unsigned char dc, unsigned char reset,
unsigned char sce):
PCD8544::PCD8544(uint8_t sclk, uint8_t sdin, uint8_t dc, uint8_t reset, uint8_t sce):
pin_sclk(sclk),
pin_sdin(sdin),
pin_dc(dc),
Expand All @@ -56,7 +54,7 @@ PCD8544::PCD8544(unsigned char sclk, unsigned char sdin,
{}


void PCD8544::begin(unsigned char width, unsigned char height, unsigned char model)
void PCD8544::begin(uint8_t width, uint8_t height, uint8_t model)
{
this->width = width;
this->height = height;
Expand Down Expand Up @@ -123,7 +121,7 @@ void PCD8544::clear()
{
this->setCursor(0, 0);

for (unsigned short i = 0; i < this->width * (this->height/8); i++) {
for (uint16_t i = 0; i < this->width * (this->height/8); i++) {
this->send(PCD8544_DATA, 0x00);
}

Expand All @@ -135,7 +133,7 @@ void PCD8544::clearLine()
{
this->setCursor(0, this->line);

for (unsigned char i = 0; i < this->width; i++) {
for (uint8_t i = 0; i < this->width; i++) {
this->send(PCD8544_DATA, 0x00);
}

Expand Down Expand Up @@ -167,7 +165,7 @@ void PCD8544::setInverse(bool inverse)
}


void PCD8544::setContrast(unsigned char level)
void PCD8544::setContrast(uint8_t level)
{
// The PCD8544 datasheet specifies a maximum Vop of 8.5V for safe
// operation in low temperatures, which limits the contrast level.
Expand All @@ -192,7 +190,7 @@ void PCD8544::home()
}


void PCD8544::setCursor(unsigned char column, unsigned char line)
void PCD8544::setCursor(uint8_t column, uint8_t line)
{
this->column = (column % this->width);
this->line = (line % (this->height/9 + 1));
Expand All @@ -202,7 +200,7 @@ void PCD8544::setCursor(unsigned char column, unsigned char line)
}


void PCD8544::createChar(unsigned char chr, const unsigned char *glyph)
void PCD8544::createChar(uint8_t chr, const uint8_t *glyph)
{
// ASCII 0-31 only...
if (chr >= ' ') {
Expand All @@ -220,8 +218,8 @@ size_t PCD8544::write(uint8_t chr)
return 0;
}

const unsigned char *glyph;
unsigned char pgm_buffer[5];
const uint8_t *glyph;
uint8_t pgm_buffer[5];

if (chr >= ' ') {
// Regular ASCII characters are kept in flash to save RAM...
Expand All @@ -239,7 +237,7 @@ size_t PCD8544::write(uint8_t chr)
}

// Output one column at a time...
for (unsigned char i = 0; i < 5; i++) {
for (uint8_t i = 0; i < 5; i++) {
this->send(PCD8544_DATA, glyph[i]);
}

Expand All @@ -257,19 +255,19 @@ size_t PCD8544::write(uint8_t chr)
}


void PCD8544::drawBitmap(const unsigned char *data, unsigned char columns, unsigned char lines)
void PCD8544::drawBitmap(const uint8_t *data, uint8_t columns, uint8_t lines)
{
unsigned char scolumn = this->column;
unsigned char sline = this->line;
uint8_t scolumn = this->column;
uint8_t sline = this->line;

// The bitmap will be clipped at the right/bottom edge of the display...
unsigned char mx = (scolumn + columns > this->width) ? (this->width - scolumn) : columns;
unsigned char my = (sline + lines > this->height/8) ? (this->height/8 - sline) : lines;
uint8_t mx = (scolumn + columns > this->width) ? (this->width - scolumn) : columns;
uint8_t my = (sline + lines > this->height/8) ? (this->height/8 - sline) : lines;

for (unsigned char y = 0; y < my; y++) {
for (uint8_t y = 0; y < my; y++) {
this->setCursor(scolumn, sline + y);

for (unsigned char x = 0; x < mx; x++) {
for (uint8_t x = 0; x < mx; x++) {
this->send(PCD8544_DATA, data[y * columns + x]);
}
}
Expand All @@ -279,36 +277,36 @@ void PCD8544::drawBitmap(const unsigned char *data, unsigned char columns, unsig
}


void PCD8544::drawColumn(unsigned char lines, unsigned char value)
void PCD8544::drawColumn(uint8_t lines, uint8_t value)
{
unsigned char scolumn = this->column;
unsigned char sline = this->line;
uint8_t scolumn = this->column;
uint8_t sline = this->line;

// Keep "value" within range...
if (value > lines*8) {
value = lines*8;
}

// Find the line where "value" resides...
unsigned char mark = (lines*8 - 1 - value)/8;
uint8_t mark = (lines*8 - 1 - value)/8;

// Clear the lines above the mark...
for (unsigned char line = 0; line < mark; line++) {
for (uint8_t line = 0; line < mark; line++) {
this->setCursor(scolumn, sline + line);
this->send(PCD8544_DATA, 0x00);
}

// Compute the byte to draw at the "mark" line...
unsigned char b = 0xff;
for (unsigned char i = 0; i < lines*8 - mark*8 - value; i++) {
uint8_t b = 0xff;
for (uint8_t i = 0; i < lines*8 - mark*8 - value; i++) {
b <<= 1;
}

this->setCursor(scolumn, sline + mark);
this->send(PCD8544_DATA, b);

// Fill the lines below the mark...
for (unsigned char line = mark + 1; line < lines; line++) {
for (uint8_t line = mark + 1; line < lines; line++) {
this->setCursor(scolumn, sline + line);
this->send(PCD8544_DATA, 0xff);
}
Expand All @@ -318,7 +316,7 @@ void PCD8544::drawColumn(unsigned char lines, unsigned char value)
}


void PCD8544::send(unsigned char type, unsigned char data)
void PCD8544::send(uint8_t type, uint8_t data)
{
digitalWrite(this->pin_dc, type);

Expand Down
46 changes: 23 additions & 23 deletions PCD8544.h
Expand Up @@ -38,14 +38,14 @@
class PCD8544: public Print {
public:
// All the pins can be changed from the default values...
PCD8544(unsigned char sclk = 3, /* clock (display pin 2) */
unsigned char sdin = 4, /* data-in (display pin 3) */
unsigned char dc = 5, /* data select (display pin 4) */
unsigned char reset = 6, /* reset (display pin 8) */
unsigned char sce = 7); /* enable (display pin 5) */
PCD8544(uint8_t sclk = 3, /* clock (display pin 2) */
uint8_t sdin = 4, /* data-in (display pin 3) */
uint8_t dc = 5, /* data select (display pin 4) */
uint8_t reset = 6, /* reset (display pin 8) */
uint8_t sce = 7); /* enable (display pin 5) */

// Display initialization (dimensions in pixels)...
void begin(unsigned char width=84, unsigned char height=48, unsigned char model=CHIP_PCD8544);
void begin(uint8_t width=84, uint8_t height=48, uint8_t model=CHIP_PCD8544);
void stop();

// Erase everything on the display...
Expand All @@ -63,49 +63,49 @@ class PCD8544: public Print {
void setInverse(bool inverse);

// Set display contrast level (0-127)...
void setContrast(unsigned char level);
void setContrast(uint8_t level);

// Place the cursor at the start of the current line...
void home();

// Place the cursor at position (column, line)...
void setCursor(unsigned char column, unsigned char line);
void setCursor(uint8_t column, uint8_t line);

// Assign a user-defined glyph (5x8) to an ASCII character (0-31)...
void createChar(unsigned char chr, const unsigned char *glyph);
void createChar(uint8_t chr, const uint8_t *glyph);

// Write an ASCII character at the current cursor position (7-bit)...
virtual size_t write(uint8_t chr);

// Draw a bitmap at the current cursor position...
void drawBitmap(const unsigned char *data, unsigned char columns, unsigned char lines);
void drawBitmap(const uint8_t *data, uint8_t columns, uint8_t lines);

// Draw a chart element at the current cursor position...
void drawColumn(unsigned char lines, unsigned char value);
void drawColumn(uint8_t lines, uint8_t value);

private:
unsigned char pin_sclk;
unsigned char pin_sdin;
unsigned char pin_dc;
unsigned char pin_reset;
unsigned char pin_sce;
uint8_t pin_sclk;
uint8_t pin_sdin;
uint8_t pin_dc;
uint8_t pin_reset;
uint8_t pin_sce;

// Chip variant in use...
unsigned char model;
uint8_t model;

// The size of the display, in pixels...
unsigned char width;
unsigned char height;
uint8_t width;
uint8_t height;

// Current cursor position...
unsigned char column;
unsigned char line;
uint8_t column;
uint8_t line;

// User-defined glyphs (below the ASCII space character)...
const unsigned char *custom[' '];
const uint8_t *custom[' '];

// Send a command or data to the display...
void send(unsigned char type, unsigned char data);
void send(uint8_t type, uint8_t data);
};


Expand Down
8 changes: 4 additions & 4 deletions charset.cpp
Expand Up @@ -31,7 +31,7 @@


// The 7-bit ASCII character set...
const PROGMEM unsigned char charset[][5] = {
const PROGMEM uint8_t charset[][5] = {
{ 0x00, 0x00, 0x00, 0x00, 0x00 }, // 20 space
{ 0x00, 0x00, 0x5f, 0x00, 0x00 }, // 21 !
{ 0x00, 0x07, 0x00, 0x07, 0x00 }, // 22 "
Expand Down Expand Up @@ -92,7 +92,7 @@ const PROGMEM unsigned char charset[][5] = {
{ 0x07, 0x08, 0x70, 0x08, 0x07 }, // 59 Y
{ 0x61, 0x51, 0x49, 0x45, 0x43 }, // 5a Z
{ 0x00, 0x7f, 0x41, 0x41, 0x00 }, // 5b [
{ 0x02, 0x04, 0x08, 0x10, 0x20 }, // 5c backslash
{ 0x02, 0x04, 0x08, 0x10, 0x20 }, // 5c backslash
{ 0x00, 0x41, 0x41, 0x7f, 0x00 }, // 5d ]
{ 0x04, 0x02, 0x01, 0x02, 0x04 }, // 5e ^
{ 0x40, 0x40, 0x40, 0x40, 0x40 }, // 5f _
Expand All @@ -106,7 +106,7 @@ const PROGMEM unsigned char charset[][5] = {
{ 0x0c, 0x52, 0x52, 0x52, 0x3e }, // 67 g
{ 0x7f, 0x08, 0x04, 0x04, 0x78 }, // 68 h
{ 0x00, 0x44, 0x7d, 0x40, 0x00 }, // 69 i
{ 0x20, 0x40, 0x44, 0x3d, 0x00 }, // 6a j
{ 0x20, 0x40, 0x44, 0x3d, 0x00 }, // 6a j
{ 0x7f, 0x10, 0x28, 0x44, 0x00 }, // 6b k
{ 0x00, 0x41, 0x7f, 0x40, 0x00 }, // 6c l
{ 0x7c, 0x04, 0x18, 0x04, 0x78 }, // 6d m
Expand All @@ -127,7 +127,7 @@ const PROGMEM unsigned char charset[][5] = {
{ 0x00, 0x00, 0x7f, 0x00, 0x00 }, // 7c |
{ 0x00, 0x41, 0x36, 0x08, 0x00 }, // 7d }
{ 0x10, 0x08, 0x08, 0x10, 0x08 }, // 7e ~
{ 0x00, 0x00, 0x00, 0x00, 0x00 } // 7f
{ 0x00, 0x00, 0x00, 0x00, 0x00 } // 7f
};


Expand Down

0 comments on commit 981d66d

Please sign in to comment.