• 灯光系统


    #include <linux/kernel.h>
    #include <linux/module.h>
    #include <linux/device.h>
    #include <linux/fs.h>
    #include <linux/types.h>
    #include <linux/moduleparam.h>
    #include <linux/slab.h>
    #include <linux/ioctl.h>
    #include <linux/cdev.h>
    #include <linux/delay.h>
     
    #include <linux/gpio.h>
    #include <mach/gpio.h>
    #include <plat/gpio-cfg.h>
    #include <linux/backlight.h>
    #include <linux/leds.h>
    
    
    static struct led_desc {
                 char *name;
                 int gpio;
    };
    
    static struct led_desc tiny4412_led[] = {
                {"led0", EXYNOS4212_GPM4(0)},
                {"led1", EXYNOS4212_GPM4(1)},
                {"led2", EXYNOS4212_GPM4(2)},
                {"led3", EXYNOS4212_GPM4(3)},
    };
    
    struct led_classdev_cdev {
                struct led_classdev led_dev;
                int gpio;
    };
    
    struct led_classdev_cdev *led_dev[4];
    
    static int PIN_NUM = sizeof(tiny4412_led)/sizeof(tiny4412_led[0]);
    
    void tiny4412_brightness_set(struct led_classdev *led_cdev,
                          enum led_brightness brightness)
    {
        struct led_classdev_cdev *cdev = (struct led_classdev_cdev *)led_cdev;
        if (brightness == LED_OFF)
             gpio_set_value(cdev->gpio, 1);
        else
             gpio_set_value(cdev->gpio, 0);
        led_cdev->brightness = brightness;
    }
    
    int led_tiny4412_init(void)
    {
       int i;
       
       for (i = 0; i < PIN_NUM; i++) {
            s3c_gpio_cfgpin(tiny4412_led[i].gpio, S3C_GPIO_OUTPUT);
            gpio_set_value(tiny4412_led[i].gpio, 1);
            led_dev[i] = kzalloc(sizeof(struct led_classdev_cdev), GFP_KERNEL);
            led_dev[i]->led_dev.brightness_set = tiny4412_brightness_set;
            led_dev[i]->led_dev.max_brightness = LED_FULL;    
            led_dev[i]->led_dev.brightness = LED_OFF;
            led_dev[i]->led_dev.flags = LED_CORE_SUSPENDRESUME;
            led_dev[i]->led_dev.name = tiny4412_led[i].name;
            led_dev[i]->gpio = tiny4412_led[i].gpio;
    
            led_classdev_register(NULL, &(led_dev[i]->led_dev));
       }
       return 0;
    }
    
    void led_tiny4412_exit(void)
    {
       int i;
        for (i = 0; i < PIN_NUM; i++) {
           led_classdev_unregister(&(led_dev[i]->led_dev));
           kfree(led_dev[i]);
        }
    }
    
    module_init(led_tiny4412_init);
    module_exit(led_tiny4412_exit);
    
    MODULE_LICENSE("GPL");

    将程序加入drivers/leds目录下:

    make menuconfig 配置内核:将LED CLASS / LED trigger 加入编译进内核

    make zImage

    烧写内核

    ls /sys/class/led*

    led0
    led1
    led2
    led3

    echo 255 > /sys/class/leds/led0/brightness 点亮第一个LED灯

    HAL程序:参考com_android_server_lights_LightsService.cpp

  • 相关阅读:
    VC++:创建,调用Win32静态链接库
    VC++:创建,调用Win32动态链接库
    C++生成和解析XML文件
    C++实现16进制字符串转换成int整形值
    一个好隐蔽的C/C++代码bug
    【C++札记】标准模板库string
    Rabbitmq C++客户端 Rabbitmq Client
    C++:标准模板库map
    C++:标准模板库vector
    C++:标准模板库(STL)
  • 原文地址:https://www.cnblogs.com/zhu-g5may/p/10503188.html
Copyright © 2020-2023  润新知