User Tools

Site Tools


framebuffer

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
framebuffer [2026-11-21 23:45 UTC (6 days ago)] – added details about ffmpeg jazzyframebuffer [2026-11-23 00:26 UTC (5 days ago)] (current) – add note about touchscreen interfaces, ffmpeg static build to run on device, framebuffer driver, brightness control, and obtaining copies of what is on framebuffer qkb
Line 1: Line 1:
 ====== Framebuffer ====== ====== Framebuffer ======
  
-Graphics can be rendered using the linux framebuffer device, ''/dev/fb0''. By default the framebuffer is 800×480 with a B8G8R8A8 pixel order.+Graphics go to ''%%/dev/fb0%%'', an 800x480 32-bit framebuffer with a 3200-byte 
 +stride and B, G, R, X byte order. It is the background plane of the display 
 +controller:
  
-The framebuffer driver implements some special ''ioctl''s, [[https://github.com/nxp-imx/linux-imx/blob/lf-6.12.y/drivers/video/fbdev/mxc/mxc_ipuv3_fb.c|its source is available here]]. Some notable ones:+^ device ^ name ^ mode ^ virtual ^ stride ^ 
 +| ''%%/dev/fb0%%'' | DISP3 BG | 800x480p-57 | 800x480 | 3200 | 
 +| ''%%/dev/fb1%%'' | DISP3 FG | 240x320p-57 | 240x960 | 960 |
  
-  * ''MXCFB_WAIT_FOR_VSYNC'' (''_IOW('F', 0x20, u_int32_t)'') blocks until vblank. The argument is ignored. +''%%/dev/fb1%%'' is the foreground plane of the same controller, above fb0. sysfs 
-  * ''MXCFB_SET_GPU_SPLIT_FMT'' (''_IOW('F', 0x2F, struct mxcfb_gpu_split_fmt)'') seems to be used to setup triple-buffering (but how to use it properly?)+reports ''%%2-layer-fb-bg%%'' for fb0 and ''%%2-layer-fb-fg%%'' for fb1. Its 240x960 
 +virtual size is three 320-line pages. nx does not open it. 
 +''%%video16%%'' and ''%%video17%%'' are registered by ''%%mxc_v4l2_output%%''; they are 
 +V4L2 output nodes, not extra framebuffers. 
 + 
 +There is no touchscreen. ''%%/dev/input%%'' does not exist, no touch driver loads, 
 +and nx opens only ''%%fb0%%'', ''%%ttymxc2%%'', ''%%ttymxc3%%'', and ''%%ttyUSB0%%''. Input is 
 +NFC taps, barcode scans, and the power button. 
 + 
 +===== Driver ===== 
 + 
 +The framebuffer driver is ''%%mxc_sdc_fb%%'', registered against a parallel RGB 
 +LCD. The device tree node is ''%%fb@0%%'' with ''%%disp_dev = "lcd"%%'', 
 +''%%interface_pix_fmt = "RGB24"%%'', ''%%mode_str = "CLAA-WVGA"%%'', and 
 +''%%default_bpp = 32%%''. The panel link is 24-bit RGB, so the fourth byte in 
 +memory is padding. Source: 
 +[[https://github.com/nxp-imx/linux-imx/blob/lf-6.12.y/drivers/video/fbdev/mxc/mxc_ipuv3_fb.c|mxc_ipuv3_fb.c]] 
 +(the unit runs 4.9; this is the current NXP tree, and the ioctl interface is the 
 +same). 
 + 
 +The kernel command line sets ''%%imx-fbdev.legacyfb_depth=32%%'', matching the 
 +DTB's ''%%default_bpp%%'' of 32. 
 + 
 +Two private ioctls are worth knowing: 
 + 
 +  * ''%%MXCFB_WAIT_FOR_VSYNC%%'' (''%%_IOW('F', 0x20, u_int32_t)%%'') blocks until vblank. The argument is ignored. 
 +  * ''%%MXCFB_SET_GPU_SPLIT_FMT%%'' (''%%_IOW('F', 0x2F, struct mxcfb_gpu_split_fmt)%%'') looks like a triple-buffer layout switch. There is no usable documentation for it. 
 + 
 +===== Backlight ===== 
 + 
 +There is no ''%%/sys/class/backlight%%'' entry and no ''%%pwm-backlight%%'' node. 
 +The PIC32 owns the backlight. It reads the ambient sensor and maps the reading 
 +onto a min/max range: 
 + 
 +^ key ^ meaning ^ 
 +| ''%%0x500b%%'' | ambient light, 0..10000 | 
 +| ''%%0x4030%%'' | brightness at ambient 0 | 
 +| ''%%0x4031%%'' | brightness at ambient 10000 | 
 + 
 +LCD brightness is 0..10000. A max above 10000 reaches full brightness before the 
 +ambient reading hits 10000. Equal values hold a fixed brightness. Max above min 
 +follows the light. Writes take effect immediately. 
 + 
 +Power-on values are 200/12000. nx sets 100/15000 at startup via 
 +''%%BackLightStartup()%%'' in ''%%/init/efad/pgm/opscript.nxs%%'', overwriting manual 
 +values. The script's presets are off 0/0, low 100/100, half 2000/2000, full 
 +10000/10000, auto half 100/5000, and auto full 200/20000. 
 + 
 +Write max first, then min: 
 + 
 +<code> 
 +stty -F /dev/ttymxc2 115200 cs8 -cstopb -parenb raw -echo 
 + 
 +# fixed half 
 +printf '\274\001\000\004\000\004\110\100\061\023\210' > /dev/ttymxc2 
 +printf '\274\001\000\004\000\004\110\100\060\023\210' > /dev/ttymxc2 
 + 
 +# back to auto 
 +printf '\274\001\000\004\000\004\110\100\061\072\230' > /dev/ttymxc2 
 +printf '\274\001\000\004\000\004\110\100\060\000\144' > /dev/ttymxc2 
 +</code> 
 + 
 +Each frame is a PIC32 ValueWrite: message type ''%%0x04%%'', payload key then value, 
 +both big-endian. See [[pic32]] for the frame layout. 
 + 
 +Read the values and the sensor with ValueRead, type ''%%0x02%%'': 
 + 
 +<code> 
 +exec 3<>/dev/ttymxc2 
 +printf '\274\001\000\002\000\002\104\120\013' >&3 
 +timeout -t 1 dd if=/dev/ttymxc2 bs=1 count=10 2>/dev/null | hexdump -C 
 +</code> 
 + 
 +The reply is ''%%BC seq 01 03 00 04 crc 50 0b <value>%%''. Indoor light reads about 35; 
 +a flashlight pointed at the sensor reaches about 3300. 
 + 
 +===== Blanking ===== 
 + 
 +The kernel command line includes ''%%consoleblank=0%%'', so the console never 
 +blanks on its own. To clear the screen, write zeros and stop the fbcon cursor 
 +from repainting: 
 + 
 +<code> 
 +echo 0 > /sys/class/graphics/fbcon/cursor_blink 
 +dd if=/dev/zero of=/dev/fb0 bs=3200 count=480 
 +</code> 
 + 
 +Those two commands are the whole blanking operation. The cursor setting matters: 
 +with the cursor blinking, it draws itself back onto the black frame. 
 + 
 +If nx is running, it owns the same buffer and will draw over the black frame on 
 +its next update. Stop it first. 
 + 
 +===== Capturing the screen ===== 
 + 
 +<code> 
 +ssh root@<unit-ip> 'cat /dev/fb0' > fb.raw 
 +</code> 
 + 
 +Read ''%%fb.raw%%'' as 800x480, stride 3200, byte order B, G, R, X. One frame is 
 +1,536,000 bytes.
  
 ===== Video output ===== ===== Video output =====
  
-People have made simple animations by exporting raw BGRA images and writing them to the framebuffer device. You can do this in ffmpeg for example:+Animations work by writing raw BGRA frames to the framebuffer. Export them with 
 +ffmpeg:
  
 <code> <code>
-ffmpeg -i .\input.mp4 -map 0:v -vf "scale=800:-1,crop=800:480:0:(in_h-480)/2" -c:v rawvideo -pix_fmt bgra -f image2 frame_%06d.raw   +ffmpeg -i input.mp4 -map 0:v -vf "scale=800:-1,crop=800:480:0:(in_h-480)/2" \ 
 +  -c:v rawvideo -pix_fmt bgra -f image2 frame_%06d.raw
 </code> </code>
  
-Beware that these files get very large, to the point that reading them out can max out USB bandwidth. +The crop centres a taller input and throws away the rest. Raw frames are 
-And then on the pm3, the animation can be played back with a fairly simple:+1.5 MB each, so a minute at 30 fps is well over 2 GB. Short clips are the 
 +practical limit. 
 + 
 +Play them on the unit:
  
 <code> <code>
-for file in *.raw; do cat $file > /dev/fb0; usleep 30000; done+for file in *.raw; do cat "$file" > /dev/fb0; usleep 30000; done
 </code> </code>
  
-Alternatively, you can get a statically compiled [[https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v6.1/ffmpeg-6.1-linux-armhf-32.zip|ffmpeg binary]] and use that.+A static armhf ffmpeg can play the video directly, no frame dump:
  
 <code> <code>
-# video only +/init/efad/mp_sd/ffmpeg -re -i file.mp4 -map 0:v -c:v rawvideo -pix_fmt bgra \ 
-/init/efad/mp_sd/ffmpeg -re -i file.mp4 -map 0:v -c:v rawvideo -pix_fmt bgra -f fbdev /dev/fb0 +  -f fbdev /dev/fb0
-# video + audio (janky) +
-/init/efad/mp_sd/ffmpeg -re -i file.mp4 -map 0:v -c:v rawvideo -pix_fmt bgra -f fbdev /dev/fb0 -map 0:a -ac 1 -c:a pcm_s16le -f s16le - | aplay -c 1 -f S16_LE -r 44100 -+
 </code> </code>
  
-This assumes your input video is already cropped to exactly 800x480. The audio example is also set to use a single channel.+A prebuilt 6.1 armhf build is at 
 +[[https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v6.1/ffmpeg-6.1-linux-armhf-32.zip|ffbinaries]]. 
 + 
 +Video plus audio needs the input already cropped to 800x480 and ALSA up. The 
 +speaker amp has to be enabled first; see [[alsa]]. 
 + 
 +<code> 
 +/init/efad/mp_sd/ffmpeg -re -i file.mp4 -map 0:v -c:v rawvideo -pix_fmt bgra \ 
 +  -f fbdev /dev/fb0 -map 0:a -ac 1 -c:a pcm_s16le -f s16le - \ 
 +  | aplay -c 1 -f S16_LE -r 44100 - 
 +</code> 
 + 
 +The audio side is mono 44.1 kHz. Drop ''%%-re%%'' to write frames as fast as the CPU 
 +decodes them. ''%%MXCFB_WAIT_FOR_VSYNC%%'' is the only sync primitive the driver 
 +offers. 
framebuffer.1795304753.txt.gz · Last modified: by jazzy