Skip to content
Snippets Groups Projects
Commit 8400b8a9 authored by Eberhard Stoll's avatar Eberhard Stoll
Browse files

Initial commit

parents
Branches master
No related tags found
No related merge requests found
File added
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.c
main.c 0 → 100644
/*
* (c) 2018 Exceet electronics Gmbh: Modified sample code for goodix touch controller
*
* This is goodix tool. Its purpose is to provide some information
* like controller and configuration version about the goodix touch
* controller on the spi bus.
*
* BE AWARE:
* - The bus and the address is hard coded!
* - This tool is simple and assumes to be the only who talks to the goodix touch.
* So it can disturb a running goodix device driver or deliver wrong values.
*/
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <linux/i2c-dev.h>
#include <errno.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#define PROGRAM_VERSION "1.0"
#define I2C_ADDR 0x5d
#define I2C_DEVICE "/dev/i2c-3"
void print_help()
{
printf("Usage:\n");
printf(" goodix [-h|DEVICEFILE]\n");
printf("\n");
printf("DEVICEFILE i2c bus device like 'i2c-3' (default value)\n");
printf(" -h Help text\n");
printf("\n");
printf("Program version %s", PROGRAM_VERSION);
printf("\n");
}
int main (int argc, char **argv) {
char buffer[11];
char i2c_device[50];
int fd;
// set defaults
memset(i2c_device, '\0', sizeof(i2c_device));
strcpy(i2c_device, I2C_DEVICE);
if (argc > 2){
printf("ERROR: Too many arguments\n");
print_help();
exit(1);
}
if (2 == argc){
if ('-' == argv[1][0]){
print_help();
exit(1);
}
// Use device from commandline
strncpy(i2c_device, argv[1], sizeof(i2c_device)-1);
}
printf("i2c interface : %s\n", i2c_device);
printf("device addr : 0x%02x\n", I2C_ADDR);
fd = open(i2c_device, O_RDWR);
if (fd < 0) {
printf("Error opening file <%s>: %s\n", I2C_DEVICE, strerror(errno));
return 1;
}
// I2C_SLAVE
if (ioctl(fd, I2C_SLAVE_FORCE, I2C_ADDR) < 0) {
printf("ioctl error: %s\n", strerror(errno));
return 1;
}
// Product ID
unsigned int fw_version = 0;
unsigned int vendor_id = 1;
unsigned int xres;
unsigned int yres;
char product_id[4];
unsigned int config_version;
// Firmware version etc
buffer[0]=0x81;
buffer[1]=0x40;
write(fd, buffer, 2);
read(fd, buffer, 11);
product_id[0] = buffer[0];
product_id[1] = buffer[1];
product_id[2] = buffer[2];
product_id[3] = buffer[3];
fw_version = (buffer[5] << 8) | buffer[4];
xres = (buffer[7] << 8) | buffer[6];
yres = (buffer[9] << 8) | buffer[8];
vendor_id = buffer[10];
// Config version
buffer[0]=0x80;
buffer[1]=0x47;
write(fd, buffer, 2);
if (-1 == read(fd, buffer, 2)){
printf("read error: %s\n", strerror(errno));
return 1;
}
config_version = buffer[0];
printf("product id : %c%c%c%c\n", product_id[0], product_id[1], product_id[2], product_id[3]);
printf("fw version : 0x%04X\n", fw_version);
printf("config version: %d (0x%02X)\n", config_version, config_version);
printf("resolution x/y: %dx%d\n", xres, yres);
printf("vendor id : 0x%02X\n", vendor_id);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment