| 1 |
/* |
| 2 |
Copyright (C) 2007 T. Scott Dattalo |
| 3 |
|
| 4 |
This file is part of gpsim. |
| 5 |
|
| 6 |
gpsim is free software; you can redistribute it and/or modify |
| 7 |
it under the terms of the GNU General Public License as published by |
| 8 |
the Free Software Foundation; either version 2, or (at your option) |
| 9 |
any later version. |
| 10 |
|
| 11 |
gpsim is distributed in the hope that it will be useful, |
| 12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
GNU General Public License for more details. |
| 15 |
|
| 16 |
You should have received a copy of the GNU General Public License |
| 17 |
along with gpsim; see the file COPYING. If not, write to |
| 18 |
the Free Software Foundation, 59 Temple Place - Suite 330, |
| 19 |
Boston, MA 02111-1307, USA. */ |
| 20 |
|
| 21 |
|
| 22 |
#ifndef EXTRAS_GRAPHIC_LCD_SRC_SSD0323_H_ |
| 23 |
#define EXTRAS_GRAPHIC_LCD_SRC_SSD0323_H_ |
| 24 |
|
| 25 |
class SSD0323 { |
| 26 |
enum { |
| 27 |
e8080Mode = 6, |
| 28 |
e6800Mode = 4, |
| 29 |
eSPIMode = 0, |
| 30 |
eInvalidMode = 0xff |
| 31 |
}; |
| 32 |
|
| 33 |
enum { // 8080 6800 SPI |
| 34 |
eCS = 1, // /CS /CS /CS |
| 35 |
eRES = 2, // /Reset /Reset /Reset |
| 36 |
eE_RD = 4, // /Rd Enable /Enable |
| 37 |
eRW = 8, // /Wr Rd /Wr /Wr |
| 38 |
eDC = 0x10 // D /C D /C D /C --- Data /Command |
| 39 |
}; |
| 40 |
|
| 41 |
public: |
| 42 |
SSD0323(); |
| 43 |
|
| 44 |
void setBS(unsigned int BSpin, bool newBS); |
| 45 |
void setCS(bool); |
| 46 |
void setRES(bool); |
| 47 |
void setDC(bool); |
| 48 |
void setE_RD(bool); |
| 49 |
void setRW(bool); |
| 50 |
void setData(unsigned int); |
| 51 |
void setSCLK(bool); |
| 52 |
void setSDIN(bool); |
| 53 |
|
| 54 |
void driveDataBus(unsigned int); |
| 55 |
bool dataBusDirection(); |
| 56 |
unsigned int getDataBus(); |
| 57 |
|
| 58 |
|
| 59 |
void storeData(); |
| 60 |
void executeCommand(); |
| 61 |
|
| 62 |
void randomizeRAM(); |
| 63 |
|
| 64 |
unsigned int getData(); |
| 65 |
unsigned int getStatus(); |
| 66 |
|
| 67 |
inline unsigned int &operator[](unsigned int index) |
| 68 |
{ |
| 69 |
return (index < 128 * 80 / 2) ? m_ram[index] : prBadRam(index); |
| 70 |
} |
| 71 |
|
| 72 |
void showState(); |
| 73 |
|
| 74 |
private: |
| 75 |
void advanceColumnAddress(); |
| 76 |
void advanceRowAddress(); |
| 77 |
|
| 78 |
// called if an illegal access is made to the RAM |
| 79 |
unsigned int &prBadRam(unsigned int); |
| 80 |
|
| 81 |
// Display state |
| 82 |
unsigned int m_controlState; |
| 83 |
unsigned int m_dataBus; |
| 84 |
|
| 85 |
// Communication - |
| 86 |
// The commMode selects one of three possible communication modes |
| 87 |
// The commState holds the communication state for that mode. |
| 88 |
|
| 89 |
unsigned int m_commMode; |
| 90 |
unsigned int m_commState; |
| 91 |
unsigned int m_SPIData; |
| 92 |
|
| 93 |
// Command processing |
| 94 |
unsigned int m_commandIndex; |
| 95 |
unsigned int m_expectedCommandWords; |
| 96 |
unsigned char cmdWords[20]; |
| 97 |
|
| 98 |
// Display ram + one for bad memory access |
| 99 |
unsigned int m_ram[(128 * 80 / 2) + 1]; |
| 100 |
|
| 101 |
// State information |
| 102 |
unsigned int m_colAddr; |
| 103 |
unsigned int m_rowAddr; |
| 104 |
|
| 105 |
// helper functions |
| 106 |
bool bEnabled() |
| 107 |
{ |
| 108 |
return (m_controlState & (eCS | eRES)) == eRES; |
| 109 |
} |
| 110 |
bool bBitState(unsigned int b) |
| 111 |
{ |
| 112 |
return (m_controlState & b) == b; |
| 113 |
} |
| 114 |
void abortCurrentTransaction(); |
| 115 |
|
| 116 |
// configuration data controlled by the SSD0323 commands |
| 117 |
unsigned int m_colStartAddr; |
| 118 |
unsigned int m_colEndAddr; |
| 119 |
unsigned int m_rowStartAddr; |
| 120 |
unsigned int m_rowEndAddr; |
| 121 |
unsigned int m_Remap; |
| 122 |
unsigned int m_ContrastControl; |
| 123 |
}; |
| 124 |
|
| 125 |
#endif |