Base LCDPanel based, required for all LCDPanel drivers

LCDPanel.h

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
 * 
 * License:
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 * 
 * Author: Silvio Gissi
 * Version: 0.1 Alfa
 * 
*/

#ifndef LCDPANEL_BASE_H
#define LCDPANEL_BASE_H

#include "mbed.h"

class LCDPanel {

  public:
    LCDPanel(unsigned int width, unsigned int height, PinName cs);

    virtual void fill(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, uint16_t color);
    virtual void fill(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, const uint16_t* color);
    virtual void set_pixel(unsigned int x, unsigned int y, uint16_t color);
    
    inline void clear() { fill(0,0,_xmax,_ymax,(uint16_t)0x0000); }
    inline unsigned int height() { return _ymax+1; }
    inline unsigned int width() { return _xmax+1; }
    
  protected:
    unsigned int _ymax;
    unsigned int _xmax;
    DigitalOut _cs;
    
    class CsTransaction
    {
        private: LCDPanel *p;
        public:
            CsTransaction(LCDPanel *panel) : p(panel) { p->_cs=0; }
            ~CsTransaction() { p->_cs=1; }
    };
    virtual void command(unsigned int command,unsigned int size=0,...)=0;
    virtual void data(unsigned int size,...)=0;
    virtual void pixel(uint16_t color)=0;
    virtual void window(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2)=0;

};

#endif // LCDPANEL_BASE_H