Hi all!

I have a problem accessing the struct fb_cmap on my embedded board.
I tried the code below, but without success. The thing, that goes wrong is

if (ioctl(fbfd, FBIOGETCMAP, &cmap) == -1) {
   perror("Error get color map");
   exit(1);
}

If I use a reference like above, I get 
Error get color map: Invalid argument

If I use the struct itself, 
ioctl(fbfd, FBIOGETCMAP, &cmap)
I get Error get color map: Bad address 

Could anyone please give me a hint, what to do? I spent hours with google, 
but without any success,

Thanke in advance!
Bye,
Andy

here is the hwole code I used:

#include "stdlib.h"
#include "unistd.h"
#include "stdio.h"
#include "fcntl.h"
#include "linux/fb.h"
#include "sys/mman.h"
#include "sys/ioctl.h"

int main()
{
    int fbfd = 0;
    struct fb_var_screeninfo vinfo;
    struct fb_fix_screeninfo finfo;
    struct fb_cmap cmap;
    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 == -1) {
        perror("Error: cannot open framebuffer device");
        exit(1);
    }
    printf("The framebuffer device was opened successfully.\n");

    // Get fixed screen information
    if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo) == -1) {
        perror("Error reading fixed information");
        exit(2);
    }

     // Get variable screen information
    if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo) == -1) {
        perror("Error reading variable information");
        exit(3);
    }
    printf("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, 
vinfo.bits_per_pixel);

    // Figure out the size of the screen in bytes
    screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
 
    // Check depth
    if (vinfo.bits_per_pixel != 8) {
        perror("Error: not 8 bits/pixel");
        exit(1);
    }
 
    // Map the device to memory
    fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED,
                       fbfd, 0);
    if ((int)fbp == -1) {
        perror("Error: failed to map framebuffer device to memory");
        exit(4);
    }
    printf("The framebuffer device was mapped to memory successfully.\n"); 
 
 
    // Draw block
    for (y = 100; y < 300; y++) {
        for (x = 100; x < 300; x++) { 
            location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) +
                       (y+vinfo.yoffset) * finfo.line_length;
            *((unsigned short int*)(fbp + location)) = 0;
        }
    } 
 
    // Read color map
      if (ioctl(fbfd, FBIOGETCMAP, &cmap) == -1) {
        perror("Error get color map");
        exit(1);
    }
    printf("Colormap %d %d", cmap.start, cmap.len);

    // Change color 0
    cmap.red[cmap.start+0] = 0xFF;
    cmap.green[cmap.start+0] = 0xFF;
    cmap.blue[cmap.start+0] = 0xFF;
 
    if (ioctl(fbfd, FBIOPUTCMAP, &cmap) == -1) {
        perror("Error set color map");
        exit(1);
    } 
    printf("Colormap set");

    munmap(fbp, screensize);
    close(fbfd);
    return 0;
}

Reply via email to