diff -Nuar st2205term-0.10//dpf.h st2205term-0.11//dpf.h --- st2205term-0.10//dpf.h 1970-01-01 07:30:00.000000000 +0730 +++ st2205term-0.11//dpf.h 2012-04-29 10:05:41.887853428 +0800 @@ -0,0 +1,188 @@ +/** libdpf header file + * + * (c) 2010, 2011 + * + */ + +#include +#include "usbuser.h" +#include "spiflash.h" + +#define ADDR unsigned int + +#define MODE_SG 0x00 ///< generic device mode (original) +#define MODE_USB 0x01 ///< libusb operation mode (hacked) +#define MODE_USBHID 0x02 ///< libusb HID boot mode + +#define FLAG_CAN_LOCK 0x80 ///< Has the locking feature (new firmware) + +enum { + DEVERR_FILE = -16, + DEVERR_OPEN, + DEVERR_HEX, + DEVERR_CHK, + DEVERR_IO, + DEVERR_MALLOC, + DEVERR_TIMEOUT, + DEVERR_UNSUPP, +}; + +/** The DPF context structure */ +struct dpf_context; +#define DPFHANDLE struct dpf_context * + +typedef struct { + int (*mem_read)(DPFHANDLE h, unsigned char *buf, ADDR offset, int len); + int (*mem_write)(DPFHANDLE h, + ADDR dst, const unsigned char *buf, unsigned short n); + int (*go)(DPFHANDLE h, ADDR start); + int (*bootstrap)(DPFHANDLE h, + ADDR dest, unsigned char *src, unsigned short n, ADDR start); + int (*flash_probe)(DPFHANDLE h, unsigned char *id); + int (*flash_cmd)(DPFHANDLE h, int command, int cmdlen, ADDR addr); + int (*flash_status)(DPFHANDLE h, uint8_t *status); + int (*flash_read)(DPFHANDLE h, uint8_t *buf, ADDR offset, int len); + int (*flash_writechunk)(DPFHANDLE h, + const uint8_t *buf, ADDR offset, int len); + int (*flash_lock)(DPFHANDLE h, char enable); +} AccessMethods; + +typedef +struct dpf_context { + unsigned char mode; + unsigned char flags; + union { + usb_dev_handle *udev; + int fd; + } dev; + AccessMethods methods; + unsigned int width; + unsigned int height; + int bpp; + int proto; + char* buff; + unsigned char* oldpix; + int offx; + int offy; +} DPFContext; + + +/** A value proxy for the property API */ +typedef struct dpf_proxy { + union { + short integer; + char *sequence; + } value; + char type; +} DPFValue; + +enum { + TYPE_INTEGER, + TYPE_STRING, +}; + +/** + Opens the DPF device. if dev is not NULL, open device, otherwise, look for + USB device. + */ +int dpf_open(const char *dev, DPFHANDLE *h); + +/** Close DPF device */ +void dpf_close(DPFHANDLE h); + +/** Set color register + * \param rgb RGB tuple */ +int dpf_setcol(DPFHANDLE h, const unsigned char *rgb); + +/** Blit data to screen + * + * \param buf buffer to 16 bpp RGB 565 image data + * \param rect rectangle tuple: [x0, y0, x1, y1] + */ + +int dpf_screen_blit(DPFHANDLE h, const unsigned char *buf, short rect[4]); + +/** Set property on DPF + * \param token Property token + * \param value Pointer to value + */ +int dpf_setproperty(DPFHANDLE h, int token, const DPFValue *value); + +/* USB raw */ + +int emulate_scsi(usb_dev_handle *d, unsigned char *cmd, int cmdlen, char out, + unsigned char *data, unsigned long block_len); + +const char *dev_errstr(int err); + +// Private stuff: +int dpf_usb_open(int index, usb_dev_handle **u); +int sgdev_open(const char *portname, int *fd); +int usb_rawread(usb_dev_handle *dev, unsigned char *buf, int len); +int usb_rawwrite(usb_dev_handle *dev, const unsigned char *buf, int len); +int probe(DPFHANDLE h); + +//////////////////////////////////////////////////////////////////////////// +// Bootloader functionality + +int bl_go(DPFContext *dpf, uint16_t jmpoffset); + +//////////////////////////////////////////////////////////////////////////// +// FLASH stuff + +// Maximum size for flash_read +#define MAX_CHUNKSIZE 0x10000 + +int read_mem(DPFHANDLE h, unsigned char *buf, ADDR src, unsigned short len); +int write_mem(DPFHANDLE h, + ADDR dst, const unsigned char *buf, unsigned short len); + +int load_hexfile(DPFHANDLE h, const char *hexfile); +int code_go(DPFHANDLE h, ADDR start); + +int dpf_bootstrap(DPFHANDLE h, + ADDR dst, unsigned char *src, unsigned short n, ADDR start); + +int flash_cmd(DPFHANDLE h, int command, int cmdlen, ADDR addr); +int flash_probe(DPFContext *h, unsigned char *id); +int flash_erase(DPFHANDLE h, ADDR offset); +int flash_erase_full(DPFHANDLE h); +int flash_write(DPFHANDLE h, const unsigned char *buf, ADDR offset, int len); +int flash_read(DPFHANDLE h, unsigned char *buf, ADDR offset, int len); + +int load_ihx(DPFHANDLE h, const char *fname, unsigned char *data, + unsigned int *buflen, unsigned int reloc); + +int patch_sector(DPFHANDLE h, + ADDR reloc, unsigned long addr, const char *hexfile); + +//////////////////////////////////////////////////////////////////////////// +/* DPF specific stuff: */ + +#define RGB565_0(r, g, b) \ + (( ((r) & 0xf8) ) | (((g) & 0xe0) >> 5)) +#define RGB565_1(r, g, b) \ + (( ((g) & 0x1c) << 3 ) | (((b) & 0xf8) >> 3)) + +#define RGB565(r, g, b) { RGB565_0(r, g, b), RGB565_1(r, g, b) } + +#define RGB565_S(r, g, b) ((RGB565_0(r, g, b) << 8) | RGB565_1(r, g, b)) + +int dpfcpy(ADDR dst, unsigned char *src, unsigned short n); + +// int clr_screen(DPFHANDLE h, const unsigned char *col); +int write_screen(DPFHANDLE h, const unsigned char *buf, unsigned int len); + + +// Some internal address offsets. They may change, but so far all types +// seem to have the same +// +// w: word, : length, [LE, BE] +// +// FIXME: Use packed struct later. + +// FIXME: Should be 0x0020, once we have the firmware replaced +#define OFFSET_PROPS 0x3f0020 ///< w[2]:LE : Resolution X, Y + + + diff -Nuar st2205term-0.10//mak st2205term-0.11//mak --- st2205term-0.10//mak 2010-12-26 04:52:52.000000000 +0800 +++ st2205term-0.11//mak 2012-04-29 10:05:41.883853570 +0800 @@ -1,8 +1,11 @@ #!/bin/bash # compile using libst2205 -gcc -Wall -g -O2 -DHAVE_ST2205 -o st2205term st2205term.c -lrote -lst2205 +#gcc -Wall -g -O2 -DHAVE_ST2205 -o st2205term st2205term.c -lrote -lst2205 +# compile using dpf + +gcc -Wall -g -O2 -DHAVE_DPF -o st2205term st2205term.c -lrote -ldpf # compile using libdlo # gcc -Wall -g -O2 -DHAVE_DLO -o st2205term st2205term.c -lrote -ldlo diff -Nuar st2205term-0.10//spiflash.h st2205term-0.11//spiflash.h --- st2205term-0.10//spiflash.h 1970-01-01 07:30:00.000000000 +0730 +++ st2205term-0.11//spiflash.h 2012-04-29 10:05:41.883853570 +0800 @@ -0,0 +1,30 @@ +/** \file flashcmd_st.h + * + * ST compatible flash cmds + * + */ + + +#define SPM_RDID 0x9f // Read Id +#define SPM_NO_CMD 0x00 // No command + +#define SPM_WREN 0x06 // Write enable +#define SPM_WRDI 0x04 // Write disable +#define SPM_RDSR 0x05 // Read status register +#define SPM_WRSR 0x01 // Write status register +#define SPM_READ 0x03 // Read data bytes +#define SPM_PP 0x02 // Page program +#define SPM_DP 0xb9 // Deep power down +#define SPM_RES 0xab // Release from deep power down + // and read signature +#define SPM_FLASH_SE 0xd8 // Sector erase +#define SPM_FLASH_BE 0xc7 // Bulk erase +#define SPM_FLASH_FAST_READ 0x0B // Read data bytes fast + +#define SPM_SR_SRWD 0x80 // SR write protection (HW) + +// Status register bit definitions +#define SPS_WIP 0x01 // write in progress +#define SPS_WEL 0x02 // write enable latch + + diff -Nuar st2205term-0.10//st2205term.c st2205term-0.11//st2205term.c --- st2205term-0.10//st2205term.c 2010-12-28 23:00:41.000000000 +0800 +++ st2205term-0.11//st2205term.c 2012-04-29 10:05:41.883853570 +0800 @@ -16,6 +16,8 @@ // To compile, choose one of the following depending on what display libraries you have... // libst2205: gcc -Wall -g -O2 -DHAVE_ST2205 -o st2205term st2205term.c -lrote -lst2205 // libdlo: gcc -Wall -g -O2 -DHAVE_DLO -o st2205term st2205term.c -lrote -ldlo +// libdpf: gcc -Wall -g -O2 -DHAVE_ST2205 -o st2205term st2205term.c -lrote -ldpf +// libdlo: gcc -Wall -g -O2 -DHAVE_DLO -o st2205term st2205term.c -lrote -ldlo // libst2205 and libdlo: gcc -Wall -g -O2 -DHAVE_ST2205 -DHAVE_DLO -o st2205term st2205term.c -lrote -lst2205 -ldlo #define _GNU_SOURCE @@ -54,6 +56,11 @@ static unsigned char *bad_row=NULL; static unsigned int *lasthash=NULL,*hash=NULL; // 32bit hash of each terminal row #endif +#ifdef HAVE_DPF +#include "dpf.h" +static DPFHANDLE picframe; +static unsigned char colormap[8][2]; +#endif static int sw=0,sh=0; // screen width, height static unsigned char *pixels=NULL; // pixel buffer that is copied to device @@ -99,7 +106,7 @@ static int shift_active=0,ctrl_active=0,alt_active=0; // type of output device selected on cmdline -static int use_st2205=0,use_dlo=0; +static int use_st2205=0,use_dlo=0,use_dpf=0; // blinking cursor? static int blinking_cursor=0,blink_toggle=1; @@ -265,7 +272,33 @@ } } #endif - +#ifdef HAVE_DPF + if (use_dpf) + { + char *d=f->data; + if (ch>32 && ch<127) d+=(f->w+1)*f->h*(ch-32); + unsigned char rgb_fg=colormap[fg][0],rgb_bg=colormap[bg][0]; + unsigned char rgb_fgh=colormap[fg][1],rgb_bgh=colormap[bg][1]; + int m,n; + for (m=0;mh;m++) { //Each font character if a rectangular array of pixels. +//m is the y-coordinate within the pixel array which ranges from 0..font height (f->h-1) + unsigned char *p=pixels+(y+m)*(sw+sw)+x+x; + + for (n=0;nw;n++) { +// n is the x-coordinate within the pixel array which ranges from 0..font width (f->w-1) + + if (*d++=='#'){ + *p++=rgb_fg; + *p++=rgb_fgh; + } else { + *p++=rgb_bg; + *p++=rgb_bgh; + } + } + d++; // skip linefeed + } + } +#endif #ifdef HAVE_DLO if (use_dlo) { @@ -317,6 +350,12 @@ source_row=(int*)calloc(th,sizeof(int)); bad_row=(unsigned char*)calloc(th,sizeof(unsigned char)); #endif + #ifdef HAVE_DPF + int i; + for (i=0;i<8;i++){ + colormap[i][0]=(unsigned char)(RGB565_0(rgb_colors[i][0],rgb_colors[i][1],rgb_colors[i][2])); + colormap[i][1]=(unsigned char)(RGB565_1(rgb_colors[i][0],rgb_colors[i][1],rgb_colors[i][2]));} + #endif } static void destroy_terminal() { @@ -394,7 +433,35 @@ fprintf(stderr,"ERROR: displaylink support is not compiled into binary!\n"); exit(1); #endif } - + if (use_dpf) + { +#ifdef HAVE_DPF + static char device[PATH_MAX]; + if (picframe==NULL) + { + char *dev=NULL; + if (dev==NULL) + { + static char path[PATH_MAX]; + dev="usb0"; + } + strcpy(device,dev); + int r=dpf_open(device,&picframe); + if (picframe) + { + sw=picframe->width; + sh=picframe->height; + pixels=(unsigned char*)malloc(sw*sh*2); + create_terminal(); + fprintf(stderr,"INFO: successfully connected to picframe\n"); + } + else fprintf(stderr,"WARN: failed to connect to picframe\n"); + //} + } +#else + fprintf(stderr,"ERROR: dpf support is not compiled into binary!\n"); exit(1); +#endif + } if (use_st2205) { #ifdef HAVE_ST2205 @@ -537,6 +604,7 @@ if (strncmp(argv[i],"--keymap=",9)==0) { keymapfile=argv[i]+9; continue; } if (strncmp(argv[i],"--fontdata=",9)==0) { fontsfile=argv[i]+11; continue; } if (strncmp(argv[i],"--picframe=",11)==0) { st2205dev=argv[i]+11; use_st2205=1; continue; } + if (strcmp(argv[i],"--dpf")==0) { use_dpf=1; continue; } if (strcmp(argv[i],"--dlo")==0) { use_dlo=1; continue; } if (strcmp(argv[i],"--dlo-fast-scroll=yes")==0) { fast_scroll=1; continue; } if (strcmp(argv[i],"--dlo-fast-scroll=no")==0) { fast_scroll=0; continue; } @@ -548,7 +616,7 @@ bad=1; break; } - if (use_st2205==0 && use_dlo==0) use_st2205=1; + if (use_st2205==0 && use_dlo==0) use_dpf=1; if (keymapfile==NULL) { static char path[PATH_MAX]; @@ -743,9 +811,21 @@ { if (picframe->oldpix) { free(picframe->oldpix); picframe->oldpix=NULL; } // avoid libst2205 incremental update bug st2205_send_data(picframe,pixels); + + } #endif - + #ifdef HAVE_DPF + if (use_dpf && picframe!=NULL) // push changes to picframe - copies entire display + { + short rect[4]; + rect[0]=0; + rect[1]=0; + rect[2]=sw; + rect[3]=sh; + dpf_screen_blit(picframe,pixels,rect); + } + #endif #ifdef HAVE_DLO if (use_dlo && !dlo_broken) // push changes to displaylink device { @@ -761,6 +841,7 @@ dot.x=minx; dot.y=miny; if (dlo_copy_host_bmp(uid,flags,&fbuf,NULL,&dot)!=dlo_ok) + dlo_broken=1; } #endif diff -Nuar st2205term-0.10//usbuser.h st2205term-0.11//usbuser.h --- st2205term-0.10//usbuser.h 1970-01-01 07:30:00.000000000 +0730 +++ st2205term-0.11//usbuser.h 2012-04-29 10:05:41.887853428 +0800 @@ -0,0 +1,29 @@ +/* USB user commands + * + * Only temporary. Should move to dpflib or into a dclib configuration. + * + */ + +#define PROTOCOL_VERSION 1 + +/** Our vendor specific USB commands to do stuff on the DPF */ + +#define USBCMD_GETPROPERTY 0x00 ///< Get property +#define USBCMD_SETPROPERTY 0x01 ///< Set property +#define USBCMD_MEMREAD 0x04 ///< Memory read +#define USBCMD_APPLOAD 0x05 ///< Load and run applet +#define USBCMD_FILLRECT 0x11 ///< Fill screen rectangle +#define USBCMD_BLIT 0x12 ///< Blit to screen +#define USBCMD_COPYRECT 0x13 ///< Copy screen rectangle +#define USBCMD_FLASHLOCK 0x20 ///< Lock USB for flash access +#define USBCMD_PROBE 0xff ///< Get version code (probe) + +/* Some special return codes */ +#define USB_IN_SEQUENCE 0x7f ///< We're inside a command sequence + +// Property handling: + +#define PROPERTY_BRIGHTNESS 0x01 +#define PROPERTY_FGCOLOR 0x02 +#define PROPERTY_BGCOLOR 0x03 +#define PROPERTY_ORIENTATION 0x10