logo du siteLe Site du Gnu-Bricoleur

/!\ Un blog plébiscité par Chuck Norris O_o

Pinephone - A simple compas app (Kompass ? :°)

Rédigé par SuperGNU Aucun commentaire

This article is still a Draft, it's just temporarily published for personal convenience

Foreword : This article is a log of the process I followed to develop a simple compass app for Manjaro Plasma Mobile on the Pinephone (the app in itself should be compatible with more systems and devices but this is my primary target and test device incidentally). It should be considered as such and certainly not as a tutorial to develop a new app. Further disclaimer, I am not even a developer, I am just an electrical engineer playing with Linux and software, my knowledge is really lacking and I'm sure several steps are unnecessary and/or plain wrong

Genesis of the project

I was looking for a small project to put me back on track with my Braveheart smartphone since I haven't been playing much with it since the last article. On the plasma-mobile "random project assignor" I got this. The linked problem to solve is this one Seems like a perfect project, simple enough, small so that it doesn't takes up a ton of time, with a useful and concrete result. I'm sold !

Preliminary research

According to this list the Pinephone compas is a ST LIS3MDL sensor. Actually, according to :

STmicroelectronics LIS3MDL ultra-low-power three-axis magnetometer, LGA-12 2.0x2.0x1.0 mm [datasheet] Note: The LIS3MDL is currently unavailable, so it has been replaced in the PinePhone Beta Edition with the Voltafield AF8133L e-Compass, which is unlisted on the Voltafield web site, but the AF8133J is listed. Presumably U1200 will be unpopulated and U1203 will be populated in the Beta Edition, since they appear to be alternatives.

And :

U1203: Asahi Kasei Microdevices (AKM) AK09911 3-axis electronic compass IC with Hall sensor, 8-pin WL-CSP (BGA), 1.2×1.2×0.5 mm or Voltafield Technology Corp. (VTC) AF8133J 3-axis electronic compass with proprietary anisotropic magneto resistive (AMR) technology, 8-pin WLCSP 1.2x1.2x0.5 mm Note: These parts appear to be alternatives to be used if the LIS3MDL is unavailable, so U1203 was probably unpopulated in BraveHeart and the Community Editions, but will be populated in the Beta Edition.

It's a little bit more complicated but given that I have the BraveHeart edition I apparently have a LIS3MDL

