datasheet

Tiny210触摸屏之一线触摸屏驱动

2018-10-12来源: eefocus 关键字:Tiny210  触摸屏  线触摸屏驱动

1wire_ts.c源码:

#include "linux/errno.h"

#include "linux/kernel.h"

#include "linux/module.h"

#include "linux/slab.h"

#include "linux/input.h"

#include "linux/init.h"

#include "linux/serio.h"

#include "linux/delay.h"

#include "linux/clk.h"

#include "linux/miscdevice.h"

#include "linux/platform_device.h"

#include "linux/timer.h"

#include "linux/param.h"

#include "linux/poll.h"

#include "linux/proc_fs.h"

#include "linux/gpio.h"

#include "linux/cdev.h"

#include "linux/sched.h"

#include "linux/interrupt.h"

#include "linux/irq.h"

#include "linux/err.h"

#include "linux/io.h"

#include "asm/system.h"

#include "asm/leds.h"

#include "asm/mach-types.h"

#include "asm/irq.h"

#include "asm/mach/time.h"

#include "asm/io.h"

#include "asm/irq.h"

#include "asm/uaccess.h"

#include "mach/map.h"

#include "mach/regs-irq.h"

#include "mach/regs-clock.h"

#include "mach/regs-gpio.h"

#include "plat/regs-timer.h"     

#include "plat/gpio-cfg.h"

#include "plat/clock.h"

#include "plat/cpu.h"

static DECLARE_WAIT_QUEUE_HEAD(ts_waitq);

#define MHZ (1000*1000)

#define PRINT_MHZ(m)             ((m) / MHZ), ((m / 1000) % 1000)

#define TOUCH_DEVICE_NAME    "tiny_ts"

#define SAMPLE_BPS 9600

#define SLOW_LOOP_FEQ 25

#define FAST_LOOP_FEQ 60

#define REQ_TS   0x40U

#define REQ_INFO 0x60U

enum {

    IDLE,

    START,

    REQUEST,

    WAITING,

    RESPONSE,

    STOPING,

} one_wire_status = IDLE;

struct timer_regs {

    unsigned long tcfg0;

    unsigned long tcfg1;

    unsigned long tcon;

    unsigned long reserved1[9];

    unsigned long tcntb3;

    unsigned long tcmpb3;

    unsigned long tcnto3;

    unsigned long reserved2[2];

    unsigned long tint_cstat;    

};

static struct timer_regs *timer_regs;

static unsigned long *gph1con;

static unsigned long *gph1dat;

static int ts_ready;

static unsigned ts_status;

static unsigned lcd_type, firmware_ver;

static unsigned total_received, total_error;

static unsigned last_req, last_res;

static unsigned long TCNT_FOR_SAMPLE_BIT;

static volatile unsigned int io_bit_count;

static volatile unsigned int io_data;

static volatile unsigned char one_wire_request;

static int exitting;

static struct timer_list ts_timer;

static inline void notify_ts_data(unsigned x, unsigned y, unsigned down)

{

    if (!down && !(ts_status &(1U << 31))) {

        // up repeat, give it up

        return;

    }

    ts_status = ((x << 16) | (y)) | (down << 31);

    ts_ready = 1;

    wake_up_interruptible(&ts_waitq);

}

static ssize_t ts_read(struct file *filp, char *buffer, size_t count, loff_t *ppos)

{

    unsigned long err;

    if (!ts_ready) {

        if (filp->f_flags & O_NONBLOCK)

            return -EAGAIN;

        else

            wait_event_interruptible(ts_waitq, ts_ready);

    }

    ts_ready = 0;

    if (count < sizeof ts_status) {

        return -EINVAL;

    } else {

        count = sizeof ts_status;

    }

    err = copy_to_user((void *)buffer, (const void *)(&ts_status), sizeof ts_status);

    return err ? -EFAULT : sizeof ts_status;

}

static unsigned int ts_poll( struct file *file, struct poll_table_struct *wait)

{

    unsigned int mask = 0;

    poll_wait(file, &ts_waitq, wait);

    if (ts_ready)

        mask |= POLLIN | POLLRDNORM;

    return mask;

}

static struct file_operations ts_fops = {

    owner:        THIS_MODULE,

    read:           ts_read,    

    poll:            ts_poll,

};

static struct miscdevice ts_misc = {

    .minor        = 181,

    .name         = TOUCH_DEVICE_NAME,

    .fops           = &ts_fops,

};

static inline void notify_info_data(unsigned char _lcd_type,unsigned char ver_year, 

                                                         unsigned char week)

{

    if (_lcd_type != 0xFF) {

        lcd_type = _lcd_type;

        firmware_ver = ver_year * 100 + week;

    }

}

static inline void set_pin_value(int v)

{

    if (v) {

        *gph1dat |= 1<<2;

    } else {

        *gph1dat &= ~(1<<2);

    }

}

static inline int get_pin_value(void)

{

    if(*gph1dat & (1<<2))

        return 1;

    else

        return 0;

}

// CRC

static const unsigned char crc8_tab[] = {

0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0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A, 0x33, 0x34,

0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B,

0x76, 0x71, 0x78, 0x7F, 0x6A, 0x6D, 0x64, 0x63,

0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B,

0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13,

0xAE, 0xA9, 0xA0, 0xA7, 0xB2, 0xB5, 0xBC, 0xBB,

0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83,

0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB,

0xE6, 0xE1, 0xE8, 0xEF, 0xFA, 0xFD, 0xF4, 0xF3,

};

#define crc8_init(crc) ((crc) = 0XACU)

#define crc8(crc, v) ( (crc) = crc8_tab[(crc) ^(v)])

