x
Fork of FT810 by
Revision 10:6a81aeca25e3, committed 2018-07-23
- Comitter:
- JackB
- Date:
- Mon Jul 23 12:22:23 2018 +0000
- Parent:
- 9:ca6a7c6a2f4b
- Commit message:
- FT813
Changed in this revision
diff -r ca6a7c6a2f4b -r 6a81aeca25e3 inc/FT_DataTypes.h --- a/inc/FT_DataTypes.h Thu Dec 22 20:19:22 2016 +0000 +++ b/inc/FT_DataTypes.h Mon Jul 23 12:22:23 2018 +0000 @@ -57,9 +57,4 @@ #endif /*_FT_DATATYPES_H_*/ - /* Nothing beyond this*/ - - - -
diff -r ca6a7c6a2f4b -r 6a81aeca25e3 inc/FT_Gpu.h --- a/inc/FT_Gpu.h Thu Dec 22 20:19:22 2016 +0000 +++ b/inc/FT_Gpu.h Mon Jul 23 12:22:23 2018 +0000 @@ -16,14 +16,328 @@ #define RAM_G_SIZE 1024*1024L #define FT81X_VERSION "1.0.4" +#define DL_CLEAR 0x26000000UL /* requires OR'd arguments */ +#define DL_CLEAR_RGB 0x02000000UL /* requires OR'd arguments */ +#define DL_COLOR_RGB 0x04000000UL /* requires OR'd arguments */ +#define DL_POINT_SIZE 0x0D000000UL /* requires OR'd arguments */ +#define DL_END 0x21000000UL +#define DL_BEGIN 0x1F000000UL /* requires OR'd arguments */ +#define DL_DISPLAY 0x00000000UL + +#define CLR_COL 0x4 +#define CLR_STN 0x2 +#define CLR_TAG 0x1 + +/* Host commands */ +#define FT8_ACTIVE 0x00 /* place FT8xx in active state */ +#define FT8_STANDBY 0x41 /* place FT8xx in Standby (clk running) */ +#define FT8_SLEEP 0x42 /* place FT8xx in Sleep (clk off) */ +#define FT8_PWRDOWN 0x50 /* place FT8xx in Power Down (core off) */ +#define FT8_CLKEXT 0x44 /* select external clock source */ +#define FT8_CLKINT 0x48 /* select internal clock source */ +#define FT8_CORERST 0x68 /* reset core - all registers default and processors reset */ +#define FT8_CLK48M 0x62 /* select 48MHz PLL output */ +#define FT8_CLK36M 0x61 /* select 36MHz PLL output */ + + +/* defines used for graphics commands */ +#define FT8_NEVER 0UL +#define FT8_LESS 1UL +#define FT8_LEQUAL 2UL +#define FT8_GREATER 3UL +#define FT8_GEQUAL 4UL +#define FT8_EQUAL 5UL +#define FT8_NOTEQUAL 6UL +#define FT8_ALWAYS 7UL + + +/* Bitmap formats */ +#define FT8_ARGB1555 0UL +#define FT8_L1 1UL +#define FT8_L4 2UL +#define FT8_L8 3UL +#define FT8_RGB332 4UL +#define FT8_ARGB2 5UL +#define FT8_ARGB4 6UL +#define FT8_RGB565 7UL +#define FT8_PALETTED 8UL +#define FT8_TEXT8X8 9UL +#define FT8_TEXTVGA 10UL +#define FT8_BARGRAPH 11UL + + +/* Bitmap filter types */ +#define FT8_NEAREST 0UL +#define FT8_BILINEAR 1UL + + +/* Bitmap wrap types */ +#define FT8_BORDER 0UL +#define FT8_REPEAT 1UL + + +/* Stencil defines */ +#define FT8_KEEP 1UL +#define FT8_REPLACE 2UL +#define FT8_INCR 3UL +#define FT8_DECR 4UL +#define FT8_INVERT 5UL + + +/* Graphics display list swap defines */ +#define FT8_DLSWAP_DONE 0UL +#define FT8_DLSWAP_LINE 1UL +#define FT8_DLSWAP_FRAME 2UL + + +/* Interrupt bits */ +#define FT8_INT_SWAP 0x01 +#define FT8_INT_TOUCH 0x02 +#define FT8_INT_TAG 0x04 +#define FT8_INT_SOUND 0x08 +#define FT8_INT_PLAYBACK 0x10 +#define FT8_INT_CMDEMPTY 0x20 +#define FT8_INT_CMDFLAG 0x40 +#define FT8_INT_CONVCOMPLETE 0x80 + + +/* Touch mode */ +#define FT8_TMODE_OFF 0 +#define FT8_TMODE_ONESHOT 1 +#define FT8_TMODE_FRAME 2 +#define FT8_TMODE_CONTINUOUS 3 + + +/* Alpha blending */ +#define FT8_ZERO 0UL +#define FT8_ONE 1UL +#define FT8_SRC_ALPHA 2UL +#define FT8_DST_ALPHA 3UL +#define FT8_ONE_MINUS_SRC_ALPHA 4UL +#define FT8_ONE_MINUS_DST_ALPHA 5UL + + +/* Graphics primitives */ +#define FT8_BITMAPS 1UL +#define FT8_POINTS 2UL +#define FT8_LINES 3UL +#define FT8_LINE_STRIP 4UL +#define FT8_EDGE_STRIP_R 5UL +#define FT8_EDGE_STRIP_L 6UL +#define FT8_EDGE_STRIP_A 7UL +#define FT8_EDGE_STRIP_B 8UL +#define FT8_RECTS 9UL + + +/* Widget command */ +#define FT8_OPT_MONO 1 +#define FT8_OPT_NODL 2 +#define FT8_OPT_FLAT 256 +#define FT8_OPT_CENTERX 512 +#define FT8_OPT_CENTERY 1024 +#define FT8_OPT_CENTER (FT8_OPT_CENTERX | FT8_OPT_CENTERY) +#define FT8_OPT_NOBACK 4096 +#define FT8_OPT_NOTICKS 8192 +#define FT8_OPT_NOHM 16384 +#define FT8_OPT_NOPOINTER 16384 +#define FT8_OPT_NOSECS 32768 +#define FT8_OPT_NOHANDS 49152 +#define FT8_OPT_RIGHTX 2048 +#define FT8_OPT_SIGNED 256 + + +/* Defines related to inbuilt font */ +#define FT8_NUMCHAR_PERFONT (128L) /* number of font characters per bitmap handle */ +#define FT8_FONT_TABLE_SIZE (148L) /* size of the font table - utilized for loopup by the graphics engine */ +#define FT8_FONT_TABLE_POINTER (0xFFFFCUL) /* pointer to the inbuilt font tables starting from bitmap handle 16 */ + + +/* Audio sample type defines */ +#define FT8_LINEAR_SAMPLES 0UL /* 8bit signed samples */ +#define FT8_ULAW_SAMPLES 1UL /* 8bit ulaw samples */ +#define FT8_ADPCM_SAMPLES 2UL /* 4bit ima adpcm samples */ + + +/* Synthesized sound */ +#define FT8_SILENCE 0x00 +#define FT8_SQUAREWAVE 0x01 +#define FT8_SINEWAVE 0x02 +#define FT8_SAWTOOTH 0x03 +#define FT8_TRIANGLE 0x04 +#define FT8_BEEPING 0x05 +#define FT8_ALARM 0x06 +#define FT8_WARBLE 0x07 +#define FT8_CAROUSEL 0x08 +#define FT8_PIPS(n) (0x0F + (n)) +#define FT8_HARP 0x40 +#define FT8_XYLOPHONE 0x41 +#define FT8_TUBA 0x42 +#define FT8_GLOCKENSPIEL 0x43 +#define FT8_ORGAN 0x44 +#define FT8_TRUMPET 0x45 +#define FT8_PIANO 0x46 +#define FT8_CHIMES 0x47 +#define FT8_MUSICBOX 0x48 +#define FT8_BELL 0x49 +#define FT8_CLICK 0x50 +#define FT8_SWITCH 0x51 +#define FT8_COWBELL 0x52 +#define FT8_NOTCH 0x53 +#define FT8_HIHAT 0x54 +#define FT8_KICKDRUM 0x55 +#define FT8_POP 0x56 +#define FT8_CLACK 0x57 +#define FT8_CHACK 0x58 +#define FT8_MUTE 0x60 +#define FT8_UNMUTE 0x61 + + +/* Synthesized sound frequencies, midi note */ +#define FT8_MIDI_A0 21 +#define FT8_MIDI_A_0 22 +#define FT8_MIDI_B0 23 +#define FT8_MIDI_C1 24 +#define FT8_MIDI_C_1 25 +#define FT8_MIDI_D1 26 +#define FT8_MIDI_D_1 27 +#define FT8_MIDI_E1 28 +#define FT8_MIDI_F1 29 +#define FT8_MIDI_F_1 30 +#define FT8_MIDI_G1 31 +#define FT8_MIDI_G_1 32 +#define FT8_MIDI_A1 33 +#define FT8_MIDI_A_1 34 +#define FT8_MIDI_B1 35 +#define FT8_MIDI_C2 36 +#define FT8_MIDI_C_2 37 +#define FT8_MIDI_D2 38 +#define FT8_MIDI_D_2 39 +#define FT8_MIDI_E2 40 +#define FT8_MIDI_F2 41 +#define FT8_MIDI_F_2 42 +#define FT8_MIDI_G2 43 +#define FT8_MIDI_G_2 44 +#define FT8_MIDI_A2 45 +#define FT8_MIDI_A_2 46 +#define FT8_MIDI_B2 47 +#define FT8_MIDI_C3 48 +#define FT8_MIDI_C_3 49 +#define FT8_MIDI_D3 50 +#define FT8_MIDI_D_3 51 +#define FT8_MIDI_E3 52 +#define FT8_MIDI_F3 53 +#define FT8_MIDI_F_3 54 +#define FT8_MIDI_G3 55 +#define FT8_MIDI_G_3 56 +#define FT8_MIDI_A3 57 +#define FT8_MIDI_A_3 58 +#define FT8_MIDI_B3 59 +#define FT8_MIDI_C4 60 +#define FT8_MIDI_C_4 61 +#define FT8_MIDI_D4 62 +#define FT8_MIDI_D_4 63 +#define FT8_MIDI_E4 64 +#define FT8_MIDI_F4 65 +#define FT8_MIDI_F_4 66 +#define FT8_MIDI_G4 67 +#define FT8_MIDI_G_4 68 +#define FT8_MIDI_A4 69 +#define FT8_MIDI_A_4 70 +#define FT8_MIDI_B4 71 +#define FT8_MIDI_C5 72 +#define FT8_MIDI_C_5 73 +#define FT8_MIDI_D5 74 +#define FT8_MIDI_D_5 75 +#define FT8_MIDI_E5 76 +#define FT8_MIDI_F5 77 +#define FT8_MIDI_F_5 78 +#define FT8_MIDI_G5 79 +#define FT8_MIDI_G_5 80 +#define FT8_MIDI_A5 81 +#define FT8_MIDI_A_5 82 +#define FT8_MIDI_B5 83 +#define FT8_MIDI_C6 84 +#define FT8_MIDI_C_6 85 +#define FT8_MIDI_D6 86 +#define FT8_MIDI_D_6 87 +#define FT8_MIDI_E6 88 +#define FT8_MIDI_F6 89 +#define FT8_MIDI_F_6 90 +#define FT8_MIDI_G6 91 +#define FT8_MIDI_G_6 92 +#define FT8_MIDI_A6 93 +#define FT8_MIDI_A_6 94 +#define FT8_MIDI_B6 95 +#define FT8_MIDI_C7 96 +#define FT8_MIDI_C_7 97 +#define FT8_MIDI_D7 98 +#define FT8_MIDI_D_7 99 +#define FT8_MIDI_E7 100 +#define FT8_MIDI_F7 101 +#define FT8_MIDI_F_7 102 +#define FT8_MIDI_G7 103 +#define FT8_MIDI_G_7 104 +#define FT8_MIDI_A7 105 +#define FT8_MIDI_A_7 106 +#define FT8_MIDI_B7 107 +#define FT8_MIDI_C8 108 + + +/* GPIO bits */ +#define FT8_GPIO0 0 +#define FT8_GPIO1 1 /* default gpio pin for audio shutdown, 1 - eanble, 0 - disable */ +#define FT8_GPIO7 7 /* default gpio pin for display enable, 1 - enable, 0 - disable */ + + +/* Display rotation */ +#define FT8_DISPLAY_0 0 /* 0 degrees rotation */ +#define FT8_DISPLAY_180 1 /* 180 degrees rotation */ +#define FT8_DISPLAY_90 1 /* 90 degrees rotation */ +#define FT8_DISPLAY_270 1 /* 270 degrees rotation */ + +#define FT8_DISPLAY_LANDSCAPE_0 0 /* 0 degrees rotation */ +#define FT8_DISPLAY_LANDSCAPE_180 1 /* 180 degrees rotation */ +#define FT8_DISPLAY_PORTRAIT_90CCW 2 /* 270 degrees rotation */ +#define FT8_DISPLAY_PORTRAIT_90CW 3 /* 90 degrees rotation */ + + +// 0 ARGB1555 +// 1 L1 +// 2 L4 +// 3 L8 +// 4 RGB332 +// 5 ARGB2 +// 6 ARGB4 +// 7 RGB565 +// 8 PALETTED +// 9 TEXT8X8 +// 10 TEXTVGA +// 11 BARGRAPH +// 14 PALETTED565 +// 15 PALETTED4444 +// 16 PALETTED8 +// 17 L2 + + // 0 OPT_RGB565 + // 1 OPT_MONO + // 2 OPT_NODL + // 256 OPT_FLAT + // 256 OPT_SIGNED + // 512 OPT_CENTERX + // 1024 OPT_CENTERY + // 1536 OPT_CENTER + // 2048 OPT_RIGHTX + // 4096 OPT_NOBACK + // 8192 OPT_NOTICKS + #define ADC_DIFFERENTIAL 1UL #define ADC_SINGLE_ENDED 0UL #define ADPCM_SAMPLES 2UL #define ALWAYS 7UL -#define ARGB1555 0UL -#define ARGB2 5UL -#define ARGB4 6UL -#define BARGRAPH 11UL +#define ARGB1555 0UL // ARGB1555, L1, L4, L8, RGB332, ARGB2, ARGB4, RGB565, PALETTED, TEXT8X8, TEXTVGA, BARGRAPH, PALETTED565, PALETTED4444, PALETTED8, L2 +#define ARGB2 5UL // ARGB1555, L1, L4, L8, RGB332, ARGB2, ARGB4, RGB565, PALETTED, TEXT8X8, TEXTVGA, BARGRAPH, PALETTED565, PALETTED4444, PALETTED8, L2 +#define ARGB4 6UL // ARGB1555, L1, L4, L8, RGB332, ARGB2, ARGB4, RGB565, PALETTED, TEXT8X8, TEXTVGA, BARGRAPH, PALETTED565, PALETTED4444, PALETTED8, L2 +#define BARGRAPH 11UL // ARGB1555, L1, L4, L8, RGB332, ARGB2, ARGB4, RGB565, PALETTED, TEXT8X8, TEXTVGA, BARGRAPH, PALETTED565, PALETTED4444, PALETTED8, L2 #define BILINEAR 1UL #define BITMAPS 1UL #define BORDER 0UL @@ -122,10 +436,10 @@ #define INT_VGA 13UL #define INVERT 5UL #define KEEP 1UL -#define L1 1UL -#define L2 17UL -#define L4 2UL -#define L8 3UL +#define L1 1UL // ARGB1555, L1, L4, L8, RGB332, ARGB2, ARGB4, RGB565, PALETTED, TEXT8X8, TEXTVGA, BARGRAPH, PALETTED565, PALETTED4444, PALETTED8, L2 +#define L2 17UL // ARGB1555, L1, L4, L8, RGB332, ARGB2, ARGB4, RGB565, PALETTED, TEXT8X8, TEXTVGA, BARGRAPH, PALETTED565, PALETTED4444, PALETTED8, L2 +#define L4 2UL // ARGB1555, L1, L4, L8, RGB332, ARGB2, ARGB4, RGB565, PALETTED, TEXT8X8, TEXTVGA, BARGRAPH, PALETTED565, PALETTED4444, PALETTED8, L2 +#define L8 3UL // ARGB1555, L1, L4, L8, RGB332, ARGB2, ARGB4, RGB565, PALETTED, TEXT8X8, TEXTVGA, BARGRAPH, PALETTED565, PALETTED4444, PALETTED8, L2 #define LEQUAL 2UL #define LESS 1UL #define LINEAR_SAMPLES 0UL @@ -143,6 +457,7 @@ #define OPT_FLAT 256UL #define OPT_FULLSCREEN 8UL #define OPT_MEDIAFIFO 16UL +#define OPT_RGB565 0UL #define OPT_MONO 1UL #define OPT_NOBACK 4096UL #define OPT_NODL 2UL @@ -155,16 +470,18 @@ #define OPT_RIGHTX 2048UL #define OPT_SIGNED 256UL #define OPT_SOUND 32UL -#define PALETTED 8UL -#define PALETTED4444 15UL -#define PALETTED565 14UL -#define PALETTED8 16UL +#define PALETTED 8UL // 0 ARGB1555, 1 L1, 2 L4, 3 L8, 4 RGB332, 5 ARGB2, 6 ARGB4, 7 RGB565, 8 PALETTED, 9 TEXT8X8, 10 TEXTVGA, 11 BARGRAPH +#define PALETTED4444 15UL // 0 ARGB1555, 1 L1, 2 L4, 3 L8, 4 RGB332, 5 ARGB2, 6 ARGB4, 7 RGB565, 8 PALETTED, 9 TEXT8X8, 10 TEXTVGA, 11 BARGRAPH +#define PALETTED565 14UL // 0 ARGB1555, 1 L1, 2 L4, 3 L8, 4 RGB332, 5 ARGB2, 6 ARGB4, 7 RGB565, 8 PALETTED, 9 TEXT8X8, 10 TEXTVGA, 11 BARGRAPH +#define PALETTED8 16UL // 0 ARGB1555, 1 L1, 2 L4, 3 L8, 4 RGB332, 5 ARGB2, 6 ARGB4, 7 RGB565, 8 PALETTED, 9 TEXT8X8, 10 TEXTVGA, 11 BARGRAPH +#define POINTS 2UL #define FTPOINTS 2UL -#define RAM_CMD 3178496UL -#define RAM_DL 3145728UL +#define RAM_CMD 3178496UL // 0x30 8000 +#define RAM_DL 3145728UL // 0x30 0000 #define RAM_G 0UL -#define RAM_REG 3153920UL -#define RAM_ROMSUB 3186688UL +#define RAM_REG 3153920UL // 0x30 2000 +#define RAM_ROMSUB 3186688UL // 0x30 A000 +#define RAM_SCREENSHOT 3940352UL // 0x3C 2000 (not documented!) #define RECTS 9UL #define ROMFONT_TABLEADDRESS 3145724UL @@ -284,13 +601,16 @@ #define REG_VSIZE 3153992UL #define REG_VSYNC0 3153996UL #define REG_VSYNC1 3154000UL + +#define REG_TOUCH_CONFIG 3154280UL // Jack +#define VAL_TOUCH_CONFIG 0x0381 #define REPEAT 1UL #define REPLACE 2UL -#define RGB332 4UL -#define RGB565 7UL +#define RGB332 4UL // 0 ARGB1555, 1 L1, 2 L4, 3 L8, 4 RGB332, 5 ARGB2, 6 ARGB4, 7 RGB565, 8 PALETTED, 9 TEXT8X8, 10 TEXTVGA, 11 BARGRAPH +#define RGB565 7UL // 0 ARGB1555, 1 L1, 2 L4, 3 L8, 4 RGB332, 5 ARGB2, 6 ARGB4, 7 RGB565, 8 PALETTED, 9 TEXT8X8, 10 TEXTVGA, 11 BARGRAPH #define SRC_ALPHA 2UL -#define TEXT8X8 9UL -#define TEXTVGA 10UL +#define TEXT8X8 9UL // 0 ARGB1555, 1 L1, 2 L4, 3 L8, 4 RGB332, 5 ARGB2, 6 ARGB4, 7 RGB565, 8 PALETTED, 9 TEXT8X8, 10 TEXTVGA, 11 BARGRAPH +#define TEXTVGA 10UL // 0 ARGB1555, 1 L1, 2 L4, 3 L8, 4 RGB332, 5 ARGB2, 6 ARGB4, 7 RGB565, 8 PALETTED, 9 TEXT8X8, 10 TEXTVGA, 11 BARGRAPH #define TOUCHMODE_CONTINUOUS 3UL #define TOUCHMODE_FRAME 2UL #define TOUCHMODE_OFF 0UL @@ -306,7 +626,9 @@ #define BITMAP_HANDLE(handle) ((5UL<<24)|(((handle)&31UL)<<0)) #define CELL(cell) ((6UL<<24)|(((cell)&127UL)<<0)) #define BITMAP_LAYOUT(format,linestride,height) ((7UL<<24)|(((format)&31UL)<<19)|(((linestride)&1023UL)<<9)|(((height)&511UL)<<0)) +#define BITMAP_LAYOUT_H(linestride,height) ((40UL<<24)|(((linestride)&3UL)<<2)|(((height)&3UL)<<0)) #define BITMAP_SIZE(filter,wrapx,wrapy,width,height) ((8UL<<24)|(((filter)&1UL)<<20)|(((wrapx)&1UL)<<19)|(((wrapy)&1UL)<<18)|(((width)&511UL)<<9)|(((height)&511UL)<<0)) +#define BITMAP_SIZE_H(width,height) ((41UL<<24)|(((width)&3UL)<<2)|(((height)&3UL)<<0)) #define ALPHA_FUNC(func,ref) ((9UL<<24)|(((func)&7UL)<<8)|(((ref)&255UL)<<0)) #define STENCIL_FUNC(func,ref,mask) ((10UL<<24)|(((func)&7UL)<<16)|(((ref)&255UL)<<8)|(((mask)&255UL)<<0)) #define BLEND_FUNC(src,dst) ((11UL<<24)|(((src)&7UL)<<3)|(((dst)&7UL)<<0)) @@ -333,8 +655,6 @@ #define COLOR_MASK(r,g,b,a) ((32UL<<24)|(((r)&1UL)<<3)|(((g)&1UL)<<2)|(((b)&1UL)<<1)|(((a)&1UL)<<0)) #define CLEAR(c,s,t) ((38UL<<24)|(((c)&1UL)<<2)|(((s)&1UL)<<1)|(((t)&1UL)<<0)) #define VERTEX_FORMAT(frac) ((39UL<<24)|(((frac)&7UL)<<0)) -#define BITMAP_LAYOUT_H(linestride,height) ((40UL<<24)|(((linestride)&3UL)<<2)|(((height)&3UL)<<0)) -#define BITMAP_SIZE_H(width,height) ((41UL<<24)|(((width)&3UL)<<2)|(((height)&3UL)<<0)) #define PALETTE_SOURCE(addr) ((42UL<<24)|(((addr)&4194303UL)<<0)) #define VERTEX_TRANSLATE_X(x) ((43UL<<24)|(((x)&131071UL)<<0)) #define VERTEX_TRANSLATE_Y(y) ((44UL<<24)|(((y)&131071UL)<<0)) @@ -370,9 +690,4 @@ ft_uint32_t PointerToFontGraphicsData; }FT_Gpu_Fonts_t; - - - /* Nothing beyond this */ - -
diff -r ca6a7c6a2f4b -r 6a81aeca25e3 inc/FT_Gpu_Hal.h --- a/inc/FT_Gpu_Hal.h Thu Dec 22 20:19:22 2016 +0000 +++ b/inc/FT_Gpu_Hal.h Mon Jul 23 12:22:23 2018 +0000 @@ -11,11 +11,11 @@ * * Copyright 2013 Future Technology Devices International Limited * - * Project: FT800 or EVE compatible silicon + * Project: FT813 or EVE compatible silicon * File Description: - * This file defines the generic APIs of host access layer for the FT800 or EVE compatible silicon. - * Application shall access FT800 or EVE resources over these APIs. In addition, there are - * some helper functions defined for FT800 coprocessor engine as well as host commands. + * This file defines the generic APIs of host access layer for the FT813 or EVE compatible silicon. + * Application shall access FT813 or EVE resources over these APIs. In addition, there are + * some helper functions defined for FT813 coprocessor engine as well as host commands. * Rivision History: * ported to mbed by Peter Drescher, DC2PD 2014 * @@ -64,11 +64,20 @@ ft_uint32_t address; ft_uint8_t *buffer; } Ft_Gpu_App_Transfer_t; - -class FT800 + +typedef struct { + char name[50]; + uint32_t addr; + uint32_t size; + uint16_t fmt; + uint16_t w; + uint16_t h; +} Ft_Gpu_App_Bitmap_t; + +class FT813 { public: - FT800(PinName mosi, + FT813(PinName mosi, PinName miso, PinName sck, PinName ss, @@ -80,6 +89,19 @@ DigitalOut _ss; DigitalOut _pd; InterruptIn _f800_isr; + ft_uint16_t _count; + ft_uint32_t _address; + ft_uint32_t _addresses[64]; + ft_uint16_t _bitmap_count; + ft_uint32_t _orientation; + ft_uint16_t _bitmapCount; + ft_uint32_t _bitmapAddress; + +Ft_Gpu_App_Bitmap_t _bitmaps[64]; + +//uint32_t screenshot[800*480]; + + public: /* Global used for buffer optimization */ //Ft_Gpu_Hal_Context_t host,*phost; @@ -110,15 +132,15 @@ /*The basic APIs Level 1*/ - ft_bool_t Init( ); - ft_bool_t Open( ); + ft_bool_t Init(); + ft_bool_t Open(); /*The APIs for reading/writing transfer continuously only with small buffer system*/ ft_void_t StartTransfer(FT_GPU_TRANSFERDIR_T rw,ft_uint32_t addr); ft_uint8_t Transfer8(ft_uint8_t value); ft_uint16_t Transfer16(ft_uint16_t value); ft_uint32_t Transfer32(ft_uint32_t value); - ft_void_t EndTransfer( ); + ft_void_t EndTransfer(); /*Read & Write APIs for both burst and single transfer,depending on buffer size*/ ft_void_t Read(Ft_Gpu_App_Transfer_t *transfer); @@ -190,64 +212,78 @@ ft_void_t HostCommand(ft_uint8_t cmd); ft_int32_t Dec2Ascii(ft_char8_t *pSrc,ft_int32_t value); + + ft_void_t DLstart(); + ft_void_t Swap(); + ft_void_t ColdStart(); + ft_void_t Interrupt(ft_uint32_t ms); + ft_void_t Append(ft_uint32_t ptr, ft_uint32_t num); + ft_void_t RegRead(ft_uint32_t ptr, ft_uint32_t result); + ft_void_t MemWrite(ft_uint32_t ptr, ft_uint32_t num); + ft_void_t Inflate(ft_uint32_t ptr); + ft_void_t LoadImage(ft_uint32_t ptr, ft_uint32_t options); + ft_void_t MediaFifo(ft_uint32_t ptr, ft_uint32_t size); + ft_void_t PlayVideo(ft_uint32_t opts); + ft_void_t VideoStart(); + ft_void_t VideoFrame(ft_uint32_t dst, ft_uint32_t ptr); + ft_void_t Memcrc(ft_uint32_t ptr, ft_uint32_t num, ft_uint32_t result); + ft_void_t MemZero(ft_uint32_t ptr, ft_uint32_t num); + ft_void_t MemSet(ft_uint32_t ptr, ft_uint32_t value, ft_uint32_t num); + ft_void_t Memcpy(ft_uint32_t dest, ft_uint32_t src, ft_uint32_t num); + ft_void_t Button(ft_int16_t x, ft_int16_t y, ft_int16_t w, ft_int16_t h, ft_int16_t font, ft_uint16_t options, const ft_char8_t* s); + ft_void_t Clock(ft_int16_t x, ft_int16_t y, ft_int16_t r, ft_uint16_t options, ft_uint16_t h, ft_uint16_t m, ft_uint16_t s, ft_uint16_t ms); + ft_void_t FgColor(ft_uint32_t c); + ft_void_t BgColor(ft_uint32_t c); + ft_void_t GradColor(ft_uint32_t c); + ft_void_t Gauge(ft_int16_t x, ft_int16_t y, ft_int16_t r, ft_uint16_t options, ft_uint16_t major, ft_uint16_t minor, ft_uint16_t val, ft_uint16_t range); + ft_void_t Gradient(ft_int16_t x0, ft_int16_t y0, ft_uint32_t rgb0, ft_int16_t x1, ft_int16_t y1, ft_uint32_t rgb1); + ft_void_t Keys(ft_int16_t x, ft_int16_t y, ft_int16_t w, ft_int16_t h, ft_int16_t font, ft_uint16_t options, const ft_char8_t* s); + ft_void_t Progress(ft_int16_t x, ft_int16_t y, ft_int16_t w, ft_int16_t h, ft_uint16_t options, ft_uint16_t val, ft_uint16_t range); + ft_void_t Scrollbar(ft_int16_t x, ft_int16_t y, ft_int16_t w, ft_int16_t h, ft_uint16_t options, ft_uint16_t val, ft_uint16_t size, ft_uint16_t range); + ft_void_t Slider(ft_int16_t x, ft_int16_t y, ft_int16_t w, ft_int16_t h, ft_uint16_t options, ft_uint16_t val, ft_uint16_t range); + ft_void_t Dial(ft_int16_t x, ft_int16_t y, ft_int16_t r, ft_uint16_t options, ft_uint16_t val); + ft_void_t Toggle(ft_int16_t x, ft_int16_t y, ft_int16_t w, ft_int16_t font, ft_uint16_t options, ft_uint16_t state, const ft_char8_t* s); ft_void_t Text(ft_int16_t x, ft_int16_t y, ft_int16_t font, ft_uint16_t options, const ft_char8_t* s); + ft_void_t SetBase(ft_uint32_t base); ft_void_t Number(ft_int16_t x, ft_int16_t y, ft_int16_t font, ft_uint16_t options, ft_int32_t n); ft_void_t LoadIdentity(); - ft_void_t Toggle(ft_int16_t x, ft_int16_t y, ft_int16_t w, ft_int16_t font, ft_uint16_t options, ft_uint16_t state, const ft_char8_t* s); - ft_void_t Gauge(ft_int16_t x, ft_int16_t y, ft_int16_t r, ft_uint16_t options, ft_uint16_t major, ft_uint16_t minor, ft_uint16_t val, ft_uint16_t range); - ft_void_t RegRead(ft_uint32_t ptr, ft_uint32_t result); + ft_void_t SetMatrix(); + ft_void_t GetMatrix(ft_int32_t a, ft_int32_t b, ft_int32_t c, ft_int32_t d, ft_int32_t e, ft_int32_t f); + ft_void_t GetPtr(ft_uint32_t result); ft_void_t GetProps(ft_uint32_t ptr, ft_uint32_t w, ft_uint32_t h); - ft_void_t Memcpy(ft_uint32_t dest, ft_uint32_t src, ft_uint32_t num); + ft_void_t Scale(ft_int32_t sx, ft_int32_t sy); + ft_void_t Rotate(ft_int32_t a); + ft_void_t Translate(ft_int32_t tx, ft_int32_t ty); + ft_void_t Calibrate(ft_uint32_t result); + ft_void_t SetRotate(ft_uint32_t r); ft_void_t Spinner(ft_int16_t x, ft_int16_t y, ft_uint16_t style, ft_uint16_t scale); - ft_void_t BgColor(ft_uint32_t c); - ft_void_t Swap(); - ft_void_t Inflate(ft_uint32_t ptr); - ft_void_t Translate(ft_int32_t tx, ft_int32_t ty); + ft_void_t ScreenSaver(); + ft_void_t Sketch(ft_int16_t x, ft_int16_t y, ft_uint16_t w, ft_uint16_t h, ft_uint32_t ptr, ft_uint16_t format); ft_void_t Stop(); - ft_void_t Slider(ft_int16_t x, ft_int16_t y, ft_int16_t w, ft_int16_t h, ft_uint16_t options, ft_uint16_t val, ft_uint16_t range); - ft_void_t Interrupt(ft_uint32_t ms); - ft_void_t FgColor(ft_uint32_t c); - ft_void_t Rotate(ft_int32_t a); - ft_void_t Button(ft_int16_t x, ft_int16_t y, ft_int16_t w, ft_int16_t h, ft_int16_t font, ft_uint16_t options, const ft_char8_t* s); - ft_void_t MemWrite(ft_uint32_t ptr, ft_uint32_t num); - ft_void_t Scrollbar(ft_int16_t x, ft_int16_t y, ft_int16_t w, ft_int16_t h, ft_uint16_t options, ft_uint16_t val, ft_uint16_t size, ft_uint16_t range); - ft_void_t GetMatrix(ft_int32_t a, ft_int32_t b, ft_int32_t c, ft_int32_t d, ft_int32_t e, ft_int32_t f); - ft_void_t Sketch(ft_int16_t x, ft_int16_t y, ft_uint16_t w, ft_uint16_t h, ft_uint32_t ptr, ft_uint16_t format); - ft_void_t MemSet(ft_uint32_t ptr, ft_uint32_t value, ft_uint32_t num); - ft_void_t Calibrate(ft_uint32_t result); ft_void_t SetFont(ft_uint32_t font, ft_uint32_t ptr); - ft_void_t RomFont( ft_uint32_t font, ft_uint32_t rom_slot); + ft_void_t SetFont2(ft_uint32_t font, ft_uint32_t ptr, ft_uint32_t firstchar); + ft_void_t SetScratch(ft_uint32_t handle); + ft_void_t RomFont(ft_uint32_t font, ft_uint32_t rom_slot); + ft_void_t Track(ft_int16_t x, ft_int16_t y, ft_int16_t w, ft_int16_t h, ft_int16_t tag); + ft_void_t Snapshot(ft_uint32_t ptr); + ft_void_t Snapshot2(ft_uint32_t fmt, ft_uint32_t ptr, ft_int16_t x, ft_int16_t y, ft_int16_t w, ft_int16_t h); + ft_void_t SetBitmap(ft_int32_t addr, ft_int16_t fmt, ft_uint16_t width, ft_uint16_t height); + ft_void_t Logo(); + ft_void_t Bitmap_Transform(ft_int32_t x0, ft_int32_t y0, ft_int32_t x1, ft_int32_t y1, ft_int32_t x2, ft_int32_t y2, ft_int32_t tx0, ft_int32_t ty0, ft_int32_t tx1, ft_int32_t ty1, ft_int32_t tx2, ft_int32_t ty2, ft_uint16_t result); - ft_void_t GradColor(ft_uint32_t c); - ft_void_t Append(ft_uint32_t ptr, ft_uint32_t num); - ft_void_t MemZero(ft_uint32_t ptr, ft_uint32_t num); - ft_void_t Scale(ft_int32_t sx, ft_int32_t sy); - ft_void_t Clock(ft_int16_t x, ft_int16_t y, ft_int16_t r, ft_uint16_t options, ft_uint16_t h, ft_uint16_t m, ft_uint16_t s, ft_uint16_t ms); - ft_void_t Gradient(ft_int16_t x0, ft_int16_t y0, ft_uint32_t rgb0, ft_int16_t x1, ft_int16_t y1, ft_uint32_t rgb1); - ft_void_t SetMatrix(); - ft_void_t Track(ft_int16_t x, ft_int16_t y, ft_int16_t w, ft_int16_t h, ft_int16_t tag); - ft_void_t GetPtr(ft_uint32_t result); - ft_void_t Progress(ft_int16_t x, ft_int16_t y, ft_int16_t w, ft_int16_t h, ft_uint16_t options, ft_uint16_t val, ft_uint16_t range); - ft_void_t ColdStart(); - ft_void_t Keys(ft_int16_t x, ft_int16_t y, ft_int16_t w, ft_int16_t h, ft_int16_t font, ft_uint16_t options, const ft_char8_t* s); - ft_void_t Dial(ft_int16_t x, ft_int16_t y, ft_int16_t r, ft_uint16_t options, ft_uint16_t val); - ft_void_t LoadImage(ft_uint32_t ptr, ft_uint32_t options); - ft_void_t DLstart(); - ft_void_t Snapshot(ft_uint32_t ptr); - ft_void_t ScreenSaver(); - ft_void_t Memcrc(ft_uint32_t ptr, ft_uint32_t num, ft_uint32_t result); + - ft_void_t Logo(); + ft_void_t SendCmd(ft_uint32_t cmd); + ft_void_t SendStr(const ft_char8_t *s); + ft_void_t StartFunc(ft_uint16_t count); +// ft_void_t EndFunc(ft_uint16_t count); + ft_void_t EndFunc(); + + ft_void_t TouchTransform(ft_int32_t x0, ft_int32_t y0, ft_int32_t x1, ft_int32_t y1, ft_int32_t x2, ft_int32_t y2, ft_int32_t tx0, ft_int32_t ty0, ft_int32_t tx1, ft_int32_t ty1, ft_int32_t tx2, ft_int32_t ty2, ft_uint16_t result); + ft_void_t BitmapTransform(ft_int32_t x0, ft_int32_t y0, ft_int32_t x1, ft_int32_t y1, ft_int32_t x2, ft_int32_t y2, ft_int32_t tx0, ft_int32_t ty0, ft_int32_t tx1, ft_int32_t ty1, ft_int32_t tx2, ft_int32_t ty2, ft_uint16_t result); + ft_void_t MemCrc(ft_uint32_t ptr, ft_uint32_t num, ft_uint32_t result); - ft_void_t SendCmd( ft_uint32_t cmd); - ft_void_t SendStr( const ft_char8_t *s); - ft_void_t StartFunc( ft_uint16_t count); - ft_void_t EndFunc( ft_uint16_t count); - ft_void_t TouchTransform( ft_int32_t x0, ft_int32_t y0, ft_int32_t x1, ft_int32_t y1, ft_int32_t x2, ft_int32_t y2, ft_int32_t tx0, ft_int32_t ty0, ft_int32_t tx1, ft_int32_t ty1, ft_int32_t tx2, ft_int32_t ty2, ft_uint16_t result); - ft_void_t BitmapTransform( ft_int32_t x0, ft_int32_t y0, ft_int32_t x1, ft_int32_t y1, ft_int32_t x2, ft_int32_t y2, ft_int32_t tx0, ft_int32_t ty0, ft_int32_t tx1, ft_int32_t ty1, ft_int32_t tx2, ft_int32_t ty2, ft_uint16_t result); - ft_void_t MemCrc( ft_uint32_t ptr, ft_uint32_t num, ft_uint32_t result); - - ft_uint16_t fifo_Freespace( ); + ft_uint16_t fifo_Freespace(); ft_void_t DL(ft_uint32_t cmd); ft_void_t WrDlCmd_Buffer(ft_uint32_t cmd); @@ -257,21 +293,91 @@ ft_void_t fadein(); ft_void_t DLSwap(ft_uint8_t DL_Swap_Type); + ft_void_t Point(ft_int16_t x, ft_int16_t y, ft_uint16_t size); + ft_void_t Line(ft_int16_t x0, ft_int16_t y0, ft_int16_t x1, ft_int16_t y1, ft_int16_t width); + ft_void_t Rect(ft_int16_t x0, ft_int16_t y0, ft_int16_t x1, ft_int16_t y1, ft_int16_t corner); + ft_void_t RectWH(ft_int16_t x0, ft_int16_t y0, ft_int16_t w, ft_int16_t h, ft_int16_t corner); + ft_uint8_t LoadJpg(char* filename, ft_int16_t* x_size, ft_int16_t* y_size); + ft_uint8_t LoadPng(char* filename, ft_int16_t* x_size, ft_int16_t* y_size); + //Curt added Load_raw 7/22/16 + int LoadRaw(char* filename); + int LoadRawFile(ft_uint32_t address, char* filename); + + void FillBitmap(ft_int16_t bitmap_number); + void ClearBitmapCount(void); + ft_uint32_t ReadBigInt32(unsigned char* data, ft_uint32_t offset); + + ft_uint8_t Jpg(char *jpg_filename, int x, int y); + ft_uint8_t Png(char *png_filename, int x, int y); + ft_uint8_t Png(char *png_filename, int x, int y, ft_int32_t address); + + ft_uint8_t JpgSplash(char *jpg_filename, ft_uint8_t r, ft_uint8_t g, ft_uint8_t b); + + ft_uint16_t CoProFIFO_FreeSpace(void); + void Wait4CoProFIFO(ft_uint32_t room); + void Wait4CoProFIFOEmpty(void); + ft_uint8_t CheckIfCoProFIFOEmpty(void); + ft_uint32_t WriteBlockRAM(ft_uint32_t Add, const ft_uint8_t *buff, ft_uint32_t count); + + ft_void_t Sound_ON(); ft_void_t Sound_OFF(); - int Load_jpg(char* filename, ft_int16_t* x_size, ft_int16_t* y_size,ft_uint32_t address); - - //Curt added Load_raw 7/22/16 - int Load_raw(char* filename); - +// int Load_jpg(char* filename, ft_int16_t* x_size, ft_int16_t* y_size,ft_uint32_t address); + ft_void_t Calibrate(); + ft_uint8_t read_calibrate_reg(ft_uint8_t i); + ft_uint32_t read_calibrate_reg32(ft_uint8_t i); ft_void_t read_calibrate(ft_uint8_t data[24]); ft_void_t write_calibrate(ft_uint8_t data[24]); + ft_void_t write_calibrate32(ft_uint32_t data[6]); ft_uint32_t color_rgb(ft_uint8_t red,ft_uint8_t green, ft_uint8_t blue); ft_uint32_t clear_color_rgb(ft_uint8_t red,ft_uint8_t green, ft_uint8_t blue); - + + void SetBacklight(ft_uint16_t brightness); + + void Tag(ft_uint8_t s); + void ClearTag(ft_uint8_t s); + void TagMask(ft_uint8_t mask); + void BitmapLayoutH(ft_uint8_t linestride, ft_uint8_t height); + void BitmapSizeH(ft_uint8_t width, ft_uint8_t height); + + ft_void_t SetLoadAddress(ft_uint32_t address); + ft_void_t SetBitmapCount(ft_uint8_t count); + ft_uint32_t GetBitmapAddress(ft_uint8_t count); + void SetThemeDefaultColor(void); + void SetThemeColor(ft_uint32_t c); + void ShowCalibrationInCode(void); + void SetOrientation(ft_uint8_t orientation); + void ShowBitmap(ft_uint8_t bitmap, ft_int16_t fmt, ft_uint16_t x, ft_uint16_t y, ft_uint16_t width, ft_uint16_t height); + void ShowBitmapAtAddress(ft_uint32_t addr, ft_int16_t fmt, ft_uint16_t x, ft_uint16_t y, ft_uint16_t width, ft_uint16_t height); + int GetImageIndexFromName(char *name); + int ResetInflateFileBitmap(void); + uint32_t GetRamUsage(void); + uint16_t GetRamNoOfBitmaps(void); + int LoadInflateFileBitmap(char *name, uint16_t fmt, uint16_t w, uint16_t h); + int ShowBitmapByName(char *name, uint16_t w, uint16_t h); + uint16_t GetTouchedTag(void); + uint16_t GetTouchedTag(uint8_t point_number); + uint8_t GetTag(void); + uint16_t GetTagX(void); + uint16_t GetTagY(void); + uint8_t GetTouchTag(void); + uint16_t GetTouchTagX(void); + uint16_t GetTouchTagY(void); + uint16_t GetTouchConfig(void); + void SetTouchConfig(uint16_t TouchConfigVal); + + void screenShot(void); + + int LoadRawFile(ft_uint32_t address, const char *filename); + int LoadInflateFile(ft_uint32_t address, const char *filename); + int LoadImageFile(ft_uint32_t address, const char *filename); + ft_void_t SetEndAddressForSize(ft_uint32_t addr); + + ft_void_t Wr8s(ft_uint32_t addr, ft_uint8_t *buffer, ft_uint8_t length); + }; // end of class -#endif /*FT_GPU_HAL_H*/ \ No newline at end of file +#endif /*FT_GPU_HAL_H*/
diff -r ca6a7c6a2f4b -r 6a81aeca25e3 inc/FT_Hal_Utils.h --- a/inc/FT_Hal_Utils.h Thu Dec 22 20:19:22 2016 +0000 +++ b/inc/FT_Hal_Utils.h Mon Jul 23 12:22:23 2018 +0000 @@ -6,7 +6,6 @@ #ifndef _FT_HAL_UTILS_H_ #define _FT_HAL_UTILS_H_ - #define RGB(r, g, b) ((((vc_int32_t)(r)) << 16) | (((vc_int32_t)(g)) << 8) | (b)) #define SQ(v) ((v) * (v)) #define MIN(x,y) ((x) > (y) ? (y) : (x)) @@ -18,7 +17,3 @@ #define ABS(x) ((x) > (0) ? (x) : (-x)) #endif /* _FT_HAL_UTILS_H_ */ - - - -
diff -r ca6a7c6a2f4b -r 6a81aeca25e3 inc/FT_LCD_Type.h --- a/inc/FT_LCD_Type.h Thu Dec 22 20:19:22 2016 +0000 +++ b/inc/FT_LCD_Type.h Mon Jul 23 12:22:23 2018 +0000 @@ -1,29 +1,160 @@ -//this file modified by Curtis Mattull 7/21/16 -// to add support for beyondtek lcd screen - -//comment out line 12 unless using beyondtek - -/* mbed Library for FTDI FT810 Enbedded Video Engine "EVE" - * ported to mbed by David Childs, based on the great work of Peter Drescher (DC2PD 2014) +/* mbed Library for FTDI FT800 Enbedded Video Engine "EVE" + * ported to mbed by Peter Drescher, DC2PD 2014 * Released under the MIT License: http://mbed.org/license/mit */ -// This is for the 800x480 screen that comes with the FTDI FT810 demo board - + + /* change this file to adapt other LCD screens */ + + // https://github.com/RudolphRiedel/FT800-FT813/blob/master/FT8_config.h + #ifndef FT_LCD_TYPE_H #define FT_LCD_TYPE_H + +// http://www.ftdichip.com/Products/Modules/EVE2Modules.html + +//#define ME800A_HV35R (1) // 480x320 +//#define ME810A_HV35R (1) // 480x320 +//#define EVE2_43G (1) // 480x272 +//#define ME812A_WH50R (1) // 800x480 +//#define ME812AU_WH50R (1) // 800x480 +#define ME813A_WH50C (1) // 800x480 +//#define ME813AU_WH50C (1) // 800x480 +//#define ME810A_WH70R (1) +//#define ME811A_WH70C (1) + +#define SAMAPP_ENABLE_APIS_SET0 +#define SAMAPP_ENABLE_APIS_SET1 +#define SAMAPP_ENABLE_APIS_SET2 +#define SAMAPP_ENABLE_APIS_SET3 +#define SAMAPP_ENABLE_APIS_SET4 +#define SAMAPP_ENABLE_APIS_SET5 +#define SAMAPP_ENABLE_APIS_SET6 +#define SAMAPP_ENABLE_APIS_SET7 +#define SAMAPP_ENABLE_APIS_SET8 +#define SAMAPP_ENABLE_APIS_SET9 + /* Global variables for display resolution to support various display panels */ +/* Default is WQVGA - 480x272 */ + +/* Macros for display panels */ + +// QVGA 320x240 +#define FT_DISPLAY_HSIZE_QVGA_320x240 (320L) // DispWidth display width +#define FT_DISPLAY_VSIZE_QVGA_320x240 (240L) // DispHeight display height +#define FT_DISPLAY_HCYCLE_QVGA_320x240 (408L) // DispHCycle +#define FT_DISPLAY_HOFFSET_QVGA_320x240 (70L) // DispHOffset +#define FT_DISPLAY_HSYNC0_QVGA_320x240 (0L) // DispHSync0 +#define FT_DISPLAY_HSYNC1_QVGA_320x240 (10L) // DispHSync1 +#define FT_DISPLAY_VCYCLE_QVGA_320x240 (263L) // DispVCycle +#define FT_DISPLAY_VOFFSET_QVGA_320x240 (13L) // DispVOffset +#define FT_DISPLAY_VSYNC0_QVGA_320x240 (0L) // DispVSync0 +#define FT_DISPLAY_VSYNC1_QVGA_320x240 (2L) // DispVSync1 +#define FT_DISPLAY_PCLK_QVGA_320x240 (8) // DispPCLK +#define FT_DISPLAY_SWIZZLE_QVGA_320x240 (2) // DispSwizzle +#define FT_DISPLAY_PCLKPOL_QVGA_320x240 (0) // DispPCLKPol +#define FT_DISPLAY_DISPCSPREAD_QVGA_320x240 (1) // DispCSpread +#define FT_DISPLAY_DISPDITHER_QVGA (1) // DispDither + +// WQVGA 480x272 +#define FT_DISPLAY_HSIZE_WQVGA_480x272 (480L) // DispWidth display width +#define FT_DISPLAY_VSIZE_WQVGA_480x272 (272L) // DispHeight display height +#define FT_DISPLAY_HCYCLE_WQVGA_480x272 (548L) // DispHCycle +#define FT_DISPLAY_HOFFSET_WQVGA_480x272 (43L) // DispHOffset +#define FT_DISPLAY_HSYNC0_WQVGA_480x272 (0L) // DispHSync0 +#define FT_DISPLAY_HSYNC1_WQVGA_480x272 (41L) // DispHSync1 +#define FT_DISPLAY_VCYCLE_WQVGA_480x272 (292L) // DispVCycle +#define FT_DISPLAY_VOFFSET_WQVGA_480x272 (12L) // DispVOffset +#define FT_DISPLAY_VSYNC0_WQVGA_480x272 (0L) // DispPCLKPol +#define FT_DISPLAY_VSYNC1_WQVGA_480x272 (10L) // DispVSync1 +#define FT_DISPLAY_PCLK_WQVGA_480x272 (5) // DispPCLK +#define FT_DISPLAY_SWIZZLE_WQVGA_480x272 (0) // DispSwizzle +#define FT_DISPLAY_PCLKPOL_WQVGA_480x272 (1) // DispPCLKPol +#define FT_DISPLAY_DISPCSPREAD_WQVGA_480x272 (1) // DispCSpread +#define FT_DISPLAY_DISPDITHER_WQVGA_480x272 (1) // DispDither -#define my_DispWidth 800 -#define my_DispHeight 480 -#define my_DispHCycle 1056 -#define my_DispHOffset 46 -#define my_DispHSync0 210 -#define my_DispHSync1 230 -#define my_DispVCycle 525 -#define my_DispVOffset 23 -#define my_DispVSync0 22 -#define my_DispVSync1 32 -#define my_DispPCLK 1 -#define my_DispSwizzle 0 -#define my_DispPCLKPol 1 +// HVGA 320x480 Portrait +#define FT_DISPLAY_HSIZE_HVGA_480x320 (320L) // DispWidth display width +#define FT_DISPLAY_VSIZE_HVGA_480x320 (480L) // DispHeight display height +#define FT_DISPLAY_HCYCLE_HVGA_480x320 (400L) // DispHCycle +#define FT_DISPLAY_HOFFSET_HVGA_480x320 (40L) // DispHOffset +#define FT_DISPLAY_HSYNC0_HVGA_480x320 (0L) // DispHSync0 +#define FT_DISPLAY_HSYNC1_HVGA_480x320 (10L) // DispHSync1 +#define FT_DISPLAY_VCYCLE_HVGA_480x320 (500L) // DispVCycle +#define FT_DISPLAY_VOFFSET_HVGA_480x320 (10L) // DispVOffset +#define FT_DISPLAY_VSYNC0_HVGA_480x320 (0L) // DispPCLKPol +#define FT_DISPLAY_VSYNC1_HVGA_480x320 (5L) // DispVSync1 +#define FT_DISPLAY_PCLK_HVGA_480x320 (4) // DispPCLK +#define FT_DISPLAY_SWIZZLE_HVGA_480x320 (2) // DispSwizzle +#define FT_DISPLAY_PCLKPOL_HVGA_480x320 (1) // DispPCLKPol +#define FT_DISPLAY_DISPCSPREAD_HVGA_480x320 (1) // DispCSpread +#define FT_DISPLAY_DISPDITHER_HVGA_480x320 (1) // DispDither + +// ME812A-WH50R, ME812AU-WH50R, ME813A_WH50C, ME813AU_WH50C +// WVGA 800x480 +#define FT_DISPLAY_HSIZE_WVGA_800x480 (800L) // DispWidth display width +#define FT_DISPLAY_VSIZE_WVGA_800x480 (480L) // DispHeight display height +#define FT_DISPLAY_HCYCLE_WVGA_800x480 (928L) // DispHCycle +#define FT_DISPLAY_HOFFSET_WVGA_800x480 (88L) // DispHOffset +#define FT_DISPLAY_HSYNC0_WVGA_800x480 (0L) // DispHSync0 +#define FT_DISPLAY_HSYNC1_WVGA_800x480 (48L) // DispHSync1 +#define FT_DISPLAY_VCYCLE_QVGA_800x480 (525L) // DispVCycle +#define FT_DISPLAY_VOFFSET_WVGA_800x480 (32L) // DispVOffset +#define FT_DISPLAY_VSYNC0_WVGA_800x480 (0L) // DispVSync1 +#define FT_DISPLAY_VSYNC1_WVGA_800x480 (3L) // DispVSync1 +#define FT_DISPLAY_PCLK_WVGA_800x480 (2) // DispPCLK +#define FT_DISPLAY_SWIZZLE_WVGA_800x480 (0) // DispSwizzle +#define FT_DISPLAY_PCLKPOL_WVGA_800x480 (1) // DispPCLKPol +#define FT_DISPLAY_DISPCSPREAD_WVGA_800x480 (0) // DispCSpread +#define FT_DISPLAY_DISPDITHER_WVGA_800x480 (1) // DispDither -#endif \ No newline at end of file +#if defined(EVE2_43G) +#define my_DispWidth FT_DISPLAY_HSIZE_WQVGA_480x272 +#define my_DispHeight FT_DISPLAY_VSIZE_WQVGA_480x272 +#define my_DispHCycle FT_DISPLAY_HCYCLE_WQVGA_480x272 +#define my_DispHOffset FT_DISPLAY_HOFFSET_WQVGA_480x272 +#define my_DispHSync0 FT_DISPLAY_HSYNC0_WQVGA_480x272 +#define my_DispHSync1 FT_DISPLAY_HSYNC1_WQVGA_480x272 +#define my_DispVCycle FT_DISPLAY_VCYCLE_WQVGA_480x272 +#define my_DispVOffset FT_DISPLAY_VOFFSET_WQVGA_480x272 +#define my_DispVSync0 FT_DISPLAY_VSYNC0_WQVGA_480x272 +#define my_DispVSync1 FT_DISPLAY_VSYNC1_WQVGA_480x272 +#define my_DispPCLK FT_DISPLAY_PCLK_WQVGA_480x272 +#define my_DispSwizzle FT_DISPLAY_SWIZZLE_WQVGA_480x272 +#define my_DispPCLKPol FT_DISPLAY_PCLKPOL_WQVGA_480x272 +#endif + +#if defined(ME800A_HV35R) || defined(ME810A_HV35R) +#define my_DispWidth FT_DISPLAY_HSIZE_WQVGA_480x272 +#define my_DispHeight FT_DISPLAY_VSIZE_WQVGA_480x272 +#define my_DispHCycle FT_DISPLAY_HCYCLE_WQVGA_480x272 +#define my_DispHOffset FT_DISPLAY_HOFFSET_WQVGA_480x272 +#define my_DispHSync0 FT_DISPLAY_HSYNC0_WQVGA_480x272 +#define my_DispHSync1 FT_DISPLAY_HSYNC1_WQVGA_480x272 +#define my_DispVCycle FT_DISPLAY_VCYCLE_WQVGA_480x272 +#define my_DispVOffset FT_DISPLAY_VOFFSET_WQVGA_480x272 +#define my_DispVSync0 FT_DISPLAY_VSYNC0_WQVGA_480x272 +#define my_DispVSync1 FT_DISPLAY_VSYNC1_WQVGA_480x272 +#define my_DispPCLK FT_DISPLAY_PCLK_WQVGA_480x272 +#define my_DispSwizzle FT_DISPLAY_SWIZZLE_WQVGA_480x272 +#define my_DispPCLKPol FT_DISPLAY_PCLKPOL_WQVGA_480x272 +#endif + +#if defined(ME813A_WH50C) || defined(ME813AU_WH50C) || defined(ME812A_WH50R) || defined(ME812AU_WH50R) +#define my_DispWidth FT_DISPLAY_HSIZE_WVGA_800x480 +#define my_DispHeight FT_DISPLAY_VSIZE_WVGA_800x480 +#define my_DispHCycle FT_DISPLAY_HCYCLE_WVGA_800x480 +#define my_DispHOffset FT_DISPLAY_HOFFSET_WVGA_800x480 +#define my_DispHSync0 FT_DISPLAY_HSYNC0_WVGA_800x480 +#define my_DispHSync1 FT_DISPLAY_HSYNC1_WVGA_800x480 +#define my_DispVCycle FT_DISPLAY_VCYCLE_QVGA_800x480 +#define my_DispVOffset FT_DISPLAY_VOFFSET_WVGA_800x480 +#define my_DispVSync0 FT_DISPLAY_VSYNC0_WVGA_800x480 +#define my_DispVSync1 FT_DISPLAY_VSYNC1_WVGA_800x480 +#define my_DispPCLK FT_DISPLAY_PCLK_WVGA_800x480 +#define my_DispSwizzle FT_DISPLAY_SWIZZLE_WVGA_800x480 +#define my_DispPCLKPol FT_DISPLAY_PCLKPOL_WVGA_800x480 +#endif + +/* the GLYN display has inverted backlite */ +//#define Inv_Backlite + +#endif
diff -r ca6a7c6a2f4b -r 6a81aeca25e3 inc/FT_Platform.h --- a/inc/FT_Platform.h Thu Dec 22 20:19:22 2016 +0000 +++ b/inc/FT_Platform.h Mon Jul 23 12:22:23 2018 +0000 @@ -13,12 +13,6 @@ #include "FT_LCD_Type.h" #include "FT_color.h" - #endif /*_FT_PLATFORM_H_*/ -/* Nothing beyond this*/ - - - - - +/* Nothing beyond this*/
diff -r ca6a7c6a2f4b -r 6a81aeca25e3 inc/FT_color.h --- a/inc/FT_color.h Thu Dec 22 20:19:22 2016 +0000 +++ b/inc/FT_color.h Mon Jul 23 12:22:23 2018 +0000 @@ -34,5 +34,3 @@ #define Cyan 0,255,255 #define Aquamarine 127,255,212 #define LightGray 211,211,211 - -
diff -r ca6a7c6a2f4b -r 6a81aeca25e3 src/FT_CoPro_Cmds.cpp --- a/src/FT_CoPro_Cmds.cpp Thu Dec 22 20:19:22 2016 +0000 +++ b/src/FT_CoPro_Cmds.cpp Mon Jul 23 12:22:23 2018 +0000 @@ -1,549 +1,758 @@ -/* mbed Library for FTDI FT800 Enbedded Video Engine "EVE" +/* mbed Library for FTDI FT813 Enbedded Video Engine "EVE" * based on Original Code Sample from FTDI * ported to mbed by Peter Drescher, DC2PD 2014 * Released under the MIT License: http://mbed.org/license/mit */ #include "FT_Platform.h" - -ft_void_t FT800::SendCmd( ft_uint32_t cmd) +ft_void_t FT813::SendCmd(ft_uint32_t cmd) { - Transfer32( cmd); + Transfer32(cmd); } -ft_void_t FT800::SendStr( const ft_char8_t *s) +ft_void_t FT813::SendStr(const ft_char8_t *s) { - TransferString( s); + TransferString(s); } - -ft_void_t FT800::StartFunc( ft_uint16_t count) +ft_void_t FT813::StartFunc(ft_uint16_t count) { - CheckCmdBuffer( count); - StartCmdTransfer( FT_GPU_WRITE,count); + _count = count; + CheckCmdBuffer(_count); + StartCmdTransfer(FT_GPU_WRITE, _count); } -ft_void_t FT800::EndFunc( ft_uint16_t count) +ft_void_t FT813::EndFunc() { - EndTransfer( ); - Updatecmdfifo( count); + EndTransfer(); + Updatecmdfifo(_count); +} + +// Start a new display list +// FT81x Series Programmers Guide Section 5.11 +ft_void_t FT813::DLstart() +{ +// _address = 0; + StartFunc(FT_CMD_SIZE); + SendCmd(CMD_DLSTART); + EndFunc(); } -ft_void_t FT800::Text( ft_int16_t x, ft_int16_t y, ft_int16_t font, ft_uint16_t options, const ft_char8_t* s) +// Swap the current display list with the new display list +// FT81x Series Programmers Guide Section 5.12 +ft_void_t FT813::Swap() { - StartFunc( FT_CMD_SIZE*3 + strlen(s) + 1); - SendCmd( CMD_TEXT); - //Copro_SendCmd( (((ft_uint32_t)y<<16)|(ft_uint32_t)x)); - SendCmd( (((ft_uint32_t)y<<16)|(x & 0xffff))); - SendCmd( (((ft_uint32_t)options<<16)|(ft_uint32_t)font)); - SendStr( s); - EndFunc( (FT_CMD_SIZE*3 + strlen(s) + 1)); + StartFunc(FT_CMD_SIZE); + SendCmd(CMD_SWAP); + EndFunc(); +} + +// Set co-processor engine state to default values +// FT81x Series Programmers Guide Section 5.13 +ft_void_t FT813::ColdStart() +{ + StartFunc(FT_CMD_SIZE); + SendCmd(CMD_COLDSTART); + EndFunc(); } -ft_void_t FT800::Number( ft_int16_t x, ft_int16_t y, ft_int16_t font, ft_uint16_t options, ft_int32_t n) +// Trigger interrupt INT_CMDFLAG +// FT81x Series Programmers Guide Section 5.14 +ft_void_t FT813::Interrupt(ft_uint32_t ms) { - StartFunc( FT_CMD_SIZE*4); - SendCmd( CMD_NUMBER); - SendCmd( (((ft_uint32_t)y<<16)|(x & 0xffff))); - SendCmd( (((ft_uint32_t)options<<16)|font)); - SendCmd( n); - EndFunc( (FT_CMD_SIZE*4)); + StartFunc(FT_CMD_SIZE*2); + SendCmd(CMD_INTERRUPT); + SendCmd(ms); + EndFunc(); } -ft_void_t FT800::LoadIdentity( ) +// Append more commands to current display list +// FT81x Series Programmers Guide Section 5.15 +ft_void_t FT813::Append(ft_uint32_t ptr, ft_uint32_t num) { - StartFunc( FT_CMD_SIZE*1); - SendCmd( CMD_LOADIDENTITY); - EndFunc( (FT_CMD_SIZE*1)); + StartFunc(FT_CMD_SIZE*3); + SendCmd(CMD_APPEND); + SendCmd(ptr); + SendCmd(num); + EndFunc(); +} + +// Read a register value +// FT81x Series Programmers Guide Section 5.16 +ft_void_t FT813::RegRead(ft_uint32_t ptr, ft_uint32_t result) +{ + StartFunc(FT_CMD_SIZE*3); + SendCmd(CMD_REGREAD); + SendCmd(ptr); + SendCmd(0); + EndFunc(); } -ft_void_t FT800::Toggle( ft_int16_t x, ft_int16_t y, ft_int16_t w, ft_int16_t font, ft_uint16_t options, ft_uint16_t state, const ft_char8_t* s) +/* commands to operate on memory: */ + +// Write bytes into memory +// FT81x Series Programmers Guide Section 5.17 +ft_void_t FT813::MemWrite(ft_uint32_t ptr, ft_uint32_t num) { - StartFunc( FT_CMD_SIZE*4 + strlen(s) + 1); - SendCmd( CMD_TOGGLE); - SendCmd( (((ft_uint32_t)y<<16)|(x & 0xffff))); - SendCmd( (((ft_uint32_t)font<<16)|w)); - SendCmd( (((ft_uint32_t)state<<16)|options)); - SendStr( s); - EndFunc( (FT_CMD_SIZE*4 + strlen(s) + 1)); + StartFunc(FT_CMD_SIZE*3); + SendCmd(CMD_MEMWRITE); + SendCmd(ptr); + SendCmd(num); + EndFunc(); } -/* Error handling for val is not done, so better to always use range of 65535 in order that needle is drawn within display region */ -ft_void_t FT800::Gauge( ft_int16_t x, ft_int16_t y, ft_int16_t r, ft_uint16_t options, ft_uint16_t major, ft_uint16_t minor, ft_uint16_t val, ft_uint16_t range) +// Decompress data into memory +// FT81x Series Programmers Guide Section 5.18 +ft_void_t FT813::Inflate(ft_uint32_t ptr) { - StartFunc( FT_CMD_SIZE*5); - SendCmd( CMD_GAUGE); - SendCmd( (((ft_uint32_t)y<<16)|(x & 0xffff))); - SendCmd( (((ft_uint32_t)options<<16)|r)); - SendCmd( (((ft_uint32_t)minor<<16)|major)); - SendCmd( (((ft_uint32_t)range<<16)|val)); - EndFunc( (FT_CMD_SIZE*5)); + StartFunc(FT_CMD_SIZE*2); + SendCmd(CMD_INFLATE); + SendCmd(ptr); + EndFunc(); } -ft_void_t FT800::RegRead( ft_uint32_t ptr, ft_uint32_t result) +// Load a JPEG or PNG image +// FT81x Series Programmers Guide Section 5.19 +ft_void_t FT813::LoadImage(ft_uint32_t ptr, ft_uint32_t options) { - StartFunc( FT_CMD_SIZE*3); - SendCmd( CMD_REGREAD); - SendCmd( ptr); - SendCmd( 0); - EndFunc( (FT_CMD_SIZE*3)); - + StartFunc(FT_CMD_SIZE*3); + SendCmd(CMD_LOADIMAGE); + SendCmd(ptr); + SendCmd(options); + EndFunc(); } -ft_void_t FT800::GetProps( ft_uint32_t ptr, ft_uint32_t w, ft_uint32_t h) +// Set up a streaming media FIFO in RAM_G +// FT81x Series Programmers Guide Section 5.20 +ft_void_t FT813::MediaFifo(ft_uint32_t ptr, ft_uint32_t size) { - StartFunc( FT_CMD_SIZE*4); - SendCmd( CMD_GETPROPS); - SendCmd( ptr); - SendCmd( w); - SendCmd( h); - EndFunc( (FT_CMD_SIZE*4)); + StartFunc(FT_CMD_SIZE*3); + SendCmd(CMD_MEDIAFIFO); + SendCmd(ptr); + SendCmd(size); + EndFunc(); +} + +// Video playback +// FT81x Series Programmers Guide Section 5.21 +ft_void_t FT813::PlayVideo(ft_uint32_t opts) +{ + StartFunc(FT_CMD_SIZE*2); + SendCmd(CMD_PLAYVIDEO); + SendCmd(opts); + EndFunc(); } -ft_void_t FT800::Memcpy( ft_uint32_t dest, ft_uint32_t src, ft_uint32_t num) +// Initialize video frame decoder +// FT81x Series Programmers Guide Section 5.22 +ft_void_t FT813::VideoStart() { - StartFunc( FT_CMD_SIZE*4); - SendCmd( CMD_MEMCPY); - SendCmd( dest); - SendCmd( src); - SendCmd( num); - EndFunc( (FT_CMD_SIZE*4)); + StartFunc(FT_CMD_SIZE); + SendCmd(CMD_VIDEOSTART); + EndFunc(); } -ft_void_t FT800::Spinner( ft_int16_t x, ft_int16_t y, ft_uint16_t style, ft_uint16_t scale) +// Load the next frame of video +// FT81x Series Programmers Guide Section 5.23 +ft_void_t FT813::VideoFrame(ft_uint32_t dst, ft_uint32_t ptr) { - StartFunc( FT_CMD_SIZE*3); - SendCmd( CMD_SPINNER); - SendCmd( (((ft_uint32_t)y<<16)|(x & 0xffff))); - SendCmd( (((ft_uint32_t)scale<<16)|style)); - EndFunc( (FT_CMD_SIZE*3)); + StartFunc(FT_CMD_SIZE*3); + SendCmd(CMD_VIDEOFRAME); + SendCmd(dst); + SendCmd(ptr); + EndFunc(); } -ft_void_t FT800::BgColor( ft_uint32_t c) +// Compute a CRC-32 for memory +// FT81x Series Programmers Guide Section 5.24 +ft_void_t FT813::MemCrc(ft_uint32_t ptr, ft_uint32_t num, ft_uint32_t result) { - StartFunc( FT_CMD_SIZE*2); - SendCmd( CMD_BGCOLOR); - SendCmd( c); - EndFunc( (FT_CMD_SIZE*2)); + StartFunc(FT_CMD_SIZE*4); + SendCmd(CMD_MEMCRC); + SendCmd(ptr); + SendCmd(num); + SendCmd(result); + EndFunc(); } -ft_void_t FT800::Swap() +// Write zero to a block of memory +// FT81x Series Programmers Guide Section 5.25 +ft_void_t FT813::MemZero(ft_uint32_t ptr, ft_uint32_t num) { - StartFunc( FT_CMD_SIZE*1); - SendCmd( CMD_SWAP); - EndFunc( (FT_CMD_SIZE*1)); + StartFunc(FT_CMD_SIZE*3); + SendCmd(CMD_MEMZERO); + SendCmd(ptr); + SendCmd(num); + EndFunc(); } -ft_void_t FT800::Inflate( ft_uint32_t ptr) +// Fill memory with a byte value +// FT81x Series Programmers Guide Section 5.26 +ft_void_t FT813::MemSet(ft_uint32_t ptr, ft_uint32_t value, ft_uint32_t num) { - StartFunc( FT_CMD_SIZE*2); - SendCmd( CMD_INFLATE); - SendCmd( ptr); - EndFunc( (FT_CMD_SIZE*2)); + StartFunc(FT_CMD_SIZE*4); + SendCmd(CMD_MEMSET); + SendCmd(ptr); + SendCmd(value); + SendCmd(num); + EndFunc(); } -ft_void_t FT800::Translate( ft_int32_t tx, ft_int32_t ty) +// Cmd_Memcpy - background copy a block of data +// FT81x Series Programmers Guide Section 5.27 +ft_void_t FT813::Memcpy(ft_uint32_t dest, ft_uint32_t src, ft_uint32_t num) { - StartFunc( FT_CMD_SIZE*3); - SendCmd( CMD_TRANSLATE); - SendCmd( tx); - SendCmd( ty); - EndFunc( (FT_CMD_SIZE*3)); + StartFunc(FT_CMD_SIZE*4); + SendCmd(CMD_MEMCPY); + SendCmd(dest); + SendCmd(src); + SendCmd(num); + EndFunc(); } -ft_void_t FT800::Stop() -{ - StartFunc( FT_CMD_SIZE*1); - SendCmd( CMD_STOP); - EndFunc( (FT_CMD_SIZE*1)); -} +/* commands to draw graphics objects: */ +// ******************** Screen Object Creation CoProcessor Command Functions ****************************** -ft_void_t FT800::Slider( ft_int16_t x, ft_int16_t y, ft_int16_t w, ft_int16_t h, ft_uint16_t options, ft_uint16_t val, ft_uint16_t range) +// Draw a button +// FT81x Series Programmers Guide Section 5.28 +ft_void_t FT813::Button(ft_int16_t x, ft_int16_t y, ft_int16_t w, ft_int16_t h, ft_int16_t font, ft_uint16_t options, const ft_char8_t* s) { - StartFunc( FT_CMD_SIZE*5); - SendCmd( CMD_SLIDER); - SendCmd( (((ft_uint32_t)y<<16)|(x & 0xffff))); - SendCmd( (((ft_uint32_t)h<<16)|w)); - SendCmd( (((ft_uint32_t)val<<16)|options)); - SendCmd( range); - EndFunc( (FT_CMD_SIZE*5)); + StartFunc(FT_CMD_SIZE*4 + strlen(s) + 1); + SendCmd(CMD_BUTTON); + SendCmd((((ft_uint32_t)y<<16)|(x & 0xffff))); + SendCmd((((ft_uint32_t)h<<16)|w)); + SendCmd((((ft_uint32_t)options<<16)|font)); // patch from Ivano Pelicella to draw flat buttons + SendStr(s); + EndFunc(); } -ft_void_t FT800::TouchTransform( ft_int32_t x0, ft_int32_t y0, ft_int32_t x1, ft_int32_t y1, ft_int32_t x2, ft_int32_t y2, ft_int32_t tx0, ft_int32_t ty0, ft_int32_t tx1, ft_int32_t ty1, ft_int32_t tx2, ft_int32_t ty2, ft_uint16_t result) +// Draw an analog clock +// FT81x Series Programmers Guide Section 5.29 +ft_void_t FT813::Clock(ft_int16_t x, ft_int16_t y, ft_int16_t r, ft_uint16_t options, ft_uint16_t h, ft_uint16_t m, ft_uint16_t s, ft_uint16_t ms) { - StartFunc( FT_CMD_SIZE*6*2+FT_CMD_SIZE*2); - SendCmd( CMD_TOUCH_TRANSFORM); - SendCmd( x0); - SendCmd( y0); - SendCmd( x1); - SendCmd( y1); - SendCmd( x2); - SendCmd( y2); - SendCmd( tx0); - SendCmd( ty0); - SendCmd( tx1); - SendCmd( ty1); - SendCmd( tx2); - SendCmd( ty2); - SendCmd( result); - EndFunc( (FT_CMD_SIZE*6*2+FT_CMD_SIZE*2)); + StartFunc(FT_CMD_SIZE*5); + SendCmd(CMD_CLOCK); + SendCmd((((ft_uint32_t)y<<16)|(x & 0xffff))); + SendCmd((((ft_uint32_t)options<<16)|r)); + SendCmd((((ft_uint32_t)m<<16)|h)); + SendCmd((((ft_uint32_t)ms<<16)|s)); + EndFunc(); +} + +// Set the foreground color +// FT81x Series Programmers Guide Section 5.30 +ft_void_t FT813::FgColor(ft_uint32_t c) +{ + StartFunc(FT_CMD_SIZE*2); + SendCmd(CMD_FGCOLOR); + SendCmd(c); + EndFunc(); +} + +// Set the background color +// FT81x Series Programmers Guide Section 5.31 +ft_void_t FT813::BgColor(ft_uint32_t c) +{ + StartFunc(FT_CMD_SIZE*2); + SendCmd(CMD_BGCOLOR); + SendCmd(c); + EndFunc(); } -ft_void_t FT800::Interrupt( ft_uint32_t ms) +// Set the 3D button highlight color - Set Highlight Gradient Color +// FT81x Series Programmers Guide Section 5.32 +ft_void_t FT813::GradColor(ft_uint32_t c) { - StartFunc( FT_CMD_SIZE*2); - SendCmd( CMD_INTERRUPT); - SendCmd( ms); - EndFunc( (FT_CMD_SIZE*2)); + StartFunc(FT_CMD_SIZE*2); + SendCmd(CMD_GRADCOLOR); + SendCmd(c); + EndFunc(); +} + +// Draw a gauge +// FT81x Series Programmers Guide Section 5.33 +/* Error handling for val is not done, so better to always use range of 65535 in order that needle is drawn within display region */ +ft_void_t FT813::Gauge(ft_int16_t x, ft_int16_t y, ft_int16_t r, ft_uint16_t options, ft_uint16_t major, ft_uint16_t minor, ft_uint16_t val, ft_uint16_t range) +{ + StartFunc(FT_CMD_SIZE*5); + SendCmd(CMD_GAUGE); + SendCmd((((ft_uint32_t)y<<16)|(x & 0xffff))); + SendCmd((((ft_uint32_t)options<<16)|r)); + SendCmd((((ft_uint32_t)minor<<16)|major)); + SendCmd((((ft_uint32_t)range<<16)|val)); + EndFunc(); } -ft_void_t FT800::FgColor( ft_uint32_t c) +// Draw a smooth color gradient +// FT81x Series Programmers Guide Section 5.34 +ft_void_t FT813::Gradient(ft_int16_t x0, ft_int16_t y0, ft_uint32_t rgb0, ft_int16_t x1, ft_int16_t y1, ft_uint32_t rgb1) { - StartFunc( FT_CMD_SIZE*2); - SendCmd( CMD_FGCOLOR); - SendCmd( c); - EndFunc( (FT_CMD_SIZE*2)); + StartFunc(FT_CMD_SIZE*5); + SendCmd(CMD_GRADIENT); + SendCmd((((ft_uint32_t)y0<<16)|(x0 & 0xffff))); + SendCmd(rgb0); + SendCmd((((ft_uint32_t)y1<<16)|(x1 & 0xffff))); + SendCmd(rgb1); + EndFunc(); } -ft_void_t FT800::Rotate( ft_int32_t a) +// Draw a row of keys +// FT81x Series Programmers Guide Section 5.35 +ft_void_t FT813::Keys(ft_int16_t x, ft_int16_t y, ft_int16_t w, ft_int16_t h, ft_int16_t font, ft_uint16_t options, const ft_char8_t* s) { - StartFunc( FT_CMD_SIZE*2); - SendCmd( CMD_ROTATE); - SendCmd( a); - EndFunc( (FT_CMD_SIZE*2)); + StartFunc(FT_CMD_SIZE*4 + strlen(s) + 1); + SendCmd(CMD_KEYS); + SendCmd((((ft_uint32_t)y<<16)|(x & 0xffff))); + SendCmd((((ft_uint32_t)h<<16)|w)); + SendCmd((((ft_uint32_t)options<<16)|font)); + SendStr(s); + EndFunc(); } -ft_void_t FT800::Button( ft_int16_t x, ft_int16_t y, ft_int16_t w, ft_int16_t h, ft_int16_t font, ft_uint16_t options, const ft_char8_t* s) +// Draw a progress bar +// FT81x Series Programmers Guide Section 5.36 +ft_void_t FT813::Progress(ft_int16_t x, ft_int16_t y, ft_int16_t w, ft_int16_t h, ft_uint16_t options, ft_uint16_t val, ft_uint16_t range) { - StartFunc( FT_CMD_SIZE*4 + strlen(s) + 1); - SendCmd( CMD_BUTTON); - SendCmd( (((ft_uint32_t)y<<16)|(x & 0xffff))); - SendCmd( (((ft_uint32_t)h<<16)|w)); - SendCmd( (((ft_uint32_t)options<<16)|font)); // patch from Ivano Pelicella to draw flat buttons - SendStr( s); - EndFunc( (FT_CMD_SIZE*4 + strlen(s) + 1)); -} - -ft_void_t FT800::MemWrite( ft_uint32_t ptr, ft_uint32_t num) -{ - StartFunc( FT_CMD_SIZE*3); - SendCmd( CMD_MEMWRITE); - SendCmd( ptr); - SendCmd( num); - EndFunc( (FT_CMD_SIZE*3)); + StartFunc(FT_CMD_SIZE*5); + SendCmd(CMD_PROGRESS); + SendCmd((((ft_uint32_t)y<<16)|(x & 0xffff))); + SendCmd((((ft_uint32_t)h<<16)|w)); + SendCmd((((ft_uint32_t)val<<16)|options)); + SendCmd(range); + EndFunc(); } -ft_void_t FT800::Scrollbar( ft_int16_t x, ft_int16_t y, ft_int16_t w, ft_int16_t h, ft_uint16_t options, ft_uint16_t val, ft_uint16_t size, ft_uint16_t range) +// Draw a scroll bar +// FT81x Series Programmers Guide Section 5.37 +ft_void_t FT813::Scrollbar(ft_int16_t x, ft_int16_t y, ft_int16_t w, ft_int16_t h, ft_uint16_t options, ft_uint16_t val, ft_uint16_t size, ft_uint16_t range) { - StartFunc( FT_CMD_SIZE*5); - SendCmd( CMD_SCROLLBAR); - SendCmd( (((ft_uint32_t)y<<16)|(x & 0xffff))); - SendCmd( (((ft_uint32_t)h<<16)|w)); - SendCmd( (((ft_uint32_t)val<<16)|options)); - SendCmd( (((ft_uint32_t)range<<16)|size)); - EndFunc( (FT_CMD_SIZE*5)); + StartFunc(FT_CMD_SIZE*5); + SendCmd(CMD_SCROLLBAR); + SendCmd((((ft_uint32_t)y<<16)|(x & 0xffff))); + SendCmd((((ft_uint32_t)h<<16)|w)); + SendCmd((((ft_uint32_t)val<<16)|options)); + SendCmd((((ft_uint32_t)range<<16)|size)); + EndFunc(); } -ft_void_t FT800::GetMatrix( ft_int32_t a, ft_int32_t b, ft_int32_t c, ft_int32_t d, ft_int32_t e, ft_int32_t f) +// Draw a slider +// FT81x Series Programmers Guide Section 5.38 +ft_void_t FT813::Slider(ft_int16_t x, ft_int16_t y, ft_int16_t w, ft_int16_t h, ft_uint16_t options, ft_uint16_t val, ft_uint16_t range) { - StartFunc( FT_CMD_SIZE*7); - SendCmd( CMD_GETMATRIX); - SendCmd( a); - SendCmd( b); - SendCmd( c); - SendCmd( d); - SendCmd( e); - SendCmd( f); - EndFunc( (FT_CMD_SIZE*7)); + StartFunc(FT_CMD_SIZE*5); + SendCmd(CMD_SLIDER); + SendCmd((((ft_uint32_t)y<<16)|(x & 0xffff))); + SendCmd((((ft_uint32_t)h<<16)|w)); + SendCmd((((ft_uint32_t)val<<16)|options)); + SendCmd(range); + EndFunc(); +} + +// Draw a rotary dial control +// FT81x Series Programmers Guide Section 5.39 +// This is much like a Gauge except for the helpful range parameter. For some reason, all dials are 65535 around. +ft_void_t FT813::Dial(ft_int16_t x, ft_int16_t y, ft_int16_t r, ft_uint16_t options, ft_uint16_t val) +{ + StartFunc(FT_CMD_SIZE*4); + SendCmd(CMD_DIAL); + SendCmd((((ft_uint32_t)y<<16)|(x & 0xffff))); + SendCmd((((ft_uint32_t)options<<16)|r)); + SendCmd(val); + EndFunc(); } -ft_void_t FT800::Sketch( ft_int16_t x, ft_int16_t y, ft_uint16_t w, ft_uint16_t h, ft_uint32_t ptr, ft_uint16_t format) +// Draw a toggle switch +// FT81x Series Programmers Guide Section 5.40 +ft_void_t FT813::Toggle(ft_int16_t x, ft_int16_t y, ft_int16_t w, ft_int16_t font, ft_uint16_t options, ft_uint16_t state, const ft_char8_t* s) { - StartFunc( FT_CMD_SIZE*5); - SendCmd( CMD_SKETCH); - SendCmd( (((ft_uint32_t)y<<16)|(x & 0xffff))); - SendCmd( (((ft_uint32_t)h<<16)|w)); - SendCmd( ptr); - SendCmd( format); - EndFunc( (FT_CMD_SIZE*5)); + StartFunc(FT_CMD_SIZE*4 + strlen(s) + 1); + SendCmd(CMD_TOGGLE); + SendCmd((((ft_uint32_t)y<<16)|(x & 0xffff))); + SendCmd((((ft_uint32_t)font<<16)|w)); + SendCmd((((ft_uint32_t)state<<16)|options)); + SendStr(s); + EndFunc(); } -ft_void_t FT800::MemSet( ft_uint32_t ptr, ft_uint32_t value, ft_uint32_t num) + +// Draw Text +// FT81x Series Programmers Guide Section 5.41 +ft_void_t FT813::Text(ft_int16_t x, ft_int16_t y, ft_int16_t font, ft_uint16_t options, const ft_char8_t* s) { - StartFunc( FT_CMD_SIZE*4); - SendCmd( CMD_MEMSET); - SendCmd( ptr); - SendCmd( value); - SendCmd( num); - EndFunc( (FT_CMD_SIZE*4)); + StartFunc(FT_CMD_SIZE*3 + strlen(s) + 1); + SendCmd(CMD_TEXT); + //Copro_SendCmd((((ft_uint32_t)y<<16)|(ft_uint32_t)x)); + SendCmd((((ft_uint32_t)y<<16)|(x & 0xffff))); + SendCmd((((ft_uint32_t)options<<16)|(ft_uint32_t)font)); + SendStr(s); + EndFunc(); } -ft_void_t FT800::GradColor( ft_uint32_t c) + +// Set the base for number output +// FT81x Series Programmers Guide Section 5.42 +ft_void_t FT813::SetBase(ft_uint32_t base) { - StartFunc( FT_CMD_SIZE*2); - SendCmd( CMD_GRADCOLOR); - SendCmd( c); - EndFunc( (FT_CMD_SIZE*2)); + StartFunc(FT_CMD_SIZE*2); + SendCmd(CMD_SETBASE); + SendCmd(base); + EndFunc(); } -ft_void_t FT800::BitmapTransform( ft_int32_t x0, ft_int32_t y0, ft_int32_t x1, ft_int32_t y1, ft_int32_t x2, ft_int32_t y2, ft_int32_t tx0, ft_int32_t ty0, ft_int32_t tx1, ft_int32_t ty1, ft_int32_t tx2, ft_int32_t ty2, ft_uint16_t result) + +// Draw number +// FT81x Series Programmers Guide Section 5.43 +ft_void_t FT813::Number(ft_int16_t x, ft_int16_t y, ft_int16_t font, ft_uint16_t options, ft_int32_t n) { - StartFunc( FT_CMD_SIZE*6*2+FT_CMD_SIZE*2); - SendCmd( CMD_BITMAP_TRANSFORM); - SendCmd( x0); - SendCmd( y0); - SendCmd( x1); - SendCmd( y1); - SendCmd( x2); - SendCmd( y2); - SendCmd( tx0); - SendCmd( ty0); - SendCmd( tx1); - SendCmd( ty1); - SendCmd( tx2); - SendCmd( ty2); - SendCmd( result); - EndFunc( (FT_CMD_SIZE*6*2+FT_CMD_SIZE*2)); + StartFunc(FT_CMD_SIZE*4); + SendCmd(CMD_NUMBER); + SendCmd((((ft_uint32_t)y<<16)|(x & 0xffff))); + SendCmd((((ft_uint32_t)options<<16)|font)); + SendCmd(n); + EndFunc(); } -ft_void_t FT800::Calibrate( ft_uint32_t result) + +// Set the current matrix to the identity matrix +// FT81x Series Programmers Guide Section 5.44 +ft_void_t FT813::LoadIdentity() { - StartFunc( FT_CMD_SIZE*2); - SendCmd( CMD_CALIBRATE); - SendCmd( result); - EndFunc( (FT_CMD_SIZE*2)); - WaitCmdfifo_empty( ); + StartFunc(FT_CMD_SIZE); + SendCmd(CMD_LOADIDENTITY); + EndFunc(); +} -} -ft_void_t FT800::SetFont( ft_uint32_t font, ft_uint32_t ptr) +// Write the current matrix to the display list +// FT81x Series Programmers Guide Section 5.45 +ft_void_t FT813::SetMatrix() { - StartFunc( FT_CMD_SIZE*3); - SendCmd( CMD_SETFONT); - SendCmd( font); - SendCmd( ptr); - EndFunc( (FT_CMD_SIZE*3)); + StartFunc(FT_CMD_SIZE); + SendCmd(CMD_SETMATRIX); + EndFunc(); } -//Curtis Mattull added this function on 11/14/16, copied from above... -ft_void_t FT800::RomFont( ft_uint32_t rom_slot, ft_uint32_t font) + +// Retrieves the current matrix coefficients +// FT81x Series Programmers Guide Section 5.46 +ft_void_t FT813::GetMatrix(ft_int32_t a, ft_int32_t b, ft_int32_t c, ft_int32_t d, ft_int32_t e, ft_int32_t f) { - StartFunc( FT_CMD_SIZE*3); - SendCmd( CMD_ROMFONT); - SendCmd( rom_slot); - SendCmd( font); - EndFunc( (FT_CMD_SIZE*3)); + StartFunc(FT_CMD_SIZE*7); + SendCmd(CMD_GETMATRIX); + SendCmd(a); + SendCmd(b); + SendCmd(c); + SendCmd(d); + SendCmd(e); + SendCmd(f); + EndFunc(); } - -ft_void_t FT800::Logo( ) +// Get the end memory address of data inflated by CMD_INFLATE - Get the last used address from CoPro operation +// FT81x Series Programmers Guide Section 5.47 +ft_void_t FT813::GetPtr(ft_uint32_t result) { - StartFunc( FT_CMD_SIZE*1); - SendCmd( CMD_LOGO); - EndFunc( FT_CMD_SIZE*1); + StartFunc(FT_CMD_SIZE*2); + SendCmd(CMD_GETPTR); + SendCmd(result); + EndFunc(); } -ft_void_t FT800::Append( ft_uint32_t ptr, ft_uint32_t num) -{ - StartFunc( FT_CMD_SIZE*3); - SendCmd( CMD_APPEND); - SendCmd( ptr); - SendCmd( num); - EndFunc( (FT_CMD_SIZE*3)); -} -ft_void_t FT800::MemZero( ft_uint32_t ptr, ft_uint32_t num) + +// Get the image properties decompressed by CMD_LOADIMAGE +// FT81x Series Programmers Guide Section 5.48 +// Jack +ft_void_t FT813::GetProps(ft_uint32_t ptr, ft_uint32_t w, ft_uint32_t h) { - StartFunc( FT_CMD_SIZE*3); - SendCmd( CMD_MEMZERO); - SendCmd( ptr); - SendCmd( num); - EndFunc( (FT_CMD_SIZE*3)); + StartFunc(FT_CMD_SIZE*4); + SendCmd(CMD_GETPROPS); + SendCmd(ptr); + SendCmd(w); + SendCmd(h); + EndFunc(); } -ft_void_t FT800::Scale( ft_int32_t sx, ft_int32_t sy) + +// Apply a scale to the current matrix +// FT81x Series Programmers Guide Section 5.49 +ft_void_t FT813::Scale(ft_int32_t sx, ft_int32_t sy) { - StartFunc( FT_CMD_SIZE*3); - SendCmd( CMD_SCALE); - SendCmd( sx); - SendCmd( sy); - EndFunc( (FT_CMD_SIZE*3)); + StartFunc(FT_CMD_SIZE*3); + SendCmd(CMD_SCALE); + SendCmd(sx); + SendCmd(sy); + EndFunc(); } -ft_void_t FT800::Clock( ft_int16_t x, ft_int16_t y, ft_int16_t r, ft_uint16_t options, ft_uint16_t h, ft_uint16_t m, ft_uint16_t s, ft_uint16_t ms) + +// Apply a rotation to the current matrix +// FT81x Series Programmers Guide Section 5.50 +ft_void_t FT813::Rotate(ft_int32_t a) { - StartFunc( FT_CMD_SIZE*5); - SendCmd( CMD_CLOCK); - SendCmd( (((ft_uint32_t)y<<16)|(x & 0xffff))); - SendCmd( (((ft_uint32_t)options<<16)|r)); - SendCmd( (((ft_uint32_t)m<<16)|h)); - SendCmd( (((ft_uint32_t)ms<<16)|s)); - EndFunc( (FT_CMD_SIZE*5)); + StartFunc(FT_CMD_SIZE*2); + SendCmd(CMD_ROTATE); + SendCmd(a); + EndFunc(); } -ft_void_t FT800::Gradient( ft_int16_t x0, ft_int16_t y0, ft_uint32_t rgb0, ft_int16_t x1, ft_int16_t y1, ft_uint32_t rgb1) +// Apply a translation to the current matrix +// FT81x Series Programmers Guide Section 5.51 +ft_void_t FT813::Translate(ft_int32_t tx, ft_int32_t ty) +{ + StartFunc(FT_CMD_SIZE*3); + SendCmd(CMD_TRANSLATE); + SendCmd(tx); + SendCmd(ty); + EndFunc(); +} + +// Execute the touch screen calibration routine +// FT81x Series Programmers Guide Section 5.52 +// * This business about "result" in the manual really seems to be simply leftover cruft of no purpose - send zero +ft_void_t FT813::Calibrate(ft_uint32_t result) { - StartFunc( FT_CMD_SIZE*5); - SendCmd( CMD_GRADIENT); - SendCmd( (((ft_uint32_t)y0<<16)|(x0 & 0xffff))); - SendCmd( rgb0); - SendCmd( (((ft_uint32_t)y1<<16)|(x1 & 0xffff))); - SendCmd( rgb1); - EndFunc( (FT_CMD_SIZE*5)); + StartFunc(FT_CMD_SIZE*2); + SendCmd(CMD_CALIBRATE); + SendCmd(result); + EndFunc(); + WaitCmdfifo_empty(); +} + +// Rotate the screen +// FT81x Series Programmers Guide Section 5.53 +ft_void_t FT813::SetRotate(ft_uint32_t r) +{ + StartFunc(FT_CMD_SIZE*2); + SendCmd(CMD_SETROTATE); + SendCmd(r); + EndFunc(); +} + +// Start an animated spinner +// FT81x Series Programmers Guide Section 5.54 +ft_void_t FT813::Spinner(ft_int16_t x, ft_int16_t y, ft_uint16_t style, ft_uint16_t scale) +{ + StartFunc(FT_CMD_SIZE*3); + SendCmd(CMD_SPINNER); + SendCmd((((ft_uint32_t)y<<16)|(x & 0xffff))); + SendCmd((((ft_uint32_t)scale<<16)|style)); + EndFunc(); +} + +// Start an animated screensaver +// FT81x Series Programmers Guide Section 5.55 +ft_void_t FT813::ScreenSaver() +{ + StartFunc(FT_CMD_SIZE); + SendCmd(CMD_SCREENSAVER); + EndFunc(); } -ft_void_t FT800::SetMatrix( ) +// Start a continuous sketch update +// FT81x Series Programmers Guide Section 5.56 +ft_void_t FT813::Sketch(ft_int16_t x, ft_int16_t y, ft_uint16_t w, ft_uint16_t h, ft_uint32_t ptr, ft_uint16_t format) { - StartFunc( FT_CMD_SIZE*1); - SendCmd( CMD_SETMATRIX); - EndFunc( (FT_CMD_SIZE*1)); + StartFunc(FT_CMD_SIZE*5); + SendCmd(CMD_SKETCH); + SendCmd((((ft_uint32_t)y<<16)|(x & 0xffff))); + SendCmd((((ft_uint32_t)h<<16)|w)); + SendCmd(ptr); + SendCmd(format); + EndFunc(); } -ft_void_t FT800::Track( ft_int16_t x, ft_int16_t y, ft_int16_t w, ft_int16_t h, ft_int16_t tag) +// Stop any of spinner, screensaver or sketch +// FT81x Series Programmers Guide Section 5.57 +ft_void_t FT813::Stop() { - StartFunc( FT_CMD_SIZE*4); - SendCmd( CMD_TRACK); - SendCmd( (((ft_uint32_t)y<<16)|(x & 0xffff))); - SendCmd( (((ft_uint32_t)h<<16)|w)); - SendCmd( tag); - EndFunc( (FT_CMD_SIZE*4)); + StartFunc(FT_CMD_SIZE); + SendCmd(CMD_STOP); + EndFunc(); } -ft_void_t FT800::GetPtr( ft_uint32_t result) +// Set up a custom font +// FT81x Series Programmers Guide Section 5.58 +ft_void_t FT813::SetFont(ft_uint32_t font, ft_uint32_t ptr) { - StartFunc( FT_CMD_SIZE*2); - SendCmd( CMD_GETPTR); - SendCmd( result); - EndFunc( (FT_CMD_SIZE*2)); + StartFunc(FT_CMD_SIZE*3); + SendCmd(CMD_SETFONT); + SendCmd(font); + SendCmd(ptr); + EndFunc(); } -ft_void_t FT800::Progress( ft_int16_t x, ft_int16_t y, ft_int16_t w, ft_int16_t h, ft_uint16_t options, ft_uint16_t val, ft_uint16_t range) +// Set up a custom font +// FT81x Series Programmers Guide Section 5.59 +ft_void_t FT813::SetFont2(ft_uint32_t font, ft_uint32_t ptr, ft_uint32_t firstchar) { - StartFunc( FT_CMD_SIZE*5); - SendCmd( CMD_PROGRESS); - SendCmd( (((ft_uint32_t)y<<16)|(x & 0xffff))); - SendCmd( (((ft_uint32_t)h<<16)|w)); - SendCmd( (((ft_uint32_t)val<<16)|options)); - SendCmd( range); - EndFunc( (FT_CMD_SIZE*5)); + StartFunc(FT_CMD_SIZE*4); + SendCmd(CMD_SETFONT2); + SendCmd(font); + SendCmd(ptr); + SendCmd(firstchar); + EndFunc(); } -ft_void_t FT800::ColdStart( ) +// Set the scratch bitmap for widget use +// FT81x Series Programmers Guide Section 5.60 +ft_void_t FT813::SetScratch(ft_uint32_t handle) { - StartFunc( FT_CMD_SIZE*1); - SendCmd( CMD_COLDSTART); - EndFunc( (FT_CMD_SIZE*1)); + StartFunc(FT_CMD_SIZE*2); + SendCmd(CMD_SETSCRATCH); + SendCmd(handle); + EndFunc(); } -ft_void_t FT800::Keys( ft_int16_t x, ft_int16_t y, ft_int16_t w, ft_int16_t h, ft_int16_t font, ft_uint16_t options, const ft_char8_t* s) +// Load a ROM font into bitmap handle +// FT81x Series Programmers Guide Section 5.61 +ft_void_t FT813::RomFont(ft_uint32_t rom_slot, ft_uint32_t font) { - StartFunc( FT_CMD_SIZE*4 + strlen(s) + 1); - SendCmd( CMD_KEYS); - SendCmd( (((ft_uint32_t)y<<16)|(x & 0xffff))); - SendCmd( (((ft_uint32_t)h<<16)|w)); - SendCmd( (((ft_uint32_t)options<<16)|font)); - SendStr( s); - EndFunc( (FT_CMD_SIZE*4 + strlen(s) + 1)); + StartFunc(FT_CMD_SIZE*3); + SendCmd(CMD_ROMFONT); + SendCmd(rom_slot); + SendCmd(font); + EndFunc(); } -ft_void_t FT800::Dial( ft_int16_t x, ft_int16_t y, ft_int16_t r, ft_uint16_t options, ft_uint16_t val) +// Track touches for a graphics object - Make Track (for a slider) +// FT81x Series Programmers Guide Section 5.62 +// tag refers to the tag # previously assigned to the object that this track is tracking. +ft_void_t FT813::Track(ft_int16_t x, ft_int16_t y, ft_int16_t w, ft_int16_t h, ft_int16_t tag) { - StartFunc( FT_CMD_SIZE*4); - SendCmd( CMD_DIAL); - SendCmd( (((ft_uint32_t)y<<16)|(x & 0xffff))); - SendCmd( (((ft_uint32_t)options<<16)|r)); - SendCmd( val); - EndFunc( (FT_CMD_SIZE*4)); + StartFunc(FT_CMD_SIZE*4); + SendCmd(CMD_TRACK); + SendCmd((((ft_uint32_t)y<<16)|(x & 0xffff))); + SendCmd((((ft_uint32_t)h<<16)|w)); + SendCmd(tag); + EndFunc(); +} + +// Take a snapshot of the current screen +// FT81x Series Programmers Guide Section 5.63 +ft_void_t FT813::Snapshot(ft_uint32_t ptr) +{ + StartFunc(FT_CMD_SIZE*2); + SendCmd(CMD_SNAPSHOT); + SendCmd(ptr); + EndFunc(); } -ft_void_t FT800::LoadImage( ft_uint32_t ptr, ft_uint32_t options) +// Take a snapshot of part of the current screen +// FT81x Series Programmers Guide Section 5.64 +ft_void_t FT813::Snapshot2(ft_uint32_t fmt, ft_uint32_t ptr, ft_int16_t x, ft_int16_t y, ft_int16_t w, ft_int16_t h) { - StartFunc( FT_CMD_SIZE*3); - SendCmd( CMD_LOADIMAGE); - SendCmd( ptr); - SendCmd( options); - EndFunc( (FT_CMD_SIZE*3)); + StartFunc(FT_CMD_SIZE*5); + SendCmd(CMD_SNAPSHOT2); + SendCmd(fmt); + SendCmd(ptr); + SendCmd((((ft_uint32_t)y<<16)|(x & 0xffff))); + SendCmd((((ft_uint32_t)h<<16)|(w & 0xffff))); + EndFunc(); } -ft_void_t FT800::DLstart( ) +// Set up display list for bitmap - Cmd_SetBitmap - generate DL commands for bitmap parms +// FT81x Series Programmers Guide Section 5.65 +ft_void_t FT813::SetBitmap(ft_int32_t addr, ft_int16_t fmt, ft_uint16_t width, ft_uint16_t height) { - StartFunc( FT_CMD_SIZE*1); - SendCmd( CMD_DLSTART); - EndFunc( (FT_CMD_SIZE*1)); + StartFunc(FT_CMD_SIZE*4); + SendCmd(CMD_SETBITMAP); + SendCmd(addr); + SendCmd((((ft_uint32_t)width<<16)|(fmt & 0xffff))); + SendCmd((((ft_uint32_t)0<<16)|(height & 0xffff))); + EndFunc(); } -ft_void_t FT800::Snapshot( ft_uint32_t ptr) +// Play FTDI logo animation +// FT81x Series Programmers Guide Section 5.66 +ft_void_t FT813::Logo() { - StartFunc( FT_CMD_SIZE*2); - SendCmd( CMD_SNAPSHOT); - SendCmd( ptr); - EndFunc( (FT_CMD_SIZE*2)); -} - -ft_void_t FT800::ScreenSaver( ) -{ - StartFunc( FT_CMD_SIZE*1); - SendCmd( CMD_SCREENSAVER); - EndFunc( (FT_CMD_SIZE*1)); + StartFunc(FT_CMD_SIZE); + SendCmd(CMD_LOGO); + EndFunc(); } -ft_void_t FT800::MemCrc( ft_uint32_t ptr, ft_uint32_t num, ft_uint32_t result) +// ******************** Miscellaneous Operation CoProcessor Command Functions ****************************** + +// ? +// FT81x Series Programmers Guide Section ? +ft_void_t FT813::TouchTransform(ft_int32_t x0, ft_int32_t y0, ft_int32_t x1, ft_int32_t y1, ft_int32_t x2, ft_int32_t y2, ft_int32_t tx0, ft_int32_t ty0, ft_int32_t tx1, ft_int32_t ty1, ft_int32_t tx2, ft_int32_t ty2, ft_uint16_t result) { - StartFunc( FT_CMD_SIZE*4); - SendCmd( CMD_MEMCRC); - SendCmd( ptr); - SendCmd( num); - SendCmd( result); - EndFunc( (FT_CMD_SIZE*4)); -} - - -ft_void_t FT800::DL(ft_uint32_t cmd) -{ - WrCmd32(cmd); - /* Increment the command index */ - CmdBuffer_Index += FT_CMD_SIZE; + StartFunc(FT_CMD_SIZE*6*2+FT_CMD_SIZE*2); + SendCmd(CMD_TOUCH_TRANSFORM); + SendCmd(x0); + SendCmd(y0); + SendCmd(x1); + SendCmd(y1); + SendCmd(x2); + SendCmd(y2); + SendCmd(tx0); + SendCmd(ty0); + SendCmd(tx1); + SendCmd(ty1); + SendCmd(tx2); + SendCmd(ty2); + SendCmd(result); + EndFunc(); } -ft_void_t FT800::WrDlCmd_Buffer(ft_uint32_t cmd) +// ? +// FT81x Series Programmers Guide Section ? +ft_void_t FT813::BitmapTransform(ft_int32_t x0, ft_int32_t y0, ft_int32_t x1, ft_int32_t y1, ft_int32_t x2, ft_int32_t y2, ft_int32_t tx0, ft_int32_t ty0, ft_int32_t tx1, ft_int32_t ty1, ft_int32_t tx2, ft_int32_t ty2, ft_uint16_t result) { - Wr32((RAM_DL+DlBuffer_Index),cmd); - /* Increment the command index */ - DlBuffer_Index += FT_CMD_SIZE; + StartFunc(FT_CMD_SIZE*6*2+FT_CMD_SIZE*2); + SendCmd(CMD_BITMAP_TRANSFORM); + SendCmd(x0); + SendCmd(y0); + SendCmd(x1); + SendCmd(y1); + SendCmd(x2); + SendCmd(y2); + SendCmd(tx0); + SendCmd(ty0); + SendCmd(tx1); + SendCmd(ty1); + SendCmd(tx2); + SendCmd(ty2); + SendCmd(result); + EndFunc(); } -ft_void_t FT800::Flush_DL_Buffer() +ft_void_t FT813::DL(ft_uint32_t cmd) { - DlBuffer_Index = 0; - + WrCmd32(cmd); + /* Increment the command index */ + CmdBuffer_Index += FT_CMD_SIZE; } -ft_void_t FT800::Flush_Co_Buffer() +ft_void_t FT813::WrDlCmd_Buffer(ft_uint32_t cmd) { - CmdBuffer_Index = 0; + Wr32((RAM_DL+DlBuffer_Index), cmd); + /* Increment the command index */ + DlBuffer_Index += FT_CMD_SIZE; } +ft_void_t FT813::Flush_DL_Buffer() +{ + DlBuffer_Index = 0; +} + +ft_void_t FT813::Flush_Co_Buffer() +{ + CmdBuffer_Index = 0; +} /* API to check the status of previous DLSWAP and perform DLSWAP of new DL */ /* Check for the status of previous DLSWAP and if still not done wait for few ms and check again */ -ft_void_t FT800::DLSwap(ft_uint8_t DL_Swap_Type) +ft_void_t FT813::DLSwap(ft_uint8_t DL_Swap_Type) { - ft_uint8_t Swap_Type = DLSWAP_FRAME,Swap_Done = DLSWAP_FRAME; + ft_uint8_t Swap_Type = DLSWAP_FRAME, Swap_Done = DLSWAP_FRAME; - if(DL_Swap_Type == DLSWAP_LINE) - { + if(DL_Swap_Type == DLSWAP_LINE) { Swap_Type = DLSWAP_LINE; } /* Perform a new DL swap */ - Wr8(REG_DLSWAP,Swap_Type); + Wr8(REG_DLSWAP, Swap_Type); /* Wait till the swap is done */ - while(Swap_Done) - { + while(Swap_Done) { Swap_Done = Rd8(REG_DLSWAP); - if(DLSWAP_DONE != Swap_Done) - { + if(DLSWAP_DONE != Swap_Done) { Sleep(10);//wait for 10ms } } } - - /* Nothing beyond this */ - - - -
diff -r ca6a7c6a2f4b -r 6a81aeca25e3 src/FT_GPU_Hal.cpp --- a/src/FT_GPU_Hal.cpp Thu Dec 22 20:19:22 2016 +0000 +++ b/src/FT_GPU_Hal.cpp Mon Jul 23 12:22:23 2018 +0000 @@ -1,4 +1,4 @@ -/* mbed Library for FTDI FT800 Enbedded Video Engine "EVE" +/* mbed Library for FTDI FT813 Enbedded Video Engine "EVE" * based on Original Code Sample from FTDI * ported to mbed by Peter Drescher, DC2PD 2014 * Released under the MIT License: http://mbed.org/license/mit @@ -11,160 +11,165 @@ #include "FT_LCD_Type.h" //Serial pc(USBTX, USBRX); -FT800::FT800(PinName mosi, +#define SPI_SPEED_START 10000000 +#define SPI_SPEED_AFTER 27000000 + +FT813::FT813(PinName mosi, PinName miso, PinName sck, PinName ss, PinName intr, PinName pd) - : - - _spi(mosi, miso, sck), - _ss(ss), - _pd(pd), - _f800_isr(InterruptIn(intr)) - { - _spi.format(8,0); // 8 bit spi mode 0 - _spi.frequency(1000000); // start with 10 Mhz SPI clock - _ss = 1; // cs high - _pd = 1; // PD high - Bootup(); - } +: +_spi(mosi, miso, sck), +_ss(ss), +_pd(pd), +_f800_isr(InterruptIn(intr)) +{ + _spi.format(8, 0); // 8 bit spi mode 0 + _spi.frequency(SPI_SPEED_START); // start with 10 Mhz SPI clock + _ss = 1; // cs high + _pd = 1; // PD high + Bootup(); + _address = 0; + _bitmap_count = 0; + _bitmapCount = 0; + _bitmapAddress = 0; +} -ft_bool_t FT800::Bootup(void){ +ft_bool_t FT813::Bootup(void) +{ // terminal.printf("Bootup() entered\r\n"); Open(); BootupConfig(); return(1); - } +} -ft_void_t FT800::BootupConfig(void){ +ft_void_t FT813::BootupConfig(void) +{ ft_uint8_t chipid; /* Do a power cycle for safer side */ - Powercycle( FT_TRUE); + Powercycle(FT_TRUE); /* 7/8/16: Curt added the sleep delay below... */ // Sleep(30); /* Set the clk to external clock */ - HostCommand( FT_GPU_EXTERNAL_OSC); + HostCommand(FT_GPU_EXTERNAL_OSC); Sleep(10); - /* Access address 0 to wake up the FT800 */ - HostCommand( FT_GPU_ACTIVE_M); + /* Access address 0 to wake up the FT813 */ + HostCommand(FT_GPU_ACTIVE_M); Sleep(500); /* Switch PLL output to 48MHz */ -// HostCommand( FT_GPU_PLL_48M); + HostCommand(FT_GPU_PLL_48M); Sleep(10); /* Do a core reset for safer side */ - HostCommand( FT_GPU_CORE_RESET); + HostCommand(FT_GPU_CORE_RESET); Sleep(500); - //Read Register ID to check if FT800 is ready. - chipid = Rd8( REG_ID); + //Read Register ID to check if FT813 is ready. + chipid = Rd8(REG_ID); // chipid = Rd8(0x0C0000); -// pc.printf("ID%08X\n", chipid); +// printf("ID1: 0x%08X\n", chipid); while(chipid != 0x7C) - +// wait(1); +// printf("ID2: 0x%08X\n", chipid); // Speed up - _spi.frequency(30000000); // 30 Mhz SPI clock DC -// _spi.frequency(20000000); // 20 Mhz SPI clock DC -// _spi.frequency(12000000); // 12 Mhz SPI clock +// _spi.frequency(50000000); // 30 Mhz SPI clock DC + _spi.frequency(SPI_SPEED_AFTER); // 20 Mhz SPI clock DC +// _spi.frequency(12000000); // 12 Mhz SPI clock /* Configuration of LCD display */ DispHCycle = my_DispHCycle; - Wr16( REG_HCYCLE, DispHCycle); + Wr16(REG_HCYCLE, DispHCycle); DispHOffset = my_DispHOffset; - Wr16( REG_HOFFSET, DispHOffset); + Wr16(REG_HOFFSET, DispHOffset); DispWidth = my_DispWidth; - Wr16( REG_HSIZE, DispWidth); + Wr16(REG_HSIZE, DispWidth); DispHSync0 = my_DispHSync0; - Wr16( REG_HSYNC0, DispHSync0); + Wr16(REG_HSYNC0, DispHSync0); DispHSync1 = my_DispHSync1; - Wr16( REG_HSYNC1, DispHSync1); + Wr16(REG_HSYNC1, DispHSync1); DispVCycle = my_DispVCycle; - Wr16( REG_VCYCLE, DispVCycle); + Wr16(REG_VCYCLE, DispVCycle); DispVOffset = my_DispVOffset; - Wr16( REG_VOFFSET, DispVOffset); + Wr16(REG_VOFFSET, DispVOffset); DispHeight = my_DispHeight; - Wr16( REG_VSIZE, DispHeight); + Wr16(REG_VSIZE, DispHeight); DispVSync0 = my_DispVSync0; - Wr16( REG_VSYNC0, DispVSync0); + Wr16(REG_VSYNC0, DispVSync0); DispVSync1 = my_DispVSync1; - Wr16( REG_VSYNC1, DispVSync1); + Wr16(REG_VSYNC1, DispVSync1); DispSwizzle = my_DispSwizzle; - Wr8( REG_SWIZZLE, DispSwizzle); + Wr8(REG_SWIZZLE, DispSwizzle); DispPCLKPol = my_DispPCLKPol; - Wr8( REG_PCLK_POL, DispPCLKPol); - Wr8( REG_CSPREAD, 0); + Wr8(REG_PCLK_POL, DispPCLKPol); + Wr8(REG_CSPREAD, 0); DispPCLK = my_DispPCLK; - Wr8( REG_PCLK, DispPCLK);//after this display is visible on the LCD + Wr8(REG_PCLK, DispPCLK); // After this display is visible on the LCD - Wr16( REG_PWM_HZ, 10000); + Wr16(REG_PWM_HZ, 10000); //#ifdef Inv_Backlite // turn on backlite -// Wr16( REG_PWM_DUTY, 0); +// Wr16(REG_PWM_DUTY, 0); //#else - Wr16( REG_PWM_DUTY, 127); + Wr16(REG_PWM_DUTY, 255); // Brightness 127 //#endif - Wr8( REG_GPIO_DIR,0x82); //| Rd8( REG_GPIO_DIR)); - Wr8( REG_GPIO,0x080); //| Rd8( REG_GPIO)); + Wr8(REG_GPIO_DIR, 0x82); //| Rd8(REG_GPIO_DIR)); + Wr8(REG_GPIO, 0x080); //| Rd8(REG_GPIO)); - Wr32( RAM_DL, CLEAR(1,1,1)); - Wr32( RAM_DL+4, DISPLAY()); - Wr32( REG_DLSWAP,1); + Wr32(RAM_DL, CLEAR(1, 1, 1)); + Wr32(RAM_DL+4, DISPLAY()); + Wr32(REG_DLSWAP, 1); - Wr16( REG_PCLK, DispPCLK); + Wr16(REG_PCLK, DispPCLK); - /* Touch configuration - configure the resistance value to 1200 - this value is specific to customer requirement and derived by experiment */ -// Wr16( REG_TOUCH_RZTHRESH,2400); - Wr16( REG_TOUCH_RZTHRESH,0xFFFF); - + /* Touch configuration - configure the resistance value to 1200 */ + /* This value is specific to customer requirement and derived by experiment */ +// Wr16(REG_TOUCH_RZTHRESH,2400); + Wr16(REG_TOUCH_RZTHRESH, 0xFFFF); } - - /* API to initialize the SPI interface */ -ft_bool_t FT800::Init() +ft_bool_t FT813::Init() { - // is done in constructor + // This is done in the constructor return 1; } - -ft_bool_t FT800::Open() +ft_bool_t FT813::Open() { cmd_fifo_wp = dl_buff_wp = 0; status = OPENED; return 1; } -ft_void_t FT800::Close( ) +ft_void_t FT813::Close() { status = CLOSED; } -ft_void_t FT800::DeInit() +ft_void_t FT813::DeInit() { - } /*The APIs for reading/writing transfer continuously only with small buffer system*/ -ft_void_t FT800::StartTransfer( FT_GPU_TRANSFERDIR_T rw,ft_uint32_t addr) +ft_void_t FT813::StartTransfer(FT_GPU_TRANSFERDIR_T rw, ft_uint32_t addr) { - if (FT_GPU_READ == rw){ + if (FT_GPU_READ == rw) { _ss = 0; // cs low _spi.write(addr >> 16); _spi.write(addr >> 8); _spi.write(addr & 0xff); _spi.write(0); //Dummy Read Byte status = READING; - }else{ + } else { _ss = 0; // cs low _spi.write(0x80 | (addr >> 16)); _spi.write(addr >> 8); @@ -175,110 +180,131 @@ /*The APIs for writing transfer continuously only*/ -ft_void_t FT800::StartCmdTransfer( FT_GPU_TRANSFERDIR_T rw, ft_uint16_t count) +ft_void_t FT813::StartCmdTransfer(FT_GPU_TRANSFERDIR_T rw, ft_uint16_t count) { - StartTransfer( rw, cmd_fifo_wp + RAM_CMD); + StartTransfer(rw, cmd_fifo_wp + RAM_CMD); } -ft_uint8_t FT800::TransferString( const ft_char8_t *string) +ft_uint8_t FT813::TransferString(const ft_char8_t *string) { ft_uint16_t length = strlen(string); - while(length --){ - Transfer8( *string); - string ++; + while(length --) { + Transfer8(*string); + string++; } //Append one null as ending flag - Transfer8( 0); + Transfer8(0); return(1); } -ft_uint8_t FT800::Transfer8( ft_uint8_t value) +ft_uint8_t FT813::Transfer8(ft_uint8_t value) { return _spi.write(value); } -ft_uint16_t FT800::Transfer16( ft_uint16_t value) +ft_uint16_t FT813::Transfer16(ft_uint16_t value) { ft_uint16_t retVal = 0; - if (status == WRITING){ - Transfer8( value & 0xFF);//LSB first - Transfer8( (value >> 8) & 0xFF); - }else{ - retVal = Transfer8( 0); - retVal |= (ft_uint16_t)Transfer8( 0) << 8; + if (status == WRITING) { + Transfer8(value & 0xFF);//LSB first + Transfer8((value >> 8) & 0xFF); + } else { + retVal = Transfer8(0); + retVal |= (ft_uint16_t)Transfer8(0) << 8; } return retVal; } -ft_uint32_t FT800::Transfer32( ft_uint32_t value) +ft_uint32_t FT813::Transfer32(ft_uint32_t value) { ft_uint32_t retVal = 0; - if (status == WRITING){ - Transfer16( value & 0xFFFF);//LSB first - Transfer16( (value >> 16) & 0xFFFF); - }else{ - retVal = Transfer16( 0); - retVal |= (ft_uint32_t)Transfer16( 0) << 16; + if (status == WRITING) { + Transfer16(value & 0xFFFF);//LSB first + Transfer16((value >> 16) & 0xFFFF); + } else { + retVal = Transfer16(0); + retVal |= (ft_uint32_t)Transfer16(0) << 16; } return retVal; } -ft_void_t FT800::EndTransfer( ) +ft_void_t FT813::EndTransfer() { _ss = 1; status = OPENED; } - -ft_uint8_t FT800::Rd8( ft_uint32_t addr) +ft_uint8_t FT813::Rd8(ft_uint32_t addr) { ft_uint8_t value; - StartTransfer( FT_GPU_READ,addr); - value = Transfer8( 0); - EndTransfer( ); + StartTransfer(FT_GPU_READ, addr); + value = Transfer8(0); + EndTransfer(); return value; } -ft_uint16_t FT800::Rd16( ft_uint32_t addr) + +ft_uint16_t FT813::Rd16(ft_uint32_t addr) { ft_uint16_t value; - StartTransfer( FT_GPU_READ,addr); - value = Transfer16( 0); - EndTransfer( ); + StartTransfer(FT_GPU_READ, addr); + value = Transfer16(0); + EndTransfer(); return value; } -ft_uint32_t FT800::Rd32( ft_uint32_t addr) + +ft_uint32_t FT813::Rd32(ft_uint32_t addr) { ft_uint32_t value; - StartTransfer( FT_GPU_READ,addr); - value = Transfer32( 0); - EndTransfer( ); + StartTransfer(FT_GPU_READ, addr); + value = Transfer32(0); + EndTransfer(); return value; } -ft_void_t FT800::Wr8( ft_uint32_t addr, ft_uint8_t v) -{ - StartTransfer( FT_GPU_WRITE,addr); - Transfer8( v); - EndTransfer( ); -} -ft_void_t FT800::Wr16( ft_uint32_t addr, ft_uint16_t v) +ft_void_t FT813::Wr8(ft_uint32_t addr, ft_uint8_t v) { - StartTransfer( FT_GPU_WRITE,addr); - Transfer16( v); - EndTransfer( ); -} -ft_void_t FT800::Wr32( ft_uint32_t addr, ft_uint32_t v) -{ - StartTransfer( FT_GPU_WRITE,addr); - Transfer32( v); - EndTransfer( ); +// StartTransfer(FT_GPU_WRITE, addr); +// if (FT_GPU_READ == rw) { // if (FT_GPU_READ == FT_GPU_WRITE) +// _ss = 0; // cs low +// _spi.write(addr >> 16); +// _spi.write(addr >> 8); +// _spi.write(addr & 0xff); +// _spi.write(0); //Dummy Read Byte +// status = READING; +// } else { + _ss = 0; // cs low + _spi.write(0x80 | (addr >> 16)); + _spi.write(addr >> 8); + _spi.write(addr & 0xff); + status = WRITING; +// } + +// Transfer8(v); + _spi.write(v); +// EndTransfer(); + _ss = 1; + status = OPENED; } -ft_void_t FT800::HostCommand( ft_uint8_t cmd) +ft_void_t FT813::Wr16(ft_uint32_t addr, ft_uint16_t v) +{ + StartTransfer(FT_GPU_WRITE, addr); + Transfer16(v); + EndTransfer(); +} + +ft_void_t FT813::Wr32(ft_uint32_t addr, ft_uint32_t v) +{ + StartTransfer(FT_GPU_WRITE, addr); + Transfer32(v); + EndTransfer(); +} + +ft_void_t FT813::HostCommand(ft_uint8_t cmd) { _ss = 0; _spi.write(cmd); @@ -287,247 +313,236 @@ _ss = 1; } -ft_void_t FT800::ClockSelect( FT_GPU_PLL_SOURCE_T pllsource) +ft_void_t FT813::ClockSelect(FT_GPU_PLL_SOURCE_T pllsource) { - HostCommand( pllsource); + HostCommand(pllsource); } -ft_void_t FT800::PLL_FreqSelect( FT_GPU_PLL_FREQ_T freq) +ft_void_t FT813::PLL_FreqSelect(FT_GPU_PLL_FREQ_T freq) { - HostCommand( freq); + HostCommand(freq); } -ft_void_t FT800::PowerModeSwitch( FT_GPU_POWER_MODE_T pwrmode) +ft_void_t FT813::PowerModeSwitch(FT_GPU_POWER_MODE_T pwrmode) { - HostCommand( pwrmode); + HostCommand(pwrmode); } -ft_void_t FT800::CoreReset( ) +ft_void_t FT813::CoreReset() { - HostCommand( 0x68); + HostCommand(0x68); } - -ft_void_t FT800::Updatecmdfifo( ft_uint16_t count) +ft_void_t FT813::Updatecmdfifo(ft_uint16_t count) { - cmd_fifo_wp = ( cmd_fifo_wp + count) & 4095; + cmd_fifo_wp = (cmd_fifo_wp + count) & 4095; //4 byte alignment - cmd_fifo_wp = ( cmd_fifo_wp + 3) & 0xffc; - Wr16( REG_CMD_WRITE, cmd_fifo_wp); + cmd_fifo_wp = (cmd_fifo_wp + 3) & 0xffc; + Wr16(REG_CMD_WRITE, cmd_fifo_wp); } - -ft_uint16_t FT800::fifo_Freespace( ) +ft_uint16_t FT813::fifo_Freespace() { ft_uint16_t fullness,retval; - fullness = ( cmd_fifo_wp - Rd16( REG_CMD_READ)) & 4095; + fullness = (cmd_fifo_wp - Rd16(REG_CMD_READ)) & 4095; retval = (FT_CMD_FIFO_SIZE - 4) - fullness; return (retval); } -ft_void_t FT800::WrCmdBuf( ft_uint8_t *buffer,ft_uint16_t count) +ft_void_t FT813::WrCmdBuf(ft_uint8_t *buffer, ft_uint16_t count) { ft_uint32_t length =0, SizeTransfered = 0; -#define MAX_CMD_FIFO_TRANSFER fifo_Freespace( ) +#define MAX_CMD_FIFO_TRANSFER fifo_Freespace() do { length = count; - if (length > MAX_CMD_FIFO_TRANSFER){ + if (length > MAX_CMD_FIFO_TRANSFER) { length = MAX_CMD_FIFO_TRANSFER; } - CheckCmdBuffer( length); + CheckCmdBuffer(length); - StartCmdTransfer( FT_GPU_WRITE,length); + StartCmdTransfer(FT_GPU_WRITE, length); - SizeTransfered = 0; + SizeTransfered = 0; while (length--) { - Transfer8( *buffer); - buffer++; - SizeTransfered ++; +// Transfer8(*buffer); + _spi.write(*buffer); + buffer++; + SizeTransfered++; } - length = SizeTransfered; + length = SizeTransfered; - EndTransfer( ); - Updatecmdfifo( length); + EndTransfer(); + Updatecmdfifo(length); - WaitCmdfifo_empty( ); + WaitCmdfifo_empty(); count -= length; - }while (count > 0); + } while (count > 0); } - -ft_void_t FT800::WrCmdBufFromFlash( FT_PROGMEM ft_prog_uchar8_t *buffer,ft_uint16_t count) +ft_void_t FT813::WrCmdBufFromFlash(FT_PROGMEM ft_prog_uchar8_t *buffer, ft_uint16_t count) { ft_uint32_t length =0, SizeTransfered = 0; -#define MAX_CMD_FIFO_TRANSFER fifo_Freespace( ) +#define MAX_CMD_FIFO_TRANSFER fifo_Freespace() do { length = count; - if (length > MAX_CMD_FIFO_TRANSFER){ + if (length > MAX_CMD_FIFO_TRANSFER) { length = MAX_CMD_FIFO_TRANSFER; } - CheckCmdBuffer( length); + CheckCmdBuffer(length); - StartCmdTransfer( FT_GPU_WRITE,length); + StartCmdTransfer(FT_GPU_WRITE,length); - - SizeTransfered = 0; + SizeTransfered = 0; while (length--) { - Transfer8( ft_pgm_read_byte_near(buffer)); + Transfer8(ft_pgm_read_byte_near(buffer)); buffer++; - SizeTransfered ++; + SizeTransfered++; } - length = SizeTransfered; + length = SizeTransfered; - EndTransfer( ); - Updatecmdfifo( length); + EndTransfer(); + Updatecmdfifo(length); - WaitCmdfifo_empty( ); + WaitCmdfifo_empty(); count -= length; - }while (count > 0); + } while (count > 0); } - -ft_void_t FT800::CheckCmdBuffer( ft_uint16_t count) +ft_void_t FT813::CheckCmdBuffer(ft_uint16_t count) { ft_uint16_t getfreespace; - do{ - getfreespace = fifo_Freespace( ); - }while(getfreespace < count); + do { + getfreespace = fifo_Freespace(); + } while(getfreespace < count); } -ft_void_t FT800::WaitCmdfifo_empty( ) +ft_void_t FT813::WaitCmdfifo_empty() { - while(Rd16( REG_CMD_READ) != Rd16( REG_CMD_WRITE)); + while(Rd16(REG_CMD_READ) != Rd16(REG_CMD_WRITE)); - cmd_fifo_wp = Rd16( REG_CMD_WRITE); + cmd_fifo_wp = Rd16(REG_CMD_WRITE); } -ft_void_t FT800::WaitLogo_Finish( ) +ft_void_t FT813::WaitLogo_Finish() { - ft_int16_t cmdrdptr,cmdwrptr; + ft_int16_t cmdrdptr, cmdwrptr; - do{ - cmdrdptr = Rd16( REG_CMD_READ); - cmdwrptr = Rd16( REG_CMD_WRITE); - }while ((cmdwrptr != cmdrdptr) || (cmdrdptr != 0)); - cmd_fifo_wp = 0; + do { + cmdrdptr = Rd16(REG_CMD_READ); + cmdwrptr = Rd16(REG_CMD_WRITE); + } while ((cmdwrptr != cmdrdptr) || (cmdrdptr != 0)); + cmd_fifo_wp = 0; } - -ft_void_t FT800::ResetCmdFifo( ) +ft_void_t FT813::ResetCmdFifo() { cmd_fifo_wp = 0; } - -ft_void_t FT800::WrCmd32( ft_uint32_t cmd) +ft_void_t FT813::WrCmd32(ft_uint32_t cmd) { - CheckCmdBuffer( sizeof(cmd)); + CheckCmdBuffer(sizeof(cmd)); - Wr32( RAM_CMD + cmd_fifo_wp,cmd); + Wr32(RAM_CMD + cmd_fifo_wp, cmd); - Updatecmdfifo( sizeof(cmd)); + Updatecmdfifo(sizeof(cmd)); } - -ft_void_t FT800::ResetDLBuffer( ) +ft_void_t FT813::ResetDLBuffer() { - dl_buff_wp = 0; + dl_buff_wp = 0; } -/* Toggle PD_N pin of FT800 board for a power cycle*/ -ft_void_t FT800::Powercycle( ft_bool_t up) +/* Toggle PD_N pin of FT813 board for a power cycle*/ +ft_void_t FT813::Powercycle(ft_bool_t up) { if (up) { - //Toggle PD_N from low to high for power up switch - _pd = 0; - Sleep(20); + //Toggle PD_N from low to high for power up switch + _pd = 0; + Sleep(20); - _pd = 1; - Sleep(20); - }else - { - //Toggle PD_N from high to low for power down switch - _pd = 1; - Sleep(20); + _pd = 1; + Sleep(20); + } else { + //Toggle PD_N from high to low for power down switch + _pd = 1; + Sleep(20); - _pd = 0; - Sleep(20); + _pd = 0; + Sleep(20); } } -ft_void_t FT800::WrMemFromFlash( ft_uint32_t addr,const ft_prog_uchar8_t *buffer, ft_uint32_t length) +ft_void_t FT813::WrMemFromFlash(ft_uint32_t addr, const ft_prog_uchar8_t *buffer, ft_uint32_t length) { //ft_uint32_t SizeTransfered = 0; - StartTransfer( FT_GPU_WRITE,addr); + StartTransfer(FT_GPU_WRITE,addr); while (length--) { - Transfer8( ft_pgm_read_byte_near(buffer)); + Transfer8(ft_pgm_read_byte_near(buffer)); buffer++; } - EndTransfer( ); + EndTransfer(); } -ft_void_t FT800::WrMem( ft_uint32_t addr,const ft_uint8_t *buffer, ft_uint32_t length) +ft_void_t FT813::WrMem(ft_uint32_t addr, const ft_uint8_t *buffer, ft_uint32_t length) { //ft_uint32_t SizeTransfered = 0; - StartTransfer( FT_GPU_WRITE,addr); + StartTransfer(FT_GPU_WRITE,addr); while (length--) { - Transfer8( *buffer); + Transfer8(*buffer); buffer++; } - EndTransfer( ); + EndTransfer(); } - -ft_void_t FT800::RdMem( ft_uint32_t addr, ft_uint8_t *buffer, ft_uint32_t length) +ft_void_t FT813::RdMem(ft_uint32_t addr, ft_uint8_t *buffer, ft_uint32_t length) { //ft_uint32_t SizeTransfered = 0; - StartTransfer( FT_GPU_READ,addr); + StartTransfer(FT_GPU_READ,addr); while (length--) { - *buffer = Transfer8( 0); + *buffer = Transfer8(0); buffer++; } - EndTransfer( ); + EndTransfer(); } -ft_int32_t FT800::Dec2Ascii(ft_char8_t *pSrc,ft_int32_t value) +ft_int32_t FT813::Dec2Ascii(ft_char8_t *pSrc, ft_int32_t value) { ft_int16_t Length; - ft_char8_t *pdst,charval; - ft_int32_t CurrVal = value,tmpval,i; - ft_char8_t tmparray[16],idx = 0; + ft_char8_t *pdst, charval; + ft_int32_t CurrVal = value, tmpval,i; + ft_char8_t tmparray[16], idx = 0; Length = strlen(pSrc); pdst = pSrc + Length; - if(0 == value) - { + if(0 == value) { *pdst++ = '0'; *pdst++ = '\0'; return 0; } - if(CurrVal < 0) - { + if(CurrVal < 0) { *pdst++ = '-'; CurrVal = - CurrVal; } /* insert the value */ - while(CurrVal > 0){ + while(CurrVal > 0) { tmpval = CurrVal; CurrVal /= 10; tmpval = tmpval - CurrVal*10; @@ -535,8 +550,7 @@ tmparray[idx++] = charval; } - for(i=0;i<idx;i++) - { + for(i = 0; i < idx; i++) { *pdst++ = tmparray[idx - i - 1]; } *pdst++ = '\0'; @@ -544,20 +558,17 @@ return 0; } - -ft_void_t FT800::Sleep(ft_uint16_t ms) +ft_void_t FT813::Sleep(ft_uint16_t ms) { wait_ms(ms); } -ft_void_t FT800::Sound_ON(){ - Wr8( REG_GPIO, 0x02 | Rd8( REG_GPIO)); +ft_void_t FT813::Sound_ON() +{ + Wr8(REG_GPIO, 0x02 | Rd8(REG_GPIO)); } -ft_void_t FT800::Sound_OFF(){ - Wr8( REG_GPIO, 0xFD & Rd8( REG_GPIO)); +ft_void_t FT813::Sound_OFF() +{ + Wr8(REG_GPIO, 0xFD & Rd8(REG_GPIO)); } - - - -
diff -r ca6a7c6a2f4b -r 6a81aeca25e3 src/FT_Hal_Utils.cpp --- a/src/FT_Hal_Utils.cpp Thu Dec 22 20:19:22 2016 +0000 +++ b/src/FT_Hal_Utils.cpp Mon Jul 23 12:22:23 2018 +0000 @@ -2,65 +2,891 @@ #include "mbed.h" //#include "SDFileSystem.h" +#define DEBUG + +/* meta-commands, sequences of several display-list entries condensed into simpler to use functions at the price of some overhead */ + +ft_void_t FT813::Point(ft_int16_t x, ft_int16_t y, ft_uint16_t size) +{ + ft_uint32_t calc; + + StartFunc(FT_CMD_SIZE*4); + SendCmd(DL_BEGIN | FT8_POINTS); + calc = POINT_SIZE(size*16); + SendCmd(calc); + calc = VERTEX2F(x * 16, y * 16); + SendCmd(calc); + SendCmd(DL_END); + EndFunc(); +} + +ft_void_t FT813::Line(ft_int16_t x0, ft_int16_t y0, ft_int16_t x1, ft_int16_t y1, ft_int16_t width) +{ + ft_uint32_t calc; + + StartFunc(FT_CMD_SIZE*5); + SendCmd(DL_BEGIN | FT8_LINES); + calc = LINE_WIDTH(width * 16); + SendCmd(calc); + calc = VERTEX2F(x0 * 16, y0 * 16); + SendCmd(calc); + calc = VERTEX2F(x1 * 16, y1 * 16); + SendCmd(calc); + SendCmd(DL_END); + EndFunc(); +} + +ft_void_t FT813::Rect(ft_int16_t x0, ft_int16_t y0, ft_int16_t x1, ft_int16_t y1, ft_int16_t corner) +{ + ft_uint32_t calc; + + StartFunc(FT_CMD_SIZE*5); + SendCmd(DL_BEGIN | FT8_RECTS); + calc = LINE_WIDTH(corner * 16); + SendCmd(calc); + calc = VERTEX2F(x0 * 16, y0 * 16); + SendCmd(calc); + calc = VERTEX2F(x1 * 16, y1 * 16); + SendCmd(calc); + SendCmd(DL_END); + EndFunc(); +} + +ft_void_t FT813::RectWH(ft_int16_t x0, ft_int16_t y0, ft_int16_t w, ft_int16_t h, ft_int16_t corner) +{ + ft_uint32_t calc; + x0 += corner; + y0 += corner; + w -= corner*2; + h -= corner*2; + ft_int16_t x1 = x0 + w; + ft_int16_t y1 = y0 + h; + StartFunc(FT_CMD_SIZE*5); + SendCmd(DL_BEGIN | FT8_RECTS); + calc = LINE_WIDTH(corner * 16); + SendCmd(calc); + calc = VERTEX2F(x0 * 16, y0 * 16); + SendCmd(calc); + calc = VERTEX2F(x1 * 16, y1 * 16); + SendCmd(calc); + SendCmd(DL_END); + EndFunc(); +} + +/* Function to load JPG file from the filesystem into the FT800 buffer. */ +/* First the graphics data have to be load into the FT800 buffer. */ +/* The FT800 will decode the JPG data into a bitmap. */ +/* In the second step this bitmap will displayed on the LCD. */ +/* return 0 if jpg is ok */ +/* return x_size and y_size of jpg */ +ft_uint8_t FT813::LoadJpg(char* filename, ft_int16_t* x_size, ft_int16_t* y_size) +{ +// unsigned char pbuff[8192]; + int bufferSize = 8192; +// void* pbuff; + char* pbuff = (char*)malloc(bufferSize); +// char pbuff[BUFFER_SIZE] = {0}; + unsigned short marker; + unsigned short length; + unsigned char data[4]; + + ft_uint16_t blocklen; + +// printf("LoadJpg: Open filename \"%s\".\n", filename); + + FILE *fp = fopen(filename, "rb"); + if(fp == NULL) { + free(pbuff); + printf("LoadJpg: Cannot open file \"%s\".\n", filename); + return (-1); // cannot open file + } + + // https://en.wikipedia.org/wiki/JPEG + // search for 0xFFC0 marker + fseek(fp, 0, SEEK_END); + unsigned int filesize = ftell(fp); + printf("LoadJpg: Size: %d.\n", filesize); + + fseek(fp, 2, SEEK_SET); // Beginning of file + fread(data, 4, 1, fp); // Read first 4 bytes + marker = data[0] << 8 | data[1]; + length = data[2] << 8 | data[3]; + do { + if(marker == 0xFFC0) + break; + if(marker & 0xFF00 != 0xFF00) + break; + if (fseek(fp, length - 2,SEEK_CUR) != 0) // Skip marker + break; + fread(data, 4, 1, fp); + marker = data[0] << 8 | data[1]; + length = data[2] << 8 | data[3]; + } while(1); + + if(marker != 0xFFC0) { + free(pbuff); + printf("LoadJpg: marker != 0xFFC0\n"); + return (-2); // No FFC0 Marker, wrong format no baseline DCT-based JPEG + } + + fseek(fp, 1, SEEK_CUR); // Skip marker + fread(data, 8, 1, fp); // Read next 8 bytes & extract height & width + *y_size = (data[0] << 8 | data[1]); + *x_size = (data[2] << 8 | data[3]); + uint16_t size_y = (data[0] << 8 | data[1]); + uint16_t size_x = (data[2] << 8 | data[3]); + + uint16_t disp_x = DispWidth; + uint16_t disp_y = DispHeight; + if ((_orientation == FT8_DISPLAY_PORTRAIT_90CW) || (_orientation == FT8_DISPLAY_PORTRAIT_90CCW)) { + disp_x = DispHeight; + disp_y = DispWidth; + } + +// http://www.ftdichip.com/Support/Documents/AppNotes/AN_339%20Using%20JPEGs%20with%20the%20FT800%20series.pdf, page 11 +// if (marker_next_byte[0] == 0xC2){ //check if progressive JPEG +// error_code = 3; +// } + +// if(*x_size > TFT.FT_DispWidth || *y_size > TFT.FT_DispHeight) return (-3); // to big to fit on screen + if(*x_size > disp_x || *y_size > disp_y) + { + free(pbuff); + printf("LoadJpg: Too big to fit on screen\n"); + printf("LoadJpg: JPG (%dx%d) does not fit on TFT (%dx%d)\n", *x_size, *y_size, DispWidth, DispHeight); + return (-3); // Too big to fit on screen + } + +// printf("LoadJpg: JPG (%dx%d) fits on TFT (%dx%d)\n", *x_size, *y_size, DispWidth, DispHeight); + + fseek(fp, 0, SEEK_SET); + + + WrCmd32(CMD_LOADIMAGE); + WrCmd32(_address); //destination address of jpg decode + + // Keep track of of the start addresses of loaded images + // Increment _address + _addresses[_bitmap_count] = _address; + _bitmap_count++; + _address += (uint32_t) (size_x * size_y * 2); + _addresses[_bitmap_count] = _address; + // 0 OPT_RGB565 + // 1 OPT_MONO + // 2 OPT_NODL + // 256 OPT_FLAT + // 256 OPT_SIGNED + // 512 OPT_CENTERX + // 1024 OPT_CENTERY + // 1536 OPT_CENTER + // 2048 OPT_RIGHTX + // 4096 OPT_NOBACK + // 8192 OPT_NOTICKS + WrCmd32(0); //output format of the bitmap - default is rgb565 + while(filesize > 0) { + /* download the data into the command buffer by 8kb one shot */ + blocklen = filesize > bufferSize ? bufferSize : filesize; +// printf("LoadJpg: blocklen: %d\n", blocklen); +// printf("LoadJpg: filesize: %d\n", filesize); + + /* copy the data into pbuff and then transfter it to command buffer */ +// int size = fread(&pbuff[0], 1, blocklen, fp); + int size = fread(pbuff, 1, blocklen, fp); +// printf("LoadJpg: fread: %d, %d\n", blocklen, size); + filesize -= blocklen; + /* copy data continuously into command memory */ +// TFT.Ft_Gpu_Hal_WrCmdBuf(pbuff, blocklen); //alignment is already taken care by this api + WrCmdBuf((uint8_t *)pbuff, blocklen); //alignment is already taken care by this api + } + fclose(fp); + free(pbuff); + + return(0); +} + +ft_uint8_t FT813::LoadPng(char* filename, ft_int16_t* x_size, ft_int16_t* y_size) +{ + int bufferSize = 8192; + ft_uint32_t filesize = 0; + ft_uint16_t blocklen = 0; + uint32_t marker1; + uint32_t marker2; + unsigned short length; + unsigned char data[32]; + +// printf("------------------------------\n"); + printf("LoadPng: Filename \"%s\".\n", filename); + + FILE *fp = fopen(filename, "rb"); + if(fp == NULL) { + printf("LoadPng: Cannot open file \"%s\".\n", filename); + return (-1); // cannot open file + } + + // Get file size + fseek(fp, 0, SEEK_END); // End of file + filesize = ftell(fp); + fseek(fp, 0, SEEK_SET); // Beginning of file + printf("LoadPng: Filesize %d\n", filesize); + + // search for 0x89504E47 and 0x0D0A1A0A markers "‰PNG...." + fread(data, 1, 32, fp); // Read first 32 bytes +// rewind(fp); // Beginning of file + fseek(fp, 0, SEEK_SET); // Beginning of file + + // Check that this is indeed a PNG file + unsigned char png_header[] = {0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A}; + // Make sure you have an IHDR + unsigned char ihdr_name[] = "IHDR"; + if ((memcmp(data, png_header, 8)) || (memcmp(data+8+4, ihdr_name, 4))) { + printf("LoadPng: Invalid PNG file.\n"); + return (-2); // No FFC0 Marker, wrong format no baseline DCT-based JPEG + } + + // PNG actually stores integers in big-endian. + *x_size = ReadBigInt32(data, 24 - 8); + *y_size = ReadBigInt32(data, 24 - 4); + uint16_t size_x = ReadBigInt32(data, 24 - 8); + uint16_t size_y = ReadBigInt32(data, 24 - 4); + + uint16_t disp_x = DispWidth; + uint16_t disp_y = DispHeight; + if ((_orientation == FT8_DISPLAY_PORTRAIT_90CW) || (_orientation == FT8_DISPLAY_PORTRAIT_90CCW)) { + disp_x = DispHeight; + disp_y = DispWidth; + } + + if(*x_size > disp_x || *y_size > disp_y) + { + printf("LoadPng: Too big to fit on screen\n"); + printf("LoadPng: PNG (%dx%d) does not fit on TFT (%dx%d)\n", *x_size, *y_size, DispWidth, DispHeight); + return (-3); // Too big to fit on screen + } + +// printf("LoadPng: PNG (%dx%d) fits on TFT (%dx%d)\n", *x_size, *y_size, DispWidth, DispHeight); + + // http://www.ftdichip.com/Support/Documents/AppNotes/AN_339%20Using%20JPEGs%20with%20the%20FT800%20series.pdf + // CMD_LOADIMAGE: This function will decode the JPEG file, produce + // either RGB565 or L8 bitmap data and store this in graphics RAM. + // It also writes commands to the display list to set the source, layout and size of the + // image (BITMAP_SOURCE, BITMAP_LAYOUT and BITMAP_SIZE). + // Note that only a BEGIN and VERTEX2F (or VERTEX2II) display list commands are then + // required to complete the display list needed to render the image. + WrCmd32(CMD_LOADIMAGE); + WrCmd32(_address); //destination address of png decode + // 0 OPT_RGB565 + // 1 OPT_MONO + // 2 OPT_NODL + // 256 OPT_FLAT + // 256 OPT_SIGNED + // 512 OPT_CENTERX + // 1024 OPT_CENTERY + // 1536 OPT_CENTER + // 2048 OPT_RIGHTX + // 4096 OPT_NOBACK + // 8192 OPT_NOTICKS + // By default, option OPT_RGB565 means the loaded bitmap is in RGB565 format. + + // Keep track of of the start addresses of loaded images + // Increment _address + _addresses[_bitmap_count] = _address; + _bitmap_count++; + _address += (uint32_t) (size_x * size_y * 2); + _addresses[_bitmap_count] = _address; + printf("LoadPng: Bitmap# %d, Res. %dx%d, Address %d-%d\n", _bitmap_count - 1, *x_size, *y_size, _addresses[_bitmap_count-1], _addresses[_bitmap_count]); + + WrCmd32(OPT_RGB565); // Output format of the bitmap OPT_RGB565 +// unsigned int filesizeCounter = filesize; + char* pbuff = (char*)malloc(bufferSize); + while(filesize > 0) { + blocklen = filesize > bufferSize ? bufferSize : filesize; + int size = fread(pbuff, 1, blocklen, fp); + filesize -= blocklen; + + WrCmdBuf((uint8_t *)pbuff, blocklen); //alignment is already taken care by this api + } + fclose(fp); + // If the number of bytes in the JPEG file to be written to the command buffer is not a multiple of + // four, then one, two or three bytes (of any value) should be added to ensure four-byte alignment of + // the next command. +// blocklen = filesize % 4; +// memset(pbuff, 0, blocklen); +// WrCmdBuf((uint8_t *)pbuff, blocklen); //alignment is already taken care by this api + + free(pbuff); + + printf("LoadPng: Done.\n"); + + return(0); +} + +int FT813::LoadRaw(char* filename) +{ + ft_uint16_t filesize = 0; + ft_uint16_t blocklen; + ft_uint16_t ram_start = _address; + int bufferSize = 8192; + + FILE *fp = fopen(filename, "rb"); // open file + if (fp == NULL) + { + // Cannot open file + printf("Unable to open: %s\n", filename); + return -1; + } + fseek(fp, 0, SEEK_END); // set file position to end of file + filesize = ftell(fp); // determine file size + fseek(fp, 0, SEEK_SET); // return to beginning of file + + // Keep track of of the start addresses of loaded images + // Increment _address + _addresses[_bitmap_count] = _address; + _bitmap_count++; + _address += (uint32_t) filesize; + _addresses[_bitmap_count] = _address; + printf("LoadRaw: Bitmap# %d, Address %d-%d\n", _bitmap_count - 1, _addresses[_bitmap_count-1], _addresses[_bitmap_count]); + + char* pbuff = (char*)malloc(bufferSize); + while(filesize > 0) + { + //copy the .raw file data to pbuff[8192] in 8k block + blocklen = filesize > bufferSize ? bufferSize : filesize; + fread(pbuff, 1, blocklen, fp); + filesize -= blocklen; + //write pbuff contents to graphics RAM at address ram_start = 0x00 + Wr8s(ram_start, (uint8_t *)pbuff, blocklen); //alignment is already taken care by this api + ram_start += blocklen; + } + fclose(fp); + free(pbuff); + return 0; +} + +int FT813::LoadRawFile(ft_uint32_t address, const char *filename) +{ + int bufferSize = 8192; + ft_uint32_t filesize = 0; + ft_uint16_t blocklen = 0; + + _address = address; + ft_uint32_t addr = address; + + FILE *fp = fopen(filename, "rb"); + if (fp == NULL) + { + printf("LoadRawFile: Cannot open file \"%s\".\n", filename); + return 0; + } + fseek(fp, 0, SEEK_END); // End of file + filesize = ftell(fp); + fseek(fp, 0, SEEK_SET); // Beginning of file + + // Keep track of of the start addresses of loaded images + // Increment _address + _addresses[_bitmap_count] = _address; + _bitmap_count++; + _address += (uint32_t) filesize; + _addresses[_bitmap_count] = _address; + printf("LoadRawFile: Bitmap# %d, Address %d-%d\n", _bitmap_count - 1, _addresses[_bitmap_count-1], _addresses[_bitmap_count]); + + char* pbuff = (char*)malloc(bufferSize); + while (filesize > 0) + { + blocklen = filesize > bufferSize ? bufferSize : filesize; + fread(pbuff, 1, blocklen, fp); + filesize -= blocklen; + WrMem(addr, (ft_uint8_t *)pbuff, blocklen); + addr += blocklen; +// WrCmdBuf((ft_uint8_t *)pbuff, blocklen); //alignment is already taken care by this api + } + fclose(fp); + free(pbuff); + + printf("LoadRawFile: Done.\n"); + return 1; +} + +int FT813::LoadInflateFile(ft_uint32_t address, const char *filename) +{ + int bufferSize = 8192; + ft_uint32_t filesize = 0; + ft_uint16_t blocklen = 0; + ft_uint32_t addr = address; + ft_uint32_t filesize_org = address; + + _address = address; + + FILE *fp = fopen(filename, "rb"); // read Binary (rb) + if (fp == NULL) + { + printf("LoadInflateFile: Cannot open file \"%s\".\n", filename); + return 0; + } + fseek(fp, 0, SEEK_END); // End of file + filesize = ftell(fp); + fseek(fp, 0, SEEK_SET); // Beginning of file + + // Keep track of of the start addresses of loaded images + // Increment _address + _addresses[_bitmap_count] = _address; + _bitmap_count++; +// _address += (uint32_t) 0; + _addresses[_bitmap_count] = _address; +// printf("# %d, Addr %d\n", _bitmap_count - 1, _addresses[_bitmap_count-1]); + + WrCmd32(CMD_INFLATE); + WrCmd32(address); //destination address of bin decode + + char* pbuff = (char*)malloc(bufferSize); + while (filesize > 0) + { + blocklen = filesize > bufferSize ? bufferSize : filesize; + int size = fread(pbuff, 1, blocklen, fp); /* copy the data into pbuff and then transfter it to command buffer */ + filesize -= blocklen; + +// WrMem(addr, (ft_uint8_t *)pbuff, blocklen); +// addr += blocklen; + + //Do not call "Ft_Gpu_Hal_WrCmdBuf_nowait" because it may cause emulator process hang. + WrCmdBuf((ft_uint8_t *)pbuff, blocklen); //alignment is already taken care by this api +// WaitCmdfifo_empty(); + } + // If the number of bytes in the JPEG file to be written to the command buffer is not a multiple of + // four, then one, two or three bytes (of any value) should be added to ensure four-byte alignment of + // the next command. +// blocklen = filesize_org % 4; +// memset(pbuff, 0, blocklen); +// WrMem(addr, (ft_uint8_t *)pbuff, blocklen); +// WrCmdBuf((uint8_t *)pbuff, blocklen); //alignment is already taken care by this api + +// WaitCmdfifo_empty(); + + fclose(fp); /* close the opened jpg file */ + free(pbuff); + return 1; +} + +int FT813::LoadImageFile(ft_uint32_t address, const char *filename) +{ + int bufferSize = 8192; + ft_uint32_t filesize = 0; + ft_uint16_t blocklen = 0; + + _address = address; + + FILE *fp = fopen(filename, "rb"); // read Binary (rb) + if (fp == NULL) + { + printf("LoadImageFile: Cannot open file \"%s\".\n", filename); + return 0; + } + // TODO: Let it write into the scratch display list handle, + // and read it out and write into the bitmapInfo the proper + // values to use. Replace compressed bool with uint8 enum to + // specify the loading mechanism + fseek(fp, 0, SEEK_END); // End of file + filesize = ftell(fp); + fseek(fp, 0, SEEK_SET); // Beginning of file + + // Keep track of of the start addresses of loaded images + // Increment _address + _addresses[_bitmap_count] = _address; + _bitmap_count++; + _address += (uint32_t) filesize; + _addresses[_bitmap_count] = _address; + printf("LoadImageFile: Bitmap# %d, Address %d-%d\n", _bitmap_count - 1, _addresses[_bitmap_count-1], _addresses[_bitmap_count]); + + WrCmd32(CMD_LOADIMAGE); + WrCmd32(address); //destination address of png decode + // 0 OPT_RGB565 + // 1 OPT_MONO + // 2 OPT_NODL + // 256 OPT_FLAT + // 256 OPT_SIGNED + // 512 OPT_CENTERX + // 1024 OPT_CENTERY + // 1536 OPT_CENTER + // 2048 OPT_RIGHTX + // 4096 OPT_NOBACK + // 8192 OPT_NOTICKS + // By default, option OPT_RGB565 means the loaded bitmap is in RGB565 format. + WrCmd32(OPT_RGB565); // Output format of the bitmap OPT_RGB565 +// WrCmd32(OPT_NODL); + char* pbuff = (char*)malloc(bufferSize); + while (filesize > 0) + { + blocklen = filesize > bufferSize ? bufferSize : filesize; + int size = fread(pbuff, 1, blocklen, fp); /* copy the data into pbuff and then transfter it to command buffer */ + filesize -= blocklen; +// blocklen += 3; +// blocklen -= blocklen % 4; + + //Do not call "Ft_Gpu_Hal_WrCmdBuf_nowait" because it may cause emulator process hang. + WrCmdBuf((ft_uint8_t *)pbuff, blocklen); //alignment is already taken care by this api + } +// WaitCmdfifo_empty(); + + fclose(fp); /* close the opened jpg file */ + free(pbuff); + return 1; +} + +ft_void_t FT813::SetEndAddressForSize(ft_uint32_t addr) +{ + _addresses[_bitmap_count] = _addresses[_bitmap_count - 1] + addr; +} + +ft_void_t FT813::Wr8s(ft_uint32_t addr, ft_uint8_t *buffer, ft_uint8_t length) +{ +// StartTransfer(FT_GPU_WRITE, addr); +// if (FT_GPU_READ == rw) { // if (FT_GPU_READ == FT_GPU_WRITE) +// _ss = 0; // cs low +// _spi.write(addr >> 16); +// _spi.write(addr >> 8); +// _spi.write(addr & 0xff); +// _spi.write(0); //Dummy Read Byte +// status = READING; +// } else { + _ss = 0; // cs low + _spi.write(0x80 | (addr >> 16)); + _spi.write(addr >> 8); + _spi.write(addr & 0xff); + status = WRITING; +// } + +// Transfer8(v); +// _spi.write(v); + + while (length--) { +// Transfer8(*buffer); + _spi.write(*buffer); + buffer++; +// SizeTransfered++; + } + +// EndTransfer(); + _ss = 1; + status = OPENED; +} + +//{ +//ft_uint8_t imbuff[8192]; +//ft_uint16_t blocklen; +////decompress the .bin file using CMD_INFLATE +//WrCmd32(phost,CMD_INFLATE); +////specify starting address in graphics RAM +//WrCmd32(phost,0L); +////check filesize and adjust number of bytes to multiple of 4 +//chdir("..\\..\\..\\Test"); //change directory to location (Test) of .bin file +//pfile = fopen("lenaface40.bin","rb"); +//fseek(pfile,0,SEEK_END); //set file position to end of file +//filesize = ftell(pfile); // determine file size +//fseek(pfile,0,SEEK_SET); // return to beginning of file +//while(filesize > 0) +//{ +// //copy the .raw file data to imbuff[8192] in 8k blocks +//blocklen = filesize>8192?8192:filesize; +//fread(imbuff,1,blocklen,pfile); +//filesize -= blocklen; //reduce filesize by blocklen +////write imbuff contents to the FT800 FIFO command buffer +//Ft_Gpu_Hal_WrCmdBuf(phost,imbuff,blocklen); +//} +//fclose(pfile); /* close the opened .bin file */ +//} + +int FT813::LoadRawFile(ft_uint32_t address, char* filename) +{ + ft_uint16_t filesize; + ft_uint16_t blocklen; + ft_uint32_t addr = address; + int bufferSize = 8192; + + FILE *fp = fopen(filename, "rb"); // open file + if (fp == NULL) + { + // Cannot open file + printf("Unable to open: %s\n", filename); + return -1; + } + fseek(fp, 0, SEEK_END); // set file position to end of file + filesize = ftell(fp); // determine file size + fseek(fp, 0, SEEK_SET); // return to beginning of file +#ifdef DEBUG + printf("LoadRawFile: %s %d @ %d\n", filename, filesize, address); +#endif + + char* pbuff = (char*)malloc(bufferSize); + while(filesize > 0) + { + //copy the .raw file data to pbuff[8192] in 8k block + blocklen = filesize > bufferSize ? bufferSize : filesize; + fread(pbuff, 1, blocklen, fp); + filesize -= blocklen; + //write pbuff contents to graphics RAM at addr + WrMem(addr, (ft_uint8_t *)pbuff, blocklen); + addr += blocklen; + } + fclose(fp); + free(pbuff); + return 0; +} + +void FT813::FillBitmap(ft_int16_t bitmap_number) +{ + int bufferSize = 8192; + uint8_t* pbuff = (uint8_t*)malloc(bufferSize); + // Clear buffer + memset(pbuff, 0, bufferSize); + + ft_int32_t addr_start = _addresses[bitmap_number]; + ft_int32_t addr_end = _addresses[bitmap_number+1]; + printf("FillBitmap %d (%d - %d).\n", bitmap_number, addr_start, addr_end); +// ft_int32_t bufferSize = addr_end - addr_start; + ft_int32_t filesize = addr_end - addr_start; +// ft_int32_t addr = addr_start; + + WrCmd32(CMD_LOADIMAGE); + WrCmd32(addr_start); //destination address of png decode + WrCmd32(0); //output format of the bitmap - default is rgb565 + printf("filesize = %d\n", filesize); + printf("while(filesize > 0)...\n"); + while(filesize > 0) { + ft_uint16_t blocklen = filesize > bufferSize ? bufferSize : filesize; +// printf("WrCmdBuf %d.\n", bufferSize); + filesize -= blocklen; + printf("blocklen = %d\n", blocklen); + printf("WrCmdBuf...\n"); + WrCmdBuf(pbuff, blocklen); //alignment is already taken care by this api + printf("Done.\n"); + } + printf("free(pbuff)...\n"); + free(pbuff); + printf("Done.\n"); +} + +void FT813::ClearBitmapCount(void) +{ + _bitmap_count = 0; +} + +ft_uint32_t FT813::ReadBigInt32(unsigned char* data, ft_uint32_t offset) +{ + return (data[offset + 0] << 24 | data[24 - 4 + 1] << 16 | data[offset + 2] << 8 | data[offset + 3]); +} + +// Loads JPG at x, y on the screen +ft_uint8_t FT813::Jpg(char *jpg_filename, int x, int y) +{ + ft_int16_t x_size,y_size; + int err; + + err = LoadJpg(jpg_filename, & x_size, & y_size); // load graphic data into buffer and decode jpg to bitmap + if(err != 0) { // something is wrong - display error + printf("LoadJpg: Error.\n"); + return(-1); + } + DL(BEGIN(BITMAPS)); +// LoadIdentity(); +// SetMatrix(); + DL(VERTEX2F(x * 16, y * 16)); + + // jpg is loaded and decoded into bitmap +// printf("jpg %s is loaded and decoded into bitmap (%dx%d)\n", jpg_filename, x_size, y_size); + + return(0); +} + +// Loads PNG at x, y on the screen +ft_uint8_t FT813::Png(char *png_filename, int x, int y) +{ + ft_int16_t x_size,y_size; + int err; + + err = LoadPng(png_filename, & x_size, & y_size); // load graphic data into buffer and decode png to bitmap + if(err != 0) { // something is wrong - display error + printf("LoadPng: Error.\n"); + return(-1); + } + DL(BEGIN(BITMAPS)); +// LoadIdentity(); +// SetMatrix(); + DL(VERTEX2F(x * 16, y * 16)); + + // png is loaded and decoded into bitmap +// printf("png %s is loaded and decoded into bitmap (%dx%d)\n", png_filename, x_size, y_size); + + return(0); +} + +// Loads PNG at x, y on the screen at given address +ft_uint8_t FT813::Png(char *png_filename, int x, int y, ft_int32_t address) +{ + ft_int16_t x_size,y_size; + int err; + _address = address; + err = LoadPng(png_filename, & x_size, & y_size); // load graphic data into buffer and decode png to bitmap + if(err != 0) { // something is wrong - display error + printf("LoadPng: Error.\n"); + return(-1); + } + DL(BEGIN(BITMAPS)); +// LoadIdentity(); +// SetMatrix(); + DL(VERTEX2F(x * 16, y * 16)); + +// DL(DISPLAY()); //ends the display,commands after this ignored + + // png is loaded and decoded into bitmap + printf("png %s is loaded and decoded into bitmap (%dx%d)\n", png_filename, x_size, y_size); + + return(0); +} + +// Loads JPG at the center of the screen (splash screen) +// Background color specified +ft_uint8_t FT813::JpgSplash(char *jpg_filename, ft_uint8_t r, ft_uint8_t g, ft_uint8_t b) +{ + ft_int16_t x_size,y_size; + int err; + + DLstart(); // start a new display command list + DL(CLEAR_COLOR_RGB(r, g, b)); // set the clear color to white + DL(CLEAR(1, 1, 1)); // clear buffers -> color buffer,stencil buffer, tag buffer + + err = LoadJpg(jpg_filename, & x_size, & y_size); // load graphic data into buffer and decode jpg to bitmap + if(err != 0) { // something is wrong - display error + printf("LoadJpg: Error.\n"); + return(-1); + } + + DL(BEGIN(BITMAPS)); + LoadIdentity(); + SetMatrix(); + int x = (DispWidth - x_size) / 2; + int y = (DispHeight - y_size) / 2; + DL(VERTEX2F(x * 16, y * 16)); + + DL(DISPLAY()); // Display the image + Swap(); // Swap the current display list + Flush_Co_Buffer(); // Download the command list into fifo + WaitCmdfifo_empty(); // Wait till coprocessor completes the operation + + return(0); +} + +// *************************************************************************************************************** +// *** Utility and helper functions ****************************************************************************** +// *************************************************************************************************************** + +// Find the space available in the GPU AKA CoProcessor AKA command buffer AKA FIFO +ft_uint16_t FT813::CoProFIFO_FreeSpace(void) +{ + ft_uint16_t cmdBufferDiff, cmdBufferRd, cmdBufferWr, retval; + + cmdBufferRd = Rd16(REG_CMD_READ + RAM_REG); + cmdBufferWr = Rd16(REG_CMD_WRITE + RAM_REG); + + cmdBufferDiff = (cmdBufferWr-cmdBufferRd) % FT_CMD_FIFO_SIZE; // FT81x Programmers Guide 5.1.1 + retval = (FT_CMD_FIFO_SIZE - 4) - cmdBufferDiff; + return (retval); +} + +// Sit and wait until there are the specified number of bytes free in the <GPU/CoProcessor> incoming FIFO +void FT813::Wait4CoProFIFO(ft_uint32_t room) +{ + ft_uint16_t getfreespace; + + do { + getfreespace = CoProFIFO_FreeSpace(); + } while(getfreespace < room); +} + +// Sit and wait until the CoPro FIFO is empty +void FT813::Wait4CoProFIFOEmpty(void) +{ + while(Rd16(REG_CMD_READ + RAM_REG) != Rd16(REG_CMD_WRITE + RAM_REG)); +} + +// Check if the CoPro FIFO is empty +// returns 1 if the CoPro FIFO is empty +// returns 0 if the CoPro FIFO is not empty +ft_uint8_t FT813::CheckIfCoProFIFOEmpty(void) +{ + return (Rd16(REG_CMD_READ + RAM_REG) == Rd16(REG_CMD_WRITE + RAM_REG)) ? 1 : 0; +} + +// Write a block of data into Eve RAM space a byte at a time. +// Return the last written address + 1 (The next available RAM address) +ft_uint32_t FT813::WriteBlockRAM(ft_uint32_t Add, const ft_uint8_t *buff, ft_uint32_t count) +{ + ft_uint32_t index; + ft_uint32_t WriteAddress = Add; // I want to return the value instead of modifying the variable in place + + for (index = 0; index < count; index++) { + Wr8(WriteAddress++, buff[index]); + } + return (WriteAddress); +} + /* function to load jpg file from filesystem */ /* return 0 if jpg is ok */ /* return x_size and y_size of jpg */ -int FT800::Load_jpg(char* filename, ft_int16_t* x_size, ft_int16_t* y_size, ft_uint32_t address) -{ - unsigned char pbuff[8291]; - unsigned short marker; - unsigned short length; - unsigned char data[4]; - - ft_uint16_t blocklen; -// sd.mount(); - FILE *fp = fopen(filename, "r"); - if(fp == NULL) return (-1); // connot open file +//int FT813::Load_jpg(char* filename, ft_int16_t* x_size, ft_int16_t* y_size, ft_uint32_t address) +//{ +// unsigned char pbuff[8192]; +// unsigned short marker; +// unsigned short length; +// unsigned char data[4]; +// +// ft_uint16_t blocklen; +//// sd.mount(); +// FILE *fp = fopen(filename, "r"); +// if(fp == NULL) return (-1); // connot open file +// +// // search for 0xFFC0 marker +// fseek(fp, 0, SEEK_END); +// unsigned int filesize = ftell(fp); +// fseek(fp, 2, SEEK_SET); +// fread(data,4,1,fp); +// marker = data[0] << 8 | data[1]; +// length = data[2] << 8 | data[3]; +// do { +// if(marker == 0xFFC0) break; +// if(marker & 0xFF00 != 0xFF00) break; +// if (fseek(fp, length - 2,SEEK_CUR) != 0) break; +// fread(data,4,1,fp); +// marker = data[0] << 8 | data[1]; +// length = data[2] << 8 | data[3]; +// } while(1); +// if(marker != 0xFFC0) return (-2); // no FFC0 Marker, wrong format no baseline DCT-based JPEG +// fseek(fp, 1,SEEK_CUR); +// fread(data,4,1,fp); +// *y_size = (data[0] << 8 | data[1]); +// *x_size = (data[2] << 8 | data[3]); +// +// //if(*x_size > DispWidth || *y_size > DispHeight) return (-3); // to big to fit on screen +// +// fseek(fp, 0, SEEK_SET); +// WrCmd32(CMD_LOADIMAGE); // load a JPEG image +// WrCmd32(address); //destination address of jpg decode +// WrCmd32(0); //output format of the bitmap - default is rgb565 +// while(filesize > 0) { +// /* download the data into the command buffer by 8kb one shot */ +// blocklen = filesize>8192?8192:filesize; +// /* copy the data into pbuff and then transfter it to command buffer */ +// fread(pbuff,1,blocklen,fp); +// filesize -= blocklen; +// /* copy data continuously into command memory */ +// WrCmdBuf(pbuff, blocklen); //alignment is already taken care by this api +// } +// fclose(fp); +//// sd.unmount(); +// +// return(0); +//} - // search for 0xFFC0 marker - fseek(fp, 0, SEEK_END); - unsigned int Fsize = ftell(fp); - fseek(fp, 2, SEEK_SET); - fread(data,4,1,fp); - marker = data[0] << 8 | data[1]; - length = data[2] << 8 | data[3]; - do { - if(marker == 0xFFC0) break; - if(marker & 0xFF00 != 0xFF00) break; - if (fseek(fp, length - 2,SEEK_CUR) != 0) break; - fread(data,4,1,fp); - marker = data[0] << 8 | data[1]; - length = data[2] << 8 | data[3]; - } while(1); - if(marker != 0xFFC0) return (-2); // no FFC0 Marker, wrong format no baseline DCT-based JPEG - fseek(fp, 1,SEEK_CUR); - fread(data,4,1,fp); - *y_size = (data[0] << 8 | data[1]); - *x_size = (data[2] << 8 | data[3]); - - //if(*x_size > DispWidth || *y_size > DispHeight) return (-3); // to big to fit on screen - - fseek(fp, 0, SEEK_SET); - WrCmd32(CMD_LOADIMAGE); // load a JPEG image - WrCmd32(address); //destination address of jpg decode - WrCmd32(0); //output format of the bitmap - default is rgb565 - while(Fsize > 0) { - /* download the data into the command buffer by 8kb one shot */ - blocklen = Fsize>8192?8192:Fsize; - /* copy the data into pbuff and then transfter it to command buffer */ - fread(pbuff,1,blocklen,fp); - Fsize -= blocklen; - /* copy data continuously into command memory */ - WrCmdBuf(pbuff, blocklen); //alignment is already taken care by this api - } - fclose(fp); -// sd.unmount(); - - return(0); -} - -//int FT800::Load_raw(char* filename) +//int FT813::Load_raw(char* filename) //{ // ft_uint8_t imbuff[8192]; // ft_uint16_t filesize; @@ -90,47 +916,39 @@ // return 0; //} - - - - - /* calibrate touch */ -ft_void_t FT800::Calibrate() +ft_void_t FT813::Calibrate() { /*************************************************************************/ /* Below code demonstrates the usage of calibrate function. Calibrate */ /* function will wait untill user presses all the three dots. Only way to*/ /* come out of this api is to reset the coprocessor bit. */ /*************************************************************************/ - { - - DLstart(); // start a new display command list - DL(CLEAR_COLOR_RGB(64,64,64)); // set the clear color R, G, B - DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer - DL(COLOR_RGB(0xff,0xff,0xff)); // set the current color R, G, B - Text((DispWidth/2), (DispHeight/2), 27, OPT_CENTER, "Please Tap on the dot"); // draw Text at x,y, font 27, centered - Calibrate(0); // start the calibration of touch screen - Flush_Co_Buffer(); // download the commands into FT800 FIFO - WaitCmdfifo_empty(); // Wait till coprocessor completes the operation - } + DLstart(); // start a new display command list + DL(CLEAR_COLOR_RGB(64,64,64)); // set the clear color R, G, B + DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer + DL(COLOR_RGB(0xff,0xff,0xff)); // set the current color R, G, B + Text((DispWidth/2), (DispHeight/2), 27, OPT_CENTER, "Please tap on the dot"); // draw Text at x,y, font 27, centered + Calibrate(0); // start the calibration of touch screen + Flush_Co_Buffer(); // download the commands into FT813 FIFO + WaitCmdfifo_empty(); // Wait till coprocessor completes the operation } /* API to give fadeout effect by changing the display PWM from 100 till 0 */ -ft_void_t FT800::fadeout() +ft_void_t FT813::fadeout() { - ft_int32_t i; + ft_int32_t i; for (i = 100; i >= 0; i -= 3) { - Wr8(REG_PWM_DUTY,i); + Wr8(REG_PWM_DUTY, i); Sleep(2);//sleep for 2 ms } } /* API to perform display fadein effect by changing the display PWM from 0 till 100 and finally 128 */ -ft_void_t FT800::fadein() +ft_void_t FT813::fadein() { ft_int32_t i; @@ -144,25 +962,516 @@ Wr8(REG_PWM_DUTY,i); } -ft_void_t FT800::read_calibrate(ft_uint8_t data[24]){ +ft_uint8_t FT813::read_calibrate_reg(ft_uint8_t i) { + return Rd8(REG_TOUCH_TRANSFORM_A + i); +} + +ft_uint32_t FT813::read_calibrate_reg32(ft_uint8_t i) { + return (Rd8(REG_TOUCH_TRANSFORM_A + i)) + // lsb + (Rd8(REG_TOUCH_TRANSFORM_A + i+1) << 8) + + (Rd8(REG_TOUCH_TRANSFORM_A + i+2) << 16) + + (Rd8(REG_TOUCH_TRANSFORM_A + i+3) << 24); // msb +} + +ft_void_t FT813::read_calibrate(ft_uint8_t data[24]) { + unsigned int i; + for(i = 0; i < 24; i++) { + data[i] = Rd8(REG_TOUCH_TRANSFORM_A + i); + } +} + +ft_void_t FT813::write_calibrate(ft_uint8_t data[24]) { + unsigned int i; + for(i = 0; i < 24; i++) { + Wr8(REG_TOUCH_TRANSFORM_A + i, data[i]); + } +} + +ft_void_t FT813::write_calibrate32(ft_uint32_t data[6]) { unsigned int i; - for(i=0;i<24;i++){ - data[i] = Rd8(REG_TOUCH_TRANSFORM_A + i); - } + for(i = 0; i < 6; i++) { + Wr8(REG_TOUCH_TRANSFORM_A + i*4, (data[i]) & 0xff); // lsb + Wr8(REG_TOUCH_TRANSFORM_A + i*4 + 1, (data[i] >> 8) & 0xff); + Wr8(REG_TOUCH_TRANSFORM_A + i*4 + 2, (data[i] >> 16) & 0xff); + Wr8(REG_TOUCH_TRANSFORM_A + i*4 + 3, (data[i] >> 24) & 0xff); // msb + } +} + +ft_uint32_t FT813::color_rgb(ft_uint8_t red, ft_uint8_t green, ft_uint8_t blue){ + return ((4UL<<24)|(((red)&255UL)<<16)|(((green)&255UL)<<8)|(((blue)&255UL)<<0)); +} + +ft_uint32_t FT813::clear_color_rgb(ft_uint8_t red, ft_uint8_t green, ft_uint8_t blue){ + return ((2UL<<24)|(((red)&255UL)<<16)|(((green)&255UL)<<8)|(((blue)&255UL)<<0)); +} + +// Define the backlight PWM output duty cycle. +void FT813::SetBacklight(ft_uint16_t brightness) +{ + brightness = brightness * brightness / 255; + if (brightness > 256) + brightness = 256; + if (brightness < 16) + brightness = 16; + Wr16(REG_PWM_DUTY, brightness); // Brightness +} + +void FT813::Tag(ft_uint8_t tag) +{ + DL(TAG(tag)); +} + +void FT813::ClearTag(ft_uint8_t tag) +{ + DL(CLEAR_TAG(tag)); +} + +void FT813::TagMask(ft_uint8_t mask) +{ + DL(TAG_MASK(mask)); +} + +void FT813::BitmapLayoutH(ft_uint8_t linestride, ft_uint8_t height) +{ + DL((40 << 24) | (((linestride) & 3) << 2) | (((height) & 3) << 0)); +} + +void FT813::BitmapSizeH(ft_uint8_t width, ft_uint8_t height) +{ + DL((41UL << 24) | (((width) & 3) << 2) | (((height) & 3) << 0)); +} + +ft_void_t FT813::SetLoadAddress(ft_uint32_t address) +{ + _address = address; // Old, try to get rid of this + _bitmapAddress = address; +} + +ft_void_t FT813::SetBitmapCount(ft_uint8_t count) +{ + _bitmap_count = count; // Old, try to get rid of this + _bitmapCount = count; +} + +ft_uint32_t FT813::GetBitmapAddress(ft_uint8_t bitmap_number) +{ + return _addresses[bitmap_number]; +} + +void FT813::SetThemeDefaultColor(void) +{ + // Default + GradColor(COLOR_RGB(0xff, 0xff, 0xff)); // Default 0xffffff + FgColor(COLOR_RGB(0x00, 0x38, 0x70)); // Default 0x003870 (0, 56, 112) + BgColor(COLOR_RGB(0x00, 0x20, 0x40)); // Default 0x002040 (0, 32, 64) +} + +void FT813::SetThemeColor(ft_uint32_t c) +{ + GradColor(COLOR_RGB(0xff, 0xff, 0xff)); // Default 0xffffff + ft_uint8_t r = (c >> 16) & 0xff; + ft_uint8_t g = (c >> 8) & 0xff; + ft_uint8_t b = c & 0xff; + ft_uint8_t rfg = r * 112 / 255; + ft_uint8_t gfg = g * 112 / 255; + ft_uint8_t bfg = b * 112 / 255; + ft_uint8_t rbg = r * 64 / 255; + ft_uint8_t gbg = g * 64 / 255; + ft_uint8_t bbg = b * 64 / 255; + FgColor(COLOR_RGB(rfg, gfg, bfg)); // Default 0x003870 + BgColor(COLOR_RGB(rbg, gbg, bbg)); // Default 0x002040 +} + +// ShowCalibration +void FT813::ShowCalibrationInCode(void) +{ + // Read calibrate registers + printf("// Calibration values:\n"); + printf(" ft_uint32_t canned_calibration_data[] = {\n"); + for(int i = 0; i < 24; i+=4) { + printf(" "); + printf("0x%08x", read_calibrate_reg32(i)); + if (i < 20) + printf(","); + printf("\n"); + } + printf(" };\n"); + printf(" write_calibrate32(canned_calibration_data);\n"); +} + +// Set screen orientation and preload canned touch screen calibration values +void FT813::SetOrientation(ft_uint8_t orientation) +{ +// TFT.SetRotate(0); // Standard landscape +// TFT.SetRotate(1); // Rotate 180 to landscape (upside down) +// TFT.SetRotate(2); // Rotate 90 CCW to portrait +// TFT.SetRotate(3); // Rotate 90 CW to portrait +// TFT.SetRotate(4); // Mirror over landscape X +// TFT.SetRotate(5); // Mirror over landscape Y +// TFT.SetRotate(6); // Rotate 90 CCW to portrait and mirror over portrait X +// TFT.SetRotate(7); // Rotate 90 CW to portrait and mirror over portrait X + + _orientation = orientation; + + SetRotate(orientation); // Standard landscape + // Canned calibration for the orientation + + if (orientation == FT8_DISPLAY_LANDSCAPE_0) + { + // Landscape 0 + ft_uint32_t canned_calibration_data[] = { + 0x000109b0, // 68016 + 0x0000023d, // 573 + 0x0000fa64, // 64100 + 0xffffffcf, // -49 + 0xfffefc9a, // -66406 + 0x01ee8754 // 32409428 + }; + write_calibrate32(canned_calibration_data); + } + + if (orientation == FT8_DISPLAY_PORTRAIT_90CW) + { + ft_uint32_t canned_calibration_data[] = { + 0xfffff994, + 0xffff07d3, + 0x01e4b85c, + 0xfffef6f5, + 0x000002ad, + 0x032eb4d4 + }; + write_calibrate32(canned_calibration_data); + } + + if (orientation == FT8_DISPLAY_PORTRAIT_90CCW) + { + // Calibration rotate 90 CCW to portrait + ft_uint32_t canned_calibration_data[] = { + 0x00000491, + 0x0000fd0b, + 0xfff6f84b, + 0x00010503, + 0x000006b7, + 0xffeeb0b7 + }; + write_calibrate32(canned_calibration_data); + } +} + +void FT813::ShowBitmap(ft_uint8_t bitmap, ft_int16_t fmt, ft_uint16_t x, ft_uint16_t y, ft_uint16_t width, ft_uint16_t height) +{ + ft_int32_t addr = GetBitmapAddress(bitmap); + DL(BITMAP_SOURCE(addr)); +// ft_int16_t stride = width * 2; +// 1-bits/p L1 +// if (fmt == L1) { +// stride = width / 8; +// } +// 2-bits/p L2 +// if (fmt == L2) { +// stride = width / 4; +// } +// 4-bits/p L4 +// if (fmt == L4) { +// stride = width / 2; +// } +// 8-bits/p L8 RGB332 ARGB2 PALETTED565 PALETTED4444 PALETTED8 +// if ((fmt == L8) || +// (fmt == RGB332) || +// (fmt == ARGB2) || +// (fmt == PALETTED565) || +// (fmt == PALETTED4444) || +// (fmt == PALETTED8)) { +// stride = width; +// } +// 16-bits/p ARGB1555 ARGB4 RGB565 +// if ((fmt == ARGB1555) || +// (fmt == ARGB4) || +// (fmt == RGB565)) { +// stride = width * 2; +// } +// DL(BITMAP_LAYOUT(fmt, stride, h)); // 10-bit linestride, 9-bit height +// DL(BITMAP_LAYOUT_H(stride >> 10, h >> 9)); // msb bits +// DL(BITMAP_SIZE(NEAREST, BORDER, BORDER, w, h)); // 9-bit width, 9-bit height +// DL(BITMAP_SIZE_H(w >> 9, h >> 9)); // msb bits + + SetBitmap(addr, fmt, width, height); + +// DL(VERTEX2II(x, y, 0, 0)); + DL(VERTEX2F(x * 16, y * 16)); } -ft_void_t FT800::write_calibrate(ft_uint8_t data[24]){ - unsigned int i; - for(i=0;i<24;i++) { - Wr8(REG_TOUCH_TRANSFORM_A + i,data[i]); +void FT813::ShowBitmapAtAddress(ft_uint32_t addr, ft_int16_t fmt, ft_uint16_t x, ft_uint16_t y, ft_uint16_t width, ft_uint16_t height) +{ + DL(BITMAP_SOURCE(addr)); +// ft_int16_t stride = width * 2; + // 1-bits/p L1 +// if (fmt == L1) { +// stride = width / 8; +// } + // 2-bits/p L2 +// if (fmt == L2) { +// stride = width / 4; +// } + // 4-bits/p L4 +// if (fmt == L4) { +// stride = width / 2; +// } + // 8-bits/p L8 RGB332 ARGB2 PALETTED565 PALETTED4444 PALETTED8 +// if ((fmt == L8) || +// (fmt == RGB332) || +// (fmt == ARGB2) || +// (fmt == PALETTED565) || +// (fmt == PALETTED4444) || +// (fmt == PALETTED8)) { +// stride = width; +// } + // 16-bits/p ARGB1555 ARGB4 RGB565 +// if ((fmt == ARGB1555) || +// (fmt == ARGB4) || +// (fmt == RGB565)) { +// stride = width * 2; +// } +// DL(BITMAP_LAYOUT(fmt, stride, h)); // 10-bit linestride, 9-bit height +// DL(BITMAP_LAYOUT_H(stride >> 10, h >> 9)); // msb bits +// DL(BITMAP_SIZE(NEAREST, BORDER, BORDER, w, h)); // 9-bit width, 9-bit height +// DL(BITMAP_SIZE_H(w >> 9, h >> 9)); // msb bits + + SetBitmap(addr, fmt, width, height); + +// DL(VERTEX2II(x, y, 0, 0)); + DL(VERTEX2F(x * 16, y * 16)); +} + +int FT813::GetImageIndexFromName(char *name) +{ + for (int i = 0; i < _bitmapCount; i++) { + if(strstr(_bitmaps[i].name, name) != NULL) { + return i; } + } + return -1; +} + +int FT813::ResetInflateFileBitmap(void) +{ + _bitmapAddress = 0; + _bitmapCount = 0; +} + +uint32_t FT813::GetRamUsage(void) +{ + return _bitmapAddress; +} + +uint16_t FT813::GetRamNoOfBitmaps(void) +{ + return _bitmapCount; +} + +int FT813::LoadInflateFileBitmap(char *name, uint16_t fmt, uint16_t w, uint16_t h) +{ + strcpy(_bitmaps[_bitmapCount].name, name); + _bitmaps[_bitmapCount].fmt = fmt; + _bitmaps[_bitmapCount].w = w; + _bitmaps[_bitmapCount].h = h; + _bitmaps[_bitmapCount].addr = _bitmapAddress; + // 1-bits/p L1 + if (_bitmaps[_bitmapCount].fmt == L1) { + _bitmaps[_bitmapCount].size = _bitmaps[_bitmapCount].w * _bitmaps[_bitmapCount].h / 8; + } + // 2-bits/p L2 + if (_bitmaps[_bitmapCount].fmt == L2) { + _bitmaps[_bitmapCount].size = _bitmaps[_bitmapCount].w * _bitmaps[_bitmapCount].h / 4; + } + // 4-bits/p L4 + if (_bitmaps[_bitmapCount].fmt == L4) { + _bitmaps[_bitmapCount].size = _bitmaps[_bitmapCount].w * _bitmaps[_bitmapCount].h / 2; + } + // 8-bits/p L8 RGB332 ARGB2 PALETTED565 PALETTED4444 PALETTED8 + if ((_bitmaps[_bitmapCount].fmt == L8) || + (_bitmaps[_bitmapCount].fmt == RGB332) || + (_bitmaps[_bitmapCount].fmt == ARGB2) || + (_bitmaps[_bitmapCount].fmt == PALETTED565) || + (_bitmaps[_bitmapCount].fmt == PALETTED4444) || + (_bitmaps[_bitmapCount].fmt == PALETTED8)) { + _bitmaps[_bitmapCount].size = _bitmaps[_bitmapCount].w * _bitmaps[_bitmapCount].h; + } + // 16-bits/p ARGB1555 ARGB4 RGB565 + if ((_bitmaps[_bitmapCount].fmt == ARGB1555) || + (_bitmaps[_bitmapCount].fmt == ARGB4) || + (_bitmaps[_bitmapCount].fmt == RGB565)) { + _bitmaps[_bitmapCount].size = _bitmaps[_bitmapCount].w * _bitmaps[_bitmapCount].h * 2; + } + LoadInflateFile(_bitmaps[_bitmapCount].addr, _bitmaps[_bitmapCount].name); // x 0, y 0, w 32, h 32, size 1024 + _bitmapAddress += _bitmaps[_bitmapCount].size; + _bitmapCount++; +} + +int FT813::ShowBitmapByName(char *name, uint16_t x, uint16_t y) +{ + int index = GetImageIndexFromName(name); + ShowBitmapAtAddress(_bitmaps[index].addr, _bitmaps[index].fmt, x, y, _bitmaps[index].w, _bitmaps[index].h); +} + +uint16_t FT813::GetTouchedTag(void) +{ + // REG_TOUCH_TAG + // If the screen is being touched, the screen coordinates are looked up in the screen's tag buffer, + // delivering a final 8-bit tag value, in REG_TOUCH_TAG. + // REG_TOUCH_TAG_XY + // Because the tag lookup takes a full frame, and touch coordinates change continuously, + // the original (x; y) used for the tag lookup is also available in REG_TOUCH_TAG_XY. + uint32_t TrackRegisterVal = Rd32(REG_TRACKER); // check if one of the tracking fields is touched + return TrackRegisterVal & 0xffff; } -ft_uint32_t FT800::color_rgb(ft_uint8_t red,ft_uint8_t green, ft_uint8_t blue){ - return ((4UL<<24)|(((red)&255UL)<<16)|(((green)&255UL)<<8)|(((blue)&255UL)<<0)); +uint16_t FT813::GetTouchedTag(uint8_t point_number) +{ + // REG_TOUCH_TAG + // If the screen is being touched, the screen coordinates are looked up in the screen's tag buffer, + // delivering a final 8-bit tag value, in REG_TOUCH_TAG. + // REG_TOUCH_TAG_XY + // Because the tag lookup takes a full frame, and touch coordinates change continuously, + // the original (x; y) used for the tag lookup is also available in REG_TOUCH_TAG_XY. + // check if one of the tracking fields is touched + uint32_t TrackRegisterVal = 0; + switch (point_number) { + case 0: + TrackRegisterVal = Rd32(REG_TRACKER); // First point + break; + case 1: + TrackRegisterVal = Rd32(REG_TRACKER_1); // Second point + break; + case 2: + TrackRegisterVal = Rd32(REG_TRACKER_2); // Third point + break; + case 3: + TrackRegisterVal = Rd32(REG_TRACKER_3); // Fourth point + break; + case 4: + TrackRegisterVal = Rd32(REG_TRACKER_4); // Fift point + break; } + return TrackRegisterVal & 0xffff; +} + +uint8_t FT813::GetTag(void) +{ + // REG_TOUCH_TAG + // If the screen is being touched, the screen coordinates are looked up in the screen's tag buffer, + // delivering a final 8-bit tag value, in REG_TOUCH_TAG. + // REG_TOUCH_TAG_XY + // Because the tag lookup takes a full frame, and touch coordinates change continuously, + // the original (x; y) used for the tag lookup is also available in REG_TOUCH_TAG_XY. + uint32_t TagRegisterVal = Rd32(REG_TAG); // check if one of the tracking fields is touched + return TagRegisterVal & 0xff; +} + +uint16_t FT813::GetTagX(void) +{ + // REG_TOUCH_TAG + // If the screen is being touched, the screen coordinates are looked up in the screen's tag buffer, + // delivering a final 8-bit tag value, in REG_TOUCH_TAG. + // REG_TOUCH_TAG_XY + // Because the tag lookup takes a full frame, and touch coordinates change continuously, + // the original (x; y) used for the tag lookup is also available in REG_TOUCH_TAG_XY. + uint32_t TagRegisterVal = Rd32(REG_TAG_X); // check if one of the tracking fields is touched + return TagRegisterVal & 0x7ff; +} + +uint16_t FT813::GetTagY(void) +{ + // REG_TOUCH_TAG + // If the screen is being touched, the screen coordinates are looked up in the screen's tag buffer, + // delivering a final 8-bit tag value, in REG_TOUCH_TAG. + // REG_TOUCH_TAG_XY + // Because the tag lookup takes a full frame, and touch coordinates change continuously, + // the original (x; y) used for the tag lookup is also available in REG_TOUCH_TAG_XY. + uint32_t TagRegisterVal = Rd32(REG_TAG_Y); // check if one of the tracking fields is touched + return TagRegisterVal & 0x7ff; +} + +uint8_t FT813::GetTouchTag(void) +{ + // REG_TOUCH_TAG + // If the screen is being touched, the screen coordinates are looked up in the screen's tag buffer, + // delivering a final 8-bit tag value, in REG_TOUCH_TAG. + // REG_TOUCH_TAG_XY + // Because the tag lookup takes a full frame, and touch coordinates change continuously, + // the original (x; y) used for the tag lookup is also available in REG_TOUCH_TAG_XY. + uint32_t TagRegisterVal = Rd32(REG_TOUCH_TAG); // check if one of the tracking fields is touched + return TagRegisterVal & 0xff; +} + +uint16_t FT813::GetTouchTagX(void) +{ + // REG_TOUCH_TAG + // If the screen is being touched, the screen coordinates are looked up in the screen's tag buffer, + // delivering a final 8-bit tag value, in REG_TOUCH_TAG. + // REG_TOUCH_TAG_XY + // Because the tag lookup takes a full frame, and touch coordinates change continuously, + // the original (x; y) used for the tag lookup is also available in REG_TOUCH_TAG_XY. + uint32_t TagRegisterVal = Rd32(REG_TOUCH_TAG_XY); // check if one of the tracking fields is touched + return (TagRegisterVal >> 16) & 0xffff; +} + +uint16_t FT813::GetTouchTagY(void) +{ + // REG_TOUCH_TAG + // If the screen is being touched, the screen coordinates are looked up in the screen's tag buffer, + // delivering a final 8-bit tag value, in REG_TOUCH_TAG. + // REG_TOUCH_TAG_XY + // Because the tag lookup takes a full frame, and touch coordinates change continuously, + // the original (x; y) used for the tag lookup is also available in REG_TOUCH_TAG_XY. + uint32_t TagRegisterVal = Rd32(REG_TOUCH_TAG_XY); // check if one of the tracking fields is touched + return TagRegisterVal & 0xffff; +} + +uint16_t FT813::GetTouchConfig(void) +{ + // Read 0x0381 + // 0000 0011 1000 0001 + // bit 15 0: capacitive, 1: resistive + // bit 10 - 4: I2C address of touch screen module: 0x011 1000 0x38 + // bit 3: 0: FocalTech, 1: Azoteq + // bit 1 - 0: sampler clocks 0x01 + uint32_t TouchConfigVal = Rd32(REG_TOUCH_CONFIG); // check if one of the tracking fields is touched + return TouchConfigVal & 0xffff; +} + +void FT813::SetTouchConfig(uint16_t TouchConfigVal = VAL_TOUCH_CONFIG) +{ + Wr32(REG_TOUCH_CONFIG, (uint32_t) TouchConfigVal); +} + + + + + +void FT813::screenShot(void) +{ + int bufferSize = 800*480; + char* pbuff = (char*)malloc(bufferSize); -ft_uint32_t FT800::clear_color_rgb(ft_uint8_t red,ft_uint8_t green, ft_uint8_t blue){ - return ((2UL<<24)|(((red)&255UL)<<16)|(((green)&255UL)<<8)|(((blue)&255UL)<<0)); - } - \ No newline at end of file +// wr8(REG_SCREENSHOT_EN, 1); +// for (int ly = 0; ly < SCREEN_HEIGHT; ly++) { +// wr16(REG_SCREENSHOT_Y, ly); +// wr8(REG_SCREENSHOT_START, 1); +// +// //Read 64 bit registers to see if it is busy +// while (rd32(REG_SCREENSHOT_BUSY) | rd32(REG_SCREENSHOT_BUSY + 4)); +// +// wr8(REG_SCREENSHOT_READ , 1); +// for (int lx = 0; lx < SCREEN_WIDTH; lx ++) { +// //Read 32 bit pixel value from RAM_SCREENSHOT +// //The pixel format is BGRA: Blue is in lowest address and Alpha +// is in highest address +// screenshot[ly*SCREEN_HEIGHT + lx] = rd32(RAM_SCREENSHOT + lx*4); +// } +// wr8(REG_SCREENSHOT_READ, 0); +// } +// wr8(REG_SCREENSHOT_EN, 0); + + free(pbuff); +} \ No newline at end of file