Eventually, I suppose the default Plasma-mobile (let's dream :)) compass application (Kompass obviously :)) will have to support every Pinephone configuration (and every supported smartphone). I'm not sure about how an application is supposed to handle that but I have the feeling that if the magnetometer is correctly managed by the kernel as a device, it should be exposed in a generic way in the user space... I started to poke around a little bit and found this ST driver for ST mems (what about the other brands ??) following a link from this thread. Also this random repo, not sure what it does.

After flashing a fresh Manjaro Plasma-mobile on my Pinephone, i tried :

[sylvain@plasma-mobile /]$ sudo find . -name "*lis3mdl*"
[sudo] password for sylvain: 
find: ‘./proc/28998’: No such file or directory
./sys/firmware/devicetree/base/__symbols__/lis3mdl
[sylvain@plasma-mobile /]$ 

This is great news ! Apparently, the magnetometer is in the device tree !

[sylvain@plasma-mobile /]$cat ./sys/firmware/devicetree/base/__symbols__/lis3mdl
/soc/i2c@1c2b000/magnetometer@1e^@
[sylvain@plasma-mobile /]$ 

And it's connected on an I2C bus ! (From the datasheet it could also have been SPI) This means if I'm not mistaken that the device is mapped in memory at the address 0x1c2b000. So I tried :

[sylvain@plasma-mobile /]$ sudo hexdump -C --skip 0x1c2b000 /dev/mem | head
hexdump: /dev/mem: Bad address
01c2b000

Without success... Same happens for the following addresses. According to this, it's apparently normal :

You should also notice that there is no ranges property in the i2c@1,0 node. The reason for this is that unlike the external bus, devices on the i2c bus are not memory mapped on the CPU's address domain. Instead, the CPU indirectly accesses the rtc@58 device via the i2c@1,0 device. The lack of a ranges property means that a device cannot be directly accessed by any device other than it's parent.

So let's install some tools to play with I2C devices. With

[sylvain@plasma-mobile /]$ pacman -Syu i2c-tools

Now we can scan the s

[sylvain@plasma-mobile /]$ sudo i2cdetect 0 [sudo] password for sylvain: WARNING! This program can confuse your I2C bus, cause data loss and worse! I will probe file /dev/i2c-0. I will probe address range 0x08-0x77. Continue? [Y/n] Y 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: 30 31 32 33 34 35 36 -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: 50 51 52 -- 54 55 -- 57 58 59 5a 5b 5c 5d -- 5f 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- -- [sylvain@plasma-mobile /]$ sudo i2cdetect 1 WARNING! This program can confuse your I2C bus, cause data loss and worse! I will probe file /dev/i2c-1. I will probe address range 0x08-0x77. Continue? [Y/n] Y 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- UU -- -- -- UU -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- UU -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- --
[sylvain@plasma-mobile /]$ sudo i2cdetect 2 WARNING! This program can confuse your I2C bus, cause data loss and worse! I will probe file /dev/i2c-2. I will probe address range 0x08-0x77. Continue? [Y/n] Y 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- UU -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- --
[sylvain@plasma-mobile /]$ sudo i2cdetect 3 WARNING! This program can confuse your I2C bus, cause data loss and worse! I will probe file /dev/i2c-3. I will probe address range 0x08-0x77. Continue? [Y/n] Y 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- --
[sylvain@plasma-mobile /]$ sudo i2cdetect 4 WARNING! This program can confuse your I2C bus, cause data loss and worse! I will probe file /dev/i2c-4. I will probe address range 0x08-0x77. Continue? [Y/n] Y 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- UU -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- UU -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- --
[sylvain@plasma-mobile /]$ sudo i2cdetect 5 WARNING! This program can confuse your I2C bus, cause data loss and worse! I will probe file /dev/i2c-5. I will probe address range 0x08-0x77. Continue? [Y/n] Y 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- UU -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- --

https://linux.die.net/man/8/i2cdetect

"--". The address was probed but no chip answered.
"UU". Probing was skipped, because this address is currently in use by a driver. This strongly suggests that there is a chip at this address.
An address number in hexadecimal, e.g. "2d" or "4e". A chip was found at this address.

[sylvain@plasma-mobile ~]$ lsmod Module Size Used by rfcomm 53248 16 bnep 28672 2 zram 28672 2 zsmalloc 32768 1 zram ov5640 32768 2 crct10dif_ce 20480 1 8723cs 1449984 0 sun50i_codec_analog 32768 1 sun8i_adda_pr_regmap 16384 1 sun50i_codec_analog hci_uart 57344 0 btrtl 24576 1 hci_uart btbcm 24576 1 hci_uart st_magn_spi 16384 0 bluetooth 430080 44 btrtl,hci_uart,btbcm,bnep,rfcomm st_sensors_spi 16384 1 st_magn_spi st_magn_i2c 16384 0 panel_sitronix_st7703 16384 0 st_magn 20480 2 st_magn_i2c,st_magn_spi st_sensors_i2c 16384 1 st_magn_i2c inv_mpu6050_i2c 16384 0 st_sensors 20480 3 st_magn_i2c,st_magn,st_magn_spi inv_mpu6050 32768 2 inv_mpu6050_i2c industrialio_triggered_buffer 16384 2 inv_mpu6050,st_magn stk3310 16384 0 kfifo_buf 16384 1 industrialio_triggered_buffer cfg80211 315392 1 8723cs anx7688 36864 0 ecdh_generic 16384 1 bluetooth ecc 28672 1 ecdh_generic rfkill 28672 11 bluetooth,cfg80211 sun8i_codec 53248 1 sun4i_i2s 24576 2 snd_soc_ec25 16384 1 snd_soc_bt_sco 16384 1 snd_soc_simple_card 20480 2 snd_soc_simple_amplifier 16384 1 snd_soc_simple_card_utils 20480 1 snd_soc_simple_card snd_soc_core 151552 8 sun4i_i2s,snd_soc_bt_sco,sun50i_codec_analog,sun8i_codec,snd_soc_simple_amplifier,snd_soc_simple_card_utils,snd_soc_ec25,snd_soc_simple_card snd_pcm_dmaengine 20480 1 snd_soc_core snd_pcm 102400 4 sun4i_i2s,sun8i_codec,snd_soc_core,snd_pcm_dmaengine snd_timer 40960 1 snd_pcm snd 65536 8 snd_timer,sun8i_codec,snd_soc_core,snd_pcm display_connector 16384 0 soundcore 16384 1 snd leds_sgm3140 16384 0 i2c_gpio 16384 0 sun4i_lradc_keys 16384 0 [sylvain@plasma-mobile ~]$

Plasma mobile app dev guide : https://community.kde.org/Plasma/Mobile/DevGuide

git cmake make extra-cmake-modules g++ qt5-qmake qt5-default qtdeclarative5-dev libqt5svg5-dev qtquickcontrols2-5-dev libkf5config-dev kirigami2-dev qtmultimedia5-dev

gcc qt5

https://www.balena.io/blog/sensors-and-data-logging-with-embedded-linux-the-ultimate-guide-part-1/

https://wiki.analog.com/resources/tools-software/linux-software/libiio/iio_readdev https://stackoverflow.com/questions/18688763/why-is-istream-ostream-slow https://community.nxp.com/t5/i-MX-Processors/Re-how-to-read-info-from-iio-device-iio-device0/m-p/269079 https://sourceforge.net/projects/iioutils/files/iioutils/

[sylvain@plasma-mobile iio:device2]$ sudo su [sudo] password for sylvain: [root@plasma-mobile iio:device2]# echo 80 > sampling_frequency

disgusting code : https://github.com/Gnu-Bricoleur/Kompass

Info generale i2C: https://learn.sparkfun.com/tutorials/raspberry-pi-spi-and-i2c-tutorial/all

Classé dans : Pinephone Mots clés : aucun

Pinephone - 1: The arrival !!

Rédigé par SuperGNU Aucun commentaire

This is, i hope, the first of a serie of Pinephone articles summing up for myself and others what i'm learning on the Pinephone, Linux on a smartphone and contributing to the different OSs in order to turn this phone into the perfect daily driver.

I'll be learning as i write so i don't expect these articles to always represent the best or the most elegant solution but i intend them to help me figure out exactly what was needed in the middle of all i tried and maybe it can help shorten the learning path for others. Right now only 3000 "Braveheart" Pinephones have been selled and i can assume most of them are in far more knowledgeable hand than mine but come April, the software should be in a better place and Pine64 will surely sella new batch to less linux-able people and this guide might just come handy.

Lire la suite de Pinephone - 1: The arrival !!

Fil RSS des articles de cette catégorie