Accessing hardware peripherals (SDVX)

From DAVE Developer's Wiki
Revision as of 10:35, 17 October 2018 by U0007 (talk | contribs) (ts_lib)

Jump to: navigation, search
Info Box
SDVX.png Applies to SDVX

History[edit | edit source]

Version Date SDVX version Hardware Part Nr Notes
1.0.0 October 2018 SDVX 1.0.1 SDV03 or SDV04

Introduction[edit | edit source]

This is a quickstart guide to access the hardware peripheral from sysfs or kernel device nodes.

For more information regarding sysfs, go to its official page

For more information regarding kernel device driver, go to its official page

Peripherals[edit | edit source]

SD / MMC[edit | edit source]

SD device node is created by the linux kernel and mapped to multiple:

/dev/mmcblk{device}p{part}

where device is the SD device on the device tree and part is the part number


E.g. for an eMMC device with two partition:

root@sdv03-lite:~# ls -la /dev/mmcblk2*
brw-rw---- 1 root disk 179,  0 Oct  4 11:06 /dev/mmcblk2
brw-rw---- 1 root disk 179,  8 Oct  4 11:06 /dev/mmcblk2boot0
brw-rw---- 1 root disk 179, 16 Oct  4 11:06 /dev/mmcblk2boot1
brw-rw---- 1 root disk 179,  1 Oct  4 11:06 /dev/mmcblk2p1
brw-rw---- 1 root disk 179,  2 Oct  4 11:06 /dev/mmcblk2p2
brw-rw---- 1 root disk 179, 24 Oct  4 11:06 /dev/mmcblk2rpmb
root@sdv03-lite:~#

The partition can be seen using:

root@sdv03-lite:~# fdisk -l /dev/mmcblk2
Disk /dev/mmcblk2: 3.7 GiB, 3959422976 bytes, 7733248 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xcce0c36f

Device         Boot  Start     End Sectors  Size Id Type
/dev/mmcblk2p1       16384  278527  262144  128M  c W95 FAT32 (LBA)
/dev/mmcblk2p2      278528 4472831 4194304    2G 83 Linux
root@sdv03-lite:~#

1-wire[edit | edit source]

The 1-wire device on SDVx carrier board contains the hardware-programmable information stored in factory or on the field.

Main information are:

  • SOM configid: contains the factory programmed ID for HW SOM configuration - more information at the ConfigID page
  • SOM uniqueid: contains the SOM unique identification - more information at the UniqueID page
  • CB configid: contains the factory programmed ID for HW Carrier board configuration - more information at the ConfigID page
  • CB uniqueid: contains the Carrier board unique identification - more information at the UniqueID page

ConfigID and UniqueID information can be gathered from sysfs using the following commands:

root@sdv03-lite:~# cat /proc/device-tree/som/configid
00000001root@sdv03-lite:~#
root@sdv03-lite:~# cat /proc/device-tree/som/uniqueid
e317d7c9:1a0151d4root@sdv03-lite:~#
root@sdv03-lite:~# cat /proc/device-tree/cb/configid
0000002aroot@sdv03-lite:~#
root@sdv03-lite:~# cat /proc/device-tree/cb/uniqueid
b100001a:baed182droot@sdv03-lite:~#

LCD /backlight[edit | edit source]

The LCD framebuffer is mapped to /dev/fb0 device. Its configuration can be displayed using the fbset command:

root@sdv03-lite:~# fbset -fb /dev/fb0

mode "800x480-59"
    # D: 33.000 MHz, H: 31.191 kHz, V: 59.298 Hz
    geometry 800 480 800 480 16
    timings 30303 128 128 15 30 2 1
    rgba 5/11,6/5,5/0,0/0
endmode

root@sdv03-lite:~#

framebuffer[edit | edit source]

It is possible to test the framebuffer visualization using the fbi utility:

root@sdv03-lite:~# fbi -d /dev/fb0 -T 1 -a startSplash.ppm
root@sdv03-lite:~#

where:

  • -d /dev/fb0 means using the fb0 framebuffer device
  • -T 1 means using the tty1 console
  • -a means autoscale

fbi utility is a linux console framebuffer viewer that supports multiple images format: see its page

backlight[edit | edit source]

The LCD backlight is PWM controlled and can be changed directly using the sysfs entry:

root@sdv03-lite:~# cat /sys/class/backlight/backlight/brightness
75
root@sdv03-lite:~# cat /sys/class/backlight/backlight/max_brightness
100
root@sdv03-lite:~# echo 100 > /sys/class/backlight/backlight/brightness
root@sdv03-lite:~# echo 0 > /sys/class/backlight/backlight/brightness
root@sdv03-lite:~#

Touchscreen[edit | edit source]

Touchscreen device is typically mapped by the kernel on the event0 device:

