save
This commit is contained in:
@ -1,21 +1,59 @@
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#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");
|
||||
|
||||
static int __init counter_init(void) {
|
||||
pr_info("counter: LKM loaded.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void __exit counter_exit(void) {
|
||||
pr_info("counter: LKM unloaded.\n");
|
||||
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(counter_init);
|
||||
module_exit(counter_exit);
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("Wolfgang Hottgenroth <wolfgang.hottgenroth@icloud.com>");
|
||||
MODULE_DESCRIPTION("LKM for MainsCnt counter module");
|
||||
MODULE_VERSION("0.1");
|
||||
module_init(led_consumer_init);
|
||||
module_exit(led_consumer_exit);
|
||||
|
||||
|
@ -19,6 +19,28 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
fragment@1 {
|
||||
target-path = "/";
|
||||
__overlay__ {
|
||||
mygpioleds {
|
||||
compatible = "my,gpio-led-controller";
|
||||
pinctrl-names = "default";
|
||||
pinctrl-0 = <&gpio_led_blue &gpio_led_red>;
|
||||
|
||||
led-blue {
|
||||
gpios = <&gpio 26 0>;
|
||||
label = "led-blue";
|
||||
};
|
||||
|
||||
led-red {
|
||||
gpios = <&gpio 21 0>;
|
||||
label = "led-red";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user