60 lines
1.4 KiB
C
60 lines
1.4 KiB
C
#include <linux/init.h>
|
|
#include <linux/module.h>
|
|
#include <linux/gpio/consumer.h>
|
|
#include <linux/delay.h>
|
|
#include <linux/platform_device.h>
|
|
|
|
MODULE_LICENSE("GPL v2");
|
|
MODULE_AUTHOR("Du");
|
|
MODULE_DESCRIPTION("GPIO consumer API example for two LEDs");
|
|
|
|
static struct gpio_desc *led_blue;
|
|
static struct gpio_desc *led_red;
|
|
|
|
static int __init led_consumer_init(void)
|
|
{
|
|
struct device *dev = NULL;
|
|
|
|
pr_info("GPIO consumer LED module loading\n");
|
|
|
|
// GPIOs per Name aus dem Device Tree holen (via label oder node property)
|
|
led_blue = gpiod_get(dev, "led-blue", GPIOD_OUT_LOW);
|
|
if (IS_ERR(led_blue)) {
|
|
pr_err("Failed to get GPIO for blue LED\n");
|
|
return PTR_ERR(led_blue);
|
|
}
|
|
|
|
led_red = gpiod_get(dev, "led-red", GPIOD_OUT_LOW);
|
|
if (IS_ERR(led_red)) {
|
|
pr_err("Failed to get GPIO for red LED\n");
|
|
gpiod_put(led_blue);
|
|
return PTR_ERR(led_red);
|
|
}
|
|
|
|
// Test: LEDs einschalten
|
|
gpiod_set_value(led_blue, 1);
|
|
gpiod_set_value(led_red, 1);
|
|
msleep(500);
|
|
gpiod_set_value(led_blue, 0);
|
|
gpiod_set_value(led_red, 0);
|
|
|
|
pr_info("LEDs blinked using gpio/consumer\n");
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void __exit led_consumer_exit(void)
|
|
{
|
|
gpiod_set_value(led_blue, 0);
|
|
gpiod_set_value(led_red, 0);
|
|
|
|
gpiod_put(led_blue);
|
|
gpiod_put(led_red);
|
|
|
|
pr_info("GPIO consumer LED module unloaded\n");
|
|
}
|
|
|
|
module_init(led_consumer_init);
|
|
module_exit(led_consumer_exit);
|
|
|