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设备驱动程序
下一篇:最后一页

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

推荐阅读

新型Silicon Labs Tiny Gecko MCU有效延长 IoT连接设备电池寿命

中国,北京-2018年3月8日-Silicon Labs(亦称“芯科科技”,NASDAQ:SLAB)扩展其广受欢迎的EFM32™ Tiny Gecko微控制器(MCU)系列产品,旨在满足开发人员进行下一代安全、电池供电型物联网(IoT)连接设备的设计需求。Silicon Labs新型EFM32TG11 Tiny Gecko MCU为需要长电池寿命的设备提供了低成本的超低功耗解决方案,且不会减弱功能和降低安全性。Tiny Gecko 11 MCU是智能电表、个人医疗设备和家庭自动化产品的理想选择,这些产品通常具有多个传感器、本地显示和触摸控制。新型MCU可在IoT设计中作为独立微控制器或搭配网络协处理器使用,这为开发人员提供了出色
发表于 2018-03-09
新型Silicon Labs Tiny Gecko MCU有效延长 IoT连接设备电池寿命

Tiny6410 交叉编译helloworld程序

在工作目录下建立helloworld.c文件 #include <stdio.h>  main()  {      printf("helloworld!\n");  }  保存关闭后。 编译helloworld文件: root@snail:/home/workdir/qt/project/helloworld# arm-linux-gcc helloworld.c -o hellow
发表于 2017-01-12
Tiny6410 交叉编译helloworld程序

Tiny6410 设备驱动之helloworld

;  //模块初始化  static int __init hello_init(void)  {      printk(KERN_ALERT "Hello world!\n");      return 0;  }  //模块退出  static void  __exit 
发表于 2017-01-12
Tiny6410 设备驱动之helloworld

Tiny6410 LED字符设备驱动

; #define LED_3_OFF   7  #define LED_4_ON    8  #define LED_4_OFF   9       static int led_open (struct inode *inode,struct file *filp)    
发表于 2017-01-12
Tiny6410 LED字符设备驱动

瑞萨单片机教程之R8C/Tiny

第二节  Tiny系列 1.1  Tiny系列     瑞萨正在拓展在SuperH、M16C、H8、H8S等瑞萨所提供的高性能MCU各族及各系列上安装了闪存的品种,该产品群多达28类,品种超过了200种,想必也只有瑞萨能拥有如此之多的闪存MCU产品。在这些瑞萨的闪存MCU中,内置高性能内核与闪存,同时实现少引脚和小型封装的单芯片MCU,就是“Tiny系列”。 8〜32位齐全的Tiny系列(Tiny的定位图) Tiny系列拥有以下众多优点。 ① 高性能CPU(16位、32位)、小型化的20〜80引脚的少引脚封装
发表于 2016-05-17

S3C6410,Tiny6410,Mini6410,MoblieDDR内存驱动

0   扩展内存命令 [22] (见下表)   芯片号 [21:20] 映射到外部存储芯片地址的位   命令 [19:18] 具体命令(见下表)   Bank地址 [17:16] 当以MRS或EMRS命令访问时,映射到外部存储器的Bank地址位  
发表于 2016-04-26
S3C6410,Tiny6410,Mini6410,MoblieDDR内存驱动

小广播

何立民专栏

单片机及嵌入式宝典

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

电子工程世界版权所有 京ICP证060456号 京ICP备10001474号 电信业务审批[2006]字第258号函 京公海网安备110108001534 Copyright © 2005-2018 EEWORLD.com.cn, Inc. All rights reserved