레이블이 FT800인 게시물을 표시합니다. 모든 게시물 표시
레이블이 FT800인 게시물을 표시합니다. 모든 게시물 표시

2014/11/24

FT800, EVE(Embedded Video Engine) -- 4. Touch 테스트

오늘은 FT800의 터치 기능을 써먹어보자.

FT800 Programmers Guide의 5.47 CMD_CALIBRATE 항목을 유심히 읽어보자

5.47 CMD_CALIBRATE - execute the touch screen calibration routine

The calibration procedure collects three touches from the touch screen, then computes and loads an appropriate matrix into REG_TOUCH_TRANSFORM_A-F. To use it, create a display list and then use CMD_CALIBRATE. The co-processor engine overlays the touch targets on the current display list, gathers the calibration input and updates REG_TOUCH_TRANSFORM_A-F.



세 점을 터치해서 캘리브레이션 데이터를 REG_TOUCH_TRANSFORM에 저장한다. 

cmd_dlstart();
cmd(CLEAR(1,1,1));
cmt_text(80, 30, 27, OPT_CENTER, "Please tap on the dot");
cmd_calibrate();
이렇게 실행해라.

대충 이런 뜻인듯.

터치 보정 후 REG_TOUCH_TRANSFORM_A-F 레지스터의 값을 EEPROM에 저장해 두고 부팅시 저장값을 읽어와서 초기화 해주면 될거 같다.

터치 관련 레지스터나 함 찾아보자.

REG_TOUCH_ADC_MODE
-> The host can set this bit to control the ADC sampling mode of the FT800
     0 : Single Ended mode. It causes low power consumption but with less accuracy
     1 : Differential Mode. It causes higher power consumption but with more accuracy.
          The default mode after reset.

REG_TOUCH_SCREEN_XY
-> Bit[15:0] : Y coordinates of the touch screen. After doing calibration, it shall be within the height of the screen 
    size. If the touch screen is not being touched, it shall be 0x8000.
-> Bit[31:16] : X coordinates of the touch screen. After doing calibration, it shall be within the height of the screen 
    size. If the touch screen is not being touched, it shall be 0x8000.
Note : This register is the final computation output of the touch engine of the FT800. It has been mapped into screen size.

REG_TOUCH_RAW_XY
-> Bit[15:0] : raw Y coordinates of the touch screen before going through transformation matrix. 
    The valid range is from 0 to 1023. If there is no touch on screen, the value shall be 0xFFFF.
-> Bit[31:16] : raw X coordinates of the touch screen before going through transformation matrix. 
    The valid range is from 0 to 1023. If there is no touch on screen, the value shall be 0xFFFF.
Note : The coordinates in this register have not mapped into the screen coordinates. To get the screen coordinates, please refer to REG_TOUCH_SCREEN_XY.

REG_TOUCH_DIRECT_XY
-> Bit[9:0] : The 10 bit ADC value for Y coordinate.
-> Bit[25:16] : The 10 bit ADC value for X coordinate.
-> Bit[31] : 
    0 : Touch is being sensed and the two fields above contains the sensed data.
    1 : No touch is being sensed and the data in the two fields above shall be ignored.

REG_TOUCH_DIRECT_Z1Z2
-> Bit[9:0] : The 10 bit ADC value for touch screen resistance Z2.
-> Bit[25:16] : The 10 bit ADC value for touch screen resistance Z1.
Note : To know it is touched or not, please check the 31st bit of REG_TOUCH_DIRECT_XT. FT800 touch engine will do the post-processing for these Z1 and Z2 values and update the result in REG_TOUCH_RZ.

REG_ANALOG

REG_TOUCH_RZ
-> Bitp[15:0] : Resistance of touching on the touch screen. The valid value is 0 to 0x7fff.
    Highest value(0x7fff) means no touch, Lowest value(0) means maximum pressure.
    
REG_TOUCH_TRANSFORM_A-F

REG_TOUCH_TAG
-> Bit[7:0] : These bits are set as the tag value of the specific graphics object on the screen which is being touched. These bits are updated once when all the lines of the current frame is scanned out to the screen.
Note : The valid tag value range is from 1 to 255, therefore the default value of this register is zero, meaning there is no touch by default.