root@sdv03-lite:~# ls -la /dev/input
total 0
drwxr-xr-x  3 root root     140 Oct  4 11:06 .
drwxr-xr-x 12 root root    3280 Oct  4 11:06 ..
drwxr-xr-x  2 root root      60 Oct  4 11:06 by-path
crw-rw----  1 root input 13, 64 Oct  4 11:06 event0
crw-rw----  1 root input 13, 63 Oct  4 11:06 mice
crw-rw----  1 root input 13, 32 Oct  4 11:06 mouse0
lrwxrwxrwx  1 root root       6 Oct  4 11:06 touchscreen0 -> event0
root@sdv03-lite:~#

ts_lib[edit | edit source]

For testing the touchscreen behaviour, the ts_lib utilities can be used:

  • touchscreen calibration
root@sdv03-lite:~# ts_calibrate
xres = 800, yres = 480
Took 9 samples...
Top left : X =   63 Y =   74
Took 3 samples...
Top right : X =  726 Y =   81
Took 1 samples...
Bot right : X =  722 Y =  441
Took 5 samples...
Bot left : X =   73 Y =  437
Took 10 samples...
Center : X =  411 Y =  248
-23.533630 1.066568 -0.007912
-25.745605 -0.008527 1.050538
Calibration constants: -1542300 69898 -518 -1687264 -558 68848 65536
root@sdv03-lite:~# 
  • touchscreen reported coordinates:
root@sdv03-lite:~# ts_test
1538653269.165704:    398    238    156
1538653269.165704:    398    238    156
1538653269.175700:    398    238    121
1538653269.185728:    398    238    112
1538653269.195718:    399    240     88
1538653269.205688:    399    241     70
1538653269.215709:    403    241     68
1538653269.225689:    405    240     79
1538653269.235738:    408    239     98
1538653269.245698:    410    239    102
1538653269.255713:    412    238    115
1538653269.265687:    414    237    130
1538653269.275710:    416    235    136
1538653269.285682:    418    234    161
1538653269.295709:    418    233    184
1538653269.305679:    418    232    189
1538653269.325669:    419    231    180
1538653269.335691:    419    233    125
1538653269.352710:    419    237      0
^Csignal 2 caught
root@sdv03-lite:~#
tslib and X11[edit | edit source]

For using tslib under X11 framework, it is required to configure X-Windows to use the touchscreen driver. This is possible by adding an InputDevice section to /etc/X11/xorg.conf:

root@sdv03:~# cat /etc/X11/xorg.conf
Section "Device"
    Identifier  "i.MX Accelerated Framebuffer Device"
    Driver      "vivante"
    Option      "fbdev"     "/dev/fb0"
    Option      "vivante_fbdev" "/dev/fb0"
    Option      "HWcursor"  "false"
EndSection

Section "ServerFlags"
    Option "BlankTime"  "0"
    Option "StandbyTime"  "0"
    Option "SuspendTime"  "0"
    Option "OffTime"  "0"
EndSection

Section "InputDevice"
    Identifier "tslib"
    Driver "tslib"
    Option "Device" "/dev/input/event0"
    Option "ScreenNumber"   "0"
    Option "Width"      "800"
    Option "Height"     "480"
    Option "Rotate"     "NONE"
    Option "TslibDevice"    "/dev/input/event0"
    Option "CorePointer"
EndSection

root@sdv03:~#

X11[edit | edit source]

For touchscreen calibration under the X11 framework, the touchscreen should be calibrated using the xinput_calibrator utility:

root@sdv03-lite:~# xinit /etc/X11/Xsession --Xorg &
X.Org X Server 1.18.0
Release Date: 2015-11-09
X Protocol Version 11, Revision 0
Build Operating System: Linux 3.13.0-126-generic x86_64
Current Operating System: Linux test-noserialnumber 4.1.15-sdvx-1.0.1 #1 SMP PREEMPT Wed Oct 3 22:52:45 CEST 2018 armv7l
Kernel command line: root=/dev/mmcblk2p2 rootwait rw console=ttymxc2,115200 vmalloc=400M mtdparts=gpmi-nand:8M(nand-uboot),1M(nand-env1),1M(nand-env2),1M(nand-fdt),1M(nand-spare),8M(nand-kernel),6M(nand-splash),-(nand-ubi);spi0.0:1M(spi-uboot),256k(spi-env1),256k(spi-env2),512k(spi-dtb),8M(spi-kernel),4M(spi-splash),-(spi-free)
Build Date: 07 November 2017  10:46:08AM

Current version of pixman: 0.32.8
        Before reporting problems, check http://wiki.x.org
        to make sure that you have the latest version.
