Base LCDPanel based, required for all LCDPanel drivers

LCDPanel.cpp

Committer:
silviogissi
Date:
2012-03-11
Revision:
2:ab4040a7e8c9
Parent:
1:073d4f161f23

File content as of revision 2:ab4040a7e8c9:

/* LCDPanel base library for LCD/TFT Panels
 * Copyright (c) 2012, Silvio Gissi */

#include "LCDPanel.h"

 LCDPanel::LCDPanel(unsigned int width, unsigned int height, PinName cs)
    : _ymax(height-1)
    , _xmax(width-1)
    , _cs(cs)
 {
 }

// Default implementation, pixel by pixel
void LCDPanel::fill(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, uint16_t color) {
    if (x1>x2) {unsigned int tmp=x1; x1=x2; x2=tmp;}
    if (y1>y2) {unsigned int tmp=y1; y1=y2; y2=tmp;}
    CsTransaction(this);
    window(x1,y1,x2,y2);
    for(unsigned int i=0;i<(x2-x1)*(y2-y1);i++) { pixel(color); }    
}

// Default implementation, pixel by pixel
void LCDPanel::fill(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, const uint16_t* color) {
    if (x1>x2) {unsigned int tmp=x1; x1=x2; x2=tmp;}
    if (y1>y2) {unsigned int tmp=y1; y1=y2; y2=tmp;}
    CsTransaction(this);
    window(x1,y1,x2,y2);
    for(unsigned int i=0;i<(x2-x1)*(y2-y1);i++) { pixel(color[i]); }    
}

void LCDPanel::set_pixel(unsigned int x, unsigned int y, uint16_t color) {
    CsTransaction(this);
    window(x,y,1,1);
    pixel(color);
}