SYSFS application-------Use SYSFS to control the strobe light

Source: Internet
Author: User

1, create the corresponding kobj_attribute. This experiment used to turn on the flashlight, turn off the flashlight, turn on the flashing lights, turn off the flash. So create four kobj_attribute. Because the four formats are similar, only the function function implementation function is different, so this article only takes Sysfs_torch as an example to explain.

static struct Kobj_attribute Sysfs_torch = __attr (torch,s_irugo,sysfs_torch,null)
<pre name= "code" class= "CPP" >static struct Kobj_attribute sysfs_off = __attr (off,s_irugo,sysfs_off,null)

Kobj_attribute definition
struct Kobj_attribute {     struct attribute attr;     ssize_t (*show) (struct kobject *kobj, struct kobj_attribute *attr,             char *buf);     ssize_t (*store) (struct kobject *kobj, struct kobj_attribute *attr,              const char *BUF, size_t count);};


Where __attr is a macro, it is defined as follows:

#define __ATTR (_name, _mode, _show, _store) {                    . ATTR = {. Name = __stringify (_name),. Mode = _mode},            . Show   = _s How,                             . Store  = _store,                        }
2, create the corresponding function function Sysfs_torch
Static  ssize_t sysfs_torch (struct kobject *kobj,struct kobj_attribute *attr, char *buf) {
<span style= "White-space:pre" ></span> implement flashlight function code.  }
3. Create struct attribute struct array and struct Attribute_group object.

static struct attribute *flash_sysfs[] = {&sysfs_torch.attr,&sysfs_off.attr,&sysfs_flash.attr,null,}
static struct Attribute_group Flash_attr_group = {. Attrs = Flash_sysfs,}
4. Writing the init function

init function main Call function

Sysfs_create_group (struct kobject *kobj,const struct attribute_group *grp);
The pass-in parameters enable the use of SYSFS to control the flash.
You can also create a struct kobject assignment to null and create it using Kobject_create_and_add (const char *name, struct kobject *parent). Pass the return value to Sysfs_create_group
When I implement, add sysfs_create_group directly in Platform_probe, according to the command created, will be persisted and your device in the devices directory, if you do not know in that directory, you can use the command
Find./-name  "You define the name" to search.
5. Exit function





Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

SYSFS application-------Use SYSFS to control the strobe light

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.