SG12864A

Dependents:   SG12864A_TestProgram

SG12864A.h

Committer:
shintamainjp
Date:
2010-07-20
Revision:
3:86e7fba29623
Parent:
2:91c03e41c927
Child:
4:200d1ea4e76e

File content as of revision 3:86e7fba29623:

/**
 * SG12864A Graphics LCD module driver class (Version 0.0.1)
 *
 * Copyright (C) 2010 Shinichiro Nakamura (CuBeatSystems)
 * http://shinta.main.jp/
 */

#ifndef _SG12864A_H_
#define _SG12864A_H_

#include "mbed.h"

/**
 */
class SG12864A {
public:
    SG12864A(
        PinName di,
        PinName rw,
        PinName en,
        PinName db0,
        PinName db1,
        PinName db2,
        PinName db3,
        PinName db4,
        PinName db5,
        PinName db6,
        PinName db7,
        PinName cs1,
        PinName cs2,
        PinName res);
    ~SG12864A();
    enum Target {
        CS1,
        CS2
    };
    
    /*
     * High Level Interfaces. (Abstracted)
     */
    void bufferPush(void);
    void bufferPull(void);
    void bufferClear(bool reverse = false);
    void bufferDrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, bool reverse = false);
    void bufferDrawBox(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, bool reverse = false);
    void bufferFillBox(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, bool reverse = false);
    void bufferDrawString(uint8_t x, uint8_t y, char * str, bool reverse = false);
    void bufferDrawChar(uint8_t x, uint8_t y, char c, bool reverse = false);
    void bufferDrawCheckbox(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, bool state, bool reverse = false);
    void bufferDrawProgressbar(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, int min, int max, int value, bool horizontal = true, bool reverse = false);

    /*
     * High Level Interfaces.
     */
    void reset(void);
    void clear(void);

    /*
     * Middle Level Interfaces.
     */
    void setDisplayOnOff(Target t, bool on);
    void setDisplayStartLine(Target t, uint8_t displayStartLine);
    void setPageAddress(Target t, uint8_t addr);
    void setColumnAddress(Target t, uint8_t addr);
    void readStatus(Target t, uint8_t *c);
    void writeData(Target t, uint8_t c);
    void readData(Target t, uint8_t *c);
    static const int PIXEL_X = 128;
    static const int PIXEL_Y = 64;
    static const uint8_t FONT_X = 5;
    static const uint8_t FONT_Y = 7;
private:
    static const int PAGES = 8;
    static const int COLUMNS = 64;
    static const uint16_t FONT_MIN_CODE = 0x20;
    static const uint16_t FONT_MAX_CODE = 0x7F;
    static const uint8_t font5x7_data[];
    uint8_t buffer[PAGES * COLUMNS * 2];
    DigitalOut ioDI;
    DigitalOut ioRW;
    DigitalOut ioEN;
    BusInOut ioDB;
    DigitalOut ioCS1;
    DigitalOut ioCS2;
    DigitalOut ioRES;
    enum Mode {
        Data,
        Instruction
    };
    
    /*
     * Low Level Interfaces.
     */
    void setDirectionToRead();
    void setDirectionToWrite();
    void write(Target t, Mode m, uint8_t c);
    void read(Target t, Mode m, uint8_t *c);
    void reset(bool b);
};

#endif