Итак, заливаю следующим тестом:
Код
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
int main()
{
int fbfd = 0;
struct fb_var_screeninfo vinfo;
struct fb_fix_screeninfo finfo;
long int screensize = 0;
char *fbp = 0;
int x = 0, y = 0;
long int location = 0;
// Open the file for reading and writing
fbfd = open("/dev/fb0", O_RDWR);
if (!fbfd) {
printf("Error: cannot open framebuffer device.\n");
exit(1);
}
printf("The framebuffer device was opened successfully.\n");
// Get fixed screen information
if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo)) {
printf("Error reading fixed information.\n");
exit(2);
}
// Get variable screen information
if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) {
printf("Error reading variable information.\n");
exit(3);
}
printf("%dx%d, %dbpp, %d linelen %d xoffs %d yoffs\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel,\
finfo.line_length,vinfo.xoffset,vinfo.yoffset);
// Figure out the size of the screen in bytes
screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
// Map the device to memory
fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED,
fbfd, 0);
if ((int)fbp == -1) {
printf("Error: failed to map framebuffer device to memory.\n");
exit(4);
}
printf("The framebuffer device was mapped to memory successfully.\n");
for (y = 0; y < 360; y++)
for (x = 0; x < 800; x++) {
location = (x+vinfo.xoffset) * 3 + (y+vinfo.yoffset) * finfo.line_length;
int b = 0x0;
int g = 0x0; // A little green
int r = 0x00; // A lot of red
unsigned int t = r<<12 | g << 6 | b;
*((unsigned char*)(fbp + location)) = t&0xff;
*((unsigned char*)(fbp + location + 1)) = (t>>8)&0xff;
*((unsigned char*)(fbp + location + 2)) = (t>>16)&0xff;
}
// Figure out where in memory to put the pixel
for (y = 10; y < 300; y++)
for (x = 100; x < 200; x++) {
location = (x+vinfo.xoffset) * 3 + (y+vinfo.yoffset) * finfo.line_length;
int b = 0x00;
int g = 0xff; // A little green
int r = 0x00; // A lot of red
unsigned int t = r<<12 | g << 6 | b;
*((unsigned char*)(fbp + location)) = t&0xff;
*((unsigned char*)(fbp + location + 1)) = (t>>8)&0xff;
*((unsigned char*)(fbp + location + 2)) = (t>>16)&0xff;
}
x = 400; y = 100; // Where we are going to put the pixel
for (y = 10; y < 200; y++)
for (x = 300; x < 400; x++) {
location = (x+vinfo.xoffset) * 3 + (y+vinfo.yoffset) * finfo.line_length;
int b = 0x0;
int g = 0x00; // A little green
int r = 0xff; // A lot of red
unsigned int t = r<<12 | g << 6 | b;
*((unsigned char*)(fbp + location)) = t&0xff;
*((unsigned char*)(fbp + location + 1)) = (t>>8)&0xff;
*((unsigned char*)(fbp + location + 2)) = (t>>16)&0xff;
}
for (y = 10; y < 360; y++)
for (x = 500; x < 885; x++) {
location = (x+vinfo.xoffset) * 3 + (y+vinfo.yoffset) * finfo.line_length;
int b = 0xff;
int g = 0x0; // A little green
int r = 0x00; // A lot of red
unsigned int t = r<<12 | g << 6 | b;
*((unsigned char*)(fbp + location)) = t&0xff;
*((unsigned char*)(fbp + location + 1)) = (t>>8)&0xff;
*((unsigned char*)(fbp + location + 2)) = (t>>16)&0xff;
}
munmap(fbp, screensize);
close(fbfd);
return 0;
}
Цвета пишутся правильно, а вот с адресацией проблемы ...
Если писать строки больше 360 вылетает сообщение "Segmentation fault".
Зато по Х это сообщение выходит при записи начиная с 885 точки (а не 800).
Еще, я в сметении, в линухе чтоб записать в видеопамять что-либо нужно тучу драйверов поставить, проникнуться "десятью" уровнями каких-то абстракций и в итоге Я САМ ДОЛЖЕН СДВИГАТЬ RGB С УЧЕТОМ СПЕЦИФИКИ МОЕЙ TFT
Еще одна неприятность, если выводить сообщения на консоль (эту самую TFT), то в ответ на вывод сообщения которое не влезет в экран (по вертикали) вываливается сообщение
Kernel panic - not syncing: pixel_to_pat(): unsupported pixelformat и приехали ...