Linux load bitmap
Posted: Sun Apr 14, 2024 12:54 pm
Newbie here. Attempting to just display a bitmap on GTT35 under Linux in C. I'm using the driver code found in Firmware\Client\gttclient . Below is my code -- it always hangs in the midst of gtt_load_bitmap(). As you can see from the commented-out code, I also tried the gtt25_ API.
#include <termios.h>
#include <stdio.h>
#include <stdint.h>
#include <fcntl.h>
#include <unistd.h>
#include <gtt_protocol.h>
#include <gtt_device.h>
#include <gtt_text.h>
#define BAUDRATE B115200
#define port "/dev/ttyUSB0"
// Buffer for incoming data
uint8_t rx_buffer[512];
// Buffer for outgoing data
uint8_t tx_buffer[512];
int generic_write(gtt_device *device, uint8_t *data, size_t length)
{
// This function is a platform-dependent write function that
// transfers 'length' bytes of 'data' to the unit.
// This function returns the number of bytes written
return write((intptr_t)device->Context, data, length);
}
int generic_read(gtt_device *device)
{
static uint8_t buffer[512];
// This function is a platform-dependent read function that
// reads a single byte from the unit.
// this function returns the byte read when data is available
// and returns -1 if no data is currently available.
return read((intptr_t)device->Context, buffer, sizeof(buffer) / sizeof(buffer[0]));
}
// The gtt_device structre keeps the state of the gtt protocol and allows
// the library to talk to several devices connected to the same system
// it needs a platform depenend read/write function and some basic
// information about the size and location of the instance specific rx/tx buffers.
gtt_device gtt_device_instance = {
.Write = generic_write,
.Read = generic_read,
.rx_buffer = rx_buffer,
.rx_buffer_size = sizeof(rx_buffer),
.tx_buffer = tx_buffer,
.tx_buffer_size = sizeof(tx_buffer),
};
int main(int argc, char** argv) {
gtt_device *gtt = >t_device_instance;
struct termios term;
//Open the serial port
int lcd = open(port, O_RDWR | O_NOCTTY | O_NONBLOCK);
//handle errors
if (lcd < 0) {
printf("Error opening serial port %s\n", port);
return -1;
}
//Setup the serial port 8 data bits, no parity ,1 stopbit, no flow control
term.c_cflag = BAUDRATE | CS8 | CSTOPB | CLOCAL | CREAD;
term.c_iflag = 0;
term.c_oflag = 0;
term.c_lflag = 0;
term.c_cc[VMIN] = 0; // Minimum number of characters for non-blocking read
term.c_cc[VTIME] = 0; // Timeout in deciseconds for non-blocking read
tcflush(lcd, TCIFLUSH);
tcsetattr(lcd, TCSANOW, &term);
gtt->Context = (void *)(intptr_t)lcd;
//Clear the screen
printf("*********** Clearing screen....\n");
gtt_clear_screen(gtt);
//Draw a line in the default drawing color
// gtt_draw_line(gtt, 0, 0, 480, 272);
// gtt_load_bitmap(gtt, 20, "logo4835monochromeontransparent200.bmp");
printf("******** Loading bitmap...\n");
gtt_load_bitmap(gtt, 20, "Logo70A.bmp");
// gtt25_bitmap_load(gtt, 20, gtt_make_text_ascii("logo4835monochromeontransparent200.bmp"));
printf("********* Displaying bitmap...\n");
gtt_display_bitmap(gtt, 20, 0, 0);
// gtt25_bitmap_capture(gtt, 20, 0, 0, 200, 200);
printf("********* Done\n");
//Process any data coming in
/*
while (1) {
gtt_parser_process(gtt);
}
*/
return 0;
}
#include <termios.h>
#include <stdio.h>
#include <stdint.h>
#include <fcntl.h>
#include <unistd.h>
#include <gtt_protocol.h>
#include <gtt_device.h>
#include <gtt_text.h>
#define BAUDRATE B115200
#define port "/dev/ttyUSB0"
// Buffer for incoming data
uint8_t rx_buffer[512];
// Buffer for outgoing data
uint8_t tx_buffer[512];
int generic_write(gtt_device *device, uint8_t *data, size_t length)
{
// This function is a platform-dependent write function that
// transfers 'length' bytes of 'data' to the unit.
// This function returns the number of bytes written
return write((intptr_t)device->Context, data, length);
}
int generic_read(gtt_device *device)
{
static uint8_t buffer[512];
// This function is a platform-dependent read function that
// reads a single byte from the unit.
// this function returns the byte read when data is available
// and returns -1 if no data is currently available.
return read((intptr_t)device->Context, buffer, sizeof(buffer) / sizeof(buffer[0]));
}
// The gtt_device structre keeps the state of the gtt protocol and allows
// the library to talk to several devices connected to the same system
// it needs a platform depenend read/write function and some basic
// information about the size and location of the instance specific rx/tx buffers.
gtt_device gtt_device_instance = {
.Write = generic_write,
.Read = generic_read,
.rx_buffer = rx_buffer,
.rx_buffer_size = sizeof(rx_buffer),
.tx_buffer = tx_buffer,
.tx_buffer_size = sizeof(tx_buffer),
};
int main(int argc, char** argv) {
gtt_device *gtt = >t_device_instance;
struct termios term;
//Open the serial port
int lcd = open(port, O_RDWR | O_NOCTTY | O_NONBLOCK);
//handle errors
if (lcd < 0) {
printf("Error opening serial port %s\n", port);
return -1;
}
//Setup the serial port 8 data bits, no parity ,1 stopbit, no flow control
term.c_cflag = BAUDRATE | CS8 | CSTOPB | CLOCAL | CREAD;
term.c_iflag = 0;
term.c_oflag = 0;
term.c_lflag = 0;
term.c_cc[VMIN] = 0; // Minimum number of characters for non-blocking read
term.c_cc[VTIME] = 0; // Timeout in deciseconds for non-blocking read
tcflush(lcd, TCIFLUSH);
tcsetattr(lcd, TCSANOW, &term);
gtt->Context = (void *)(intptr_t)lcd;
//Clear the screen
printf("*********** Clearing screen....\n");
gtt_clear_screen(gtt);
//Draw a line in the default drawing color
// gtt_draw_line(gtt, 0, 0, 480, 272);
// gtt_load_bitmap(gtt, 20, "logo4835monochromeontransparent200.bmp");
printf("******** Loading bitmap...\n");
gtt_load_bitmap(gtt, 20, "Logo70A.bmp");
// gtt25_bitmap_load(gtt, 20, gtt_make_text_ascii("logo4835monochromeontransparent200.bmp"));
printf("********* Displaying bitmap...\n");
gtt_display_bitmap(gtt, 20, 0, 0);
// gtt25_bitmap_capture(gtt, 20, 0, 0, 200, 200);
printf("********* Done\n");
//Process any data coming in
/*
while (1) {
gtt_parser_process(gtt);
}
*/
return 0;
}