EXOTIC SILICON
“Putting a BSD system in your pocket”
Controlling the LEDs and vibration motor
WARNING
The information presented on these pages is NOT intended to be followed as a guide to installing OpenBSD on your own Pinephone device, and must not be used for this purpose.
Unlike most SBCs, the Pinephone contains a rechargeable battery intended to power the device. Correct configuration of the charging circuits, including various safety features such as thermal protection will not be enabled by the current OpenBSD kernel as of the time of writing.
Series navigation
THIS IS PART FIVE OF SEVEN (5/7) - CHECK OUT THE INDEX
Part 4
Part 6
Website themes
The Exotic Silicon website is available in ten themes, but you haven't chosen one yet!
General purpose I/O - LEDs, vibration motor and more!
Controlling the multi-colored LED and vibration motor on the Pinephone is surprisingly easy, even from a simple shell script, since they are connected as GPIO devices.
All of the connections are to the gpio3 device, with pins 18, 19, and 20 controlling the green, red, and blue LED outputs respectively, and pin 2 controlling the vibration motor.
Some other devices are also connected to various gpio pins, such the backlight, and various sensors. The device tree file lists the pin assignments for these devices if you're curious. However, in the case of the backlight, since a driver for this device already exists in OpenBSD, there doesn't seem much point in trying to control it directly.
Setting up GPIO devices
To use gpio devices on OpenBSD, it's necessary to configure them before the kern.securelevel sysctl is raised during the boot process. To do this, we just need to put the relevant commands in /etc/rc.securelevel:
Configuring the gpio pins
gpioctl gpio3 2 set out Vibration motor
gpioctl gpio3 18 set outGreen LED
gpioctl gpio3 19 set outRed LED
gpioctl gpio3 20 set outBlue LED
Then after rebooting, the configured gpio pins can be toggled from userland. It's also possible to assign a symbolic name to each of the configured pins to avoid having to hard-code pin numbers directly in the controlling program. For testing purposes, though, it's just as easy to use the numeric values.
Controlling the vibration motor
We can start and stop the vibration motor from the shell using the following commands:
Starting and stopping the vibration motor
# gpioctl gpio3 2 on
# gpioctl gpio3 2 off
Or alternatively we can toggle it to the opposite state using:
Toggling the vibration motor
# gpioctl gpio3 2 toggle
Setting up LED color combinations
Since each of the red, green, and blue LED components can either be on or off, we can set a total of seven colors, or eight if we include black:
LED color combinations
ColorPin 18Pin 19Pin 20
BlackOffOffOff
BlueOffOffOn
RedOffOnOff
Magenta / PurpleOffOnOn
GreenOnOffOff
Cyan / TurquoiseOnOffOn
YellowOnOnOff
WhiteOnOnOn
The commands are similar to those used to control the vibration motor. The following will turn on the blue LED, for example:
Turning on the blue LED
# gpioctl gpio3 20 on
Useful applications
Since we don't yet have any framebuffer output to the built-in display panel, adding an LED toggle to /etc/rc.local at least allows us to see if the phone is switched on and booted into the kernel, even when not connected to the serial console.
Series navigation
Part 1 - Building the installation media and installing.
Part 2 - Booting the completed installation and initial information gathering.
Part 3 - Starting to debug USB issues.
Part 4 - Investigating errors from sxirsb.
Part 5 - Controlling the LEDs and vibration motor.
Part 6 - PMIC and battery charging.
Part 7 - External keyboard battery.