display/display.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <dirent.h>
#include <string.h>
#include <errno.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <linux/fb.h>
#include "delta.h"
Include dependency graph for display/display.c:

Go to the source code of this file.

Functions

int display_image (int fbDev, unsigned char *screen_memory, char *filename, int waveform, struct fb_var_screeninfo *screen_info)
int downloadwaves (int fbDev, char *filename, int from_sysset)
int deltainit (int fbDev)
int deltaregdump (int fbDev)
int main (int argc, char *argv[])

Function Documentation

int deltainit ( int  fbDev  ) 

Definition at line 132 of file display/display.c.

References FBIO_DELTA_INIT.

Referenced by main().

00133 {
00134     int ret = 0;
00135     
00136     if ((ret = ioctl(fbDev, FBIO_DELTA_INIT, NULL)) != 0)
00137     {
00138         printf("Error sending FBIO_DELTA_INIT: %x\n", ret);
00139     }
00140 
00141     return ret;
00142 }

Here is the caller graph for this function:

int deltaregdump ( int  fbDev  ) 

Definition at line 145 of file display/display.c.

References FBIO_DELTA_REG_DUMP.

Referenced by main().

00146 {
00147     int ret = 0;
00148     
00149     if ((ret = ioctl(fbDev, FBIO_DELTA_REG_DUMP, NULL)) != 0)
00150     {
00151         printf("Error sending FBIO_DELTA_REG_DUMP: %x\n", ret);
00152     }
00153 
00154     return ret;
00155 }

Here is the caller graph for this function:

int display_image ( int  fbDev,
unsigned char *  screen_memory,
char *  filename,
int  waveform,
struct fb_var_screeninfo *  screen_info 
)

Copyright (C) 2008 iRex Technologies B.V. All rights reserved.

Definition at line 41 of file display/display.c.

References display_update_info::color, FBIO_DELTA_UPDATE_DISPLAY, and display_update_info::waveform.

Referenced by main().

00042 {    
00043     int ret;
00044     FILE *f;
00045     struct display_update_info info;
00046     unsigned char *tempmem = NULL;
00047     
00048     info.waveform = waveform;
00049     info.color = 0;
00050 
00051     /* Allocate temp buffer to hold the file data */
00052     if ( screen_info )
00053     {
00054         tempmem = malloc( screen_info->xres * screen_info->yres);
00055     }
00056     else
00057     {
00058         printf("Invalid screen info\n");
00059         return -1;
00060     }        
00061     
00062     if (tempmem == NULL)
00063     {
00064         printf("Not enough memory\n");
00065         return -1;
00066     }
00067 
00068     /* open the image */
00069     if (!(f = fopen(filename, "r")))
00070     {
00071         printf("Error opening file %s\n", filename);
00072         return -1;
00073     }
00074 
00075     printf("Read %ld bytes\n", (unsigned long)fread(tempmem, 1, screen_info->xres * screen_info->yres, f));
00076 
00077     /* close the image */
00078     fclose(f);
00079     memcpy(screen_memory, tempmem, screen_info->xres * screen_info->yres);
00080     free(tempmem);
00081 
00082     printf("Displaying %s\n", filename);
00083 
00084     /* tell the display to update itself */
00085     if ((ret = ioctl(fbDev, FBIO_DELTA_UPDATE_DISPLAY, &info)))
00086     {
00087         printf("Error sending FBIO_DISPLAY: %x\n", ret);
00088     }
00089     
00090     return ret;
00091 }

Here is the caller graph for this function:

int downloadwaves ( int  fbDev,
char *  filename,
int  from_sysset 
)

Definition at line 94 of file display/display.c.

References FBIO_DELTA_UPLOADWAVES, wave_info::size, wave_info::wave, and WAVEFORM_SIZE.

Referenced by main().

00095 {
00096     int ret;
00097     FILE *f;
00098     struct wave_info info;
00099     
00100     /* open the wave file */
00101     if (!(f = fopen(filename, "r")))
00102     {
00103         printf("Error opening file %s\n", filename);
00104         return -1;
00105     }
00106 
00107     if (from_sysset)
00108     {
00109       fseek(f, 128*(1<<10), SEEK_SET);
00110     }
00111     info.wave = malloc(128 * 1024);
00112     if (info.wave == NULL)
00113     {
00114         printf("Not enough memory\n");
00115         return -1;
00116     }
00117     info.size = fread(info.wave, 1, WAVEFORM_SIZE, f);
00118 
00119     /* close the image */
00120     fclose(f);
00121 
00122     if ((ret = ioctl(fbDev, FBIO_DELTA_UPLOADWAVES, &info)) != 0)
00123     {
00124         printf("Error sending FBIO_DELTA_UPLOADWAVES: %x\n", ret);
00125     }
00126     free(info.wave);
00127 
00128     return ret;
00129 }

Here is the caller graph for this function:

int main ( int  argc,
char *  argv[] 
)

Definition at line 158 of file display/display.c.

References display_update_info::color, deltainit(), deltaregdump(), display_image(), downloadwaves(), fbDev, FBIO_DELTA_ERASE, FBIO_DELTA_REG_WRITE, FBIO_DETA_FPGA_VERSION, FBIO_DETA_VCOM_SET, serial, usage(), and display_update_info::waveform.

00159 {
00160     int fbDev;
00161     int ret;
00162     unsigned char *screen_memory;
00163     FILE *f;
00164     struct display_update_info info;
00165     char serial[16];
00166     double vcom = 0;
00167     signed long vcom_int;
00168     int waveform;
00169     unsigned int fpga_version;
00170     struct fb_var_screeninfo var;
00171 
00172     fbDev = open ("/dev/fb0", O_RDWR);
00173     if (fbDev == -1)   
00174     {
00175         printf("Error opening framebufferdevice. # mknod /dev/fb0 c 29 0\n");
00176         exit(-1);
00177     }
00178 
00179     ret = ioctl(fbDev, FBIOGET_VSCREENINFO, &var);
00180 #ifdef DEBUG
00181     fprintf(stderr, ">> fb geometry %u %u %u %u %u\n", var.xres, var.yres, 
00182             var.xres_virtual, var.yres_virtual, var.bits_per_pixel);
00183 #endif    
00184     if((ret == -1) || (var.xres == 0) || (var.yres == 0))
00185     {
00186         printf("Failed to read out framebuffer screen info\n");        
00187         exit(-1);
00188     }
00189     
00190     screen_memory = (unsigned char *) mmap(0, var.xres * var.yres, PROT_READ | PROT_WRITE, MAP_SHARED, fbDev, 0);
00191     if(screen_memory == ((void *)-1))
00192     {
00193         perror("\nError mmap-ping\n");
00194         exit(-1);
00195     }
00196 
00197     if(argc < 2)
00198         goto usage;
00199 
00200     if(!strcasecmp(argv[1], "REGDUMP"))
00201     {
00202         if(argc != 2)
00203             goto usage;
00204         /* Delta register dump */
00205         printf("Delta registers dump:\n");
00206         deltaregdump(fbDev);
00207         printf("OK\n");
00208     }
00209     else if(!strcasecmp(argv[1], "REGWRITE"))
00210     {
00211       unsigned char addr, value;
00212       unsigned long addr_value;
00213       unsigned int tmp;
00214 
00215         if(argc != 4)
00216             goto usage;
00217 
00218       sscanf(argv[2], "%x", &tmp);
00219       addr = tmp & 0xFF;
00220 
00221       sscanf(argv[3], "%x", &tmp);
00222       value = tmp & 0xFF;
00223 
00224       addr_value = (addr << 16) | value;
00225 
00226         ret = ioctl(fbDev, FBIO_DELTA_REG_WRITE, &addr_value);
00227         if (ret == -1)
00228         {
00229             printf("Error writing register\n");
00230         }
00231     }
00232     else if(!strcasecmp(argv[1], "INIT"))
00233     {
00234         if(argc != 2)
00235             goto usage;
00236         /* Delta init */
00237         printf("Initializing Delta....  ");
00238         deltainit(fbDev);
00239         printf("OK\n");
00240     }
00241     else if(!strcasecmp(argv[1], "SYSWAVES"))
00242     {
00243         if(argc != 3)
00244             goto usage;
00245         /* Upload the waves */
00246         printf("Uploading waves from sysset....  ");
00247         downloadwaves(fbDev, argv[2], 1);
00248         printf("OK\n");
00249     }
00250     else if(!strcasecmp(argv[1], "WAVES"))
00251     {
00252         if(argc != 3)
00253             goto usage;
00254         /* Upload the waves */
00255         printf("Uploading waves....  ");
00256         downloadwaves(fbDev, argv[2], 0);
00257         printf("OK\n");
00258     }
00259     else if(!strcasecmp(argv[1], "ERASE"))
00260     {
00261         if(argc != 3)
00262             goto usage;
00263         /* Upload the waves */
00264         printf("Erasing display....  ");
00265         info.waveform = 1;
00266         info.color = atoi(argv[2]);
00267         if(info.color < 0) 
00268             info.color = 0;
00269         if(info.color >15) 
00270             info.color = 15;
00271         ret=ioctl(fbDev, FBIO_DELTA_ERASE, &info);       
00272         printf("OK\n");
00273     }
00274     else if(!strcasecmp(argv[1], "UPDATE"))
00275     {
00276         if(argc < 3)
00277             goto usage;
00278         if(argc == 4)
00279             waveform = atoi(argv[3]);
00280         else
00281             waveform = 1;
00282         /* Upload the waves */
00283         printf("Updating display.... ");
00284         /* map the framebuffer memory */
00285         ret = display_image(fbDev, screen_memory, argv[2], waveform, &var);
00286         munmap(screen_memory, var.xres * var.yres);
00287         printf("OK\n");
00288     }
00289     else if(!strcasecmp(argv[1], "SERIAL"))
00290     {
00291         if(argc != 2)
00292             goto usage;
00293         f = fopen("/sys/bus/w1/devices/w1_bus_master1/w1_master_slaves", "r");
00294         fgets(serial, 16, f);            
00295         fclose(f);
00296         printf("Display serial: %s\n", serial); 
00297     }
00298     else if(!strncasecmp(argv[1], "VCOM_SET", 5))
00299     {
00300         if(argc != 3)
00301             goto usage;
00302         vcom = atof(argv[2]);
00303         if(vcom < -5)
00304             vcom = -5;
00305         if(vcom > 5)
00306             vcom = 5;
00307         vcom_int = (signed long)(1000 * vcom);
00308         ret = ioctl(fbDev, FBIO_DETA_VCOM_SET, &vcom_int);
00309         if (ret == -1)
00310         {
00311             printf("Error setting VCOM\n");
00312         }
00313     }
00314     else if(!strncasecmp(argv[1], "FPGA_VER", 8))
00315     {
00316         if(argc != 2)
00317             goto usage;
00318         ret = ioctl(fbDev, FBIO_DETA_FPGA_VERSION, &fpga_version);
00319         if (ret == -1)
00320         {
00321             printf("Error getting FPGA version\n");
00322         }
00323         else
00324         {
00325             printf("%04X\n", fpga_version);
00326         }
00327     }
00328     else if (!strncasecmp(argv[1], "XRES", 4))
00329     {
00330         printf("%d\n", var.xres);
00331     }
00332     else if (!strncasecmp(argv[1], "YRES", 4))
00333     {
00334         printf("%d\n", var.yres);
00335     }
00336     else
00337     {
00338         printf("Unknow command: %s\n\n", argv[1]);
00339         munmap(screen_memory, var.xres * var.yres);
00340         exit(-1);
00341     }
00342     munmap(screen_memory, var.xres * var.yres);
00343     return ret;
00344 
00345 usage:
00346     printf("Usage: %s COMMAND [parameter]\n\n", argv[0]);
00347     printf("Valid commands are:\n");
00348     printf(" INIT     - Initialise Delta\n");
00349     printf(" WAVES    - Download wave file specified as parameter to Delta\n");
00350     printf(" SYSWAVES - Download wave file from sysset partition to Delta\n");
00351     printf(" ERASE    - Erase display to specified color\n");
00352     printf(" UPDATE   - Update display with picture\n");
00353     printf(" SERIAL   - Get display serila number\n");
00354     printf(" VCOM_SET - Set display VCOM voltage\n");
00355     printf(" FPGA_VER - Get display FPGA version\n");
00356     printf(" XRES     - Get display X-resolution\n");
00357     printf(" YRES     - Get display Y-resolution\n");
00358     printf(" REGDUMP             - Delta register dump\n");
00359     printf(" REGWRITE addr value - Delta register write\n");
00360     munmap(screen_memory, var.xres * var.yres);
00361     exit(-1);
00362 }

Here is the call graph for this function:

Generated by  doxygen 1.6.2-20100208