An Introduction to GPIO Programming
By Jeff Tranter Wednesday, June 12, 2019
编者按:本 2019 年博客系列是 ICS 最受欢迎的系列之一,现已更新(2022 年 12 月),以确保内容仍然准确、相关和有用。
本博客是 Integrated Computer Solutions (ICS) 关于 GPIO 编程的新系列博客的开篇。GPIO 即通用输入/输出,是大多数现代嵌入式计算机硬件的一项功能,也是许多嵌入式系统的关键组件。在本系列中,我将结合理论和实际编程示例,介绍嵌入式编程的这一重要方面。在第一篇文章中,我将概述 GPIO 编程、它的用途以及使用它所需了解的一些基本概念。
在接下来的文章中,我将介绍如何从文件系统或 sysfs 接口、Python(使用各种模块)以及 C 或 C++ 对 GPIO 进行编程。我将介绍一些低成本商用嵌入式板卡的功能,包括 Raspberry Pi 系列和 Toradex 的板卡。除了基本的数字输入和输出功能外,我还将介绍其他协议,如 SPI、I2C、1-Wire 和串行接口。
此外,我还会将一些低级编程与 Qt 联系起来,并展示一两个利用 Qt 功能的示例。虽然具体的代码示例是为 Raspberry Pi 或 Toradex 平台编写的,但这些概念也适用于其他硬件,只要这些硬件运行某种形式的 Linux,如 Raspbian、Yocto 或 boot2qt。
Editor's note: This 2019 blog series, among ICS' most popular, has been updated (December 2022) to ensure the content is still accurate, relevant and useful. This blog launches Integrated Computer Solutions' (ICS) new series on GPIO programming. GPIO, or General-Purpose Input/Output, is a feature of most modern embedded computer hardware and a key component of many embedded systems. In this series, I'll cover this important aspect of embedded programming, with a mix of theory and practical programming examples. In this first installment I'll present an overview of GPIO programming, what it can be used for and some basic concepts you need to know in order to use it. In upcoming posts I explain how to program GPIO, starting with the file system or sysfs interface, as well as from Python (using various modules) and from C or C++. I'll cover the capabilities of some low-cost commercial embedded boards, including the Raspberry Pi series and boards from Toradex. In addition to basic digital input and output functions, I'll address other protocols, such as SPI, I2C, 1-Wire and serial interfaces. As a bonus, I'll tie some of this low-level programming back to Qt an |