📄 tube.c
字号:
/* * s3c2410-numtube.c * *numeric tube driver for SAMSUNG UP-NETARM2410 * * Author: Qian zhengguang <qzg_uptech@126.com> * based on threewater <threewater@up-tech.com> * Date : $Date: 2007/01/08 13:22:00 $ * * $Revision: 1.1.0.0 $ * * * This file is subject to the terms and conditions of the GNU General Public * License. See the file COPYING in the main directory of this archive * for more details. * * History: * * */#include <linux/config.h>#include <linux/module.h>#include <linux/kernel.h>#include <linux/init.h>#include <linux/miscdevice.h>#include <linux/sched.h>#include <linux/delay.h>#include <linux/poll.h>#include <linux/spinlock.h>#include <linux/delay.h>#include <asm/hardware.h>#include <asm/arch/spi.h>#include <asm/arch/S3C2410.h>/* debug macros *///#undef DEBUG#define DEBUG#ifdef DEBUG#define DPRINTK( x... ) printk("s3c2410-numeric tube : " ##x)#else#define DPRINTK( x... )#endif/********************** MCP2510 Pin *********************************/#define HC595_PIN_CS (2) //GPIO_H1#define GPIO_HC595_CS (GPIO_MODE_OUT | GPIO_PULLUP_DIS | GPIO_H1)#define HC595_Enable() do {GPHDAT |= HC595_PIN_CS;udelay(100);}while(0);#define HC595_Disable() do {GPHDAT &= ~HC595_PIN_CS;}while(0);#define DEVICE_NAME "s3c2410-hc595"#define SPIRAW_MINOR 1static int Major = 0;static int opencount=0;#define TRUE 1#define FALSE 0static char tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x8e};//0-9,-,all offstatic void SendSIOData(unsigned int data){ SPISend(data,0);} static ssize_t s3c2410_hc595_write(struct file *file, const char *buffer, size_t count,loff_t * ppos){ char sendbuffer[4]; char num=0; int tensdigit=0;int singledigit=0; if( copy_from_user(sendbuffer, buffer, count)) { kfree( sendbuffer ); DPRINTK(" return -EFAULT;\n"); return -EFAULT; } singledigit=(sendbuffer[0])%10; tensdigit=(int)(sendbuffer[0]/10); DPRINTK("singledigit=%d ; tensdigit= %d \n",singledigit,tensdigit); num=tab[singledigit]; HC595_Disable(); SendSIOData(num); HC595_Enable(); udelay(100); num=tab[tensdigit]; HC595_Disable(); SendSIOData(num); HC595_Enable(); udelay(100); HC595_Disable(); return 0;}static int s3c2410_hc595_open(struct inode *inode, struct file *file){ if(opencount==1) return -EBUSY; opencount++; set_gpio_ctrl(GPIO_HC595_CS); MOD_INC_USE_COUNT; DPRINTK("device open\n"); return 0;}static int s3c2410_hc595_release(struct inode *inode, struct file *filp){ opencount--; HC595_Disable(); MOD_DEC_USE_COUNT; DPRINTK("device release\n"); return 0;}static struct file_operations s3c2410_hc595_fops = { owner: THIS_MODULE, write: s3c2410_hc595_write, open: s3c2410_hc595_open, release: s3c2410_hc595_release,};#ifdef CONFIG_DEVFS_FSstatic devfs_handle_t devfs_spi_dir, devfs_spiraw;#endifstatic int __init s3c2410_hc595_init(void){ int ret; SPI_initIO(0); Set_SIO_mode(0, SPCON_SMOD_POLL | SPCON_ENSCK | SPCON_MSTR |SPCON_CPOL_HIGH | \ SPCON_CPHA_FMTA, 33, 2, NULL, NULL, NULL); set_gpio_ctrl(GPIO_HC595_CS); ret = register_chrdev(0, DEVICE_NAME, &s3c2410_hc595_fops); if (ret < 0) { printk(DEVICE_NAME " can't get major number\n"); return ret; } Major = ret;#ifdef CONFIG_DEVFS_FS devfs_spi_dir = devfs_mk_dir(NULL, "tube", NULL); devfs_spiraw = devfs_register(devfs_spi_dir, "0", DEVFS_FL_DEFAULT, Major, SPIRAW_MINOR, S_IFCHR | S_IRUSR | S_IWUSR, &s3c2410_hc595_fops, NULL);#endif DPRINTK("Dprintk device open\n"); printk(DEVICE_NAME " initialized\n"); return 0;}static void __exit s3c2410_hc595_exit(void){ HC595_Disable() printk(DEVICE_NAME " unloaded\n");}module_init(s3c2410_hc595_init);module_exit(s3c2410_hc595_exit);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -