Difference between revisions of "Hammer LED Class Driver"

From eLinux.org
Jump to: navigation, search
Line 1: Line 1:
 
== UserSpace Access ==
 
== UserSpace Access ==
  
the LED onboard the hammer as well as the LED on the carrier board can be accessed from userspace via the sysfs interface. example interfaces are in /sys/class/leds/led0/ and /sys/class/leds/led1. both directories include a file entry "brightness". to turn a LED on, echo a non zero value to the brightness file entry:
+
the LED onboard the hammer as well as the LED on the carrier board can be accessed from userspace via the sysfs interface. example interfaces are in /sys/devices/platform/s3c24xx_led.0/leds:led0/ and /sys/devices/platform/s3c24xx_led.1/leds:led1/. both directories include a file entry "brightness". to turn a LED on, echo a non zero value to the brightness file entry:
  
echo 1 > /sys/class/leds/led0/brightness
+
echo 1 > /sys/devices/platform/s3c24xx_led.0/leds:led0/brightness
  
 
to turn a LED off, echo a zero to the the brightness file entry:
 
to turn a LED off, echo a zero to the the brightness file entry:
  
echo 0 > /sys/class/leds/led0/brightness
+
echo 0 > /sys/devices/platform/s3c24xx_led.0/leds:led0/brightness
  
  
 
you can also check the current status of the LED by using cat on the brightness file entry:
 
you can also check the current status of the LED by using cat on the brightness file entry:
  
cat /sys/class/leds/led0/brightness
+
cat /sys/devices/platform/s3c24xx_led.0/leds:led0/brightness
  
  

Revision as of 14:52, 29 January 2008

UserSpace Access

the LED onboard the hammer as well as the LED on the carrier board can be accessed from userspace via the sysfs interface. example interfaces are in /sys/devices/platform/s3c24xx_led.0/leds:led0/ and /sys/devices/platform/s3c24xx_led.1/leds:led1/. both directories include a file entry "brightness". to turn a LED on, echo a non zero value to the brightness file entry:

echo 1 > /sys/devices/platform/s3c24xx_led.0/leds:led0/brightness

to turn a LED off, echo a zero to the the brightness file entry:

echo 0 > /sys/devices/platform/s3c24xx_led.0/leds:led0/brightness


you can also check the current status of the LED by using cat on the brightness file entry:

cat /sys/devices/platform/s3c24xx_led.0/leds:led0/brightness


Adding New LEDS

a new LED connected via a GPIO can be defined in the linux-2.6.xx/arch/arm/mach-s3c2410/mach-tct_hammer.c file. each LED will need to include some platform data and a platform device definition:

static struct s3c24xx_led_platdata tct_hammer_pdata_led0 = {
	.gpio		= S3C2410_GPF0,
	.flags		= S3C24XX_LEDF_ACTLOW | S3C24XX_LEDF_TRISTATE,
	.name		= "led0",
	.def_trigger	= "timer",
};

static struct platform_device tct_hammer_led0 = {
	.name		= "s3c24xx_led",
	.id		= 0,
	.dev		= {
		.platform_data = &tct_hammer_pdata_led0,
	},
};

this uses the standard LEDS class in the main kernel tree. for additional information see the linux-2.6.xx/Documentation/leds-class.txt file.


LED Hardware

the most common way of operating a LED via a gpio is to use an active low configuration:

Led-example.jpg