• Android系统--灯光系统驱动编写


    Android系统开发--Android灯光系统tiny4412_led_class驱动编写

    框架分析

    • led_classdev_4412结构体

      • 创建led_classdev_4412结构体

      • 分配结构体空间

    
    struct led_classdev_4412 {
    
        struct led_classdev cdev;
    
        int gpio;
    
    };
    
    
    
    struct led_classdev {
    
    	const char		*name;
    
    	int			 brightness;
    
    	int			 max_brightness;
    
    	int			 flags;
    
    	/* Lower 16 bits reflect status */
    
    #define LED_SUSPENDED		(1 << 0)
    
    	/* Upper 16 bits reflect control information */
    
    #define LED_CORE_SUSPENDRESUME	(1 << 16)
    
    	/* Set LED brightness level */
    
    	/* Must not sleep, use a workqueue if needed */
    
    	void		(*brightness_set)(struct led_classdev *led_cdev,
    
    					  enum led_brightness brightness);
    
    	/* Get LED brightness level */
    
    	enum led_brightness (*brightness_get)(struct led_classdev *led_cdev);
    
    	/*
    
    	 * Activate hardware accelerated blink, delays are in milliseconds
    
    	 * and if both are zero then a sensible default should be chosen.
    
    	 * The call should adjust the timings in that case and if it can't
    
    	 * match the values specified exactly.
    
    	 * Deactivate blinking again when the brightness is set to a fixed
    
    	 * value via the brightness_set() callback.
    
    	 */
    
    	int		(*blink_set)(struct led_classdev *led_cdev,
    
    				     unsigned long *delay_on,
    
    				     unsigned long *delay_off);
    
    	struct device		*dev;
    
    	struct list_head	 node;			/* LED Device list */
    
    	const char		*default_trigger;	/* Trigger to use */
    
    	unsigned long		 blink_delay_on, blink_delay_off;
    
    	struct timer_list	 blink_timer;
    
    	int			 blink_brightness;
    
    #ifdef CONFIG_LEDS_TRIGGERS
    
    	/* Protects the trigger data below */
    
    	struct rw_semaphore	 trigger_lock;
    
    	struct led_trigger	*trigger;
    
    	struct list_head	 trig_list;
    
    	void			*trigger_data;
    
    #endif
    
    };
    
    
    
     led_devs = kzalloc(sizeof(struct led_classdev_4412) * sizeof(led_gpios)/sizeof(led_gpios[0]), GFP_KERNEL);
    
    
    • 设置led_classdev_4412中属性,并注册结构体--led_classdev_register

    • led_classdev_4412属性如下:

      1. led_cdev->max_brightness

      2. led_cdev->brightness_set

      3. led_cdev->flags

      4. led_cdev->brightness

      5. led_cdev->name

    实现代码如下:

    
    struct led_desc {
    
     int gpio;
    
     char *name;
    
    };
    
    static struct led_desc led_gpios[] = {
    
     {EXYNOS4212_GPM4(0), "led1"},
    
     {EXYNOS4212_GPM4(1), "led2"},
    
     {EXYNOS4212_GPM4(2), "led3"},
    
     {EXYNOS4212_GPM4(3), "led4"},
    
    };
    
    
    
    for (i = 0; i < sizeof(led_gpios)/sizeof(led_gpios[0]); i++)
    
     {
    
         s3c_gpio_cfgpin(led_gpios[i].gpio, S3C_GPIO_OUTPUT);
    
         gpio_set_value(led_gpios[i].gpio, 1);               //设置为LED_OFF
    
         led_devs[i].cdev.max_brightness = LED_FULL;
    
         led_devs[i].cdev.brightness_set = brightness_set_4412;
    
         led_devs[i].cdev.flags = LED_CORE_SUSPENDRESUME;
    
         led_devs[i].cdev.brightness = LED_OFF;
    
         led_devs[i].cdev.name = led_gpios[i].name;          //设置为对应的引脚设备名
    
         led_devs[i].gpio = led_gpios[i].gpio;               //记录对应引脚                
    
         /* 3. led_classdev_register */
    
         ret = led_classdev_register(NULL, &led_devs[i].cdev);
    
         /*注册失败之后,将之前注册的设备注销,并且释放空间*/
    
         if (ret) {
    
             i--;
    
         while (i >= 0) {
    
                 led_classdev_unregister(&led_devs[i].cdev);
    
                 i--;
    
             }
    
         kfree(led_devs);
    
         return -EIO;
    
         }
    
     }
    
     return 0;
    
    }
    
    
  • 相关阅读:
    Linux运维之监控CPU和内存的日志工具
    Linux磁盘缓存的有趣实验
    Linux运维之内存分析2
    Linux运维之内存分析
    使用kubectl create 和 kubectl apply创建资源对象的区别
    Docker学习:Image的本地存储结构
    Docker 空间使用分析与清理
    HeidiSQL、Navicat、mysql命令和source命令导入sql脚本的速度比较
    Centos 7.2天兔(Lepus 3.8)数据库监控系统部署
    MegaCli 监控raid状态
  • 原文地址:https://www.cnblogs.com/lkq1220/p/6480408.html
Copyright © 2020-2023  润新知