Skip to Content
Linux Device Drivers Development
book

Linux Device Drivers Development

by John Madieu
October 2017
Intermediate to advanced
586 pages
14h 8m
English
Packt Publishing
Content preview from Linux Device Drivers Development

Putting it all together

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Linux Device Drivers, Second Edition

Linux Device Drivers, Second Edition

Jonathan Corbet, Alessandro Rubini
Linux Device Drivers, 3rd Edition

Linux Device Drivers, 3rd Edition

Jonathan Corbet, Alessandro Rubini, Greg Kroah-Hartman

Publisher Resources

ISBN: 9781785280009Supplemental Content