REG_TOUCH_TAG_XY
-> Bit[15:0] : Y coordinates of the touch screen, which was used by the touch engine to look up the tag result.
-> Bit[31:16] : X coordinates of the touch screen, which was used by the touch engine to look up the tag result.
Note : Host can read this register to check the coordinates used by the touch engine to update the tag register REG_TOUCH_TAG.

REG_TOUCH_RZTHRESH
-> Bit[15:0] : These bits control the touch screen resistance threshold. Host can adjust the touch screen touching sensitivity by setting this register. The default value after reset is 0xFFFF and it means the lightest touch will be accepted by the touch engine of the FT800. The host can set this register by doing experiments. The typical value is 1200.

REG_TOUCH_OVERSAMPLE
-> Bit[3:0] : These bits control the touch screen oversample factor. The higher value of this register causes more accuracy with more power consumption, but may not be necessary. The valid range is from 1 to 15.

REG_TOUCH_SETTLE
-> Bit[3:0] : These bits control the touch screen settle time, in the unit of 6 clocks. The default value is 3, meaning the settle time is 18(3*6) system clock cycles.

REG_TOUCH_CHARGE
-> Bit[15:0] : These bits control the touch-screen charge time, in the unit of 6 system clocks. The default value after reset is 6000, i.e. the charge time will be 6000*6 clock cycles.

REG_TOUCH_MODE
-> Bit[1:0] : The host can set these two bits to control the touch screen sampling mode of the FT800 touch engine.
    00 : off mode. No sampling happens.
    01 : Single mode. Cause one single sample to occur.
    10 : Frame mode. Cause a sample at the start of each frame.
    11 : Continuous mode. Up to 1000 time per seconds. Default mode after reset.

초기화 관련 레지스터들은 초기값으로 가도 될거같다. 

터치 처리 과정은 아마도 이렇지 않을까 싶은데...

1, 터치값을 읽어와서 REG_TOUCH_RAW_XY에 저장한다.
2. 보정값을 이용해서 스크린 좌표값으로 변경한 후 REG_TOUCH_SCREEN_XY에 저장한다.
3. 2번 값으로 tag를 찾는다.

설명이 너무 느슨해서 정확한 의미를 알기가 어려운데...실제로 써보면서 확인해보자.

일단은 캘리브레이션부터

  FT800_DLstart();
FT800_DL(CLEAR_COLOR_RGB(64,64,64));
FT800_DL(CLEAR(1,1,1));
FT800_DL(COLOR_RGB(0xff,0xff,0xff));
FT800_Text((480/2), (272/2), 27, OPT_CENTER, "Please Tap on the dot");
FT800_Calibrate(0);
FT800_Flush_Co_Buffer();
FT800_WaitCmdfifo_empty();



머 이런식이다.


 
FT800_Track(249, 86, 1, 1, 1);
FT800_Flush_Co_Buffer();
FT800_WaitCmdfifo_empty();

FT800_DLstart();
FT800_DL(CLEAR_COLOR_RGB(0,0,0));
FT800_DL(CLEAR(1,1,1));
FT800_DL(TAG(1));
FT800_Dial(249, 86, 55, 0, 0x8000);
FT800_DL(DISPLAY());
FT800_Swap();
FT800_Flush_Co_Buffer();
FT800_WaitCmdfifo_empty();

while(1){
TR_Val = ft800memRead32(REG_TRACKER);
if((TR_Val & 0xff) == 1)
color = TR_Val >> 16;

do{
cmdBufferRd = ft800memRead16(REG_CMD_READ);
cmdBufferWr = ft800memRead16(REG_CMD_WRITE);
printf("%x, %x\r\n", cmdBufferRd, cmdBufferWr);
}while(cmdBufferWr != cmdBufferRd);

FT800_DLstart();
FT800_DL(CLEAR_COLOR_RGB(0,0,0));
FT800_DL(CLEAR(1,1,1));
FT800_DL(TAG(1));
FT800_Dial(249, 86, 55, 0, color);
FT800_DL(DISPLAY());
FT800_Swap();
FT800_Flush_Co_Buffer();
FT800_WaitCmdfifo_empty();


되긴 되네.

2014/11/20

FT800, EVE(Embedded Video Engine) -- 3. 돌려봅시다

MBED용 라이브러리를 IAR용으로 바꿔봤다.

FT800.h

FT800.c

잘 돌아 갈래나 모르겠네...


FT800 Programmers Guide의 2.2.5 Initialization Sequence 에는 초기화 시퀀스를 아래와 같이 소개한다.

Initialization Sequence during the boot up:
1. Use MCU SPI clock not more than 11MHz
2. Send Host Command "CLKEXT" to FT800
3. Send Host Command "ACTIVE" to enable clock to FT800
4. Configure video timing registers, except REG_PCLK
5. Write first display list
6. Write REG_DLSWAP, FT800 swaps display list immediately
7. Enable back light control for display
8. Wriet REG_PCLK, video output begins with the first display list
9. Use MCU SPI clock not more than 30MHz






























Initialization Sequence from Power Down using PD_N pin:
1. Drive the PD_N pin high
2. Wait for at least 20ms
3. Execute "Initialization Sequence during the Boot Up" from step 1 to 9

Initialization Sequence from Sleep Mode:
1. Send Host command "ACTIVE" to enable clock to FT800
2. Wait for at least 20ms
3. Execute "Initialization Sequence during Boot Up" from steps 5 to 8

Initialization sequence from standby mode:
Execute all the steps mentioned in "Initialization Sequence from Sleep Mode" except waiting for at least 20ms in step 2.


AN240 FT800 From thr Ground Up 문서의 4.2 Configuration 항목도 함 보자.

4.2 Configuration

  4.2.1 MCU setup

    4.2.1.1 SPI
      - <= 10MHz initial SPI clock
        -> Use slower clock while on internal oscillator
      - Mode zero
        -> CPOL = 0 - clock idles at zero
        -> CPHA = 0 - data is sampled on rising edge, propagated on falling edge
      - Little Endian data byte ordering

  4.2.2 Wake Up
  After configuring the MCU interface the first step in communicating with the FT800 is to wake it up.

    1) Reset the FT800
      - Drive PD_N low for 20ms, then back high
      - Wait for 20ms after PD_N is high
    2) Issue the Wake-up command
      - Write 0x00, 0x00, 0x00
    3) If using an external crystal or clock source on the FT800, issue the external clock command
      - Write 0x44, 0x00, 0x00
    4) Set the FT800 internal clock speed to 48MHz
      - Wriet 0x62, 0x00, 0x00
    5) At this point, the Host MCU SPI Master can change the SPI clock up to 30MHz
    6) Read the Device ID register
      - Read one byte from location 0x102400
      - Check for the value 0x7C
    7) Set bit 7 of REG_GPIO to 0 to turn off the LCD_DISP signal
      - Write 0x80 to location 0x102490

  4.2.3 Configuring the Display Timing
  Once the FT800 is awake and the internal clock set and Device ID checked, the next task is to configure the LCD display parameters for the chosen display with the values determined in Section 2.3.3 above.

    1) Set REG_PCLK to zero - This disables the pizel clock output while the LCD and other system parameters are configured
    2) Set the following registers with values for the chosen display. Typical WQVGA and QVGA values are shown:


























    3) Enable or disable REG_CSPREAD with a value of 01h or 00h, respectively. Enabling REG_CSPREAD will offset the R, G, and B output bits so all they do not all change at the same time.

  4.2.4 Configure the Touch Sensitivity

생략

  4.2.5 Configure the audio

생략

  4.2.6 Initialize and enable the display
  At this point, all the necessary configuration registers are initialized and the system is ready to start displaying video, as well as sensing touch events and playing audio. All of this is done through a Display List.

The Display List

 The Display List is formed by writing a series of commands to the RAM_DL memory portion of the FT800 memory map. Graphics elements are handled through commands stored in the list. Register writes for touch and audio elements are handled in line with the Display List.

The FT800 is then instructed to "swap" the Display List that was just created to make it active. While the active list is being shown on the LCD panel, or touch and audio activities processed, a new Display List is formed. Once ready, the lists swap again so the new commands are executed. This process continues for each update shown on the display, new audio sound, etc.


Display list commands are always 32 bits long. The first command on a display list should be to address 0. Subsequent commands should be sent on an increment of 4 bytes to avoid overlap.

Since the system is just starting, there is not active Display List, and the pixel clock is not yet started. The first Display List should start with a blank screen of a chosen color as an initial condition to avoid displaying any artifacts once the pixel clock is started. Here is an example start-up Display List:

    wr32(RAM_DL + 0, CLEAR_COLOR_REG(0,0,0));
    wr32(RAM_DL + 4, CLEAR(1,1,1));
    wr32(RAM_DL + 8, DISPLAY());
    wr32(REG_DLSWAP, SWAP_FRAME);

wr32(address, value) indicates the MCU would write the value (CLEAR, POINT_SIZE, etc.) to the address within the display list (RAM_DL + n). This notation is used throughout other FT800 documents.

Up until this point, no output has been generated on the LCD interface. With the configuration and initial display list in place, the LCD DISP signal, backlight and pixel clock can now be turned on:

머 그렇탄다...

초기화 함수 함 만들어봤다

void FT800_Init(void){

  uint16_t cmdBufferWr, cmdBufferRd;


  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4, GPIO_PIN_SET);

  HAL_Delay(20);

  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4, GPIO_PIN_RESET);

  HAL_Delay(20);

  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4, GPIO_PIN_SET);

  HAL_Delay(20);

       
  ft800cmdWrite(FT800_CLKEXT);

  HAL_Delay(5);

  ft800cmdWrite(FT800_ACTIVE);

  HAL_Delay(5);

  ft800memWrite16(REG_HCYCLE, 548);

  ft800memWrite16(REG_HOFFSET, 43);

  ft800memWrite16(REG_HSYNC0, 0);

  ft800memWrite16(REG_HSYNC1, 41);

  ft800memWrite16(REG_VCYCLE, 292);

  ft800memWrite16(REG_VOFFSET, 12);

  ft800memWrite16(REG_VSYNC0, 0);

  ft800memWrite16(REG_VSYNC1, 10);

  ft800memWrite8(REG_SWIZZLE, 0);

  ft800memWrite8(REG_PCLK_POL, 1);

  ft800memWrite8(REG_CSPREAD, 1);

  ft800memWrite16(REG_HSIZE, 480);

  ft800memWrite16(REG_VSIZE, 272);


  ft800memWrite32(RAM_DL, CLEAR_COLOR_RGB(0,0,0));

  ft800memWrite32(RAM_DL+4, CLEAR(1,1,1));

  ft800memWrite32(RAM_DL+8, DISPLAY());

  ft800memWrite32(REG_DLSWAP, DLSWAP_FRAME);

  ft800memWrite8(REG_PCLK, 5);


  HAL_Delay(50);

       
  ft800memWrite32(RAM_DL, CLEAR(1,1,1));

  ft800memWrite32(RAM_DL+4, BEGIN(1));

  ft800memWrite32(RAM_DL+8, VERTEX2II(220,110,31,'F'));

  ft800memWrite32(RAM_DL+12, VERTEX2II(244,110,31,'T'));

  ft800memWrite32(RAM_DL+16, VERTEX2II(270,110,31,'D'));

  ft800memWrite32(RAM_DL+20, VERTEX2II(299,110,31,'I'));

  ft800memWrite32(RAM_DL+24, END());

  ft800memWrite32(RAM_DL+28, COLOR_RGB(160,22,22));

  ft800memWrite32(RAM_DL+32, POINT_SIZE(320));

  ft800memWrite32(RAM_DL+36, BEGIN(2));

  ft800memWrite32(RAM_DL+40, VERTEX2II(192,133,0,0));

  ft800memWrite32(RAM_DL+44, END());

  ft800memWrite32(RAM_DL+48, DISPLAY());

       
  ft800memWrite32(REG_DLSWAP, DLSWAP_FRAME);


  MX_SPI1_Init_HIGH();

}









































와 나온다

2014/11/18

FT800, EVE(Embedded Video Engine) -- 2. 라이브러리 어떻게 할까.

스펙은 겁나게 맘에 드는데...

라이브러리는???

FTDI 애네 IAR ARM 라이브러리는 지원을 안해주네....어쩌라는거지


FTDI 홈페이지에서 확인 가능한 라이브러리는 Arduino, ARM, PIC 가 있다.


이 중 ARM과 PIC은 영 쓸게 아닌거 같고, Arduino는 잘 만들었지만 난 STM32를 쓰거든...



MBED에도 라이브러리가 있는 모양이다.


http://developer.mbed.org/users/dreschpe/code/FT800/

오케이 이걸 IAR용 C로 바꾸면 쓸만할거 같다.

이걸 베이스로 하자.

2014/11/17

FT800, EVE(Embedded Video Engine) -- 1. 일단 스펙 읽어보고 하드웨어를 준비하자.

USB 관련 디바이스만 만들던 FTDI가 밑도 끝도 없이 툭 내 놓은 EVE 시리즈...

MCU 기반 시스템에서 매우 큰 리소스를 점유하는 LCD를 SPI로 간단히 제어할 수 있다. 우와아!!!

보통 AVR, PIC, Cortex-M 정도의 MCU에서 Character LCD가 아닌 TFT-LCD를 구동하기는 쉽지가 않다. 단순히 정지화면만 뿌려주는거야 쉽게 구현가능하지만, 사용자의 입력을 받아서 처리한 후 화면에 뿌려주는건 어렵지...처리 속도도 그렇고 내부 용량도 그렇고...

난 MCU를 사용하는 시스템에 외부 메모리는 되도록 인터페이스하지 않는다. 별로 많지도 않은 IO를 메모리 전용으로 쓰기엔 너무 아까워서 눈물이 나니까...차라리 메모리가 좀 더 많은 디바이스를 선택하는게 낫다.

그러니까 주로 Character LCD, 좀 무리하면 흑백 그래픽 LCD 정도나 쓰지...
TFT-LCD는 리눅스 올라가는 임베디드 시스템 아니면 쳐다도 못봤지. 지금까진



MBED와 Arduino에서 돌리는 영상이다. STM32나 AVR에서 저정도로 TFT-LCD를 굴려먹을 수 있다. 우왕 신난다.



EVE(Embedded Video Engine) 시리즈는 현재 FT800과 FT801 두 가지를 사용할 수 있다.
일단 특징부터 보자.

- Targets QVGA/WQVGA displays with 1/16th resolution, maximum 512x512 resolution
- 18-bit interface with 2-bit color dither offering 262K color palette with 24-bit quality
- Store up to 2000 objects/commands in 8K byte display list
- FT800 with integrated touch controller; FT801 with I2C capacitive touch interface
- PWM output for programmable display brightness
- Anti-aliasing algorithms improve display perception
- Low-power - 24mA typical in active mode
- Integrated audio synthesizer outputs beeps, tones or recorded audio
- Support audio playback for PCM, 4bit ADPCM and u-Law coding formats
- Extended temperature range : -40 ~ 85

최대 512x512 해상도를 지원하고 320x240, 480x272 해상도를 타겟으로 한다. 2비트 디더링으로 24비트 RGB를 처리해줌. 터치, 사운드 지원하고 저전력형이고... 등등등




MCU와 FT800간의 인터페이스는 SPI로, I2C도 지원되지만 최대 3.4MHz 니까 30MHz까지 지원되는 SPI를 써야지.

Backlight 디밍 컨트롤용 PWM 핀이 있으니까 LED Driver 회로와 Audio AMP 회로만 넣으면 회로 설계는 끝이다.

정말 이걸로 LCD를 돌릴 수 있나??? 정말 이게 단가??? 터치하고 오디오는 정말 된다는건가???
싶을정도다.


FT800 데이터시트에 레퍼런스 회로도를 제공한다.


개발용 보드로 판매하는 VM800C 를 구매해서 사용하는것도 좋다. 개당 65달라 정도인거 같다.

근데 난 회로를 만들었지...
LCD를 미리 선정해놔서 어쩔수가 없다. LCD 핀맵이 다르다...ㅠㅠ


내가 사용할 LCD는 LTE430WQ-F0C-0BS 로 4.3인치 터치 LCD다.
이거 LCD 핀맵으로 설계했다.



백라이트는 다이렉트로 30V 넣어주고, 사운드는 일단 빼고 만들었다.



보드는 이런 느낌...

사운드도 넣고 LED 드라이버도 추가해 줄 생각이다.



자 다음엔 FT800 드라이버를 만들어보자.


ps. IC 가격을 깜빡했네. 엘레먼트14는 현재 1~99 단위로 $8.76
      디지키에 좀더 싼 가격대가 있기는 하다.