October 2017
Intermediate to advanced
586 pages
14h 8m
English
The following code is a summary, putting into practice all the concepts discussed regarding integer-based interfaces. This driver manages four GPIOs: two buttons (btn1 and btn2) and two LEDs (green and red). Btn1 is mapped to an IRQ, and whenever its state changes to LOW, the state of btn2 is applied to the LEDs. For example, if the state of btn1 goes LOW while btn2 is high, the GREEN and RED LEDs will be driven to HIGH:
#include <linux/init.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/gpio.h> /* For Legacy integer based GPIO */ #include <linux/interrupt.h> /* For IRQ */ static unsigned int GPIO_LED_RED = 49; static unsigned int GPIO_BTN1 = 115; static unsigned int GPIO_BTN2 = 116; static ...