1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
|
/*
Copyright (C) 1998,1999,2000 T. Scott Dattalo
This file is part of gpsim.
gpsim is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
gpsim is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with gpsim; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#ifndef __LCD_H__
#define __LCD_H__
//#include "state_machine.h"
#include <gpsim/stimuli.h>
#include <gpsim/ioports.h>
#include <gpsim/symbol.h>
#include <gpsim/trace.h>
#include <gtk/gtk.h>
class LcdDisplay;
// Create a few classes from which an LCD may be constructed
class Lcd_Port : public IOPORT
{
public:
LcdDisplay *lcd;
virtual void trace_register_write(void);
virtual void setbit(unsigned int bit_number, bool new_value);
virtual void assert_event(void);
Lcd_Port (unsigned int _num_iopins=8);
};
class ControlPort : public Lcd_Port, public BreakCallBack
{
public:
guint64 break_delta;
void put(unsigned int new_value);
virtual void assert_event(void);
ControlPort (unsigned int _num_iopins=8);
virtual void callback(void);
};
class DataPort : public Lcd_Port
{
public:
unsigned int direction;
void put(unsigned int new_value);
virtual void assert_event(void);
DataPort (unsigned int _num_iopins=8);
void update_pin_directions(unsigned int );
};
// Create a class derived from the IO_input class that
// will allow us to intercept when the I/O input is being
// driven. (This isn't done for PIC I/O pins because the
// logic for handling I/O pin changes resides in the IOPORT
// class.)
class Lcd_Input : public IO_input
{
public:
virtual void put_node_state( int new_state);
Lcd_Input (IOPORT *i, unsigned int b, char *opt_name=NULL) : IO_input(i,b,opt_name) { };
};
class LcdFont
{
public:
gint num_elements;
GdkPixmap **pixmaps;
//CreateFont(GtkWidget *, LcdDisplay *);
LcdFont(gint, GtkWidget *, LcdDisplay *);
};
//
// State Machine Events
//
enum Event {
ERD = 0,
ERC,
EWD,
EWC,
eRD,
eRC,
eWD,
eWC,
DataChange,
BAD_EVENT
};
class SMObject
{
public:
char *nameP; // Object name
SMObject(void) {
nameP = NULL;
};
SMObject(char *_nameP) {
cout << "SMObject constructor\n";
if(_nameP)
nameP = strdup(_nameP);
else
nameP = NULL;
};
~SMObject(void) {
if(nameP)
free(nameP);
};
const char *get_name(void) { return nameP; };
void new_name(char *nP) {
if(nameP)
free(nameP);
nameP = strdup(nP);
};
};
class SMEvent : public SMObject
{
public:
Event e;
SMEvent(Event _e,char *_nameP): SMObject(_nameP) {e = _e;};
SMEvent(char *_nameP=NULL) : SMObject(_nameP) {e = BAD_EVENT;};
void init(Event _e,char *_nameP) {
e = _e;
new_name(_nameP);
};
};
//
// State Machine States
//
enum State {
POWERON,
ST_INITIALIZED,
ST_COMMAND_PH0,
ST_DATA_PH0,
//_8BITMODE_START,
//_8BITMODE,
};
class LcdDisplay : public ExternalModule
{
public:
#define _8BIT_MODE_FLAG (1<<0)
#define LARGE_FONT_MODE_FLAG (1<<1)
#define _2LINE_MODE_FLAG (1<<2)
#define DISPLAY_ON_FLAG (1<<3)
#define CURSOR_ON_FLAG (1<<4)
#define BLINK_ON_FLAG (1<<5)
State current_state, previous_state;
Event last_event;
int mode_flag;
int data_latch;
int data_latch_phase;
int debug;
SMEvent ControlEvents[8];
struct {
int row;
int col;
} cursor;
//
// Here's the graphical portion
//
GdkGC *gc;
gint rows,cols; // e.g. 2x20 would be 2 rows, 20 columns
struct { // Resolution in lcd pixels e.g. 5x7
gint x;
gint y;
} dots;
struct { // Resolution in crt pixels - scaled
gint x;
gint y;
} pixels;
gfloat contrast; // pixel on/off ratio
LcdFont *fontP;
GdkColor
*dot_color; // LCD pixel color (controlled by contrast)
gint **ch_data;
gchar *title;
GtkWidget *window;
GtkWidget *darea;
gint w_width,w_height;
//
// Graphics member functions
//
void set_pixel_resolution(gint _x=5, gint _y=7) {
dots.x =_x; dots.y = _y;
};
void set_crt_resolution(gint _x=3, gint _y=3) {
pixels.x = _x; pixels.y= _y;
};
void set_contrast(gfloat _contrast=1.0) {
contrast = _contrast;
};
gint get_char_width(void) {
return (1+dots.x * pixels.x);
};
gint get_char_height(void) {
return (dots.y * pixels.y);
};
gint get_border(void) {
return 5;
};
GdkPixmap *get_pixmap(gint row, gint col);
void move_cursor(int new_row, int new_column);
void clear_display(void);
void write_data(int new_data);
void write_ddram_address(int data);
// Here's the logic portion
ControlPort *control_port;
DataPort *data_port;
// LCDStateMachine state_machine;
LcdDisplay(void);
void CreateGraphics (void);
void InitStateMachine(void);
void test(void);
void build_window( void );
void update(void);
void update( GtkWidget *drawable,
guint max_width,
guint max_height);
// Inheritances from the Package class
virtual void create_iopin_map(void);
// Inheritance from Module class
const virtual char *type(void) { return ("lcd_display"); };
static ExternalModule *construct(char *new_name);
// State Machine Functions:
void advanceState(Event e);
void newState(State s);
void revertState(void);
void viewInternals(int); // debugging
char *getEventName( Event e);
char *getStateName( State s);
void execute_command(void);
void start_data(void);
void new_command(void);
void new_data(void);
void set_8bit_mode(void) { mode_flag |= _8BIT_MODE_FLAG;};
void set_4bit_mode(void) { mode_flag &= ~_8BIT_MODE_FLAG;};
void set_2line_mode(void) { mode_flag |= _2LINE_MODE_FLAG;};
void set_1line_mode(void) { mode_flag &= ~_2LINE_MODE_FLAG;};
void set_large_font_mode(void) { mode_flag |= LARGE_FONT_MODE_FLAG;};
void set_small_font_mode(void) { mode_flag &= ~LARGE_FONT_MODE_FLAG;};
void set_display_on(void) { mode_flag |= DISPLAY_ON_FLAG;};
void set_display_off(void) { mode_flag &= ~DISPLAY_ON_FLAG;};
void set_blink_on(void) { mode_flag |= BLINK_ON_FLAG;};
void set_blink_off(void) { mode_flag &= ~BLINK_ON_FLAG;};
void set_cursor_on(void) { mode_flag |= CURSOR_ON_FLAG;};
void set_cursor_off(void) { mode_flag &= ~CURSOR_ON_FLAG;};
bool in_8bit_mode(void) {return ((mode_flag & _8BIT_MODE_FLAG) != 0);};
bool in_4bit_mode(void) {return ((mode_flag & _8BIT_MODE_FLAG) == 0);};
bool in_2line_mode(void) {return ((mode_flag & _2LINE_MODE_FLAG) != 0);};
bool in_1line_mode(void) {return ((mode_flag & _2LINE_MODE_FLAG) == 0);};
bool in_large_font_mode(void) {return ((mode_flag & LARGE_FONT_MODE_FLAG) != 0);};
bool in_small_font_mode(void) {return ((mode_flag & LARGE_FONT_MODE_FLAG) == 0);};
bool display_is_on(void) {return ((mode_flag & DISPLAY_ON_FLAG) != 0);};
bool display_is_off(void) {return ((mode_flag & DISPLAY_ON_FLAG) == 0);};
};
#endif // __LCD_H__
|