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);
}
}
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