Advertisement
Guest User

playusb.patch for AX206

a guest
May 2nd, 2012
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 23.87 KB | None | 0 0
  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-02 19:49:07.547803681 +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, FILE *tmp_file){
  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,34 +83,13 @@
  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. +  if(!(buffer=malloc(fb_varinfo.xres * fb_varinfo.yres * (3))))
  253.      FatalError("couldnt malloc");
  254.  
  255.  #if 0
  256. @@ -133,11 +114,12 @@
  257.    if (vt_num!=-1)
  258.      chvt(vt_num);
  259.  
  260. -  j= (read(fd, pict->buffer, ((pict->xres * pict->yres) * i) )!=
  261. -   (pict->xres * pict->yres *i ));
  262. +  j= (read(fd, buffer, (fb_varinfo.xres * fb_varinfo.yres *(3))) )!=
  263. +   (fb_varinfo.xres * fb_varinfo.yres *(3));
  264.  #ifdef DEBUG
  265.    printf("to read:%i read:%i\n",(pict->xres* pict->yres * i), j);
  266.  #endif
  267. +  fwrite (buffer , 1 , fb_varinfo.xres * fb_varinfo.yres *(3) , tmp_file );
  268.    if (vt_num!=-1)
  269.      chvt(vt_old);
  270.  
  271. @@ -279,21 +261,13 @@
  272.  
  273.  
  274.     /* read framebuffer into pict */
  275. -   read_fb(fb_device, vt_num, &pict);
  276. +   read_fb(fb_device, vt_num, tmp_file);
  277.  
  278.     /* compress to jpeg */
  279. -   Write_JPG(&pict, tmp_file);
  280. +   // Write_JPG(&pict, tmp_file);
  281.  
  282.     /* cleanup */
  283. -   if(pict.colormap)
  284. -   {
  285. -       free(pict.colormap->red);
  286. -       free(pict.colormap->green);
  287. -       free(pict.colormap->blue);
  288. -       free(pict.colormap->transp);
  289. -       free(pict.colormap);
  290. -   }
  291. -   free(pict.buffer);
  292. +  
  293.  
  294.     /* rewind file */
  295.     fseek(tmp_file, 0, SEEK_SET);
  296. diff -Nuar playusb/Makefile playusb-ax206//Makefile
  297. --- playusb/Makefile    2010-10-21 06:14:39.000000000 +0800
  298. +++ playusb-ax206//Makefile 2012-04-30 20:19:24.520445474 +0800
  299. @@ -1,6 +1,6 @@
  300.  CC = gcc
  301.  CFLAGS = -Wall -O2
  302. -LDFLAGS = -lrt -lusb -ljpeg
  303. +LDFLAGS = -lrt -lusb -ljpeg -ldpf
  304.  
  305.  OBJ=playusb
  306.  
  307. diff -Nuar playusb/playusb.c playusb-ax206//playusb.c
  308. --- playusb/playusb.c   2010-11-01 01:32:47.000000000 +0800
  309. +++ playusb-ax206//playusb.c    2012-05-02 19:54:20.559064735 +0800
  310. @@ -13,11 +13,9 @@
  311.  
  312.  #include "playusb.h"
  313.  
  314. -
  315.  void show_help(void)
  316.  {
  317.     printf("./playusb [OPTIONS]\n"\
  318. -          "\t-j \tshow JPEG image\n"\
  319.            "\t-f dev\tread from linux framebuffer\n"\
  320.            "\t-i \tFB refresh interval (in milliseconds)\n"\
  321.            "\t-e \twait for update events from debugfs (for mmap'ed FBs)\n"\
  322. @@ -33,205 +31,114 @@
  323.   *            -1 if no frame was found
  324.   *            -2 if system rights are too low to work with device
  325.   */
  326. -int find_photo_frame(struct usb_device **new_dev)
  327. -{
  328. -   struct usb_bus *bus;
  329. -   struct usb_device *dev;
  330. -   int i;
  331. -
  332. -
  333. -scan_bus:
  334. -   usb_init();
  335. -   usb_find_busses();
  336. -   usb_find_devices();
  337. -
  338. -   for (bus = usb_busses; bus; bus = bus->next)
  339. -   {
  340. -       for (dev = bus->devices; dev; dev = dev->next)
  341. -       {
  342. -           /* check whether device is a photo frame */
  343. -           for (i = 0; i < num_frames; i++)
  344. -           {
  345. -               if (dev->descriptor.idVendor == photo_frames[i].vendorid)
  346. -               {
  347. -                   if (dev->descriptor.idProduct == photo_frames[i].productid_photo)
  348. -                   {
  349. -                       /* frame in photo mode found */
  350. -                       printf("%s in photo mode found.\n", photo_frames[i].name);
  351. -                       *new_dev = dev;
  352. -                       return 0;
  353. -                   }
  354. -                   else if (dev->descriptor.idProduct == photo_frames[i].productid_massstorage)
  355. -                   {
  356. -                       /* frame in mass storage mode found, try to set photo mode */
  357. -                       printf("%s in mass storage mode found, try to switch mode.\n", photo_frames[i].name);
  358. -                       if (switch_usb_mode(dev) == 0)
  359. -                       {
  360. -                           printf("Frame succesfully switched to photo mode. Rescan bus ..\n");
  361. -                           /* sleep awhile until the new device is set up, then do all this again in order
  362. -                            * to initialize the new usb device */
  363. -                           sleep(1);
  364. -                           goto scan_bus;
  365. -                       }
  366. -
  367. -                       /* switch_usb_mode() returned an error, so we might not have the right rights */
  368. -                       return -2;
  369. -                   }
  370. -                   else
  371. -                   {
  372. -                       /* new frame found? */
  373. -                       printf("USB device with product id %d was not found in database.\n", dev->descriptor.idProduct);
  374. -                   }
  375. -               }
  376. -           }
  377. -       }
  378. -   }
  379.  
  380. -   return -1;
  381. -}
  382. -
  383. -int switch_usb_mode(struct usb_device* dev)
  384. +int send_data(DPFHANDLE frame, FILE *file, char *data, int len)
  385.  {
  386. -   usb_dev_handle *udev;
  387. -   char buf[256];
  388. -   int ret;
  389. -
  390. -
  391. -   /* get usb device handle */
  392. -   udev = usb_open(dev);
  393. -
  394. -   /* try to read manufacturer */
  395. -   if (usb_get_string_simple(udev, dev->descriptor.iManufacturer, buf, sizeof(buf)) == -1)
  396. -   {
  397. -       printf("Error while reading from USB device. Please check your system rights.\n");
  398. -       return -1;
  399. -   }
  400. -
  401. -   /* send control msg and switch to photo mode */
  402. -   if ((ret = usb_control_msg(udev, USB_TYPE_STANDARD | USB_ENDPOINT_IN,
  403. -                               USB_REQ_GET_DESCRIPTOR,
  404. -                               0xfe, 0xfe, 0x0, 0xfe, 1000)) < 0)
  405. -   {
  406. -       /* usb_control_msg returns -108 in my case, however things seem to work anyway */
  407. -   }
  408. -
  409. -   usb_close(udev);
  410. -
  411. -   return 0;
  412. -}
  413. -
  414. -
  415. -int send_jpeg(usb_dev_handle *dev, FILE *file, char *data, int len)
  416. -{
  417. -   char usb_hdr[USB_HDR_LEN] = {0xa5, 0x5a, 0x18, 0x04, 0xff, 0xff, 0xff, 0xff, 0x48, 0x00, 0x00, 0x00};
  418. -   char buffer[URBBUF_MAX];
  419. -   int usb_timeout = 1000;
  420. -   int usb_endpoint = 0x2;
  421. -   int filesize, offset;
  422. -   int ret;
  423. -
  424. -
  425. -   /* sanity check */
  426. -   if (file && data)
  427. -   {
  428. -       printf("Please specify either file or data input.\n");
  429. -       return -1;
  430. -   }
  431. -
  432. +   int ret,m,n;
  433. +   unsigned char r,g,b;
  434. +   int size=((frame->width)*(frame->height)*3);
  435. +   unsigned char buffer[size];
  436. +   short rect[4];
  437. +   int filesize,i;
  438. +        unsigned char * pixels=(unsigned char*)malloc((frame->width)*(frame->height)*(2));
  439. +   rect[0]=0;
  440. +   rect[1]=0;
  441. +   rect[2]=frame->width;
  442. +   rect[3]=frame->height;
  443.     if (file)
  444.     {
  445.         // get file size
  446.         fseek(file, 0, SEEK_END);
  447.         filesize = ftell(file);
  448. -       fseek(file, 0, SEEK_SET);
  449. -
  450. -       // insert filesize into command
  451. -       *(int *)(usb_hdr + 4) = filesize;
  452. -   }
  453. -   else
  454. -   {
  455. -       *(int *)(usb_hdr + 4) = len;
  456. -   }
  457. -
  458. -   // copy header into usb buffer
  459. -   memcpy(buffer, usb_hdr, USB_HDR_LEN);
  460. -   offset = USB_HDR_LEN;
  461. -
  462. -   if (file)
  463. -   {
  464. -       while(!feof(file))
  465. +       rewind (file);
  466. +       i=0;
  467. +       memset(pixels,0,(frame->width)*(frame->height)*2);
  468. +       while(!feof(file)&& ret<(size))
  469.         {
  470.             // read file into buffer
  471. -           if ((ret = fread(buffer + offset, 1, URBBUF_MAX - offset, file)) < 1)
  472. -           {
  473. -               printf("Error while reading file, fread returned: %d\n", ret);
  474. -               break;
  475. +           if ((ret = fread(buffer , 1, filesize,file)) < 1){
  476. +                                printf("Error while reading file, fread returned: %d\n", ret);
  477. +                                break;
  478. +                        }
  479. +           for (m=0,n=0;m<((frame->width)*(frame->height)*3);){
  480. +               r = buffer[m++];
  481. +                   g = buffer[m++];
  482. +                                b = buffer[m++];
  483. +                   pixels[n++] = (unsigned char)(RGB565_0(r,g,b)); //R (5 bits) + G (upper 3 bits)
  484. +                       pixels[n++] = (unsigned char)(RGB565_1(r,g,b)); //G (lower 3 bits) + B (5 bits)
  485.             }
  486. -
  487. -           // pad bytes
  488. -           memset(buffer + offset + ret, 0, URBBUF_MAX - offset - ret);
  489. -
  490. -           // send buffer to picture frame
  491. -           if ((ret = usb_bulk_write(dev, usb_endpoint, buffer, URBBUF_MAX, usb_timeout)) < 0)
  492. -           {
  493. -               // error occurred
  494. -               printf("Error while writing to USB device. Please check your system rights.\n");
  495. -               //printf("usb_bulk_write returned: %d\n", ret);
  496. -           }
  497. -
  498. -           // no header needed on subsequent chunks
  499. -           offset = 0;
  500. -       }
  501. -
  502. +           // pad bytes
  503. +           break;
  504. +                  // memset(buffer + ret, 0, URBBUF_MAX - ret);
  505. +                        // send buffer to picture frame
  506. +                      
  507. +
  508. +              }
  509. +        if ((ret = dpf_screen_blit(frame, pixels, rect)) < 0)
  510. +                        {
  511. +                                // error occurred
  512. +                                printf("Error while writing to USB device. Please check your system rights.\n");
  513. +                        }
  514.         /* rewind file */
  515.         fseek(file, 0, SEEK_SET);
  516. +
  517.     }
  518.     else
  519.     {
  520.         /* FIXME: that needs to be tested */
  521.         int bytes_sent = 0;
  522.         int bytes_to_send = 0;
  523. +       i=0;
  524.  
  525.         printf("total len is %d\n", len);
  526.  
  527. -       while (bytes_sent < len)
  528. +       while (bytes_sent < len && bytes_sent < (frame->width*frame->height*(1+(2))))
  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. +           bytes_to_send = min(URBBUF_MAX , len);
  534. +           printf("bytes_to_send: %d\n", bytes_to_send);
  535.  
  536.             // pad bytes
  537. -           memset(buffer + offset, 0, URBBUF_MAX - offset);
  538. -           memcpy(buffer + offset, data + bytes_sent, bytes_to_send);
  539. +           memset(buffer , 0, URBBUF_MAX );
  540. +           memcpy(buffer , data + bytes_sent, bytes_to_send);
  541. +           for (m=0,n=0;m<(frame->width*frame->height*(1+(2)));){
  542. +               r = buffer[m++];
  543. +                   g = buffer[m++];
  544. +                                b = buffer[m++];
  545. +               pixels[n++] = (unsigned char)(RGB565_0(r,g,b)); //R (5 bits) + G (upper 3 bits)
  546. +                       pixels[n++] = (unsigned char)(RGB565_1(r,g,b)); //G (lower 3 bits) + B (5 bits)
  547. +           }
  548. +                  
  549.             bytes_sent += bytes_to_send; // these counters are just for the data packets
  550.  
  551.             printf("bytes_sent: %d, len: %d\n", bytes_sent, len);
  552.  
  553.             // send chunk
  554. -           if ((ret = usb_bulk_write(dev, usb_endpoint, buffer, URBBUF_MAX, usb_timeout)) < 0)
  555. +              
  556. +
  557. +           printf("usb_bulk_write returned: %d\n", ret);
  558. +           break;
  559. +           // no header needed on subsequent chunks
  560. +       }
  561. +       if ((ret = dpf_screen_blit(frame, buffer, rect) < 0))
  562.             {
  563.                 // error occurred
  564.                 printf("Error occurred while writing data to device.\n");
  565.                 printf("usb_bulk_write returned: %d\n", ret);
  566.             }
  567. -
  568. -           printf("usb_bulk_write returned: %d\n", ret);
  569. -
  570. -           // no header needed on subsequent chunks
  571. -           offset = 0;
  572. -       }
  573.     }
  574. -
  575. +  
  576. +  
  577.     return 0;
  578.  }
  579.  
  580.  
  581.  int main(int argc, char *argv[])
  582.  {
  583. -   struct usb_device *dev = NULL;
  584. -   FILE *file_handle;
  585. -   char *filename = NULL;
  586. +   char * dev="usb0";
  587. +   DPFHANDLE picframe;
  588.     char *fb_device = NULL;
  589. +   FILE *file_handle;
  590.     struct timespec t;
  591.     long fb_refresh_interval = 1000; /* 1000ms*/
  592.     char *tmp_filename;
  593. @@ -248,7 +155,7 @@
  594.         return -1;
  595.     }
  596.  
  597. -   while((opt = getopt(argc, argv, "erhi:j:f:")) != -1)
  598. +   while((opt = getopt(argc, argv, "erhi:f:")) != -1)
  599.     {
  600.         switch (opt)
  601.         {
  602. @@ -256,9 +163,6 @@
  603.                 show_help();
  604.                 return 0;
  605.                 break;
  606. -           case 'j':
  607. -               filename = optarg;
  608. -               break;
  609.             case 'e':
  610.                 opmode = EVENT;
  611.                 break;
  612. @@ -279,19 +183,6 @@
  613.  
  614.  
  615.     /* sanity checks */
  616. -   if (!filename && !fb_device)
  617. -   {
  618. -       printf("both specified\n");
  619. -       show_help();
  620. -       return -1;
  621. -   }
  622. -
  623. -   if (filename && fb_device)
  624. -   {
  625. -       printf("Choose either to read from file or from a frame buffer device.\n");
  626. -       return -1;
  627. -   }
  628. -
  629.     if (fb_refresh_interval < 100)
  630.         printf("WARNING: refresh rates smaller then 100msecs may cause heavy system load\n");
  631.  
  632. @@ -302,7 +193,7 @@
  633.     signal(SIGINT, sigint);
  634.  
  635.     /* start */
  636. -   while ((ret = find_photo_frame(&dev)) != 0)
  637. +   while ((ret = dpf_open(dev,&picframe)) != 0)
  638.     {
  639.         if (ret == -2)
  640.         {
  641. @@ -319,31 +210,8 @@
  642.         sleep(1);
  643.     }
  644.  
  645. -   if ((dev_handle = usb_open(dev)) == NULL)
  646. -   {
  647. -       printf("Error while creating usb device handle.\n");
  648. -       return -1;
  649. -   }
  650. -
  651. -   if (filename)
  652. -   {
  653. -       printf("displaying %s on photo frame ..\n", filename);
  654. -
  655. -       if ((file_handle = fopen(filename, "r+")) == NULL)
  656. -       {
  657. -           printf("File %s was not found.\n", filename);
  658. -           ret = -1;
  659. -           goto exit;
  660. -       }
  661. -
  662. -       if ((ret = send_jpeg(dev_handle, file_handle, NULL, 0)) != 0)
  663. -       {
  664. -           printf("Error occurred while sending jpeg image to device.\n");
  665. -       }
  666. -
  667. -       fclose(file_handle);
  668. -   }
  669. -   else if (fb_device)
  670. +  
  671. +   if (fb_device)
  672.     {
  673.         /*
  674.          * workflow:
  675. @@ -387,7 +255,7 @@
  676.             fseek(tmpfile_handle, 0, SEEK_SET);
  677.  
  678.             /* send image to frame */
  679. -           if ((ret = send_jpeg(dev_handle, tmpfile_handle, NULL, 0)) != 0)
  680. +           if ((ret = send_data(picframe, tmpfile_handle, NULL, 0)) != 0)
  681.             {
  682.                 printf("Error occurred while sending jpeg image to device.\n");
  683.             }
  684. @@ -412,9 +280,9 @@
  685.                 fseek(tmpfile_handle, 0, SEEK_SET);
  686.  
  687.                 /* send image to frame */
  688. -               if ((ret = send_jpeg(dev_handle, tmpfile_handle, NULL, 0)) != 0)
  689. +               if ((ret = send_data(picframe, tmpfile_handle, NULL, 0)) != 0)
  690.                 {
  691. -                   printf("Error occurred while sending jpeg image to device.\n");
  692. +                   printf("Error occurred while sending image to device.\n");
  693.                 }
  694.  
  695.                 /* calculate next shot */
  696. @@ -445,9 +313,9 @@
  697.                 fseek(tmpfile_handle, 0, SEEK_SET);
  698.  
  699.                 /* send image to frame */
  700. -               if ((ret = send_jpeg(dev_handle, tmpfile_handle, NULL, 0)) != 0)
  701. +               if ((ret = send_data(picframe, tmpfile_handle, NULL, 0)) != 0)
  702.                 {
  703. -                   printf("Error occurred while sending jpeg image to device.\n");
  704. +                   printf("Error occurred while sending image to device.\n");
  705.                 }
  706.  
  707.             }
  708. diff -Nuar playusb/playusb.h playusb-ax206//playusb.h
  709. --- playusb/playusb.h   2010-11-01 01:33:08.000000000 +0800
  710. +++ playusb-ax206//playusb.h    2012-05-01 15:45:59.985296704 +0800
  711. @@ -17,6 +17,7 @@
  712.  #include <time.h>
  713.  #include <fcntl.h>
  714.  #include <getopt.h>
  715. +#include "dpf.h"
  716.  
  717.  struct frame_info
  718.  {
  719. @@ -29,49 +30,19 @@
  720.  };
  721.  
  722.  
  723. -static struct frame_info photo_frames[] = {
  724. -   {
  725. -       .name                   = "Samsung SPF-85H",
  726. -       .vendorid               = 0x04e8,
  727. -       .productid_massstorage  = 0x2012,
  728. -       .productid_photo        = 0x2013,
  729. -       .xres                   = 800,
  730. -       .yres                   = 600,
  731. -   },
  732. -   {
  733. -       .name                   = "Samsung SPF-87H",
  734. -       .vendorid               = 0x04e8,
  735. -       .productid_massstorage  = 0x2033,
  736. -       .productid_photo        = 0x2034,
  737. -       .xres                   = 800,
  738. -       .yres                   = 480,
  739. -   },
  740. -   {
  741. -       .name                   = "Samsung SPF-107H",
  742. -       .vendorid               = 0x04e8,
  743. -       .productid_massstorage  = 0x2027,
  744. -       .productid_photo        = 0x2028,
  745. -       .xres                   = 1024,
  746. -       .yres                   = 600,
  747. -   },
  748. -};
  749. -static int num_frames = sizeof(photo_frames) / sizeof(photo_frames[0]);
  750. -
  751. -int find_photo_frame(struct usb_device **new_dev);
  752. -int switch_usb_mode(struct usb_device* dev);
  753. -int send_jpeg(usb_dev_handle *dev, FILE *file, char *data, int len);
  754. +int send_data(DPFHANDLE frame, FILE *file, char *data, int len);
  755.  void sigint(int signum);
  756.  int grab_from_fb(char *fb_device, FILE *tmp_file);
  757.  
  758.  
  759.  #define min( a, b ) ( ((a) < (b)) ? (a) : (b) )
  760. -#define URBBUF_MAX 0x20000
  761. +#define URBBUF_MAX (128*128*3)
  762.  #define USB_HDR_LEN 12
  763.  #define MAX_JPEG_SIZE (2 * 1024 * 1024)
  764.  #define NSEC_PER_SEC    1000000000 /* The number of nsecs per sec. */
  765.  #define USEC_PER_SEC    1000000
  766.  
  767. -#define DEBUGFS_ENTRY "/sys/kernel/debug/spfb"
  768. +#define DEBUGFS_ENTRY "/sys/kernel/debug/ax206fb"
  769.  #define PLAYUSB_TEMPLATE "/tmp/playusb"
  770.  
  771.  
  772. diff -Nuar playusb/spiflash.h playusb-ax206//spiflash.h
  773. --- playusb/spiflash.h  1970-01-01 07:30:00.000000000 +0730
  774. +++ playusb-ax206//spiflash.h   2012-04-30 19:53:12.612948785 +0800
  775. @@ -0,0 +1,30 @@
  776. +/** \file flashcmd_st.h
  777. + *
  778. + * ST compatible flash cmds
  779. + *
  780. + */
  781. +
  782. +
  783. +#define SPM_RDID              0x9f    // Read Id
  784. +#define SPM_NO_CMD            0x00    // No command
  785. +
  786. +#define SPM_WREN              0x06    // Write enable
  787. +#define SPM_WRDI              0x04    // Write disable
  788. +#define SPM_RDSR              0x05    // Read status register
  789. +#define SPM_WRSR              0x01    // Write status register
  790. +#define SPM_READ              0x03    // Read data bytes
  791. +#define SPM_PP                0x02    // Page program
  792. +#define SPM_DP                0xb9    // Deep power down
  793. +#define SPM_RES               0xab    // Release from deep power down
  794. +                                      // and read signature
  795. +#define SPM_FLASH_SE          0xd8    // Sector erase
  796. +#define SPM_FLASH_BE          0xc7    // Bulk erase
  797. +#define SPM_FLASH_FAST_READ   0x0B    // Read data bytes fast
  798. +
  799. +#define SPM_SR_SRWD           0x80    // SR write protection (HW)
  800. +
  801. +// Status register bit definitions
  802. +#define SPS_WIP 0x01       // write in progress
  803. +#define SPS_WEL 0x02       // write enable latch
  804. +
  805. +
  806. diff -Nuar playusb/usbuser.h playusb-ax206//usbuser.h
  807. --- playusb/usbuser.h   1970-01-01 07:30:00.000000000 +0730
  808. +++ playusb-ax206//usbuser.h    2012-04-30 19:53:09.725031418 +0800
  809. @@ -0,0 +1,29 @@
  810. +/* USB user commands
  811. + *
  812. + * Only temporary. Should move to dpflib or into a dclib configuration.
  813. + *
  814. + */
  815. +
  816. +#define PROTOCOL_VERSION  1
  817. +
  818. +/** Our vendor specific USB commands to do stuff on the DPF */
  819. +
  820. +#define USBCMD_GETPROPERTY  0x00    ///< Get property
  821. +#define USBCMD_SETPROPERTY  0x01    ///< Set property
  822. +#define USBCMD_MEMREAD      0x04    ///< Memory read
  823. +#define USBCMD_APPLOAD      0x05    ///< Load and run applet
  824. +#define USBCMD_FILLRECT     0x11    ///< Fill screen rectangle
  825. +#define USBCMD_BLIT         0x12    ///< Blit to screen
  826. +#define USBCMD_COPYRECT     0x13    ///< Copy screen rectangle
  827. +#define USBCMD_FLASHLOCK    0x20    ///< Lock USB for flash access
  828. +#define USBCMD_PROBE        0xff    ///< Get version code (probe)
  829. +
  830. +/* Some special return codes */
  831. +#define USB_IN_SEQUENCE     0x7f    ///< We're inside a command sequence
  832. +
  833. +// Property handling:
  834. +
  835. +#define PROPERTY_BRIGHTNESS  0x01
  836. +#define PROPERTY_FGCOLOR     0x02
  837. +#define PROPERTY_BGCOLOR     0x03
  838. +#define PROPERTY_ORIENTATION 0x10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement