My RTOs VI-touch transplant (S5pv210+threadx+ucgui+touch)

Source: Internet
Author: User

Long time no attention to the RTOS, so also has not been updated. Recently Idle, the Gpio i²c tune, simple transplant Touch, on the s5pv210.

Debugging i²c, waste a lot of twists and turns, and finally the use of the oscilloscope to find a small mistake, tossing for a long time.

Briefly next steps:

1, first i²c Drive, using Gpio i²c Way

#include <stdio.h> #include <touch.h> #define DELAY 10#define SDA 0#define SCL 1#define Gpd1con (* (volatile uns igned long *) 0xe02000c0) #define GPD1DAT (* (volatile unsigned long *) 0xe02000c4) #define GPD1PUD (* (Volatile unsigned long * ) 0xe02000c8) #define GPD1DRV (* (volatile unsigned long *) 0xe02000cc) #define SDA2_SET_INPUT (Gpd1con &= ~ (0xf<< )) #define SDA2_SET_OUTPUT (Gpd1con = (Gpd1con & (~ (0x0f<<16)) | (0x1<<16)) #define SCL2_SET_INPUT (Gpd1con &= ~ (0xf<<20)); #define SCL2_SET_OUTPUT (Gpd1con = (Gpd1con & (0x0f<& lt;20))) | (0X1&LT;&LT;20)) #define SDA2_SET_VALUE (x) (Gpd1dat = (Gpd1dat & ~ (1<<4)) | (x << 4)) #define SCL2_SET_VALUE (x) (Gpd1dat = (Gpd1dat & ~ (1<<5)) | (x << 5)) #define Sda2_get_value ((Gpd1dat & (1<<4) > 0 1:0) #define Scl2_get_value ((Gpd1dat & (1<<5)) ; 0? 1:0) void Gpio_i2c_init (void) {Gpd1drv = (Gpd1drv & ~ (0x5 << 10) | (0x5 << 10)); Gpd1pud = (Gpd1drv & ~ (0xf <<) | 0xa << 10); Scl2_set_output; Sda2_set_output; Sda2_set_value (1); Scl2_set_value (1);} void I2c_start (void) {scl2_set_output; Sda2_set_output; Sda2_set_value (1); Scl2_set_value (1); Udelay (DELAY);          Sda2_set_value (0); Udelay (DELAY); Scl2_set_value (0); Udelay (DELAY);} void I2c_stop (void) {scl2_set_output; Sda2_set_output; Sda2_set_value (0);    Scl2_set_value (0); Udelay (DELAY); Scl2_set_value (1); Udelay (DELAY); Sda2_set_value (1); Udelay (DELAY);} void I2c_send_ack (unsigned char ack) {scl2_set_output; Sda2_set_output;if (ACK) sda2_set_value (1); else Sda2_set_value (0); Udelay (DELAY);   Scl2_set_value (1);   Udelay (DELAY); Scl2_set_value (0); Udelay (DELAY);} Char i2c_receive_ack (void) {char rc = 0; Scl2_set_output; Sda2_set_input; Scl2_set_value (1); Udelay (DELAY); if (sda2_get_value) {rc = 1;} Scl2_set_value (0); Sda2_set_output; Sda2_set_value (1); return RC;} unsigned char i2c_send_byte (unsigned char send_byte) {unsigned char rc = 0;unsigned char out_mask = 0x80;unsigned Char Valu E;unSigned char count = 8; Sda2_set_output;   Scl2_set_output;while (Count > 0) {value = ((Send_byte & out_mask)? 1:0);     if (value = = 1) {sda2_set_value (1);     } else {sda2_set_value (0);                          } udelay (DELAY);       Scl2_set_value (1);             Udelay (DELAY);   Scl2_set_value (0);          Udelay (DELAY);      Out_mask >>= 1;       count--;     }sda2_set_value (1); rc = I2c_receive_ack (); return RC;}  void I2c_read_byte (unsigned char *buffer, unsigned char ack) {unsigned char count = 0x08;unsigned char data = 0x00;unsigned char temp = 0; Sda2_set_input;    Scl2_set_output;while (Count > 0) {scl2_set_value (1); Udelay (DELAY); temp = Sda2_get_value; Data <<= 1;if (temp) data |= 0x01;    Scl2_set_value (0); Udelay (DELAY); count--; }i2c_send_ack (ack);//0 = ack 1 = nack*buffer = data;} int gpio_i2c_master_send (unsigned int slaveaddr, unsigned char *data, unsigned int length) {unsigned int i, j;int RC; Slaveaddr = (slaveaddR << 1) & ~0x01;i2c_start (), rc = I2c_send_byte (SLAVEADDR), if (RC) {printf ("I2c_send_byte no ACK 1\n"); return-1;} for (j = 0; J < length; J + +) {rc = I2c_send_byte (Data[j]);//Send Dataif (RC) {printf ("I2c_send_byte no ACK 2\n"); return-1;}} I2c_stop ();//Stop Signal udelay (); return 0;} int gpio_i2c_master_recv (unsigned int slaveaddr, unsigned char *data, unsigned int length) {unsigned int i, j;unsigned int Data;int RC; Slaveaddr = (slaveaddr << 1) | 0x01;i2c_start (); rc = I2c_send_byte (SLAVEADDR), if (RC) {printf ("I2c_read_byte no ACK 1\n"); return-1;} for (j=0; j<length; J + +) {i2c_read_byte (data++,!) ( Length-j-1));//read data;} I2c_stop ();//stop signal return length;} int i2c_read_data (unsigned int slaveaddr, char *reg, unsigned char *values, int length) {int Ret;int count = 0;retry:/* sel ECT Register*/ret = Gpio_i2c_master_send (Slaveaddr, Reg, 1), if (Ret < 0) {Udelay (DELAY * 2), if (++count < 2) goto RE Try;return ret;} /* for Setup TX transaction. */udelay (DELAY); ret = GPIO_I2C_MASTER_RECV (slaveaddr, values, length); if (Ret < 0) return Ret;udelay (DELAY); return length;} 

2. Touch Drive

The Touch IC is FT5406 and the slave address is 0x70.

With the help of Bo Friend's one-page chip data, wrote the simplest single-point read:



Multi-point is also simple, you can refer to the Android Multi-touch Protocol escalation Point

#include <touch.h> #include <exception.h>struct touch_data touch_data;int Touch_irq () {int I;int num = 0;int x , Y;char reg[1] = {0};unsigned char buf[10];i2c_read_data (0x38, Reg, buf, 7), if (num = (buf[2] & 0x0f) = = 0) {if (touch _data.ispress) {touch_data.ispress = 0;touch_data.x = -1;touch_data.y = -1;touch_event (touch_data.x, TOUCH_DATA.Y);} printf ("release\r\n"); return 0;} x = (buf[3]&0x0f) << 8 | Buf[4];y = (buf[5]&0x0f) << 8 | buf[6];//printf ("num:%d, x:%d, y:%d\r\n", num, x, y); touch_data.x= x;touch_data.y= y;if (touch_data.ispress = = 0) touch_ data.ispress = 1;touch_event (touch_data.x, TOUCH_DATA.Y); return 0;} void Touch_init (void) {unsigned char uc_reg_value;unsigned char uc_reg_addr;unsigned char buf[1];unsigned char dst[1]; Touch_int_setup (); I2c_read_data (0x38, buf, DST, 1);p rintf ("Touch fw:0x%x\r\n", dst[0]); buf[0] = 0x88;i2c_read_data ( 0x38, buf, DST, 1);p rintf ("Report rate:0x%x\r\n", Dst[0] *); buf[0] = 0x80;i2c_read_data (0x38, buf, DST, 1);p RINTF ("Touch threshold:0x%x\r\n", Dst[0] * 4); intc_enable (num_eint14);} 

The ability to access the touch firmware information in the Touch_init initialization indicates that the I²C communication is OK.


3, see the effect ^ ^






The last two animations compare cards.



4: Problems and shortcomings

Because it is a capacitive screen, interrupt start, touch, will not stop the escalation of the interruption, will lead to other threads block, the situation of stalling, especially when the screen is more complex, the latter can take the method of inquiry, placed in a separate thread or reduce the rate of touch;

In addition, LCD has only one layer of framebuffer, multi-layer display is Ucgui inefficient, later optimization can open at least two framebuffer at the same time.


5. Source code

http://download.csdn.net/detail/liujia2100/8859911


Later attempt to transplant lwIP, paired with Arduino, the Internet of things ^ ^.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

My RTOs VI-touch transplant (S5pv210+threadx+ucgui+touch)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.