Advertisement
Guest User

Patch for st2205term-0.11 for dpf

a guest
Apr 28th, 2012
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 14.34 KB | None | 0 0
  1. diff -Nuar st2205term-0.10//dpf.h st2205term-0.11//dpf.h
  2. --- st2205term-0.10//dpf.h  1970-01-01 07:30:00.000000000 +0730
  3. +++ st2205term-0.11//dpf.h  2012-04-29 10:05:41.887853428 +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 st2205term-0.10//mak st2205term-0.11//mak
  194. --- st2205term-0.10//mak    2010-12-26 04:52:52.000000000 +0800
  195. +++ st2205term-0.11//mak    2012-04-29 10:05:41.883853570 +0800
  196. @@ -1,8 +1,11 @@
  197.  #!/bin/bash
  198.  
  199.  # compile using libst2205
  200. -gcc -Wall -g -O2 -DHAVE_ST2205 -o st2205term st2205term.c -lrote -lst2205
  201. +#gcc -Wall -g -O2 -DHAVE_ST2205 -o st2205term st2205term.c -lrote -lst2205
  202.  
  203. +# compile using dpf
  204. +
  205. +gcc -Wall -g -O2 -DHAVE_DPF -o st2205term st2205term.c -lrote -ldpf
  206.  # compile using libdlo
  207.  # gcc -Wall -g -O2 -DHAVE_DLO -o st2205term st2205term.c -lrote -ldlo
  208.  
  209. diff -Nuar st2205term-0.10//spiflash.h st2205term-0.11//spiflash.h
  210. --- st2205term-0.10//spiflash.h 1970-01-01 07:30:00.000000000 +0730
  211. +++ st2205term-0.11//spiflash.h 2012-04-29 10:05:41.883853570 +0800
  212. @@ -0,0 +1,30 @@
  213. +/** \file flashcmd_st.h
  214. + *
  215. + * ST compatible flash cmds
  216. + *
  217. + */
  218. +
  219. +
  220. +#define SPM_RDID              0x9f    // Read Id
  221. +#define SPM_NO_CMD            0x00    // No command
  222. +
  223. +#define SPM_WREN              0x06    // Write enable
  224. +#define SPM_WRDI              0x04    // Write disable
  225. +#define SPM_RDSR              0x05    // Read status register
  226. +#define SPM_WRSR              0x01    // Write status register
  227. +#define SPM_READ              0x03    // Read data bytes
  228. +#define SPM_PP                0x02    // Page program
  229. +#define SPM_DP                0xb9    // Deep power down
  230. +#define SPM_RES               0xab    // Release from deep power down
  231. +                                      // and read signature
  232. +#define SPM_FLASH_SE          0xd8    // Sector erase
  233. +#define SPM_FLASH_BE          0xc7    // Bulk erase
  234. +#define SPM_FLASH_FAST_READ   0x0B    // Read data bytes fast
  235. +
  236. +#define SPM_SR_SRWD           0x80    // SR write protection (HW)
  237. +
  238. +// Status register bit definitions
  239. +#define SPS_WIP 0x01       // write in progress
  240. +#define SPS_WEL 0x02       // write enable latch
  241. +
  242. +
  243. diff -Nuar st2205term-0.10//st2205term.c st2205term-0.11//st2205term.c
  244. --- st2205term-0.10//st2205term.c   2010-12-28 23:00:41.000000000 +0800
  245. +++ st2205term-0.11//st2205term.c   2012-04-29 10:05:41.883853570 +0800
  246. @@ -16,6 +16,8 @@
  247.  // To compile, choose one of the following depending on what display libraries you have...
  248.  // libst2205:            gcc -Wall -g -O2 -DHAVE_ST2205 -o st2205term st2205term.c -lrote -lst2205
  249.  // libdlo:               gcc -Wall -g -O2 -DHAVE_DLO -o st2205term st2205term.c -lrote -ldlo
  250. +// libdpf:            gcc -Wall -g -O2 -DHAVE_ST2205 -o st2205term st2205term.c -lrote -ldpf
  251. +// libdlo:               gcc -Wall -g -O2 -DHAVE_DLO -o st2205term st2205term.c -lrote -ldlo
  252.  // libst2205 and libdlo: gcc -Wall -g -O2 -DHAVE_ST2205 -DHAVE_DLO -o st2205term st2205term.c -lrote -lst2205 -ldlo
  253.  
  254.  #define _GNU_SOURCE
  255. @@ -54,6 +56,11 @@
  256.  static unsigned char *bad_row=NULL;
  257.  static unsigned int *lasthash=NULL,*hash=NULL; // 32bit hash of each terminal row
  258.  #endif
  259. +#ifdef HAVE_DPF
  260. +#include "dpf.h"
  261. +static DPFHANDLE picframe;
  262. +static unsigned char colormap[8][2];
  263. +#endif
  264.  
  265.  static int sw=0,sh=0; // screen width, height
  266.  static unsigned char *pixels=NULL; // pixel buffer that is copied to device
  267. @@ -99,7 +106,7 @@
  268.  static int shift_active=0,ctrl_active=0,alt_active=0;
  269.  
  270.  // type of output device selected on cmdline
  271. -static int use_st2205=0,use_dlo=0;
  272. +static int use_st2205=0,use_dlo=0,use_dpf=0;
  273.  
  274.  // blinking cursor?
  275.  static int blinking_cursor=0,blink_toggle=1;
  276. @@ -265,7 +272,33 @@
  277.          }
  278.      }
  279.  #endif
  280. -
  281. +#ifdef HAVE_DPF
  282. +    if (use_dpf)
  283. +    {
  284. +        char *d=f->data;
  285. +        if (ch>32 && ch<127) d+=(f->w+1)*f->h*(ch-32);
  286. +        unsigned char rgb_fg=colormap[fg][0],rgb_bg=colormap[bg][0];
  287. +        unsigned char rgb_fgh=colormap[fg][1],rgb_bgh=colormap[bg][1];
  288. +        int m,n;
  289. +        for (m=0;m<f->h;m++) { //Each font character if a rectangular array of pixels.
  290. +//m is the y-coordinate within the pixel array which ranges from 0..font height (f->h-1)
  291. +            unsigned char *p=pixels+(y+m)*(sw+sw)+x+x;
  292. +          
  293. +            for (n=0;n<f->w;n++) {
  294. +// n is the x-coordinate within the pixel array which ranges from 0..font width (f->w-1)
  295. +                
  296. +       if (*d++=='#'){
  297. +                *p++=rgb_fg;
  298. +                *p++=rgb_fgh;
  299. +       } else {
  300. +       *p++=rgb_bg;
  301. +       *p++=rgb_bgh;
  302. +       }
  303. +            }
  304. +            d++; // skip linefeed
  305. +        }
  306. +    } 
  307. +#endif
  308.  #ifdef HAVE_DLO
  309.      if (use_dlo)
  310.      {
  311. @@ -317,6 +350,12 @@
  312.          source_row=(int*)calloc(th,sizeof(int));
  313.          bad_row=(unsigned char*)calloc(th,sizeof(unsigned char));
  314.      #endif
  315. +    #ifdef HAVE_DPF
  316. +        int i;
  317. +        for (i=0;i<8;i++){
  318. +            colormap[i][0]=(unsigned char)(RGB565_0(rgb_colors[i][0],rgb_colors[i][1],rgb_colors[i][2]));
  319. +            colormap[i][1]=(unsigned char)(RGB565_1(rgb_colors[i][0],rgb_colors[i][1],rgb_colors[i][2]));}
  320. +    #endif
  321.  }
  322.  static void destroy_terminal()
  323.  {
  324. @@ -394,7 +433,35 @@
  325.          fprintf(stderr,"ERROR: displaylink support is not compiled into binary!\n"); exit(1);
  326.  #endif
  327.      }
  328. -
  329. +    if (use_dpf)
  330. +    {
  331. +#ifdef HAVE_DPF
  332. +        static char device[PATH_MAX];
  333. +        if (picframe==NULL)
  334. +        {
  335. +            char *dev=NULL;
  336. +            if (dev==NULL)
  337. +            {
  338. +                static char path[PATH_MAX];
  339. +                dev="usb0";
  340. +            }
  341. +       strcpy(device,dev);
  342. +       int r=dpf_open(device,&picframe);
  343. +                if (picframe)
  344. +                {
  345. +                    sw=picframe->width;
  346. +                    sh=picframe->height;
  347. +                    pixels=(unsigned char*)malloc(sw*sh*2);
  348. +                    create_terminal();
  349. +                    fprintf(stderr,"INFO: successfully connected to picframe\n");
  350. +                }
  351. +                else fprintf(stderr,"WARN: failed to connect to picframe\n");
  352. +            //}
  353. +        }
  354. +#else
  355. +        fprintf(stderr,"ERROR: dpf support is not compiled into binary!\n"); exit(1);
  356. +#endif
  357. +    }
  358.      if (use_st2205)
  359.      {
  360.  #ifdef HAVE_ST2205
  361. @@ -537,6 +604,7 @@
  362.          if (strncmp(argv[i],"--keymap=",9)==0) { keymapfile=argv[i]+9; continue; }
  363.          if (strncmp(argv[i],"--fontdata=",9)==0) { fontsfile=argv[i]+11; continue; }
  364.          if (strncmp(argv[i],"--picframe=",11)==0) { st2205dev=argv[i]+11; use_st2205=1; continue; }
  365. +        if (strcmp(argv[i],"--dpf")==0) { use_dpf=1; continue; }
  366.          if (strcmp(argv[i],"--dlo")==0) { use_dlo=1; continue; }
  367.          if (strcmp(argv[i],"--dlo-fast-scroll=yes")==0) { fast_scroll=1; continue; }
  368.          if (strcmp(argv[i],"--dlo-fast-scroll=no")==0) { fast_scroll=0; continue; }
  369. @@ -548,7 +616,7 @@
  370.          bad=1;
  371.          break;
  372.      }
  373. -    if (use_st2205==0 && use_dlo==0) use_st2205=1;
  374. +    if (use_st2205==0 && use_dlo==0) use_dpf=1;
  375.      if (keymapfile==NULL)
  376.      {
  377.          static char path[PATH_MAX];
  378. @@ -743,9 +811,21 @@
  379.          {
  380.              if (picframe->oldpix) { free(picframe->oldpix); picframe->oldpix=NULL; } // avoid libst2205 incremental update bug
  381.              st2205_send_data(picframe,pixels);
  382. +      
  383. +
  384.          }
  385.          #endif
  386. -
  387. +   #ifdef HAVE_DPF
  388. +   if (use_dpf && picframe!=NULL) // push changes to picframe - copies entire display
  389. +        {
  390. +       short rect[4];
  391. +       rect[0]=0;
  392. +       rect[1]=0;
  393. +       rect[2]=sw;
  394. +       rect[3]=sh;
  395. +       dpf_screen_blit(picframe,pixels,rect);
  396. +   }
  397. +   #endif
  398.          #ifdef HAVE_DLO
  399.          if (use_dlo && !dlo_broken) // push changes to displaylink device
  400.          {
  401. @@ -761,6 +841,7 @@
  402.              dot.x=minx;
  403.              dot.y=miny;
  404.              if (dlo_copy_host_bmp(uid,flags,&fbuf,NULL,&dot)!=dlo_ok)
  405. +
  406.                  dlo_broken=1;
  407.          }
  408.          #endif
  409. diff -Nuar st2205term-0.10//usbuser.h st2205term-0.11//usbuser.h
  410. --- st2205term-0.10//usbuser.h  1970-01-01 07:30:00.000000000 +0730
  411. +++ st2205term-0.11//usbuser.h  2012-04-29 10:05:41.887853428 +0800
  412. @@ -0,0 +1,29 @@
  413. +/* USB user commands
  414. + *
  415. + * Only temporary. Should move to dpflib or into a dclib configuration.
  416. + *
  417. + */
  418. +
  419. +#define PROTOCOL_VERSION  1
  420. +
  421. +/** Our vendor specific USB commands to do stuff on the DPF */
  422. +
  423. +#define USBCMD_GETPROPERTY  0x00    ///< Get property
  424. +#define USBCMD_SETPROPERTY  0x01    ///< Set property
  425. +#define USBCMD_MEMREAD      0x04    ///< Memory read
  426. +#define USBCMD_APPLOAD      0x05    ///< Load and run applet
  427. +#define USBCMD_FILLRECT     0x11    ///< Fill screen rectangle
  428. +#define USBCMD_BLIT         0x12    ///< Blit to screen
  429. +#define USBCMD_COPYRECT     0x13    ///< Copy screen rectangle
  430. +#define USBCMD_FLASHLOCK    0x20    ///< Lock USB for flash access
  431. +#define USBCMD_PROBE        0xff    ///< Get version code (probe)
  432. +
  433. +/* Some special return codes */
  434. +#define USB_IN_SEQUENCE     0x7f    ///< We're inside a command sequence
  435. +
  436. +// Property handling:
  437. +
  438. +#define PROPERTY_BRIGHTNESS  0x01
  439. +#define PROPERTY_FGCOLOR     0x02
  440. +#define PROPERTY_BGCOLOR     0x03
  441. +#define PROPERTY_ORIENTATION 0x10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement