1. 程式人生 > >fl2440 platform 按鍵驅動的製作和測試

fl2440 platform 按鍵驅動的製作和測試

在led驅動的基礎上,繼續學習按鍵驅動

Makefile

  1
  2 obj-m := s3c_button.o
  3 KERNEL_DIR := ~/fl2440/kernel/linux-3.0.54/ 
  4 PWD := $(shell pwd)
  5 all:
  6     make -C $(KERNEL_DIR) SUBDIRS=$(PWD) modules
  7 clean:
  8      rm *.o *.ko *.mod.c
  9 
 10  .PHONY:clean

plat_button.c驅動內容

#include "s3c_driver.h"


#define DRV_AUTHOR                "Guo Wenxue <
[email protected]
>" #define DRV_DESC "S3C24XX button driver" /* Driver version*/ #define DRV_MAJOR_VER 1 #define DRV_MINOR_VER 0 #define DRV_REVER_VER 0 #define DEV_NAME DEV_BUTTON_NAME //#define DEV_MAJOR DEV_BUTTON_MAJOR #ifndef DEV_MAJOR #define DEV_MAJOR 0 /* dynamic major by default */ #endif #define BUTTON_UP 0 /* Button status is up */ #define BUTTON_DOWN 1 /* Button status is pushed down */ #define BUTTON_UNCERTAIN 2 /* Button status uncerntain */ #define TIMER_DELAY_DOWN (HZ/50) /*Remove button push down dithering timer delay 20ms */ #define TIMER_DELAY_UP (HZ/10) /*Remove button up dithering timer delay 100ms */ static int debug = DISABLE; static int dev_major = DEV_MAJOR; static int dev_minor = 0; /*============================ Platform Device part ===============================*/ /* Button hardware informtation structure*/ struct s3c_button_info { unsigned char num; /*Button nubmer */ char * name; /*Button nubmer */ int nIRQ; /*Button IRQ number*/ unsigned int setting; /*Button IRQ Pin Setting*/ unsigned int gpio; /*Button GPIO port */ }; /* The button plaotform device private data structure */ struct s3c_button_platform_data { struct s3c_button_info *buttons; int nbuttons; }; /* Button hardware informtation data*/ static struct s3c_button_info s3c_buttons[] = { [0] = { .num = 1, .name = "KEY1", .nIRQ = IRQ_EINT0, .gpio = S3C2410_GPF(0), .setting = S3C2410_GPF0_EINT0, }, [1] = { .num = 2, .name = "KEY2", .nIRQ = IRQ_EINT2, .gpio = S3C2410_GPF(2), .setting = S3C2410_GPF2_EINT2, }, [2] = { .num = 3, .name = "KEY3", .nIRQ = IRQ_EINT3, .gpio = S3C2410_GPF(3), .setting = S3C2410_GPF3_EINT3, }, [3] = { .num = 4, .name = "KEY4", .nIRQ = IRQ_EINT4, .gpio = S3C2410_GPF(4), .setting = S3C2410_GPF4_EINT4, }, }; /* The button platform device private data */ static struct s3c_button_platform_data s3c_button_data = { .buttons = s3c_buttons,//這邊要改的和.c檔名一樣 .nbuttons = ARRAY_SIZE(s3c_buttons), }; struct button_device { unsigned char *status; /* The buttons Push down or up status */ struct s3c_button_platform_data *data; /* The buttons hardware information data */ struct timer_list *timers; /* The buttons remove dithering timers */ wait_queue_head_t waitq; /* Wait queue for poll() */ volatile int ev_press; /* Button pressed event */ struct cdev cdev; struct class *dev_class; } button_device; static void platform_button_release(struct device * dev) { return; } static struct platform_device s3c_button_device = { .name = "s3c_button", .id = 1, .dev = { .platform_data = &s3c_button_data, .release = platform_button_release, }, }; static irqreturn_t s3c_button_intterupt(int irq,void *de_id) { int i; int found = 0; struct s3c_button_platform_data *pdata = button_device.data; for(i=0; i<pdata->nbuttons; i++) { if(irq == pdata->buttons[i].nIRQ) { found = 1; break; } } if(!found) /* An ERROR interrupt */ return IRQ_NONE; /* Only when button is up then we will handle this event */ if(BUTTON_UP == button_device.status[i]) { button_device.status[i] = BUTTON_UNCERTAIN; mod_timer(&(button_device.timers[i]), jiffies+TIMER_DELAY_DOWN); } return IRQ_HANDLED; } static void button_timer_handler(unsigned long data) { struct s3c_button_platform_data *pdata = button_device.data; int num =(int)data; int status = s3c2410_gpio_getpin( pdata->buttons[num].gpio ); if(LOWLEVEL == status) { if(BUTTON_UNCERTAIN == button_device.status[num]) /* Come from interrupt */ { //dbg_print("Key pressed!\n"); button_device.status[num] = BUTTON_DOWN; printk("%s pressed.\n", pdata->buttons[num].name); /* Wake up the wait queue for read()/poll() */ button_device.ev_press = 1; wake_up_interruptible(&(button_device.waitq)); } /* Cancel the dithering */ mod_timer(&(button_device.timers[num]), jiffies+TIMER_DELAY_UP); } else { //dbg_print("Key Released!\n"); button_device.status[num] = BUTTON_UP; // enable_irq(pdata->buttons[num].nIRQ); } return ; } /*===================== Button device driver part ===========================*/ static int button_open(struct inode *inode, struct file *file) { struct button_device *pdev ; struct s3c_button_platform_data *pdata; int i, result; pdev = container_of(inode->i_cdev,struct button_device, cdev); pdata = pdev->data; file->private_data = pdev; /* Malloc for all the buttons remove dithering timer */ pdev->timers = (struct timer_list *) kmalloc(pdata->nbuttons*sizeof(struct timer_list), GFP_KERNEL); if(NULL == pdev->timers) { printk("Alloc %s driver for timers failure.\n", DEV_NAME); return -ENOMEM; } memset(pdev->timers, 0, pdata->nbuttons*sizeof(struct timer_list)); /* Malloc for all the buttons status buffer */ pdev->status = (unsigned char *)kmalloc(pdata->nbuttons*sizeof(unsigned char), GFP_KERNEL); if(NULL == pdev->status) { printk("Alloc %s driver for status failure.\n", DEV_NAME); result = -ENOMEM; goto ERROR; } memset(pdev->status, 0, pdata->nbuttons*sizeof(unsigned char)); init_waitqueue_head(&(pdev->waitq)); for(i=0; i<pdata->nbuttons; i++) { /* Initialize all the buttons status to UP */ pdev->status[i] = BUTTON_UP; /* Initialize all the buttons' remove dithering timer */ setup_timer(&(pdev->timers[i]), button_timer_handler, i); /* Set all the buttons GPIO to EDGE_FALLING interrupt mode */ s3c2410_gpio_cfgpin(pdata->buttons[i].gpio, pdata->buttons[i].setting); irq_set_irq_type(pdata->buttons[i].nIRQ, IRQ_TYPE_EDGE_FALLING); /* Request for button GPIO pin interrupt */ result = request_irq(pdata->buttons[i].nIRQ, s3c_button_intterupt, IRQF_DISABLED, DEV_NAME, (void *)i); if( result ) { result = -EBUSY; goto ERROR1; } } return 0; ERROR1: kfree((unsigned char *)pdev->status); while(--i) { disable_irq(pdata->buttons[i].nIRQ); free_irq(pdata->buttons[i].nIRQ, (void *)i); } ERROR: kfree(pdev->timers); return result; } static int button_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) { struct button_device *pdev = file->private_data; struct s3c_button_platform_data *pdata; int i, ret; unsigned int status = 0; pdata = pdev->data; dbg_print("ev_press: %d\n", pdev->ev_press); if(!pdev->ev_press) { if(file->f_flags & O_NONBLOCK) { dbg_print("read() without block mode.\n"); return -EAGAIN; } else { /* Read() will be blocked here */ dbg_print("read() blocked here now.\n"); wait_event_interruptible(pdev->waitq, pdev->ev_press); } } pdev->ev_press = 0; for(i=0; i<pdata->nbuttons; i++) { dbg_print("button[%d] status=%d\n", i, pdev->status[i]); status |= (pdev->status[i]<<i); } ret = copy_to_user(buf, (void *)&status, min(sizeof(status), count)); return ret ? -EFAULT : min(sizeof(status), count); } static unsigned int button_poll(struct file *file, poll_table * wait) { struct button_device *pdev = file->private_data; unsigned int mask = 0; poll_wait(file, &(pdev->waitq), wait); if(pdev->ev_press) { mask |= POLLIN | POLLRDNORM; /* The data aviable */ } return mask; } static int button_release(struct inode *inode, struct file *file) { int i; struct button_device *pdev = file->private_data; struct s3c_button_platform_data *pdata; pdata = pdev->data; for(i=0; i<pdata->nbuttons; i++) { disable_irq(pdata->buttons[i].nIRQ); free_irq(pdata->buttons[i].nIRQ, (void *)i); del_timer(&(pdev->timers[i])); } kfree(pdev->timers); kfree((unsigned char *)pdev->status); return 0; } static struct file_operations button_fops = { .owner = THIS_MODULE, .open = button_open, .read = button_read, .poll = button_poll, .release = button_release, }; static int s3c_button_probe(struct platform_device *dev) { int result = 0; dev_t devno; /* Alloc the device for driver */ if (0 != dev_major) { devno = MKDEV(dev_major, dev_minor); result = register_chrdev_region(devno, 1, DEV_NAME); } else { result = alloc_chrdev_region(&devno, dev_minor, 1, DEV_NAME); dev_major = MAJOR(devno); } /* Alloc for device major failure */ if (result < 0) { printk("%s driver can't get major %d\n", DEV_NAME, dev_major); return result; } /* Initialize button_device structure and register cdev*/ memset(&button_device, 0, sizeof(button_device)); button_device.data = dev->dev.platform_data; cdev_init (&(button_device.cdev), &button_fops); button_device.cdev.owner = THIS_MODULE; result = cdev_add (&(button_device.cdev), devno , 1); if (result) { printk (KERN_NOTICE "error %d add %s device", result, DEV_NAME); goto ERROR; } button_device.dev_class = class_create(THIS_MODULE, DEV_NAME); if(IS_ERR(button_device.dev_class)) { printk("%s driver create class failture\n",DEV_NAME); result = -ENOMEM; goto ERROR; } #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24) device_create(button_device.dev_class, NULL, devno, NULL, DEV_NAME); #else device_create (button_device.dev_class, NULL, devno, DEV_NAME); #endif printk("S3C %s driver version %d.%d.%d initiliazed.\n", DEV_NAME, DRV_MAJOR_VER, DRV_MINOR_VER, DRV_REVER_VER); return 0; ERROR: printk("S3C %s driver version %d.%d.%d install failure.\n", DEV_NAME, DRV_MAJOR_VER, DRV_MINOR_VER, DRV_REVER_VER); cdev_del(&(button_device.cdev)); unregister_chrdev_region(devno, 1); return result; } static int s3c_button_remove(struct platform_device *dev) { dev_t devno = MKDEV(dev_major, dev_minor); cdev_del(&(button_device.cdev)); device_destroy(button_device.dev_class, devno); class_destroy(button_device.dev_class); unregister_chrdev_region(devno, 1); printk("S3C %s driver removed\n", DEV_NAME); return 0; } /*===================== Platform Device and driver regist part ===========================*/ static struct platform_driver s3c_button_driver = { .probe = s3c_button_probe, .remove = s3c_button_remove, .driver = { .name = "s3c_kbd", .owner = THIS_MODULE, }, }; static int __init s3c_button_init(void) { int ret = 0; ret = platform_device_register(&s3c_button_device); if(ret) { printk(KERN_ERR "%s: Can't register platform device %d\n", __FUNCTION__, ret); goto fail_reg_plat_dev; } dbg_print("Regist S3C %s Device successfully.\n", DEV_NAME); ret = platform_driver_register(&s3c_button_driver); if(ret) { printk(KERN_ERR "%s: Can't register platform driver %d\n", __FUNCTION__, ret); goto fail_reg_plat_drv; } dbg_print("Regist S3C %s Driver successfully.\n", DEV_NAME); return 0; fail_reg_plat_drv: platform_driver_unregister(&s3c_button_driver); fail_reg_plat_dev: return ret; } static void s3c_button_exit(void) { platform_driver_unregister(&s3c_button_driver); dbg_print("S3C %s platform device removed.\n", DEV_NAME); platform_device_unregister(&s3c_button_device); dbg_print("S3C %s platform driver removed.\n", DEV_NAME); } module_init(s3c_button_init); module_exit(s3c_button_exit); module_param(debug, int, S_IRUGO); module_param(dev_major, int, S_IRUGO); module_param(dev_minor, int, S_IRUGO); MODULE_AUTHOR(DRV_AUTHOR); MODULE_DESCRIPTION(DRV_DESC); MODULE_LICENSE("GPL"); MODULE_ALIAS("platform:S3C24XX_button");

vim plat_ioctl.h 標頭檔案

 
 17 #ifndef __PLAT_IOCTL_H
 18 #define __PLAT_IOCTL_H
 19 
 20 #include <asm/ioctl.h>
 21 
 22 /*===========================================================================
 23  *                Common ioctl command definition 
 24  *===========================================================================*/
 25 
 26 #define PLATDRV_MAGIC           0x60
 27 
 28 /*===========================================================================
 29  *                 ioctl command for all the drivers 0x01~0x0F
 30  *===========================================================================*/
 31 
 32 /*args is enable or disable*/
 33 #define SET_DRV_DEBUG               _IO (PLATDRV_MAGIC, 0x01)
  1 /*********************************************************************************
  2  *  Copyright(c)  2011, Guo Wenxue <

[email protected]>
  3  *  All ringhts reserved.
  4  *
  5  *     Filename:  s3c_ioctl.h
  6  *  Description:  ioctl() cmd argument definition here
  7  *
  8  *     ChangLog:
  9  *      1,   Version: 1.0.0
 10  *              Date: 2011-08-10
 11  *            Author: guowenxue <[email protected]>
 12  *       Descrtipion: Initial first version
 13  *
 14  *
 15  ********************************************************************************/
 16 
 17 #ifndef __PLAT_IOCTL_H
 18 #define __PLAT_IOCTL_H
 19 
 20 #include <asm/ioctl.h>
 21 
 22 /*===========================================================================
 23  *                Common ioctl command definition 
 24  *===========================================================================*/
 25 
 26 #define PLATDRV_MAGIC           0x60
 27 
 28 /*===========================================================================
 29  *                 ioctl command for all the drivers 0x01~0x0F
 30  *===========================================================================*/
 31 
 32 /*args is enable or disable*/
 33 #define SET_DRV_DEBUG               _IO (PLATDRV_MAGIC, 0x01)
 plat_ioctl.h                                                                                                                       
 34 #define GET_DRV_VER                 _IO (PLATDRV_MAGIC, 0x02)
 35 
 36 /*===========================================================================
 37  *                 ioctl command for few ioctl() cmd driver 0x10~0x2F
 38  *===========================================================================*/
 39 
 40 /* LED driver */
 41 #define LED_OFF                     _IO (PLATDRV_MAGIC, 0x18)
 42 #define LED_ON                      _IO (PLATDRV_MAGIC, 0x19)
 43 #define LED_BLINK                   _IO (PLATDRV_MAGIC, 0x1A)
 44 #define ADC_SET_CHANNEL             _IO (PLATDRV_MAGIC, 0x1B)
 45 
 46 /*===========================================================================
 47  *                   ioctl command for GPRS driver 0x30~0x4F
 48  *===========================================================================*/
 49 #define GPRS_POWERDOWN              _IO (PLATDRV_MAGIC, 0x30)
 50 #define GPRS_POWERON                _IO (PLATDRV_MAGIC, 0x31)
 51 #define GPRS_RESET                  _IO (PLATDRV_MAGIC, 0x32)
 52 #define GPRS_POWERMON               _IO (PLATDRV_MAGIC, 0x33)
 53 #define GPRS_CHK_SIMDOOR            _IO (PLATDRV_MAGIC, 0x36)
 54 #define GPRS_SET_DTR                _IO (PLATDRV_MAGIC, 0x37)
 55 #define GPRS_SET_RTS                _IO (PLATDRV_MAGIC, 0x38)
 56 #define GPRS_GET_RING               _IO (PLATDRV_MAGIC, 0x39)
 57 #define SET_PWUP_TIME               _IO (PLATDRV_MAGIC, 0x3A)
 58 #define SET_PWDOWN_TIME             _IO (PLATDRV_MAGIC, 0x3B)
 59 #define SET_RESET_TIME              _IO (PLATDRV_MAGIC, 0x3C)
 60 #define GPRS_CHK_MODEL              _IO (PLATDRV_MAGIC, 0x3E) 
 61 
 62 /*===========================================================================
 63  *                   ioctl command for EEPROM driver 0x50~0x5F
 64  *===========================================================================*/
 65 #define LL_POWEROFF                 _IO (PLATDRV_MAGIC, 0x50)
 66 #define LL_POWERON                  _IO (PLATDRV_MAGIC, 0x51)
 67 #define LL_STOP                     _IO (PLATDRV_MAGIC, 0x52)
 68 #define LL_START                    _IO (PLATDRV_MAGIC, 0x53)
 69 #define LL_READ                     _IO (PLATDRV_MAGIC, 0x54)
 70 #define LL_WRITE                    _IO (PLATDRV_MAGIC, 0x55)
 71 #define LL_DATALOW                  _IO (PLATDRV_MAGIC, 0x56)
 72 #define LL_ACKNAK                   _IO (PLATDRV_MAGIC, 0x57)
 73 
 74 
 75 #endif                          /* __PLAT_IOCTL_H */

s3c_driver.h

#ifndef __S3C_DRIVER_H
#define __S3C_DRIVER_H


#include <linux/version.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/kref.h>
#include <linux/spinlock.h>
#include <asm/uaccess.h>
#include <linux/mutex.h>
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/device.h>
#include <linux/i2c.h>
#include <linux/string.h>
#include <linux/bcd.h>
#include <linux/miscdevice.h>
#include <linux/poll.h>
#include <linux/irq.h>
#include <linux/interrupt.h>
#include <linux/sysfs.h>
#include <linux/proc_fs.h>
#include <linux/rtc.h>
#include <linux/spinlock.h>
#include <linux/usb.h>
#include <asm/uaccess.h>
#include <asm/delay.h>
#include <linux/syscalls.h>  /* For sys_access*/
#include <linux/platform_device.h>
#include <linux/unistd.h>
#include <linux/tty.h>
#include <linux/tty_flip.h>
#include <linux/serial.h>
#include <linux/serial_core.h>
#include <linux/irq.h>
#include <mach/regs-gpio.h>
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32)
#include <mach/hardware.h>
#include <mach/gpio.h>
#include <asm/irq.h>
#else 
#include <asm-arm/irq.h>
#include <asm/arch/gpio.h>
#include <asm/arch/hardware.h>
#endif
#include "plat_ioctl.h"


/* ===========================================================================
 *         S3C24XX device driver common macro definition 
 *===========================================================================*/


#define ENPULLUP                    1
#define DISPULLUP                   0


#define HIGHLEVEL                   1
#define LOWLEVEL                    0


#define INPUT                       1
#define OUTPUT                      0


#define OFF                         0
#define ON                          1


#define ENABLE                      1
#define DISABLE                     0


#define TRUE                        1
#define FALSE                       0


/* ===========================================================================
 *         S3C24XX device driver name and Major number define 
 *===========================================================================*/




#define DEV_LED_NAME                "led"
#define DEV_LED_MAJOR               203


#define DEV_BUTTON_NAME             "button"
#define DEV_BUTTON_MAJOR            "211"


#define DEV_ADC_NAME                "adc"
#define DEV_ADC_MAJOR               "212"


/*  ***** Bit Operate Define *****/
#define SET_BIT(data, i)   ((data) |=  (1 << (i)))    /*   Set the bit "i" in "data" to 1  */
#define CLR_BIT(data, i)   ((data) &= ~(1 << (i)))    /*   Clear the bit "i" in "data" to 0 */
#define NOT_BIT(data, i)   ((data) ^=  (1 << (i)))    /*   Inverse the bit "i" in "data"  */
#define GET_BIT(data, i)   ((data) >> (i) & 1)        /*   Get the value of bit "i"  in "data" */
#define L_SHIFT(data, i)   ((data) << (i))            /*   Shift "data" left for "i" bit  */
#define R_SHIFT(data, i)   ((data) >> (i))            /*   Shift "data" Right for "i" bit  */