Markers: (--) probed, (**) from config file, (==) default setting,
        (++) from command line, (!!) notice, (II) informational,
        (WW) warning, (EE) error, (NI) not implemented, (??) unknown.
(==) Log file: "/var/log/Xorg.0.log", Time: Mon Oct 15 10:43:31 2018
(==) Using config file: "/etc/X11/xorg.conf"
(==) Using system config directory "/usr/share/X11/xorg.conf.d"

root@sdv03-lite:~# export DISPLAY=:0
root@sdv03-lite:~# xinput_calibrator
        Setting calibration data: 0, 799, 0, 479
Calibrating EVDEV driver for "TSC2007 Touchscreen" id=6
        current calibration values (from XInput): min_x=0, max_x=799 and min_y=0, max_y=479

Doing dynamic recalibration:
        Setting calibration data: 31, 763, 19, 474
        --> Making the calibration permanent <--
  copy the snippet below into '/etc/X11/xorg.conf.d/99-calibration.conf'
Section "InputClass"
        Identifier      "calibration"
        MatchProduct    "TSC2007 Touchscreen"
        Option  "Calibration"   "31 763 19 474"
        Option  "SwapAxes"      "0"
EndSection
root@sdv03-lite:~# 

then copy the calibration data into the configuration file:

root@sdv03-lite:~# cat /etc/X11/xorg.conf
Section "Device"
    Identifier  "i.MX Accelerated Framebuffer Device"
    Driver      "vivante"
    Option      "fbdev"     "/dev/fb0"
    Option      "vivante_fbdev" "/dev/fb0"
    Option      "HWcursor"  "false"
EndSection

Section "ServerFlags"
    Option "BlankTime"  "0"
    Option "StandbyTime"  "0"
    Option "SuspendTime"  "0"
    Option "OffTime"  "0"
EndSection

Section "InputClass"
        Identifier      "calibration"
        MatchProduct    "TSC2007 Touchscreen"
        Option  "Calibration"   "31 763 19 474"
        Option  "SwapAxes"      "0"
EndSection

Audio[edit | edit source]

Audio device is controlled by the ALSA layer.

Two audio utilities can be used for easy access to the audio device:

  • alsamixer
  • aplay

Many controls can be directly acrivated on command line using the amixer utility: here below a simple script for configuring the audio device

root@sdv03-lite:~# cat audio.sh
amixer sset 'Speaker' on
amixer sset 'Speaker Driver' on
amixer sset 'Speaker Driver' 3
amixer sset 'Speaker Analog' 100
amixer sset 'Output Right From Right DAC' on
amixer sset 'HP Right' on
amixer sset 'HP Left' on
amixer sset 'HP Driver' 9
amixer sset 'HP Driver' on
amixer sset 'HP Analog' 95
amixer sset 'DAC' 150
amixer sset 'DAC Left Input' 'Mono'
amixer sset 'DAC Right Input' 'Mono'
amixer sset 'Output Left From Left DAC' on
amixer sset 'Output Left From MIC1LP' on
amixer sset 'Output Left From MIC1RP' on
amixer sset 'Output Right From MIC1RP' on
amixer sset 'Output Right From MIC1RP' on
amixer sset 'MIC1RP P-Terminal' 'FFR 10 Ohm'
amixer sset 'Output Right From Right DAC' on
root@sdv03-lite:~#

For playing an audio file, it is enough to use aplay utility:

root@sdv03-lite:~# aplay test_stereo_44100Hz_16bit_PCM.wav
Playing WAVE 'test_stereo_44100Hz_16bit_PCM.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
root@sdv03-lite:~# 

Bluetooth[edit | edit source]

BT device can be accessed using standard tty device driver.

AT commands[edit | edit source]

The device is controlled using AT commands via /dev/ttymxc0 port

Serial port access example using AT commands:

root@test-noserialnumber:~# microcom -s 115200 /dev/ttymxc0

+STARTUP
AT
OK
AT
OK
ATZ
OK
ATO01
OK

GPIOs[edit | edit source]

Two GPIOs control its main functionalities via sysfs entries mapped on leds interface:

  • device reset
/sys/class/leds/bt_reset/brightness

Here below a script example for resetting the BT device:

root@sdv03-lite:~# cat bt.sh
echo Reset BT
echo 1 > /sys/class/leds/bt_reset/brightness
sleep 1
echo 0 > /sys/class/leds/bt_reset/brightness
root@sdv03-lite:~# 
  • command mode
/sys/class/leds/bt_command_mode/brightness

Here below a script example for switch the BT device back to AT command mode (from data mode):

root@sdv03-lite:~# cat bt-command.sh
echo BT set command mode
echo 0 > /sys/class/leds/bt_command_mode/brightness
sleep 0.5
echo 1 > /sys/class/leds/bt_command_mode/brightness
root@sdv03-lite:~#