// once a session complete

static void one_wire_session_complete(unsigned char req, unsigned int res)

{

    unsigned char crc;

    const unsigned char *p = (const unsigned char*)&res;

    total_received ++;

    last_res = res;

    crc8_init(crc);

    crc8(crc, p[3]);

    crc8(crc, p[2]);

    crc8(crc, p[1]);

    if (crc != p[0]) {

        // CRC dismatch

        if (total_received > 100) {

            total_error++;

        }

        return;

    }

    switch(req) {

        case REQ_TS:

            {

                unsigned short x,y;

                unsigned pressed;

                x =  ((p[3] >>   4U) << 8U) + p[2];

                y =  ((p[3] &  0xFU) << 8U) + p[1];

                pressed = (x != 0xFFFU) && (y != 0xFFFU); 

notify_ts_data(x, y, pressed);

[1] [2] [3]

关键字:Tiny210  触摸屏  线触摸屏驱动

编辑:什么鱼 引用地址:http://www.eeworld.com.cn/mcu/2018/ic-news101241697.html
本网站转载的所有的文章、图片、音频视频文件等资料的版权归版权所有人所有,本站采用的非本站原创文章及图片等内容无法一一联系确认版权者。如果本网所选内容的文章作者及编辑认为其作品不宜公开自由传播,或不应无偿使用,请及时通过电子邮件或电话通知我们,以迅速采取适当措施,避免给双方造成不必要的经济损失。

上一篇:Tiny210驱动之USB设备驱动程序
下一篇:Tiny210触摸屏之触摸屏控制器驱动

关注eeworld公众号 快捷获取更多信息
关注eeworld公众号
快捷获取更多信息
关注eeworld服务号 享受更多官方福利
关注eeworld服务号
享受更多官方福利

推荐阅读

Tiny4412友善之臂ARM开发板静态IP设置(重启有效)

刚入手Tiny4412开发板,发现它的ip地址不是192.168.1.230,老是自动跳变,今天是192.168.1.7,明天开机就变成了192.168.1.8,所以就决定将其设为静态ip地址:192.168.1.240。首先参考网上提供的一个常见的方案: 要修改arm开发板的IP,如果是yaffs2文件,可以1、首先要修改/etc/init.d/rcS文件,在/sbin/ifconfig lo 127.0.0.0下添加一行/sbin/ifconfig eth0 192.168.1.20 up注:192.168.1.20 只是举例,可以改成你想要修改的IP地址本来这样修改之后就可以的,但是我发现仍然不行,使用
发表于 2018-10-14
Tiny4412友善之臂ARM开发板静态IP设置(重启有效)

Tiny4412和PC传文件(含挂载NFS文件系统)方法

=Device+TreeTiny4412裸机程序汇总地址:http://www.100ask.org/bbs/forum.php?mod=viewthread&tid=11778&highlight=tiny4412iTOP-4412实现NFS网络文件系统启动(包括安装Ubuntu NFS服务、编译配置内核)http://www.oschina.net/question/2371345_2158782==================================================================驱动测试搭建开发环境:由于采用nfs作为文件系统启动失败,所以在内核启动后在把服务器的/home/book
发表于 2018-10-14

tiny4412的Uboot启动流程

基于友善之臂tiny4412开发板,uboot版本是2010.12:一般我们将UBOOT分为2个阶段,第一阶段主要为汇编代码,用于初始化必要的硬件并将UBOOT copy到SDRAM中并跳转到SDRAM执行,第二阶段主要为c代码,主要作用是加载kernel到SDRAM,准备启动kernel的参数最后跳转到kernel处执行,当然uboot里也可以有许多扩展功能,比如下载功能,实现各种驱动程序等.第一阶段:1.首先就是uboot的入口的地址是arch/arm/cpu/armv7/start.S, 这可以从相同路径下的连接脚本u-boot.lds 中知道,如下
发表于 2018-10-14

Tiny4412的MMU解析

1、Tiny4412的MMU和S3C6410都是一样的,以前的程序都可以运行,因为MMU有两个特点:  ①MMU实在cp15协处理器里面操作的,协处理器由ARM公司统一设计,不会轻易变化,这部分代码和Samsung没有关系;  ②MMU的功能就是把虚拟地址映射物理地址上去。2、为什么裸机要讲MMU?  因为中断,ARM地址的布局。现在三星处理器地址的布局和以前不一样,以前S3C6410的0地址是可以选的,比如nand flash启动的时候0地址对应片内内存;nor flash启动的时候0地址对应nor flash的0地址。也就是0地址我们可以选择是ROM或者RAM
发表于 2018-10-14

Tiny4412异常处理

=0x70003000  test.o  -o test    arm-linux-objcopy  -O binary  test  test.binclean:    rm -f test.o  test  test.bin   *~ ===================================================================烧写测试参考:“Tiny4412从SD卡启动u-boot用linux的DNW烧写裸板程序”说明: 
发表于 2018-10-14

Tiny4412的MMU映射代码示例

;                   段映射只用到一级页表,页映射用到一级页表和二级页表。3、关于映射粒度:段映射的映射粒度有两种,1M section和16M supersection;                      
发表于 2018-10-14

小广播

何立民专栏

单片机及嵌入式宝典

北京航空航天大学教授,20余年来致力于单片机与嵌入式系统推广工作。

电子工程世界版权所有 京ICP证060456号 京ICP备10001474号 电信业务审批[2006]字第258号函 京公海网安备110108001534 Copyright © 2005-2018 EEWORLD.com.cn, Inc. All rights reserved
pt type="text/javascript" src="//v3.jiathis.com/code/jia.js?uid=2113614" charset="utf-8">