/* ===========================================================================
 *         S3C24XX device driver common function definition 
 *===========================================================================*/


#define SLEEP(x)    {DECLARE_WAIT_QUEUE_HEAD (stSleep); if (10 > x) mdelay ((x * 1000)); \
                        else wait_event_interruptible_timeout (stSleep, 0, (x / 10));}


#define VERSION_CODE(a,b,c)       ( ((a)<<16) + ((b)<<8) + (c))
#define DRV_VERSION               VERSION_CODE(DRV_MAJOR_VER, DRV_MINOR_VER, DRV_REVER_VER)
#define MAJOR_VER(a)              ((a)>>16&0xFF)
#define MINOR_VER(a)              ((a)>>8&0xFF)
#define REVER_VER(a)              ((a)&0xFF)


#define dbg_print(format,args...) if(DISABLE!=debug) \
        {printk("[kernel] ");printk(format, ##args);}    


static inline void print_version(int version)
{
#ifdef __KERNEL__
        printk("%d.%d.%d\n", MAJOR_VER(version), MINOR_VER(version), REVER_VER(version));
#else
        printf("%d.%d.%d\n", MAJOR_VER(version), MINOR_VER(version), REVER_VER(version));
#endif
}




#endif /* __S3C_DRIVER_H */

把Makefile,s3c_button.c,plat_ioctl.h,s3c_driver.h放在同一個資料夾中編譯

make之後產生s3c_button.然後傳到開發板,接下來再做按鍵驅動測試程式。

led_button.c(按鍵驅動測試程式碼)

#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>
#include <linux/fb.h>
#include <sys/mman.h>


#define KEY1 0x01
#define KEY2 0x02
#define KEY3 0x04
#define KEY4 0x08
#define PLATDRV_MAGIC   0x60
#define OFF _IO (PLATDRV_MAGIC,0x18)
#define ON _IO (PLATDRV_MAGIC,0X19)
#if 0
int  fork_1()
{    
     int pid = 0;
     pid = fork();      
     if(pid < 0)
     {
         printf("failed to fork!\n");
         return 1;
     }
     if(pid > 0)
     {
         wait(NULL);
     }

     else
     {
         execl("/bin/cp", "cp", "dev/fb0", "qwe", NULL);
     }
     return 0;
}

int fork_2()
{
    int pid = 0;
    pid = fork();
    if(pid < 0)
    {
         printf("failed to fork!\n");
         return 1;
    }

    if(pid > 0)
    {
         wait(NULL);
    }

    else
    {
         execl("/bin/tftp","tftp", "-p", "-r", "qwe", "192.168.1.8", NULL);
    }
    return 0;   
}
#endif

int main (int argc, char **argv)
{
    int button_fd;
    int led_fd;
    int ret_button;
    int current_button;
	int i=1;
	int j=1;
	int x=1;
	int y=1;
       

    button_fd = open("/dev/button", 0);
    
    

    if (button_fd < 0)
    {
        printf("open button failed.\n");
        exit(1);
    }
	
	while (1)
    {
        ret_button = read(button_fd, ¤t_button, sizeof(4));
        if (ret_button != sizeof(current_button))
        {
            printf("Read() button failed.\n");
        }
		
		else
		{
		    if (current_button == KEY1)
			{ 
                led_fd = open("/dev/led0",O_RDWR,755);
		        
                
                switch (i%2)
                {
                     case 0:
                          ioctl(led_fd, OFF, 0);
                          i++;
                          printf("Turn led0 OFF.\n");
                          break;

                     case 1:
                          ioctl(led_fd, ON, 0);
                          i++;
                          printf("Turn led0 ON.\n"); 
                          break;
				}
				
			}
			
			else if (current_button == KEY2)
			{
                   
                led_fd = open("/dev/led1",O_RDWR,755);
			    switch (j%2)
                {
                     case 0:
                          ioctl(led_fd, OFF, 1);
                          j++;
                          printf("Turn led1 OFF.\n");
                          break;
                     case 1:
                          ioctl(led_fd, ON, 1);
                          j++;
                          printf("Turn led1 ON.\n");
                          break;
				}
			}
			
			else if (current_button == KEY3)
			{
                led_fd = open("/dev/led2",O_RDWR,755);
			    switch (x%2)
                {
                     case 0:
                          ioctl(led_fd, OFF, 2);
                          x++;
                          printf("Turn led2 OFF.\n");
                          break;
                     case 1:
                          ioctl(led_fd, ON, 2);
                          x++;
                          printf("Turn led2 ON.\n");
                          break;
				}
				
			}
		    
		    else if (current_button == KEY4)
			{
                led_fd = open("/dev/led3",O_RDWR,755);
			    switch (y%2)
                {
                     case 0:
                          ioctl(led_fd, OFF, 3);
                          y++;
                          printf("Turn led3 OFF.\n");
                          break;
                     case 1:
                          ioctl(led_fd, ON, 3);
                          y++;
                          printf("Turn led3 ON.\n");
                          break;
				}
				
			}
	    }	
	
		
	
	}
	ioctl(led_fd,OFF);
    close(led_fd);
    close(button_fd);
	return 0;
}
運用交叉編譯器執行armgcc led_button.c -o   led_button(其中armgcc是我定義的變數)

將生成的led_button可執行檔案也傳到開發闆闆上


按按鍵觀看led的變化  測試就做完了!

相關推薦

fl2440 platform 按鍵驅動製作測試

在led驅動的基礎上,繼續學習按鍵驅動 Makefile   1   2 obj-m := s3c_button.o   3 KERNEL_DIR := ~/fl2440/kernel/linux-3.0.54/    4 PWD := $(shell pwd)   5 a

arm9+linux fl2440按鍵驅動 plat_button.c

        if( result )         {             result = -EBUSY;             goto ERROR1;         }     }     return 0; ERROR1:      kfree((unsigned char *)pdev

Linux音效卡驅動移植測試

一、分析驅動程式,根據開發板修改程式碼 程式碼太長,就不貼了,幾個注意點: 1、 檢視開發板原理圖和S3C2410的datasheet,UDA1341的L3MODE、L3DATA、L3CLOCK分別與S3C2410的GPB2、GPB3、GPB4相連,IISLRCK=GPE0

FCN製作自己的資料集並訓練測試

前言 這篇部落格記錄的是如何製作自己的資料集,並使用FCN模型訓練資料,前提要搭建caffe框架,可以參考這篇部落格,我製作的資料集是仿照voc2012資料集來在做的 製作影象標籤 這一部分是最難的部分,在製作標籤之前要搞清楚你的影象共分為幾類 調整影象尺寸

IMX6Q學習筆記———編寫LED驅動測試程式以及相關管腳配置

剛接觸IMX6Q不久,通過一個簡單的LED驅動和測試程式的編寫來了解管腳配置過程。 LED驅動 找到以前編寫驅動的基本框架,如下: static long xxx_ioctl(struct

oracle hash joinnested loop下的驅動表相關測試

Oracle 驅動表 Oracle驅動表也叫做外部表,也叫外層表,是在多表關聯查詢中首先遍歷的表,驅動表的每一行都要到另一個表中尋找相應的記錄,然後計算返回最終資料。 驅動表的概念只在nested l

按鍵驅動platform架構

這篇文章接著上篇文章介紹按鍵驅動的第二種實現方法,就是應用驅動和裝置分離的思想。 話不多說,直接上程式: 整個程式的結構如下: . ├── dev │   ├── key_dev.c │   └── Makefile ├── dri │   ├── key_dri.c │

編譯測試android的驅動程式學習筆記

0x00 前言     通過這篇文章,我們可以詳細的掌握android驅動程式的編譯以及對其進行測試的知識點,這裡採用goldfish核心並且在android模擬器上進行測試。 0x01 準備        首先我們應該瞭解怎麼樣下載和編譯android下面的linux核心

菜鳥一起學android4.0.3原始碼之按鍵驅動短長按功能

第一:按鍵ADB除錯    通過使用adb shell getevent,可以得到如下裝置操作後的指令,具體表示的含義,可以參考網上很多的文章,這裡就不再敘述 這裡的0035和0036分別表示螢幕上的X座標和Y座標,後面的值表示具體的座標點

linux裝置驅動歸納總結(九):1.platform匯流排的裝置驅動

linux裝置驅動歸納總結(九):1.platform匯流排的裝置和驅動 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 這一節可

FCN製作自己的資料集、訓練測試 caffe

花了兩三週的時間,在導師的催促下,把FCN的全部流程走了一遍,期間走了很多彎路,現在記錄一下。系統環境:ubuntu 16.04LTS 一、資料集的製作 注:我的資料集是仿照VOC資料集進行製作的 1.resize 資料集 我的GPU視訊記憶體4G,跑過大的圖片帶不動,需要resize圖片大小,放幾

Nodejs的測試測試驅動開發

測試是保證軟體質量必不可少的一環。測試有很多形式:手動、自動、單元測試等等。這裡我們只聊使用Mocha這個框架在Nodejs中實現單元測試。單元測試是測試等重要組成,這樣的測試只對於一個方法,這樣的一小段程式碼,實施有針對的測試。 這裡會逐步深入的講解單元測試

linux驅動開發fl2440開發板按鍵驅動

——————————————————————————————————————— 主機作業系統:Centos 6.7交叉編譯器環境:arm-linux-gcc-4.5.4 開發板平臺: FL2440 Linux核心版本: linux-3.0 開發模組: LED_BUTTON郵

Linux裝置驅動工程師之路——platform型別按鍵驅動

Linux裝置驅動工程師之路——platform按鍵驅動  Y-Kee 轉載請註明來自於衡陽師範學院08電2  Y-Kee http://blog.csdn.net/ayangke,QQ:843308498 一 、重要知識點: 1.platform裝置模型    

🔥《手把手教你》系列基礎篇之3-python+ selenium自動化測試-驅動瀏覽器元素定位大法(詳細)

1. 簡介 上一篇中,只是簡單地一帶而過的說了一些驅動瀏覽器,這一篇繼續說說驅動瀏覽器,然後再說一說元素定位的方法。 完成環境的安裝並測試之後,我們對Selenium有了一定的瞭解了,接下來我們繼續驅動瀏覽器做一些基本操作: 視窗尺寸設定、網頁截圖、重新整理、前進和後退 2. 視窗尺寸設定 在測試過程中,我們

web測試中的測試測試方法總結

動態 小數 圖片尺寸 提示信息 方便 margin style 容錯性 字符型 測試是一種思維,包括情感思維和智力思維,情感思維主要體現在一句俗語:思想決定行動上(要懷疑一切),智力思維主要體現在測試用例的設計上。具有了這樣的思想,就會找出更多的bug。 一、輸入框

日程管理APP的測試計劃測試矩陣

集成 說明 計劃 idt 無線 roi ble -c nbsp 測試計劃:(完成整個APP時間:2周) 編號 測試時間 測試內容 1 第2天 在需求設計階段,檢查產品說明文檔及設計文檔 2 第3~9天 在編碼階段,編寫測試用例 3 第10~11天 集成測試

日程管理的測試計劃測試矩陣

矩陣 ima ont -s pan size alt 計劃 技術分享 一、測試計劃 二、測試矩陣 日程管理的測試計劃和測試矩陣

mycat安裝測試

slave roo character 三臺 delet 1.4 property 啟動項 客戶端 mycat安裝和測試 一. 環境準備 本機環境是三臺centos6.5 IP 主機名 數據庫名 安裝軟件 192.168.17.4 mast

Caffe上用SSD訓練測試自己的數據

輸出 makefile b數 text play cal 上下 lba san 學習caffe第一天,用SSD上上手。 我的根目錄$caffe_root為/home/gpu/ljy/caffe 一、運行SSD示例代碼 1.到https://github.com