Driver for 4D Systems LCD screen with Picaso processor. Ported from 4D Systems Picaso Serial Linux Library

Dependencies:   MODSERIAL

Dependents:   uLCD_4D_24PTU Drawing Program RoommateTracker_ScreenAndPhone ece4180_roommate_tracker_final

Revision:
0:e314f3b805ed
Child:
2:ebe7029e2825
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/uLCD_4D_Picaso.h	Fri Mar 06 00:35:58 2015 +0000
@@ -0,0 +1,227 @@
+/**
+ * This is a class to drive 4D systems screens with Picaso graphics processors
+ * 
+ * This is a port of the 4D systems Picaso Serial Linux Library
+ * Copyright (c) 2014 4D Systems PTY Ltd, Sydney, Australia
+ * From https://github.com/4dsystems/Picaso-Serial-Linux-Library, retrieved March 5, 2015
+ *
+ * All software in this library is provided without warranty; use at your own risk.
+ */
+
+#ifndef uLCD_4D_Picaso_H
+#define	uLCD_4D_Picaso_H
+
+// This library can work with either the standard mbed Serial library or with the MODSERIAL
+// library by Andy Kirkham. MODSERIAL allows RX buffering, which could prevent dropped characters
+// at high baud rates. The version of MODSERIAL by Erik Olieman, which is supposed to support more
+// devices, does not appear to work with this library at present, for unknown reasons.
+#define LCD_USING_MODSERIAL 1
+
+#include "mbed.h"
+#include "Picaso_Types4D.h"
+
+#if LCD_USING_MODSERIAL
+#include "MODSERIAL.h"
+#endif
+
+class uLCD_4D_Picaso {
+	public:
+	
+	// Allowed serial interface baud rates.
+	enum BaudRate {
+        BAUD_110 = 0, BAUD_300, BAUD_600, BAUD_1200, BAUD_2400, BAUD_4800, BAUD_9600, BAUD_14400,
+        BAUD_19200, BAUD_31250, BAUD_38400, BAUD_56000, BAUD_57600, BAUD_115200, BAUD_128000,
+        BAUD_256000, BAUD_300000, BAUD_375000, BAUD_500000, BAUD_600000
+    };
+    
+	uLCD_4D_Picaso(PinName tx, PinName rx, PinName reset);
+	void LCD_reset();
+	
+	char file_GetC(WORD  Handle) ;
+	void blitComtoDisplay(WORD  X, WORD  Y, WORD  Width, WORD  Height, t4DByteArray  Pixels);
+	WORD bus_In(void);
+	void bus_Out(WORD Bits);
+	WORD bus_Read(void);
+	void bus_Set(WORD IOMap);
+	void bus_Write(WORD Bits);
+	void file_Unmount(void);
+	void gfx_Button(WORD  Up, WORD  x, WORD  y, WORD  buttonColour, WORD  txtColour, WORD  font, WORD  txtWidth, WORD  txtHeight, char *  text);
+	void gfx_ChangeColour(WORD  OldColor, WORD  NewColor);
+	void gfx_Circle(WORD  X, WORD  Y, WORD  Radius, WORD  Color);
+	void gfx_CircleFilled(WORD  X, WORD  Y, WORD  Radius, WORD  Color);
+	void gfx_Clipping(WORD  OnOff);
+	void gfx_ClipWindow(WORD  X1, WORD  Y1, WORD  X2, WORD  Y2);
+	void gfx_Cls(void);
+	void gfx_Ellipse(WORD  X, WORD  Y, WORD  Xrad, WORD  Yrad, WORD  Color);
+	void gfx_EllipseFilled(WORD  X, WORD  Y, WORD  Xrad, WORD  Yrad, WORD  Color);
+	void gfx_Line(WORD  X1, WORD  Y1, WORD  X2, WORD  Y2, WORD  Color);
+	void gfx_LineTo(WORD  X, WORD  Y);
+	void gfx_MoveTo(WORD  X, WORD  Y);
+	void gfx_Panel(WORD  Raised, WORD  X, WORD  Y, WORD  Width, WORD  Height, WORD  Color);
+	void gfx_Polygon(WORD  n, t4DWordArray  Xvalues, t4DWordArray  Yvalues, WORD  Color);
+	void gfx_PolygonFilled(WORD  n, t4DWordArray  Xvalues, t4DWordArray  Yvalues, WORD  Color);
+	void gfx_Polyline(WORD  n, t4DWordArray  Xvalues, t4DWordArray  Yvalues, WORD  Color);
+	void gfx_PutPixel(WORD  X, WORD  Y, WORD  Color);
+	void gfx_Rectangle(WORD  X1, WORD  Y1, WORD  X2, WORD  Y2, WORD  Color);
+	void gfx_RectangleFilled(WORD  X1, WORD  Y1, WORD  X2, WORD  Y2, WORD  Color);
+	void gfx_ScreenCopyPaste(WORD  Xs, WORD  Ys, WORD  Xd, WORD  Yd, WORD  Width, WORD  Height);
+	void gfx_Set(WORD  Func, WORD  Value);
+	void gfx_SetClipRegion(void);
+	void gfx_Triangle(WORD  X1, WORD  Y1, WORD  X2, WORD  Y2, WORD  X3, WORD  Y3, WORD  Color);
+	void gfx_TriangleFilled(WORD  X1, WORD  Y1, WORD  X2, WORD  Y2, WORD  X3, WORD  Y3, WORD  Color);
+	void media_Image(WORD  X, WORD  Y);
+	void media_SetAdd(WORD  HiWord, WORD  LoWord);
+	void media_SetSector(WORD  HiWord, WORD  LoWord);
+	void media_Video(WORD  X, WORD  Y);
+	void media_VideoFrame(WORD  X, WORD  Y, WORD  Framenumber);
+	void setbaudWait(uLCD_4D_Picaso::BaudRate Newrate);
+	void snd_BufSize(WORD  Bufsize);
+	void snd_Continue(void);
+	void snd_Pause(void);
+	void snd_Stop(void);
+	void snd_Volume(WORD  Volume);
+	void touch_DetectRegion(WORD  X1, WORD  Y1, WORD  X2, WORD  Y2);
+	void touch_Set(WORD  Mode);
+	void txt_MoveCursor(WORD  Line, WORD  Column);
+	void txt_Set(WORD  Func, WORD  Value);
+	WORD charheight(char  TestChar);
+	WORD charwidth(char  TestChar);
+	WORD file_CallFunction(WORD  Handle, WORD  ArgCount, t4DWordArray  Args);
+	WORD file_Close(WORD  Handle);
+	WORD file_Count(char * Filename);
+	WORD file_Dir(char * Filename);
+	WORD file_Erase(char * Filename);
+	WORD file_Error(void);
+	WORD file_Exec(char *Filename, WORD  ArgCount, t4DWordArray  Args);
+	WORD file_Exists(char *Filename);
+	WORD file_FindFirst(char *Filename);
+	WORD file_FindFirstRet(char *Filename, char * StringIn);
+	WORD file_FindNext(void);
+	WORD file_FindNextRet(char * StringIn);
+	WORD file_GetS(char * StringIn, WORD  Size, WORD  Handle);
+	WORD file_GetW(WORD  Handle);
+	WORD file_Image(WORD  X, WORD  Y, WORD  Handle);
+	WORD file_Index(WORD  Handle, WORD  HiSize, WORD  LoSize, WORD  Recordnum);
+	WORD file_LoadFunction(char *Filename);
+	WORD file_LoadImageControl(char *Datname, char *GCIName, WORD  Mode);
+	WORD file_Mount(void);
+	WORD file_Open(char * Filename, char  Mode);
+	WORD file_PlayWAV(char * Filename);
+	WORD file_PutC(char  Character, WORD  Handle);
+	WORD file_PutS(char * StringOut, WORD  Handle);
+	WORD file_PutW(WORD  Word, WORD  Handle);
+	WORD file_Read(t4DByteArray  Data, WORD  Size, WORD  Handle);
+	WORD file_Rewind(WORD  Handle);
+	WORD file_Run(char *Filename, WORD  ArgCount, t4DWordArray  Args);
+	WORD file_ScreenCapture(WORD  X, WORD  Y, WORD  Width, WORD  Height, WORD  Handle);
+	WORD file_Seek(WORD  Handle, WORD  HiWord, WORD  LoWord);
+	WORD file_Size(WORD  Handle, WORD *  HiWord, WORD *  LoWord);
+	WORD file_Tell(WORD  Handle, WORD *  HiWord, WORD *  LoWord);
+	WORD file_Write(WORD  Size, t4DByteArray  Source, WORD  Handle);
+	WORD gfx_BevelShadow(WORD  Value);
+	WORD gfx_BevelWidth(WORD  Value);
+	WORD gfx_BGcolour(WORD  Color);
+	WORD gfx_Contrast(WORD  Contrast);
+	WORD gfx_FrameDelay(WORD  Msec);
+	WORD gfx_Get(WORD  Mode);
+	WORD gfx_GetPixel(WORD  X, WORD  Y);
+	WORD gfx_LinePattern(WORD  Pattern);
+	WORD gfx_Orbit(WORD  Angle, WORD  Distance, WORD *  Xdest, WORD *  Ydest);
+	WORD gfx_OutlineColour(WORD  Color);
+	WORD gfx_ScreenMode(WORD  ScreenMode);
+	WORD gfx_Slider(WORD  Mode, WORD  X1, WORD  Y1, WORD  X2, WORD  Y2, WORD  Color, WORD  Scale, WORD  Value);
+	WORD gfx_Transparency(WORD  OnOff);
+	WORD gfx_TransparentColour(WORD  Color);
+	WORD img_ClearAttributes(WORD  Handle, WORD  Index, WORD  Value);
+	WORD img_Darken(WORD  Handle, WORD  Index);
+	WORD img_Disable(WORD  Handle, WORD  Index);
+	WORD img_Enable(WORD  Handle, WORD  Index);
+	WORD img_GetWord(WORD  Handle, WORD  Index, WORD  Offset );
+	WORD img_Lighten(WORD  Handle, WORD  Index);
+	WORD img_SetAttributes(WORD  Handle, WORD  Index, WORD  Value);
+	WORD img_SetPosition(WORD  Handle, WORD  Index, WORD  Xpos, WORD  Ypos);
+	WORD img_SetWord(WORD  Handle, WORD  Index, WORD  Offset , WORD  Word);
+	WORD img_Show(WORD  Handle, WORD  Index);
+	WORD img_Touched(WORD  Handle, WORD  Index);
+	WORD media_Flush(void);
+	WORD media_Init(void);
+	WORD media_RdSector(t4DSector  SectorIn);
+	WORD media_ReadByte(void);
+	WORD media_ReadWord(void);
+	WORD media_WriteByte(WORD  Byte);
+	WORD media_WriteWord(WORD  Word);
+	WORD media_WrSector(t4DSector  SectorOut);
+	WORD mem_Free(WORD  Handle);
+	WORD mem_Heap(void);
+	WORD peekM(WORD  Address) ;
+	void pokeM(WORD  Address, WORD  WordValue) ;
+	WORD pin_HI(WORD Pin);
+	WORD pin_LO(WORD Pin);
+	WORD pin_Read(WORD Pin);
+	WORD pin_Set(WORD Mode, WORD Pin);
+	void putCH(WORD  WordChar);
+	WORD putStr(char *InString);
+	WORD readString(WORD  Handle, char * StringIn);
+	WORD snd_Pitch(WORD  Pitch);
+	WORD snd_Playing(void);
+	WORD sys_GetModel(char *ModelStr);
+	WORD sys_GetPmmC(void);
+	WORD sys_GetVersion(void);
+	WORD sys_Sleep(WORD  Units);
+	WORD touch_Get(WORD  Mode);
+	WORD txt_Attributes(WORD  Attribs);
+	WORD txt_BGcolour(WORD  Color);
+	WORD txt_Bold(WORD  Bold);
+	WORD txt_FGcolour(WORD  Color);
+	WORD txt_FontID(WORD  FontNumber);
+	WORD txt_Height(WORD  Multiplier);
+	WORD txt_Inverse(WORD  Inverse);
+	WORD txt_Italic(WORD  Italic);
+	WORD txt_Opacity(WORD  TransparentOpaque);
+	WORD txt_Underline(WORD  Underline);
+	WORD txt_Width(WORD  Multiplier);
+	WORD txt_Wrap(WORD  Position);
+	WORD txt_Xgap(WORD  Pixels);
+	WORD txt_Ygap(WORD  Pixels);
+	WORD writeString(WORD  Handle, char * StringOut);
+
+	private:
+	
+	#if LCD_USING_MODSERIAL
+	MODSERIAL serial;
+	#else
+	Serial serial;
+	#endif
+	
+	DigitalOut rst;
+	Timer timer;
+	
+	void WriteBytes(char* psOutput, int count);
+	void WriteChars(char* psOutput);
+	void WriteWords(WORD* source, int count);
+	int ReadSerPort(char *psData, int iMax);
+	void getbytes(char *data, int size);
+	void GetAck();
+	WORD GetWord();
+	void getString(char *outStr, int strLen);
+	WORD GetAckResp();
+	WORD WaitForAck();
+	WORD GetAckRes2Words(WORD * word1, WORD * word2);
+	void GetAck2Words(WORD * word1, WORD * word2);
+	WORD GetAckResSector(t4DSector Sector);
+	WORD GetAckResStr(char * OutStr);
+	WORD GetAckResData(t4DByteArray OutData, WORD size);
+	void SetThisBaudrate(uLCD_4D_Picaso::BaudRate NewRate);
+	
+	void LCD_wait_ms(int ms);
+	void rxFlush();
+	
+	// 4D Global variables
+	int Error4D ;  			// Error indicator,  used and set by Intrinsic routines
+	int TimeLimit4D;		// time limit in ms for total serial command duration, 2000 (2 seconds) should be adequate for most commands
+	                        // assuming a reasonable baud rate AND low latency AND 0 for the Serial Delay Parameter
+	                        // temporary increase might be required for very long (bitmap write, large image file opens)
+	                        // or indeterminate (eg file_exec, file_run, file_callFunction)  commands// Error callback. Set to NULL if no callback is required. i.e. all errors will be handled in your code
+
+};
+#endif
\ No newline at end of file