GP1212A02A: Some proper commands implementation and experimenting with various
authorsl
Sat, 30 Aug 2014 18:43:54 +0200
changeset 1486faea78ddf0
parent 13 70907579a3b6
child 15 105f2c0d3cf1
GP1212A02A: Some proper commands implementation and experimenting with various
setup trying to get a descent frame rate.
FutabaGP1212A02.cpp
FutabaGP1212A02.h
     1.1 --- a/FutabaGP1212A02.cpp	Fri Aug 29 22:32:13 2014 +0200
     1.2 +++ b/FutabaGP1212A02.cpp	Sat Aug 30 18:43:54 2014 +0200
     1.3 @@ -80,11 +80,83 @@
     1.4  		SetNonBlocking(1);
     1.5  		//
     1.6  		SendClearCommand();
     1.7 +
     1.8 +		//Setup BMP box
     1.9 +		BmpBoxSetting(EBmpBoxIdOne,0x0000,256,64);
    1.10 +
    1.11 +		//Select current BMP box
    1.12 +		BmpBoxSelect(EBmpBoxIdOne);
    1.13 +
    1.14 +
    1.15  		}
    1.16  	return success;
    1.17  	}
    1.18  
    1.19  /**
    1.20 + Setting the BMP box
    1.21 +[Code] 1BH,5CH,42H,Pn,aL,aH,Pw,Ph
    1.22 +[Function] Setting the BMP box. BMP box can be defined the 3 area to DW. The position of BMP 
    1.23 +box is set based on the address of DW. 
    1.24 +* To write data in BMP box, BMP box select is necessary. 
    1.25 +* Specifiable horizontal size is 256dot (100H) MAX. If horizontal size specify 256dot, Pw = 00H 
    1.26 +Pn = Number of a BMP box 
    1.27 +aL = Lower byte of address 
    1.28 +aH = Upper byte of address 
    1.29 +Pw = BMP box width 
    1.30 +Ph = BMP box height 
    1.31 +
    1.32 +[Definable area]
    1.33 +Pn = 31H - BMP box 1
    1.34 +Pn = 32H - BMP box 2
    1.35 +Pn = 33H - BMP box 3
    1.36 +0000H <= aL + aH * 100 <= 07FFH 
    1.37 +01H <= Pw <= 00H (=100H) 
    1.38 +01H <= Ph <= 08H
    1.39 +*/
    1.40 +void GP1212A02A::BmpBoxSetting(TBmpBoxId aBoxId, unsigned short aAddress, int aWidth, int aHeight)
    1.41 +	{
    1.42 +	//TODO: check parameters validity
    1.43 +	//1BH,5CH,42H,Pn,aL,aH,Pw,Ph
    1.44 +	FutabaVfdReport report;
    1.45 +	report[0]=0x00; //Report ID
    1.46 +	report[1]=0x08; //Report length.
    1.47 +	report[2]=0x1B; //Command ID
    1.48 +	report[3]=0x5C; //Command ID
    1.49 +	report[4]=0x42; //Command ID
    1.50 +	report[5]=aBoxId; 
    1.51 +	report[6]=(unsigned char)aAddress; //aL = DM lower byte
    1.52 +	report[7]=aAddress>>8; //aH = DM upper byte
    1.53 +	report[8]=(aWidth==256?0x00:aWidth); //Pw = BMP box width 00==256
    1.54 +	report[9]=aHeight/8; //Ph = BMP box height.
    1.55 +	Write(report);
    1.56 +	}
    1.57 +
    1.58 +/**
    1.59 +[Code]1BH,5CH,48H,Pn
    1.60 +[Function]Select of BMP box 
    1.61 +* Execution "BMP box select" is necessary before "Setting the Text box". 
    1.62 +* In case of writing by the specified dot writing, it is necessary to cancel this command. 
    1.63 +[Definable area]
    1.64 +Pn = 30H - Remove the BMP box 
    1.65 +Pn = 31H - BMP box 1
    1.66 +Pn = 32H - BMP box 2
    1.67 +Pn = 33H - BMP box 3
    1.68 +*/
    1.69 +void GP1212A02A::BmpBoxSelect(TBmpBoxId aBoxId)
    1.70 +	{
    1.71 +	//TODO: check parameters validity 
    1.72 +	FutabaVfdReport report;
    1.73 +	report[0]=0x00; //Report ID
    1.74 +	report[1]=0x04; //Report length.
    1.75 +	report[2]=0x1B; //Command ID
    1.76 +	report[3]=0x5C; //Command ID
    1.77 +	report[4]=0x48; //Command ID
    1.78 +	report[5]=aBoxId; //BMP box ID
    1.79 +	Write(report);
    1.80 +	}
    1.81 +
    1.82 +
    1.83 +/**
    1.84  */
    1.85  void GP1212A02A::SetPixel(unsigned char aX, unsigned char aY, bool aOn)
    1.86  	{
    1.87 @@ -182,21 +254,41 @@
    1.88  
    1.89  
    1.90  /**
    1.91 -Using this function is advised against as is causes tearing.
    1.92 -Use Clear instead.
    1.93 +BMP data input 
    1.94 +[Code] 1BH,4AH,Pm,aL,aH,Ps,nL,nH,Pd...Pd
    1.95 +[Function] The BMP data is written in the DW(Display Window) or the Data memory. 
    1.96 +Pm= DW or Data memory 
    1.97 +aL = DW lower byte 
    1.98 +aH = DW upper byte 
    1.99 +Ps = Direction of writing 
   1.100 +nL = number of BMP data length lower byte 
   1.101 +nH = number of BMP data length upper byte 
   1.102 +Pd = BMP data 
   1.103 +* If X direction is selected as Ps and data is written in the last address, the data in the last address is 
   1.104 +overwritten with the remaining data.  
   1.105 +[Definable area] Pm = 30H : DW
   1.106 + Pm = 31H: Data memory 
   1.107 +0000H <= aL + aH * 100 <= 07FFH (DW)
   1.108 +0000H <= aL + aH * 100 <= 4FFFH (Data memory) 
   1.109 +Ps = 30H: Y direction 
   1.110 +Ps = 31H: X direction 
   1.111 +0001H <= nL + nH * 100 <= 0100H(DW: X direction) 
   1.112 +0001H <= nL + nH * 100 <= 0800H(DW: Y direction) 
   1.113 +0001H <= nL + nH * 100 <= 0A00H(Data memory: X direction) 
   1.114 +0001H <= nL + nH * 100 <= 5000H(Data memory: Y direction) 
   1.115  */
   1.116 -void GP1212A02A::SetFrame(int aSize, unsigned char* aPixels)
   1.117 +void GP1212A02A::BmpDataInput(TTarget aTarget, unsigned short aAddress, TDirection aDirection, unsigned short aSize, unsigned char* aPixels)
   1.118  {
   1.119  	FutabaVfdReport report;
   1.120      report[0]=0x00; //Report ID
   1.121      report[1]=(aSize<=report.Size()-10?aSize+0x08:64); //Report length. -10 is for our header first 10 bytes. +8 is for our Futaba header size
   1.122      report[2]=0x1B; //Command ID
   1.123      report[3]=0x4A; //Command ID
   1.124 -    report[4]=0x30; //DW Display Window
   1.125 -    report[5]=0x00; //aL = DW lower byte
   1.126 -    report[6]=0x00; //aH = DW upper byte
   1.127 -    report[7]=0x30; //Direction of writing: Y
   1.128 -	report[8]=aSize; //Size of pixel data in bytes (LSB)
   1.129 +    report[4]=aTarget; //Display Window or Data Memory
   1.130 +    report[5]=(unsigned char)aAddress; //aL = DW lower byte
   1.131 +    report[6]=aAddress>>8; //aH = DW upper byte
   1.132 +    report[7]=aDirection; //Direction of writing: Y or X
   1.133 +	report[8]=(unsigned char)aSize; //Size of pixel data in bytes (LSB)
   1.134  	report[9]=aSize>>8;	//Size of pixel data in bytes (MSB)
   1.135      int sizeWritten=MIN(aSize,report.Size()-10);
   1.136      memcpy(report.Buffer()+10, aPixels, sizeWritten);
   1.137 @@ -216,6 +308,70 @@
   1.138          }
   1.139  }
   1.140  
   1.141 +
   1.142 +/**
   1.143 +Data memory transfer
   1.144 +[Code] 1BH,5CH,44H,aL,aH
   1.145 +[Function] BMP data transfer from Data memory to DW. 
   1.146 +Although source data is updated, data in BMP box is not updated. To reflect the update, 
   1.147 +re-executing this command is necessary. 
   1.148 +aL = Lower byte of address 
   1.149 +aH = Upper byte of address 
   1.150 +[Definable area]
   1.151 +0000H <= aL + aH * 100 <= 4FFFH 
   1.152 +*/
   1.153 +void GP1212A02A::BmpBoxDataMemoryTransfer(unsigned short aAddress)
   1.154 +	{
   1.155 +	FutabaVfdReport report;
   1.156 +	report[0]=0x00; //Report ID
   1.157 +    report[1]=0x05; //Report length.
   1.158 +    report[2]=0x1B; //Command ID
   1.159 +    report[3]=0x5C; //Command ID
   1.160 +    report[4]=0x44; //Command ID
   1.161 +    report[5]=(unsigned char)aAddress; //aL = DM lower byte
   1.162 +    report[6]=aAddress>>8; //aH = DM upper byte
   1.163 +	Write(report);
   1.164 +	}
   1.165 +
   1.166 +/**
   1.167 +Input BMP data in the BMP box 
   1.168 +[Code] 1BH,5CH,5DH,nL,nH,Pd...Pd
   1.169 +[Function] BMP data is written the BMP box 
   1.170 +* Number of definable data is due to BMP box size. If the data is over range, the over range data is 
   1.171 +rewritten the final address. 
   1.172 +nL = Lower byte of number of definition byte 
   1.173 +nH = Upper byte of number of definition byte 
   1.174 +Pd = BMP data 
   1.175 +[Definable area] Pn : BMP box size (Pw * Ph)
   1.176 +*/
   1.177 +void GP1212A02A::BmpBoxDataInput(unsigned short aSize, unsigned char* aPixels)
   1.178 +	{
   1.179 +	FutabaVfdReport report;
   1.180 +    report[0]=0x00; //Report ID
   1.181 +    report[1]=(aSize<=report.Size()-7?aSize+0x05:64); //Report length. -7 is for our header first 10 bytes. +5 is for our Futaba header size
   1.182 +    report[2]=0x1B; //Command ID
   1.183 +    report[3]=0x5C; //Command ID
   1.184 +    report[4]=0x5D; //Display Window or Data Memory
   1.185 +	report[5]=(unsigned char)aSize; //Size of pixel data in bytes (LSB)
   1.186 +	report[6]=aSize>>8;	//Size of pixel data in bytes (MSB)
   1.187 +    int sizeWritten=MIN(aSize,report.Size()-7);
   1.188 +    memcpy(report.Buffer()+7, aPixels, sizeWritten);
   1.189 +    Write(report);
   1.190 +
   1.191 +    int remainingSize=aSize;
   1.192 +    //We need to keep on sending our pixel data until we are done
   1.193 +    while (report[1]==64)
   1.194 +        {
   1.195 +        report.Reset();
   1.196 +        remainingSize-=sizeWritten;
   1.197 +        report[0]=0x00; //Report ID
   1.198 +        report[1]=(remainingSize<=report.Size()-2?remainingSize:64); //Report length, should be 64 or the remaining size
   1.199 +        sizeWritten=(report[1]==64?63:report[1]);
   1.200 +        memcpy(report.Buffer()+2, aPixels+(aSize-remainingSize), sizeWritten);
   1.201 +        Write(report);
   1.202 +        }
   1.203 +	}
   1.204 +
   1.205  /**
   1.206  Using this function is advised against as is causes tearing.
   1.207  Use Clear instead.
   1.208 @@ -253,8 +409,13 @@
   1.209  	//Only perform buffer swapping if off screen mode is enabled
   1.210  	if (OffScreenMode())
   1.211  		{
   1.212 -		//Send host back buffer to device back buffer
   1.213 -		SetFrame(FrameBufferSizeInBytes(),iFrameNext->Ptr());
   1.214 +		//Send pixel directly into BMP box
   1.215 +		BmpBoxDataInput(FrameBufferSizeInBytes(),iFrameNext->Ptr());
   1.216 +		//Send pixel data directly into the display window
   1.217 +		//BmpDataInput(ETargetDisplayWindow,0x0000,EDirectionY, FrameBufferSizeInBytes(),iFrameNext->Ptr());
   1.218 +		//Send pixel data first to Data Memory then copy into the selected BMP box	
   1.219 +		//BmpDataInput(ETargetDataMemory,0x0000,EDirectionY, FrameBufferSizeInBytes(),iFrameNext->Ptr());
   1.220 +		//BmpBoxDataMemoryTransfer(0x0000);
   1.221  
   1.222          //Cycle through our frame buffers
   1.223          //We keep track of previous frame which is in fact our device back buffer.
     2.1 --- a/FutabaGP1212A02.h	Fri Aug 29 22:32:13 2014 +0200
     2.2 +++ b/FutabaGP1212A02.h	Sat Aug 30 18:43:54 2014 +0200
     2.3 @@ -36,7 +36,7 @@
     2.4  	virtual void Fill();
     2.5  
     2.6  	//Specific to GP1212A02A
     2.7 -	void SetFrame(int aSize, unsigned char* aPixels);
     2.8 +	
     2.9  	
    2.10      //
    2.11      void RequestDeviceId();
    2.12 @@ -56,6 +56,37 @@
    2.13  	char* DeviceId();
    2.14  	char* FirmwareRevision();
    2.15  
    2.16 +	enum TBmpBoxId
    2.17 +	{
    2.18 +		EBmpBoxIdNull=0x30,
    2.19 +		EBmpBoxIdOne=0x31,
    2.20 +		EBmpBoxIdTwo=0x32,
    2.21 +		EBmpBoxIdThree=0x33
    2.22 +	};
    2.23 +
    2.24 +	enum TTarget
    2.25 +	{
    2.26 +		ETargetDisplayWindow=0x30,
    2.27 +		ETargetDataMemory=0x31
    2.28 +	};
    2.29 +
    2.30 +
    2.31 +	enum TDirection
    2.32 +	{
    2.33 +		EDirectionY=0x30,
    2.34 +		EDirectionX=0x31
    2.35 +	};
    2.36 +
    2.37 +
    2.38 +	//General setting command
    2.39 +	void BmpDataInput(TTarget aTarget, unsigned short aAddress, TDirection aDirection, unsigned short aSize, unsigned char* aPixels);
    2.40 +
    2.41 +	//BMP box
    2.42 +	void BmpBoxSetting(TBmpBoxId aBoxId, unsigned short aAddress, int aWidth, int aHeight);
    2.43 +	void BmpBoxSelect(TBmpBoxId aBoxId);
    2.44 +	void BmpBoxDataMemoryTransfer(unsigned short aAddress);
    2.45 +	void BmpBoxDataInput(unsigned short aSize, unsigned char* aPixels);
    2.46 +
    2.47  private:
    2.48  	unsigned char OffScreenY() const;
    2.49  	void SendClearCommand();