Page 1 of 1

GLK19264 Bitmap Upload Sample

Posted: Wed Mar 16, 2011 11:21 am
by Lynx28
I've seen several posts asking how to upload bitmaps and thought I would post a function I'm using to do the uploads. The function is written in C mainly because it will be added as a utility to lcdproc and it needs to follow their code standards.

The documentation shows how to code a font, which is also the same format that should be used for bitmaps. However, I'll provide a sample Up Arrow icon that I've created for this example.

Code: Select all

The up arrow is 5x7 with the following layout

00100
01110
10101
00100
00100
00100
00100

Translated into chars: 0x23, 0xAA, 0x42, 0x10, 0x80

I put this into an array with: command, refid (0x35), size (LSB-MSB), width, height, bitmap:
unsigned char UpArrow[] = {0xfe, 0x5e, 0x35, 0x07, 0x00, 0x05, 0x07, 0x23, 0xaa, 0x42, 0x10, 0x80};

Call the function below with this command after initializing the device (lcd is the handle returned from open):
upload_bitmap(lcd, "Up Arrow", UpArrow);

Function used to perform the upload:
void upload_bitmap(int fd, const char *name, unsigned char* buff)
{
	unsigned char c = 0x00;
	unsigned char ack = 0x01;
	bool success = false;
	int idx, len;

	/* Send the upload command with ref and length. 
	   Length includes the width and height */
	printf("\nStarting %s upload\n", name);
	write(fd, buff, 5);

	/* Device will send back an ACK if there is enough room for the bitmap */
	puts("waiting for ACK");
	read(fd, &c, 1);
	if( c == ack ) {
		/* good to go... send width, height, bitmap. Each char sent is
		   echoed back and we need to send an ACK before sending the next char */
		printf("Sending width: %x\n", buff[5]);
		write(fd, &buff[5], 1);
		read(fd, &c, 1);
		if( c == buff[5] ) {
			write(fd, &ack, 1);
			printf("Sending height: %x\n", buff[6]);
			write(fd, &buff[6], 1);
			read(fd, &c, 1);
			if( c == buff[6]) {
				write(fd, &ack, 1);
				puts("Sending Bitmap");

				/* get the bitmap length, add the current buff position, and
   			   loop through the rest of the buffer making sure the char sent
				   is echoed back and sending an ACK before the next char */
				len = buff[4];
				len = ((len << 8) + buff[3] - 2) + 7;
				printf("Bitmap Length = %d bytes\n", len - 7);
				for( idx = 7; idx < len; idx++ ) {
					write(fd, &buff[idx], 1);
					read(fd, &c, 1);
					if( c == buff[idx]) {
						write(fd, &ack, 1);
					}			
					else {
						puts("Error writing bitmap!");
						break;
					}	
				}
				if( idx == len ) {
					puts("Upload successful");
					success = true;
				}
			}
		}
	}
	else {
		printf("Upload denied! %x was returned\n", c);
	}
}
EDIT: The code has been updated to include MSB when calculating the bitmap length.

The current documentation for GLK19264 is pretty good but there is a mistake in the upload protocol. As you'll see in this function after receiving the ACK (0x01) to confirm that there is room to upload the bitmap the very next char sent is the width. However, the document shows that you should send back 0x01, which is incorrect. Matrix Orbital is aware of this and will be updating the documentation.

Hopefully this helps anyone trying to write code to perform uploads.

--Lonnie

Posted: Wed Mar 16, 2011 4:15 pm
by Clark
Thanks Lonnie,

That C code should work great for other GLK19264 users, and in fact anyone with a display that accepts that command and has a firmware revision less than 8.1. We have a quick example for C# users in our AppNote section, and when I get some time I'd like to add this as well, with citations of course.

~Troy

What means MSB-LSB

Posted: Thu Mar 17, 2011 7:35 am
by Gerd
What means MSB-LSB?

I want to upload a 192x64 bitmap. 192x64/8Bi t= 1536 bytes
1536 + 2 Byte = 1538

How must 1538 be coded? which of them is right:

* 0x1538
* 0x3815
* 0x0602
* 0x0206

Thank you

Posted: Thu Mar 17, 2011 8:59 am
by Clark
Hello Gerd,

The file size is to be sent to the display with the Least Significant Byte first, and the Most Significant Byte last. In Lynx's example, if you wanted to save a 1536 byte file to reference ID 0x35, you would start the command 0xfe, 0x5e, 0x35, 0x02, 0x06.

Thanks,
~Troy

Posted: Thu Mar 17, 2011 12:27 pm
by Lynx28
Hi Troy,

Glad I can help and it would be great if you want to include this in the code samples provided by Matrix Orbital.

C# is actually the main language I use these days... had to brush off the C cobwebs to work on the driver... but the upload code should be something that anyone with C, C++, C# or Java experience can follow.

--Lonnie

Code Update

Posted: Fri Mar 18, 2011 8:17 am
by Lynx28
I was using this code to upload smaller bitmaps and originally did not include MSB when calculating the bitmap length to iterate through the remainder of the buffer.

After the post from Gerd asking about LSB-MSB I realized that the code needed to be updated to include MSB when calculating the length.

As a result, I have updated the original code and tested to make sure that the length calculation is correct when including MSB.

Thanks,
Lonnie (Lynx28)

Posted: Tue Aug 02, 2011 10:13 pm
by MarkAtESpecTech
I hit that documentation snag as well. Took awhile to figure out, I eventually looked at another doc for a different LCD than the one I am using and it was correct.

Posted: Wed Aug 03, 2011 9:25 am
by Clark
Thanks Mark; the GLK240128 and GLK24064s have all been updated, the GLK19264-7T-1U is next on the list for a manual overhaul. Until then, the appnote linked in the post above should help.

~Troy