Android kernel Sysfs Using instance of switch class

Source: Internet
Author: User

Android kernel sysfs using instance of switch class

Finally, this weekend, you can do something you want to do. By my second-rate kernel-driven developer, I'm going to parse the switch class in Sysfs . First speculate on the origin, in the common embedded Linux platform, is generally fighting each other, there is no need to follow any rules. Google has defined some subtle specifications in Android that you can completely not follow. But it's always good to follow the rules.

Let's start with a visual look at what's in the /sys/class/switch class.

First you can see that the essence is linked to the /sys/device/virtual/switch/ directory, to look at the true colors:

        This includes 4 bl is backlit ;h2w is the headset ;hdmi is hdmi;mic bl name/power/state/subsystem/uevent state is typically the state value provided to the user space in the drive.

Let's do a switch example with the simplest Hello World Example in LDD3 :

Adding less than a few lines of code has been implemented by the simplest switch , the effect is as follows:

Switch_set_state can be called directly in the driver to set different state values. Correspondingly, the application layer reads this to achieve state acquisition.

This article does not elaborate on the switch Implementation details, and gives a complete example in practical terms. of course, if you need to know the implementation details, you can see "switch_class" "Android switch module ." This can be used for "drive" implementations that want to inform the user of the space state.

By the way, one of the tips for compiling driver examples in LDD3: Make kerneldir=~/4.2.2_r1/kernel/ behind this is the Android kernel source path. Of course, the kernel in the path is compiled. Nothing needs to be changed to compile well.


A complete simple example code is attached:

/* * $Id: hello.c,v 1.5 2004/10/26 03:32:21 Corbet Exp $ */#include <linux/init.h> #include <linux/module.h> #in Clude <linux/switch.h>module_license ("Dual bsd/gpl"); struct Switch_dev sdev;static int hello_switch () {    int State, ret;    Sdev.name = "Hello";    ret = Switch_dev_register (&sdev);    if (Ret < 0)        return ret;    state = 0;    Switch_set_state (&sdev,state);    return 0;} static int hello_init (void) {PRINTK (kern_alert "Hello, world\n");    if (Hello_switch ())    {        printk (kern_err "failed to create Hello switch\n");        Return-enodev;    } return 0;} static void Hello_exit (void) {PRINTK (Kern_alert "Goodbye, cruel world\n");} Module_init (Hello_init); Module_exit (Hello_exit);


Android kernel Sysfs Using instance of switch class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.