Want more features on Pastebin? Sign Up, it's FREE!
Guest

playusb.patch for AX206 ver 2.0

By: a guest on May 3rd, 2012  |  syntax: Diff  |  size: 25.47 KB  |  views: 165  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. diff -Nuar playusb/dpf.h playusb-ax206/dpf.h
  2. --- playusb/dpf.h       1970-01-01 07:30:00.000000000 +0730
  3. +++ playusb-ax206/dpf.h 2012-04-30 19:53:00.969281946 +0800
  4. @@ -0,0 +1,188 @@
  5. +/** libdpf header file
  6. + *
  7. + * (c) 2010, 2011 <hackfin@section5.ch>
  8. + *
  9. + */
  10. +
  11. +#include <usb.h>
  12. +#include "usbuser.h"
  13. +#include "spiflash.h"
  14. +
  15. +#define ADDR unsigned int
  16. +
  17. +#define MODE_SG     0x00  ///< generic device mode (original)
  18. +#define MODE_USB    0x01  ///< libusb operation mode (hacked)
  19. +#define MODE_USBHID 0x02  ///< libusb HID boot mode
  20. +
  21. +#define FLAG_CAN_LOCK 0x80  ///< Has the locking feature (new firmware)
  22. +
  23. +enum {
  24. +       DEVERR_FILE = -16,
  25. +       DEVERR_OPEN,
  26. +       DEVERR_HEX,
  27. +       DEVERR_CHK,
  28. +       DEVERR_IO,
  29. +       DEVERR_MALLOC,
  30. +       DEVERR_TIMEOUT,
  31. +       DEVERR_UNSUPP,
  32. +};
  33. +
  34. +/** The DPF context structure */
  35. +struct dpf_context;
  36. +#define DPFHANDLE struct dpf_context *
  37. +
  38. +typedef struct {
  39. +       int (*mem_read)(DPFHANDLE h, unsigned char *buf, ADDR offset, int len);
  40. +       int (*mem_write)(DPFHANDLE h,
  41. +               ADDR dst, const unsigned char *buf, unsigned short n);
  42. +       int (*go)(DPFHANDLE h, ADDR start);
  43. +       int (*bootstrap)(DPFHANDLE h,
  44. +               ADDR dest, unsigned char *src, unsigned short n, ADDR start);
  45. +       int (*flash_probe)(DPFHANDLE h, unsigned char *id);
  46. +       int (*flash_cmd)(DPFHANDLE h, int command, int cmdlen, ADDR addr);
  47. +       int (*flash_status)(DPFHANDLE h, uint8_t *status);
  48. +       int (*flash_read)(DPFHANDLE h, uint8_t *buf, ADDR offset, int len);
  49. +       int (*flash_writechunk)(DPFHANDLE h,
  50. +               const uint8_t *buf, ADDR offset, int len);
  51. +       int (*flash_lock)(DPFHANDLE h, char enable);
  52. +} AccessMethods;
  53. +
  54. +typedef
  55. +struct dpf_context {
  56. +       unsigned char mode;
  57. +       unsigned char flags;
  58. +       union {
  59. +               usb_dev_handle *udev;
  60. +               int fd;
  61. +       } dev;
  62. +       AccessMethods methods;
  63. +       unsigned int width;
  64. +       unsigned int height;
  65. +       int bpp;
  66. +       int proto;
  67. +       char* buff;
  68. +       unsigned char* oldpix;
  69. +       int offx;
  70. +       int offy;
  71. +} DPFContext;
  72. +
  73. +
  74. +/** A value proxy for the property API */
  75. +typedef struct dpf_proxy {
  76. +       union {
  77. +               short   integer;
  78. +               char   *sequence;
  79. +       } value;
  80. +       char type;
  81. +} DPFValue;
  82. +
  83. +enum {
  84. +       TYPE_INTEGER,
  85. +       TYPE_STRING,
  86. +};
  87. +
  88. +/**
  89. + Opens the DPF device. if dev is not NULL, open device, otherwise, look for
  90. + USB device.
  91. + */
  92. +int dpf_open(const char *dev, DPFHANDLE *h);
  93. +
  94. +/** Close DPF device */
  95. +void dpf_close(DPFHANDLE h);
  96. +
  97. +/** Set color register
  98. + * \param rgb     RGB tuple */
  99. +int dpf_setcol(DPFHANDLE h, const unsigned char *rgb);
  100. +
  101. +/** Blit data to screen
  102. + *
  103. + * \param buf     buffer to 16 bpp RGB 565 image data
  104. + * \param rect    rectangle tuple: [x0, y0, x1, y1]
  105. + */
  106. +
  107. +int dpf_screen_blit(DPFHANDLE h, const unsigned char *buf, short rect[4]);
  108. +
  109. +/** Set property on DPF
  110. + * \param token       Property token
  111. + * \param value       Pointer to value
  112. + */
  113. +int dpf_setproperty(DPFHANDLE h, int token, const DPFValue *value);
  114. +
  115. +/* USB raw */
  116. +
  117. +int emulate_scsi(usb_dev_handle *d, unsigned char *cmd, int cmdlen, char out,
  118. +       unsigned char *data, unsigned long block_len);
  119. +
  120. +const char *dev_errstr(int err);
  121. +
  122. +// Private stuff:
  123. +int dpf_usb_open(int index, usb_dev_handle **u);
  124. +int sgdev_open(const char *portname, int *fd);
  125. +int usb_rawread(usb_dev_handle *dev, unsigned char *buf, int len);
  126. +int usb_rawwrite(usb_dev_handle *dev, const unsigned char *buf, int len);
  127. +int probe(DPFHANDLE h);
  128. +
  129. +////////////////////////////////////////////////////////////////////////////
  130. +// Bootloader functionality
  131. +
  132. +int bl_go(DPFContext *dpf, uint16_t jmpoffset);
  133. +
  134. +////////////////////////////////////////////////////////////////////////////
  135. +// FLASH stuff
  136. +
  137. +// Maximum size for flash_read
  138. +#define MAX_CHUNKSIZE 0x10000
  139. +
  140. +int read_mem(DPFHANDLE h, unsigned char *buf, ADDR src, unsigned short len);
  141. +int write_mem(DPFHANDLE h,
  142. +       ADDR dst, const unsigned char *buf, unsigned short len);
  143. +
  144. +int load_hexfile(DPFHANDLE h, const char *hexfile);
  145. +int code_go(DPFHANDLE h, ADDR start);
  146. +
  147. +int dpf_bootstrap(DPFHANDLE h,
  148. +       ADDR dst, unsigned char *src, unsigned short n, ADDR start);
  149. +
  150. +int flash_cmd(DPFHANDLE h, int command, int cmdlen, ADDR addr);
  151. +int flash_probe(DPFContext *h, unsigned char *id);
  152. +int flash_erase(DPFHANDLE h, ADDR offset);
  153. +int flash_erase_full(DPFHANDLE h);
  154. +int flash_write(DPFHANDLE h, const unsigned char *buf, ADDR offset, int len);
  155. +int flash_read(DPFHANDLE h, unsigned char *buf, ADDR offset, int len);
  156. +
  157. +int load_ihx(DPFHANDLE h, const char *fname, unsigned char *data,
  158. +       unsigned int *buflen, unsigned int reloc);
  159. +
  160. +int patch_sector(DPFHANDLE h,
  161. +       ADDR reloc, unsigned long addr, const char *hexfile);
  162. +
  163. +////////////////////////////////////////////////////////////////////////////
  164. +/* DPF specific stuff: */
  165. +
  166. +#define RGB565_0(r, g, b) \
  167. +       (( ((r) & 0xf8)          ) | (((g) & 0xe0) >> 5))
  168. +#define RGB565_1(r, g, b) \
  169. +       (( ((g) & 0x1c) << 3 ) | (((b) & 0xf8) >> 3))
  170. +
  171. +#define RGB565(r, g, b) { RGB565_0(r, g, b), RGB565_1(r, g, b) }
  172. +
  173. +#define RGB565_S(r, g, b) ((RGB565_0(r, g, b) << 8) | RGB565_1(r, g, b))
  174. +
  175. +int dpfcpy(ADDR dst, unsigned char *src, unsigned short n);
  176. +
  177. +// int clr_screen(DPFHANDLE h, const unsigned char *col);
  178. +int write_screen(DPFHANDLE h, const unsigned char *buf, unsigned int len);
  179. +
  180. +
  181. +// Some internal address offsets. They may change, but so far all types
  182. +// seem to have the same
  183. +//
  184. +// w: word, <n>: length, [LE, BE]
  185. +//
  186. +// FIXME: Use packed struct later.
  187. +
  188. +// FIXME: Should be 0x0020, once we have the firmware replaced
  189. +#define OFFSET_PROPS 0x3f0020   ///< w[2]:LE : Resolution X, Y
  190. +
  191. +
  192. +
  193. diff -Nuar playusb/fbgrab.c playusb-ax206/fbgrab.c
  194. --- playusb/fbgrab.c    2010-11-01 00:29:42.000000000 +0800
  195. +++ playusb-ax206/fbgrab.c      2012-05-03 20:17:33.510767884 +0800
  196. @@ -46,6 +46,7 @@
  197.  
  198.  void chvt(int num){
  199.    int fd;
  200. +  
  201.    if(!(fd = open("/dev/console", O_RDWR)))
  202.      FatalError("cannot open /dev/console");
  203.    if (ioctl(fd, VT_ACTIVATE, num))
  204. @@ -57,11 +58,12 @@
  205.      sleep (3);
  206.  }
  207.  
  208. -int read_fb(char *device, int vt_num, struct picture *pict){
  209. +int read_fb(char *device, int vt_num, unsigned char *buffer){
  210.    int fd, vt_old, i,j;
  211.    struct fb_fix_screeninfo fb_fixinfo;
  212.    struct fb_var_screeninfo fb_varinfo;
  213.    struct vt_stat vt_info;
  214. +  //char * buffer;
  215.  
  216.    if (vt_num!=-1){
  217.      if ((fd = open("/dev/console", O_RDONLY)) == -1)
  218. @@ -81,35 +83,14 @@
  219.    if (ioctl(fd, FBIOGET_VSCREENINFO, &fb_varinfo))
  220.      FatalError("ioctl FBIOGET_VSCREENINFO");
  221.  
  222. -  pict->xres=fb_varinfo.xres;
  223. -  pict->yres=fb_varinfo.yres;
  224. -  pict->bps=fb_varinfo.bits_per_pixel;
  225. -  pict->gray=fb_varinfo.grayscale;
  226. -
  227. -  if(fb_fixinfo.visual==FB_VISUAL_PSEUDOCOLOR){
  228. -    pict->colormap=(struct fb_cmap*)malloc(sizeof(struct fb_cmap));
  229. -    pict->colormap->red=(__u16*)malloc(sizeof(__u16)*(1<<pict->bps));
  230. -    pict->colormap->green=(__u16*)malloc(sizeof(__u16)*(1<<pict->bps));
  231. -    pict->colormap->blue=(__u16*)malloc(sizeof(__u16)*(1<<pict->bps));
  232. -    pict->colormap->transp=(__u16*)malloc(sizeof(__u16)*(1<<pict->bps));
  233. -    pict->colormap->start=0;
  234. -    pict->colormap->len=1<<pict->bps;
  235. -    if (ioctl(fd, FBIOGETCMAP, pict->colormap))
  236. -      FatalError("ioctl FBIOGETCMAP");
  237. -  }
  238. +        
  239.    if (vt_num!=-1)
  240.      chvt(vt_old);
  241.  
  242. -  switch(pict->bps){
  243. -  case 15:
  244. -    i=2;
  245. -    break;
  246. -  default:
  247. -    i=pict->bps>>3;
  248. -  }
  249. +  
  250.  
  251. -  if(!(pict->buffer=malloc(pict->xres*pict->yres*i)))
  252. -    FatalError("couldnt malloc");
  253. +  //if(!(buffer=malloc(fb_varinfo.xres * fb_varinfo.yres * (3))))
  254. +  //  FatalError("couldnt malloc");
  255.  
  256.  #if 0
  257.    fprintf(stdout, "Framebuffer %s is %i bytes.\n", device,
  258. @@ -133,11 +114,12 @@
  259.    if (vt_num!=-1)
  260.      chvt(vt_num);
  261.  
  262. -  j= (read(fd, pict->buffer, ((pict->xres * pict->yres) * i) )!=
  263. -       (pict->xres * pict->yres *i ));
  264. +  j= (read(fd, buffer, (fb_varinfo.xres * fb_varinfo.yres *(3))) )!=
  265. +       (fb_varinfo.xres * fb_varinfo.yres *(3));
  266.  #ifdef DEBUG
  267.    printf("to read:%i read:%i\n",(pict->xres* pict->yres * i), j);
  268.  #endif
  269. +  //fwrite (buffer , 1 , fb_varinfo.xres * fb_varinfo.yres *(3) , tmp_file );
  270.    if (vt_num!=-1)
  271.      chvt(vt_old);
  272.  
  273. @@ -272,29 +254,21 @@
  274.  }
  275.  
  276.  
  277. -int grab_from_fb(char *fb_device, FILE *tmp_file)
  278. +int grab_from_fb(char *fb_device, unsigned char * buf)
  279.  {
  280.         struct picture pict;
  281.         int vt_num = -1;
  282.  
  283.  
  284.         /* read framebuffer into pict */
  285. -       read_fb(fb_device, vt_num, &pict);
  286. +       read_fb(fb_device, vt_num, buf);
  287.  
  288.         /* compress to jpeg */
  289. -       Write_JPG(&pict, tmp_file);
  290. +       // Write_JPG(&pict, tmp_file);
  291.  
  292.         /* cleanup */
  293. -       if(pict.colormap)
  294. -       {
  295. -               free(pict.colormap->red);
  296. -           free(pict.colormap->green);
  297. -           free(pict.colormap->blue);
  298. -           free(pict.colormap->transp);
  299. -           free(pict.colormap);
  300. -       }
  301. -       free(pict.buffer);
  302. +      
  303.  
  304.         /* rewind file */
  305. -       fseek(tmp_file, 0, SEEK_SET);
  306. +       //fseek(tmp_file, 0, SEEK_SET);
  307.  }
  308. diff -Nuar playusb/Makefile playusb-ax206/Makefile
  309. --- playusb/Makefile    2010-10-21 06:14:39.000000000 +0800
  310. +++ playusb-ax206/Makefile      2012-04-30 20:19:24.520445474 +0800
  311. @@ -1,6 +1,6 @@
  312.  CC = gcc
  313.  CFLAGS = -Wall -O2
  314. -LDFLAGS = -lrt -lusb -ljpeg
  315. +LDFLAGS = -lrt -lusb -ljpeg -ldpf
  316.  
  317.  OBJ=playusb
  318.  
  319. diff -Nuar playusb/playusb.c playusb-ax206/playusb.c
  320. --- playusb/playusb.c   2010-11-01 01:32:47.000000000 +0800
  321. +++ playusb-ax206/playusb.c     2012-05-03 20:12:34.555290530 +0800
  322. @@ -13,11 +13,9 @@
  323.  
  324.  #include "playusb.h"
  325.  
  326. -
  327.  void show_help(void)
  328.  {
  329.     printf("./playusb [OPTIONS]\n"\
  330. -          "\t-j \tshow JPEG image\n"\
  331.            "\t-f dev\tread from linux framebuffer\n"\
  332.            "\t-i \tFB refresh interval (in milliseconds)\n"\
  333.            "\t-e \twait for update events from debugfs (for mmap'ed FBs)\n"\
  334. @@ -33,205 +31,67 @@
  335.   *                -1 if no frame was found
  336.   *                -2 if system rights are too low to work with device
  337.   */
  338. -int find_photo_frame(struct usb_device **new_dev)
  339. -{
  340. -       struct usb_bus *bus;
  341. -       struct usb_device *dev;
  342. -       int i;
  343. -
  344. -
  345. -scan_bus:
  346. -       usb_init();
  347. -       usb_find_busses();
  348. -       usb_find_devices();
  349. -
  350. -       for (bus = usb_busses; bus; bus = bus->next)
  351. -       {
  352. -               for (dev = bus->devices; dev; dev = dev->next)
  353. -               {
  354. -                       /* check whether device is a photo frame */
  355. -                       for (i = 0; i < num_frames; i++)
  356. -                       {
  357. -                               if (dev->descriptor.idVendor == photo_frames[i].vendorid)
  358. -                               {
  359. -                                       if (dev->descriptor.idProduct == photo_frames[i].productid_photo)
  360. -                                       {
  361. -                                               /* frame in photo mode found */
  362. -                                               printf("%s in photo mode found.\n", photo_frames[i].name);
  363. -                                               *new_dev = dev;
  364. -                                               return 0;
  365. -                                       }
  366. -                                       else if (dev->descriptor.idProduct == photo_frames[i].productid_massstorage)
  367. -                                       {
  368. -                                               /* frame in mass storage mode found, try to set photo mode */
  369. -                                               printf("%s in mass storage mode found, try to switch mode.\n", photo_frames[i].name);
  370. -                                               if (switch_usb_mode(dev) == 0)
  371. -                                               {
  372. -                                                       printf("Frame succesfully switched to photo mode. Rescan bus ..\n");
  373. -                                                       /* sleep awhile until the new device is set up, then do all this again in order
  374. -                                                        * to initialize the new usb device */
  375. -                                                       sleep(1);
  376. -                                                       goto scan_bus;
  377. -                                               }
  378. -
  379. -                                               /* switch_usb_mode() returned an error, so we might not have the right rights */
  380. -                                               return -2;
  381. -                                       }
  382. -                                       else
  383. -                                       {
  384. -                                               /* new frame found? */
  385. -                                               printf("USB device with product id %d was not found in database.\n", dev->descriptor.idProduct);
  386. -                                       }
  387. -                               }
  388. -                       }
  389. -               }
  390. -       }
  391.  
  392. -       return -1;
  393. -}
  394. -
  395. -int switch_usb_mode(struct usb_device* dev)
  396. +int send_data(DPFHANDLE frame, unsigned char *data, int len)
  397.  {
  398. -       usb_dev_handle *udev;
  399. -       char buf[256];
  400. -       int ret;
  401. -
  402. -
  403. -       /* get usb device handle */
  404. -       udev = usb_open(dev);
  405. -
  406. -       /* try to read manufacturer */
  407. -       if (usb_get_string_simple(udev, dev->descriptor.iManufacturer, buf, sizeof(buf)) == -1)
  408. -       {
  409. -               printf("Error while reading from USB device. Please check your system rights.\n");
  410. -               return -1;
  411. -       }
  412. -
  413. -       /* send control msg and switch to photo mode */
  414. -       if ((ret = usb_control_msg(udev, USB_TYPE_STANDARD | USB_ENDPOINT_IN,
  415. -                                                               USB_REQ_GET_DESCRIPTOR,
  416. -                                                               0xfe, 0xfe, 0x0, 0xfe, 1000)) < 0)
  417. -       {
  418. -               /* usb_control_msg returns -108 in my case, however things seem to work anyway */
  419. -       }
  420. -
  421. -       usb_close(udev);
  422. -
  423. -       return 0;
  424. -}
  425. -
  426. -
  427. -int send_jpeg(usb_dev_handle *dev, FILE *file, char *data, int len)
  428. -{
  429. -       char usb_hdr[USB_HDR_LEN] = {0xa5, 0x5a, 0x18, 0x04, 0xff, 0xff, 0xff, 0xff, 0x48, 0x00, 0x00, 0x00};
  430. -       char buffer[URBBUF_MAX];
  431. -       int usb_timeout = 1000;
  432. -       int usb_endpoint = 0x2;
  433. -       int filesize, offset;
  434. -       int ret;
  435. -
  436. -
  437. -       /* sanity check */
  438. -       if (file && data)
  439. -       {
  440. -               printf("Please specify either file or data input.\n");
  441. -               return -1;
  442. -       }
  443. -
  444. -       if (file)
  445. -       {
  446. +       int ret,m,n;
  447. +       unsigned char r,g,b;
  448. +       //int size=((frame->width)*(frame->height)*3);
  449. +       //unsigned char buffer[size];
  450. +       short rect[4];
  451. +       int filesize,i;
  452. +        unsigned char * pixels=(unsigned char*)malloc((frame->width)*(frame->height)*(2));
  453. +       rect[0]=0;
  454. +       rect[1]=0;
  455. +       rect[2]=frame->width;
  456. +       rect[3]=frame->height;
  457.                 // get file size
  458. -               fseek(file, 0, SEEK_END);
  459. -               filesize = ftell(file);
  460. -               fseek(file, 0, SEEK_SET);
  461. -
  462. -               // insert filesize into command
  463. -               *(int *)(usb_hdr + 4) = filesize;
  464. -       }
  465. -       else
  466. -       {
  467. -               *(int *)(usb_hdr + 4) = len;
  468. -       }
  469. -
  470. -       // copy header into usb buffer
  471. -       memcpy(buffer, usb_hdr, USB_HDR_LEN);
  472. -       offset = USB_HDR_LEN;
  473. -
  474. -       if (file)
  475. -       {
  476. -               while(!feof(file))
  477. -               {
  478. +               //fseek(file, 0, SEEK_END);
  479. +               //filesize = ftell(file);
  480. +               //rewind (file);
  481. +               i=0;
  482. +               memset(pixels,0,(frame->width)*(frame->height)*2);
  483. +               //while(!feof(file)&& ret<(size))
  484. +               //{
  485.                         // read file into buffer
  486. -                       if ((ret = fread(buffer + offset, 1, URBBUF_MAX - offset, file)) < 1)
  487. -                       {
  488. -                               printf("Error while reading file, fread returned: %d\n", ret);
  489. -                               break;
  490. -                       }
  491. -
  492. -                   // pad bytes
  493. -                   memset(buffer + offset + ret, 0, URBBUF_MAX - offset - ret);
  494. -
  495. -                       // send buffer to picture frame
  496. -                       if ((ret = usb_bulk_write(dev, usb_endpoint, buffer, URBBUF_MAX, usb_timeout)) < 0)
  497. -                       {
  498. -                               // error occurred
  499. -                               printf("Error while writing to USB device. Please check your system rights.\n");
  500. -                               //printf("usb_bulk_write returned: %d\n", ret);
  501. +                       //if ((ret = fread(buffer , 1, filesize,file)) < 1){
  502. +                        //        printf("Error while reading file, fread returned: %d\n", ret);
  503. +                        //        break;
  504. +                        //}
  505. +                       for (m=0,n=0;m<((frame->width)*(frame->height)*3);){
  506. +                               r = data[m++];
  507. +                               g = data[m++];
  508. +                                b = data[m++];
  509. +                               pixels[n++] = (unsigned char)(RGB565_0(r,g,b)); //R (5 bits) + G (upper 3 bits)
  510. +                               pixels[n++] = (unsigned char)(RGB565_1(r,g,b)); //G (lower 3 bits) + B (5 bits)
  511.                         }
  512. -
  513. -                       // no header needed on subsequent chunks
  514. -                       offset = 0;
  515. -               }
  516. -
  517. -               /* rewind file */
  518. -               fseek(file, 0, SEEK_SET);
  519. -       }
  520. -       else
  521. -       {
  522. -               /* FIXME: that needs to be tested */
  523. -               int bytes_sent = 0;
  524. -               int bytes_to_send = 0;
  525. -
  526. -               printf("total len is %d\n", len);
  527. -
  528. -               while (bytes_sent < len)
  529. -               {
  530. -                       // copy chunks into usb_buffer
  531. -                       bytes_to_send = min(URBBUF_MAX - offset, len);
  532. -                       printf("bytes_to_send: %d, offset: %d\n", bytes_to_send, offset);
  533. -
  534.                         // pad bytes
  535. -                       memset(buffer + offset, 0, URBBUF_MAX - offset);
  536. -                       memcpy(buffer + offset, data + bytes_sent, bytes_to_send);
  537. -                       bytes_sent += bytes_to_send; // these counters are just for the data packets
  538. -
  539. -                       printf("bytes_sent: %d, len: %d\n", bytes_sent, len);
  540. -
  541. -                       // send chunk
  542. -                       if ((ret = usb_bulk_write(dev, usb_endpoint, buffer, URBBUF_MAX, usb_timeout)) < 0)
  543. -                       {
  544. -                               // error occurred
  545. -                               printf("Error occurred while writing data to device.\n");
  546. -                               printf("usb_bulk_write returned: %d\n", ret);
  547. -                       }
  548. -
  549. -                       printf("usb_bulk_write returned: %d\n", ret);
  550. -
  551. -                       // no header needed on subsequent chunks
  552. -                       offset = 0;
  553. -               }
  554. -       }
  555. +                       //break;
  556. +                      // memset(buffer + ret, 0, URBBUF_MAX - ret);
  557. +                        // send buffer to picture frame
  558. +                      
  559. +
  560. +              //}
  561. +                if ((ret = dpf_screen_blit(frame, pixels, rect)) < 0)
  562. +                        {
  563. +                                // error occurred
  564. +                                printf("Error while writing to USB device. Please check your system rights.\n");
  565. +                        }
  566. +               /* rewind file */
  567. +               //fseek(file, 0, SEEK_SET);
  568.  
  569. +      
  570. +      
  571.         return 0;
  572.  }
  573.  
  574.  
  575.  int main(int argc, char *argv[])
  576.  {
  577. -       struct usb_device *dev = NULL;
  578. -       FILE *file_handle;
  579. -       char *filename = NULL;
  580. +       char * dev="usb0";
  581. +       DPFHANDLE picframe;
  582.         char *fb_device = NULL;
  583. +       FILE *file_handle;
  584.         struct timespec t;
  585.         long fb_refresh_interval = 1000; /* 1000ms*/
  586.         char *tmp_filename;
  587. @@ -240,7 +100,8 @@
  588.         int opt;
  589.         enum opmode_t opmode = ONCE;
  590.         char buf;
  591. -
  592. +       unsigned char * pixels;
  593. +      
  594.  
  595.         if (argc == 1)
  596.         {
  597. @@ -248,7 +109,7 @@
  598.                 return -1;
  599.         }
  600.  
  601. -       while((opt = getopt(argc, argv, "erhi:j:f:")) != -1)
  602. +       while((opt = getopt(argc, argv, "erhi:f:")) != -1)
  603.         {
  604.                 switch (opt)
  605.                 {
  606. @@ -256,9 +117,6 @@
  607.                                 show_help();
  608.                                 return 0;
  609.                                 break;
  610. -                       case 'j':
  611. -                               filename = optarg;
  612. -                               break;
  613.                         case 'e':
  614.                                 opmode = EVENT;
  615.                                 break;
  616. @@ -279,19 +137,6 @@
  617.  
  618.  
  619.         /* sanity checks */
  620. -       if (!filename && !fb_device)
  621. -       {
  622. -               printf("both specified\n");
  623. -               show_help();
  624. -               return -1;
  625. -       }
  626. -
  627. -       if (filename && fb_device)
  628. -       {
  629. -               printf("Choose either to read from file or from a frame buffer device.\n");
  630. -               return -1;
  631. -       }
  632. -
  633.         if (fb_refresh_interval < 100)
  634.                 printf("WARNING: refresh rates smaller then 100msecs may cause heavy system load\n");
  635.  
  636. @@ -302,7 +147,7 @@
  637.         signal(SIGINT, sigint);
  638.  
  639.         /* start */
  640. -       while ((ret = find_photo_frame(&dev)) != 0)
  641. +       while ((ret = dpf_open(dev,&picframe)) != 0)
  642.         {
  643.                 if (ret == -2)
  644.                 {
  645. @@ -319,31 +164,8 @@
  646.                 sleep(1);
  647.         }
  648.  
  649. -       if ((dev_handle = usb_open(dev)) == NULL)
  650. -       {
  651. -               printf("Error while creating usb device handle.\n");
  652. -               return -1;
  653. -       }
  654. -
  655. -       if (filename)
  656. -       {
  657. -               printf("displaying %s on photo frame ..\n", filename);
  658. -
  659. -               if ((file_handle = fopen(filename, "r+")) == NULL)
  660. -               {
  661. -                       printf("File %s was not found.\n", filename);
  662. -                       ret = -1;
  663. -                       goto exit;
  664. -               }
  665. -
  666. -               if ((ret = send_jpeg(dev_handle, file_handle, NULL, 0)) != 0)
  667. -               {
  668. -                       printf("Error occurred while sending jpeg image to device.\n");
  669. -               }
  670. -
  671. -               fclose(file_handle);
  672. -       }
  673. -       else if (fb_device)
  674. +       pixels=(unsigned char*)malloc((picframe->width)*(picframe->height)*(3));       
  675. +       if (fb_device)
  676.         {
  677.                 /*
  678.                  * workflow:
  679. @@ -363,17 +185,17 @@
  680.                 fclose(file_handle);
  681.  
  682.                 /* create and open temporary file */
  683. -               if (!(tmp_filename = tmpnam(NULL)))
  684. -               {
  685. -                       printf("error while creating temporary file name.\n");
  686. -                       return -1;
  687. -               }
  688. -
  689. -               if (!(tmpfile_handle = fopen(tmp_filename, "w+")))
  690. -               {
  691. -                       printf("error while opening temporary file.\n");
  692. -                       return -1;
  693. -               }
  694. +               //if (!(tmp_filename = tmpnam(NULL)))
  695. +               //{
  696. +               //      printf("error while creating temporary file name.\n");
  697. +               //      return -1;
  698. +               //}
  699. +
  700. +               //if (!(tmpfile_handle = fopen(tmp_filename, "w+")))
  701. +               //{
  702. +               //      printf("error while opening temporary file.\n");
  703. +               //      return -1;
  704. +               //}
  705.  
  706.                 /* do work depending on operation mode */
  707.                 if (opmode == ONCE)
  708. @@ -381,13 +203,13 @@
  709.                         printf("Writing content of FB device %s to picture frame ..\n", fb_device);
  710.  
  711.                         /* just read from fb once and exit */
  712. -                       grab_from_fb(fb_device, tmpfile_handle);
  713. +                       grab_from_fb(fb_device, pixels);
  714.  
  715.                         /* rewind file, so send_jpeg can read from it straight away */
  716. -                       fseek(tmpfile_handle, 0, SEEK_SET);
  717. +               //      fseek(tmpfile_handle, 0, SEEK_SET);
  718.  
  719.                         /* send image to frame */
  720. -                       if ((ret = send_jpeg(dev_handle, tmpfile_handle, NULL, 0)) != 0)
  721. +                       if ((ret = send_data(picframe, pixels, 0)) != 0)
  722.                         {
  723.                                 printf("Error occurred while sending jpeg image to device.\n");
  724.                         }
  725. @@ -406,15 +228,15 @@
  726.                                 clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &t, NULL);
  727.  
  728.                                 /* get image from fb and compress to jpeg */
  729. -                               grab_from_fb(fb_device, tmpfile_handle);
  730. +                               grab_from_fb(fb_device, pixels);
  731.  
  732.                                 /* rewind file, so send_jpeg can read from it straight away */
  733. -                               fseek(tmpfile_handle, 0, SEEK_SET);
  734. +                               //fseek(tmpfile_handle, 0, SEEK_SET);
  735.  
  736.                                 /* send image to frame */
  737. -                               if ((ret = send_jpeg(dev_handle, tmpfile_handle, NULL, 0)) != 0)
  738. +                               if ((ret = send_data(picframe, pixels, 0)) != 0)
  739.                                 {
  740. -                                       printf("Error occurred while sending jpeg image to device.\n");
  741. +                                       printf("Error occurred while sending image to device.\n");
  742.                                 }
  743.  
  744.                                 /* calculate next shot */
  745. @@ -439,15 +261,15 @@
  746.                         while ((ret = fread(&buf, 1, 1, sysfs_handle)) > -1)
  747.                         {
  748.                                 /* get image from fb and compress to jpeg */
  749. -                               grab_from_fb(fb_device, tmpfile_handle);
  750. +                               grab_from_fb(fb_device, pixels);
  751.  
  752.                                 /* rewind file, so send_jpeg can read from it straight away */
  753. -                               fseek(tmpfile_handle, 0, SEEK_SET);
  754. +                               //fseek(tmpfile_handle, 0, SEEK_SET);
  755.  
  756.                                 /* send image to frame */
  757. -                               if ((ret = send_jpeg(dev_handle, tmpfile_handle, NULL, 0)) != 0)
  758. +                               if ((ret = send_data(picframe, pixels, 0)) != 0)
  759.                                 {
  760. -                                       printf("Error occurred while sending jpeg image to device.\n");
  761. +                                       printf("Error occurred while sending image to device.\n");
  762.                                 }
  763.  
  764.                         }
  765. @@ -456,6 +278,7 @@
  766.  
  767.                         /* in case we reach this point, cleanup */
  768.                         fclose(sysfs_handle);
  769. +                       free(pixels);
  770.                 }
  771.  
  772.                 if (tmpfile_handle)
  773. diff -Nuar playusb/playusb.h playusb-ax206/playusb.h
  774. --- playusb/playusb.h   2010-11-01 01:33:08.000000000 +0800
  775. +++ playusb-ax206/playusb.h     2012-05-03 20:18:39.604775628 +0800
  776. @@ -17,6 +17,7 @@
  777.  #include <time.h>
  778.  #include <fcntl.h>
  779.  #include <getopt.h>
  780. +#include "dpf.h"
  781.  
  782.  struct frame_info
  783.  {
  784. @@ -29,49 +30,19 @@
  785.  };
  786.  
  787.  
  788. -static struct frame_info photo_frames[] = {
  789. -       {
  790. -               .name                                   = "Samsung SPF-85H",
  791. -               .vendorid                               = 0x04e8,
  792. -               .productid_massstorage  = 0x2012,
  793. -               .productid_photo                = 0x2013,
  794. -               .xres                                   = 800,
  795. -               .yres                                   = 600,
  796. -       },
  797. -       {
  798. -               .name                                   = "Samsung SPF-87H",
  799. -               .vendorid                               = 0x04e8,
  800. -               .productid_massstorage  = 0x2033,
  801. -               .productid_photo                = 0x2034,
  802. -               .xres                                   = 800,
  803. -               .yres                                   = 480,
  804. -       },
  805. -       {
  806. -               .name                                   = "Samsung SPF-107H",
  807. -               .vendorid                               = 0x04e8,
  808. -               .productid_massstorage  = 0x2027,
  809. -               .productid_photo                = 0x2028,
  810. -               .xres                                   = 1024,
  811. -               .yres                                   = 600,
  812. -       },
  813. -};
  814. -static int num_frames = sizeof(photo_frames) / sizeof(photo_frames[0]);
  815. -
  816. -int find_photo_frame(struct usb_device **new_dev);
  817. -int switch_usb_mode(struct usb_device* dev);
  818. -int send_jpeg(usb_dev_handle *dev, FILE *file, char *data, int len);
  819. +int send_data(DPFHANDLE frame, unsigned char *data, int len);
  820.  void sigint(int signum);
  821. -int grab_from_fb(char *fb_device, FILE *tmp_file);
  822. +int grab_from_fb(char *fb_device, unsigned char * buf);
  823.  
  824.  
  825.  #define min( a, b ) ( ((a) < (b)) ? (a) : (b) )
  826. -#define URBBUF_MAX 0x20000
  827. +#define URBBUF_MAX (128*128*3)
  828.  #define USB_HDR_LEN 12
  829.  #define MAX_JPEG_SIZE (2 * 1024 * 1024)
  830.  #define NSEC_PER_SEC    1000000000 /* The number of nsecs per sec. */
  831.  #define USEC_PER_SEC    1000000
  832.  
  833. -#define DEBUGFS_ENTRY "/sys/kernel/debug/spfb"
  834. +#define DEBUGFS_ENTRY "/sys/kernel/debug/ax206fb"
  835.  #define PLAYUSB_TEMPLATE "/tmp/playusb"
  836.  
  837.  
  838. diff -Nuar playusb/spiflash.h playusb-ax206/spiflash.h
  839. --- playusb/spiflash.h  1970-01-01 07:30:00.000000000 +0730
  840. +++ playusb-ax206/spiflash.h    2012-04-30 19:53:12.612948785 +0800
  841. @@ -0,0 +1,30 @@
  842. +/** \file flashcmd_st.h
  843. + *
  844. + * ST compatible flash cmds
  845. + *
  846. + */
  847. +
  848. +
  849. +#define SPM_RDID              0x9f    // Read Id
  850. +#define SPM_NO_CMD            0x00    // No command
  851. +
  852. +#define SPM_WREN              0x06    // Write enable
  853. +#define SPM_WRDI              0x04    // Write disable
  854. +#define SPM_RDSR              0x05    // Read status register
  855. +#define SPM_WRSR              0x01    // Write status register
  856. +#define SPM_READ              0x03    // Read data bytes
  857. +#define SPM_PP                0x02    // Page program
  858. +#define SPM_DP                0xb9    // Deep power down
  859. +#define SPM_RES               0xab    // Release from deep power down
  860. +                                      // and read signature
  861. +#define SPM_FLASH_SE          0xd8    // Sector erase
  862. +#define SPM_FLASH_BE          0xc7    // Bulk erase
  863. +#define SPM_FLASH_FAST_READ   0x0B    // Read data bytes fast
  864. +
  865. +#define SPM_SR_SRWD           0x80    // SR write protection (HW)
  866. +
  867. +// Status register bit definitions
  868. +#define SPS_WIP 0x01       // write in progress
  869. +#define SPS_WEL 0x02       // write enable latch
  870. +
  871. +
  872. diff -Nuar playusb/usbuser.h playusb-ax206/usbuser.h
  873. --- playusb/usbuser.h   1970-01-01 07:30:00.000000000 +0730
  874. +++ playusb-ax206/usbuser.h     2012-04-30 19:53:09.725031418 +0800
  875. @@ -0,0 +1,29 @@
  876. +/* USB user commands
  877. + *
  878. + * Only temporary. Should move to dpflib or into a dclib configuration.
  879. + *
  880. + */
  881. +
  882. +#define PROTOCOL_VERSION  1
  883. +
  884. +/** Our vendor specific USB commands to do stuff on the DPF */
  885. +
  886. +#define USBCMD_GETPROPERTY  0x00    ///< Get property
  887. +#define USBCMD_SETPROPERTY  0x01    ///< Set property
  888. +#define USBCMD_MEMREAD      0x04    ///< Memory read
  889. +#define USBCMD_APPLOAD      0x05    ///< Load and run applet
  890. +#define USBCMD_FILLRECT     0x11    ///< Fill screen rectangle
  891. +#define USBCMD_BLIT         0x12    ///< Blit to screen
  892. +#define USBCMD_COPYRECT     0x13    ///< Copy screen rectangle
  893. +#define USBCMD_FLASHLOCK    0x20    ///< Lock USB for flash access
  894. +#define USBCMD_PROBE        0xff    ///< Get version code (probe)
  895. +
  896. +/* Some special return codes */
  897. +#define USB_IN_SEQUENCE     0x7f    ///< We're inside a command sequence
  898. +
  899. +// Property handling:
  900. +
  901. +#define PROPERTY_BRIGHTNESS  0x01
  902. +#define PROPERTY_FGCOLOR     0x02
  903. +#define PROPERTY_BGCOLOR     0x03
  904. +#define PROPERTY_ORIENTATION 0x10
clone this paste RAW Paste Data