Embedded Linux Peripherals, Display, Video & Audio in C

For: Embedded Linux, BSP, camera, audio, and edge device C engineers

Write production-grade C11 user-space drivers and multimedia/industrial pipelines for Linux GPIO, evdev touchscreens, PWM, Framebuffer graphics, UART, Watchdog, SocketCAN, ALSA audio, and V4L2 video streaming.

18 lessons6 labs~13h 25mLinux 6.12C11glibc 2.39Course 4 of 4 · Advanced Capstone

What you'll build

lab m0155 min

Lab M01: Sysfs LED Controller and GPIO v2 Debounced Line Engine

Implement a warning-clean C11 embedded peripheral library (libgpio_led.a) that detaches active kernel LED triggers before clamping /sys/class/leds brightness, packs multi-line struct gpio_v2_line_values bitmasks atomically, and filters mechanical switch bounce while counting kernel kfifo sequence gaps across struct gpio_v2_line_event streams.

learner@ksa: ~/gl-c04/lab-m01
learner@ksa:~/gl-c04/lab-m01./files/gpio_led_cli ./sys_led0LED applied=255 mask=0x25 bits=0x21 accepted=3 seq_gaps=2learner@ksa:~/gl-c04/lab-m01
lab m0260 min

Lab M02: Evdev Multi-Touch Dejitter Engine and Safe Sysfs PWM Sequencer

Implement a warning-clean C11 input and actuator library (libevdev_pwm.a) that tracks Linux evdev Type-B multi-touch slots (ABS_MT_SLOT, ABS_MT_TRACKING_ID) with atomic SYN_REPORT frame commits and Manhattan dejitter filtering, paired with a EINVAL-free /sys/class/pwm period/duty transition sequencer.

learner@ksa: ~/gl-c04/lab-m02
learner@ksa:~/gl-c04/lab-m02./files/evdev_pwm_cliMT syn=3 emitted=3 slot0_xy=120,210 slot1_active=0 PWM rc=0,0 einval=0 duty=1500000/2000000learner@ksa:~/gl-c04/lab-m02
lab m0365 min

Lab M03: Stride-Safe RGB565 Framebuffer Compositor (BMP, libpng, FreeType2)

Implement a warning-clean C11 2D display compositor (libfb_comp.a) that addresses mmap-backed RGB565 scanlines via line_length byte stride, inverts bottom-up 24-bit BGR BMP icons with 4-byte row padding, alpha-blends RGBA8888 libpng badges, and rasterizes baseline-aligned FreeType2 vector glyphs.

learner@ksa: ~/gl-c04/lab-m03
learner@ksa:~/gl-c04/lab-m03./files/fb_comp_cli ./badge.pngFB pad_intact=1 bmp_top=0xF800 bmp_bot=0x07E0 blend=0x800F glyph_ok=1learner@ksa:~/gl-c04/lab-m03
lab m0460 min

Lab M04: Raw Termios UART-to-SocketCAN Bridge with Watchdog Health Gate

Implement a warning-clean C11 industrial gateway library (libuart_can.a) that configures a raw 8N1 B115200 termios link cleanly for binary control-byte payloads (0x0D, 0x03, 0x11), validates CRC-8 UART sensor frames into struct can_frame records, enforces CAN_EFF_FLAG | CAN_RTR_FLAG in SocketCAN mask filters, and gates hardware watchdog keepalives on monotonic telemetry freshness.

learner@ksa: ~/gl-c04/lab-m04
learner@ksa:~/gl-c04/lab-m04./files/uart_can_cliBRIDGE id=0x124 data=0D,03,11 sff_ok=1 eff_rejected=1 wdog_fresh=1 wdog_stale=0learner@ksa:~/gl-c04/lab-m04
lab m0565 min

Lab M05: Poll-Driven ALSA PCM Audio Engine with RIFF Parser and Q8 Gain

Implement a warning-clean C11 embedded audio engine (libalsa_engine.a) that walks variable-offset RIFF/WAVE chunk headers across odd-sized JUNK padding, applies saturating Q8 fixed-point gain without int16_t wraparound clicks, and drives poll-multiplexed alsa-lib (-lasound) playback with automatic -EPIPE XRUN recovery.

learner@ksa: ~/gl-c04/lab-m05
learner@ksa:~/gl-c04/lab-m05./files/alsa_engine_cliALSA rc=0 rate=48000 frames=1024 xruns_recovered=1 sat=32767,-32768learner@ksa:~/gl-c04/lab-m05
lab m0695 min

Lab M06: Capstone V4L2 Zero-Copy Ring, BT.601 YUYV, and Nonblocking FLV Agent

Implement the GL-C04 capstone video streaming agent (libv4l2_agent.a) combining a 4-slot <linux/videodev2.h> V4L2_MEMORY_MMAP QBUF/DQBUF capture ring, clamped integer BT.601 YUYV-to-RGB565 preview conversion, big-endian FLV (0x09 AVC video tag) muxing over a non-blocking poll socket, and frame-progress watchdog supervision.

learner@ksa: ~/gl-c04/lab-m06
learner@ksa:~/gl-c04/lab-m06./files/v4l2_agent_cliAGENT frames=12 queued=4 rgb0=0xFFFF flv_bytes=397 flv_ok=1 wdog_kicks=3learner@ksa:~/gl-c04/lab-m06

Syllabus

gl-c04/

  • m01/ Sysfs LEDs, GPIO Character UAPI & Edge Interrupts

    Drive /sys/class/leds attributes cleanly, migrate legacy /sys/class/gpio pin exports to Linux 6.12 /dev/gpiochipN v2 atomic line ioctls, and debounce hardware GPIO edge interrupts via poll().

    • Bridge VFS descriptors, mmap mappings, and poll loops from GL-C01..GL-C03 into embedded Linux hardware control by inspecting the /sys kobject tree, understanding why /dev/mem MMIO pokes race kernel drivers, and driving /sys/class/leds attributes deterministically in ISO C11.

    • Replace deprecated /sys/class/gpio global pin files with the Linux 6.12 /dev/gpiochipN v2 character-device ABI (<linux/gpio.h>), configuring glitch-free active-low outputs, atomic 64-line bitmask updates, and crash-safe descriptor lifetimes in ISO C11.

    • Register rising and falling GPIO edge detectors on /dev/gpiochipN to sleep at 0% CPU in poll(POLLIN). Diagnose legacy sysfs POLLPRI + lseek quirks versus 48-byte struct gpio_v2_line_event POLLIN streams. Implement nanosecond switch-bounce filtering from hardIRQ timestamp_ns and audit line_seqno FIFO gaps.

  • m02/ Linux Input Subsystem, Multi-Touch tslib & PWM

    Decode /dev/input/eventX struct input_event packets, track Multi-Touch Type-B slots through SYN_REPORT boundaries and tslib filter chains, and program glitch-free /sys/class/pwm waveforms.

  • m03/ Framebuffer Graphics, JPEG/PNG Codecs & FreeType

    Map /dev/fb0 scanlines with finfo.line_length stride safety, decode bottom-up BMP, libjpeg, and alpha-blended libpng surfaces, and render rotated portrait views with baseline-aligned FreeType glyphs.

  • m04/ UART Termios, Hardware Watchdog & SocketCAN

    Frame binary UART links over raw POSIX termios, supervise system liveness with /dev/watchdog ioctls and Magic Close, and exchange kernel-filtered 11/29-bit SocketCAN frames.

  • m05/ ALSA Audio Architecture, PCM Rings & Mixer Loopback

    Negotiate alsa-lib hardware/software ring parameters in frame units, stream variable-chunk WAV playback and capture with XRUN recovery, and build poll-driven full-duplex audio loops with snd_mixer_t.

  • m06/ V4L2 Zero-Copy Video Capture & RTMP Edge Streaming

    Configure V4L2 capability/format negotiation and zero-copy MMAP rings, convert live YUYV camera frames to RGB565, and architect supervised V4L2 + H.264/FLV RTMP edge streaming appliances.

Prerequisites

  • requiredGL-C01..GL-C03 (or equivalent): POSIX file I/O, ioctl, mmap, poll/epoll, pthreads, and sockets in C11
  • requiredLinux user-space build fluency (gcc -std=c11 -Wall -Wextra -Werror, pkg-config, and GNU Make)
  • Bridged in M1Linux 6.12 /dev/gpiochipN v2 character UAPI taught side-by-side with legacy /sys/class/gpio (Module 1)
  • Bridged in M2Multi-touch Type-B slot state machine & tslib filter pipeline over synthetic evdev streams (Module 2)
  • Bridged in M3Stride-safe Framebuffer mmap, libjpeg/libpng scanlines & FreeType baseline layout on host surfaces (Module 3)
  • Bridged in M4–M6PTY-backed termios UART loopback, Watchdog keepalive, SocketCAN filters, ALSA XRUN recovery & V4L2/RTMP streaming (Modules 4–6)

Series map

  1. GL-C01Syscalls, File Tables & Buffering — Kernel boundary, glibc, GCC/Make, POSIX file I/O, VFS open-file tables, atomic I/O, stdio & durability
  2. GL-C02Filesystems, Signals, Processes & Threads — stat/inodes, directory traversal, system info/time, POSIX signals, fork/exec/wait, daemons & pthreads
  3. GL-C03Advanced I/O, IPC, Sockets, CMake & MQTT — Nonblocking I/O, select/poll/epoll, mmap, record locks, pipes/shm, TCP/UDP sockets, CMake & MQTT
  4. GL-C04Embedded Linux Peripherals, Display, Video & Audio — Sysfs GPIO/LED/PWM, evdev/tslib input, Framebuffer/JPEG/PNG/FreeType, UART/Watchdog/SocketCAN, ALSA & V4L2/RTMP this course

Related live cohorts: DRV-120 · Linux Device Drivers (live cohort) EMB-201 · ARM Board Bring-Up: TF-A, U-Boot & Kernel (live cohort)

Companion formats

Slide deck

16:9 review slides with terminal listings, diagrams, and speaker notes.

Reference handbook

Printable HTML and PDF engineering reference covering every module and UAPI.

Flashcards

Leitner spaced-repetition terminal cards and TSV deck for syscalls, flags, and pitfalls.

Kernel Systems Academy engineering studio

Every Kernel Systems Academy course follows our 35% principles / 20% guided investigation / 45% engineering studio pedagogy. Listings are compiled against Linux 6.12 · C11 · glibc 2.39 under strict compiler flags (-Wall -Wextra -Werror), and each module culminates in an evidence-checked lab graded locally by ./check.sh.

Frequently asked questions

Can I study this course offline from disk?

Yes. All fonts, stylesheets, diagrams, search indexes, and progress trackers use relative paths and local browser storage, so the bundle works identically over HTTP and file://.

How are the hands-on labs graded?

Each lab directory includes starter source files and an executable ./check.sh runner emitting TAP version 13 diagnostics (ok / not ok) and exiting 0 when every check passes.

What is included in the free preview?

Preview lessons and the opening module lab are unlocked in full so you can inspect our C11 listings, strace transcripts, and ./check.sh workflow before subscribing.

search — fzf

0/0 ───────────────────────────────────────────

keyboard shortcuts — less

/
search
f
focus mode
[
previous
]
next
?
help
Esc
close

figure