User Space Drivers

Configfs Interface

This driver provides a configfs interface for creating user-defined devices that use the various ev3dev drivers. Currently, only ports, sensors and LEDs are implemented. Motors could be added in the future.

Usage

Note

All commands assume root privileges.

Here is an example of how to create a port and a sensor:

  • Make sure module is loaded:

    modprobe user-lego-configfs
    
  • Go to the configfs directory for this driver:

    cd /sys/kernel/config/lego_user_device
    
  • Create a new port called p1:

    mkdir p1
    
  • Check out the new port - there should be live and sensors directories:

    cd p1
    ls
    
  • This also creates a new port that is linked to sys/class/lego-port:

    ls /sys/devices/lego_user_device/lego-port/
    
  • Now create a sensor named s1 attached to this port:

    mkdir sensors/s1
    
  • Check out the sensor:

    ls sensors/s1
    
  • These attributes correspond to attributes in the lego-sensor class. Set them as appropriate. For example:

    echo "my-driver" > sensors/s1/driver_name
    
  • Once the attributes have been set, export the sensor by linking it to live:

    ln -s sensors/s1 live
    

    There will be two new devices created, one in /sys/class/user-lego-sensor/ and one in /sys/class/lego-sensor. The lego-sensor class device is used just as any other sensor. The user-lego-sensor device is used to feed data into the sensor. See the user-lego-sensor-class docs for more info.

  • To remove the sensor and port, perform the operations in reverse:

    rm link/s1
    rmdir sensors/s1
    cd ..
    rmdir p1
    

The user-lego-sensor Subsystem

The user-lego-sensor class provides an interface for implementing user-defined sensors in userspace.

Identifying sensors

Since the name of the sensor<N> device node does not correspond to the port that a sensor is plugged in to, you must look at the address attribute if you need to know which port a sensor is plugged in to. This will match the address of the corresponding sensor in the lego-sensor class.

Sysfs

Sensors can be found at /sys/class/user-lego-sensor/sensor<N>, where <N> is incremented each time a sensor is loaded.

Note

The number <N> does not correspond to the address of sensor.

sysfs attributes
Attribute Access Description
bin_data write-only Writing stores the data which can be read using the bin_data and value<N> attributes in the corresponding lego-sensor class device.
text_value write-only Writing stores the value which can be read using the text_value attribute in the corresponding lego-sensor class device. It is currently limited to 512 bytes in length.