Article: NuttX RTOS for PinePhone: Feature Phone UI in LVGL, Zig and WebAssembly
#31
(07-16-2023, 02:17 AM)WhiteHexagon Wrote: btw I saw you got a nice deployment option setup to save SDCard switching for your RISC-V work, very nice!  Any chance something similar would work for the PP. 

Hmmm we need the network to be up for the U-Boot Bootloader to fetch the boot files over TFTP. Wonder if we can connect an Ethernet Dongle over USB?

Or maybe we use this PinePhone microSD Extender?

https://pine64.com/product/pinephone-microsd-extender/
  Reply
#32
yeah the networking looks like another binary blob fun and games.
I was waiting for the pinetab2 wifi dust to settle before doing another order, although I think it would still mean 2 separate orders. Maybe when the EU store has more bits I look into that option. I saw one project with two connectors and a switch, but I dont need more challenges Smile

btw yesterday I was messing around with LVGL. A couple interesting discoveries:

Fonts: am I limited to 1 font at a time? only changing the default seems to work. I followed your post, and I see them being linked into my binary, but using them doesnt seem to override the default.

Colors: There is a mysterious difference between the canvas2d and PP, possibly just the red and blue reversed. It was late so I investigate more today, I thought it was RGBA, but I saw nuttx 32 bit color mode might be different, but that wouldnt explain the canvas2d, unless there is a byte order change on the memory blit into the screen buffer.

oh and just a minor point, I noticed the phone is a bit taller than we have been using 1440 vs 1280, since I was trying to add an extra debug area at the bottom Smile
  Reply
#33
Yes, the display size is 720×1440.
  Reply
#34
(07-19-2023, 02:37 AM)WhiteHexagon Wrote: Colors: There is a mysterious difference between the canvas2d and PP, possibly just the red and blue reversed.

Yep the colours for PinePhone vs JavaScript Canvas are swapped, probably ARGB vs RGBA. We should swap the colour bytes here:

https://github.com/lupyuen/pinephone-lvg...js#L41-L50

Code:
// Load the WebAssembly Pointer into a JavaScript Image Data
const imageDataArray = new Uint8Array(memory.buffer, ptr, len)
imageData.data.set(imageDataArray);

// TODO: Swap the Colour Bytes (ARGB vs RGBA)

// Render the Image Data to the HTML Canvas
context.clearRect(0, 0, canvas.width, canvas.height);
context.putImageData(imageData, 0, 0);

To use multiple fonts, check out the LVGL Widgets Demo:

https://github.com/lupyuen2/wip-pinephon...#L172-L187
  Reply
#35
(07-20-2023, 01:46 AM)lupyuen Wrote: https://github.com/lupyuen/pinephone-lvg...js#L41-L50

Probably going to have a performance impact? I attempted instead to change the color order in the union (lv_color32_t) in lv_color.h but no luck.  Changing the macro LV_COLOR_MAKE32 and swapping the R+B did work...  but is clearly not the solution Smile

Today got wasted with trying to understand optionals between Zig and C.  I wasnt expecting a C pointer to become a Zig optional, and now I see why you wrapped some of the GUI objects into Zig structs Smile  I was only trying to wrap my GUI code in a nice generics struct hehe.

Anyway I made a nice little panel so that I can better debug Register values, it just shows hex and binary values so that I can check flags, masks etc.

First attempt at attachments ...    
  Reply
#36
That's really cool @WhiteHexagon ! I'm preparing a presentation on NuttX for PinePhone at the Apache Community Conference, I'll share more details later :-)

Video Presentation: https://drive.google.com/file/d/1WL-6HVj...authuser=0

Presentation Slides: https://codeberg.org/lupyuen/pages/src/b...n/nuttx.md
  Reply
#37
Wow, great work! I never use youtube, so thank you for the direct video link. The education idea is already really taking off with a start like that, well done! I hadn't quite realised how long you had been working on this project, since I only just got my PP. You have done well considering the lack of hard information out there! I have been feeling a bit of that frustration already. So I gave up on Lima driver for now.

Here I reorganised my Zig code into 'hardware' layer and 'api' layer. So trying to present a nice public API for interacting with my zig hardware layer. Since the audio work touches a lot of hardware, I now have in Zig minimal hardware coverage for CCU, GPIO, I2SPCM, KAYADC and the start of audio codec. The funny thing is that in the big shuffle my RGB LED code seems to also have a switched color scheme to GRB hehe or maybe the schematic is wrong and it was always like that, since it already has a conflict in the diagram Smile

At my API level I have Volume and Led so far, the easy ones Wink back on Audio now... I thought about rather than routing the modem audio, first of all I just try and play back a PCM sample through the speaker. Should be easy, right? Right? Wink
  Reply
#38
ok, so I found some info in the lichee sources, it seems like a whole linux, not just pinephone specific, so no wonder I was getting lost Smile Plus I hadnt got my head around drivers/everything being file based, which made searching even harder. Maybe now I get some answers Smile and I should have realised sooner, because I know for sure one of your articles talks about the device tree and locating drivers Smile
  Reply
#39
Well I ended up with a tight loop waiting for a Audio register lock in Zig. Seems the only approach, but it got me thinking about CPU temperatures. Looks like nothing is enabled on the SoC by default, which was quite a surprise! and worry... so switched focus again to look at that Smile
  Reply
#40
I think I got some kind of CPU thermal value, counting backwards Smile just need to work out what value to use for CPU temperature shutdown, not that I am stressing the device too much yet Wink

PS being able to do this in Zig is really nice, I get type safety on the poke() (saved me twice) and errors every time I miscount the bit flags in the registers, which saves me at least 3 times a day Wink




Code:
pub const THS_FILT_CTRL_ADDR = Reg32(THS_FILT_CTRL_REG, THS_BASE_ADDR + THS_FILTER);
pub const THS_FILT_CTRL_REG = packed struct(u32) {
    FILTER_TYPE: Filter = Filter.TYPE4,
    FILTER_EN: bool = false,
    _3: u29 = 0,

    pub const Filter = enum(u2) {
        TYPE2 = 0b00,
        TYPE4 = 0b01,
        TYPE8 = 0b10,
        TYPE16 = 0b11,
    };
};


I am still not sure on the naming scheme still, since the ADDR and REG are pretty much the same thing, but the usage below reads okay I think, and I want to be easily searchable for the register names in the 'User Manual'.  Although probably I change the _ADDR to be _REG, and the _REG to be _VAL or _TYPE, not sure yet, will do some more work on the audio side and see what reads best Smile  It is not very linux like, but I am still trying to get my head around linux abstractions, device trees, file based drivers, etc etc.  Just having some fun for now! Smile  Will also probably break down the CCU chapter into smaller manageable units, it's huge as I am sure you noticed!

Code:
    var fltr = thermals.THS_FILT_CTRL_ADDR.peek();
    fltr.FILTER_TYPE = thermals.THS_FILT_CTRL_REG.Filter.TYPE8;
    fltr.FILTER_EN = true;
    thermals.THS_FILT_CTRL_ADDR.poke(fltr);
  Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Using Signal on PinePhone in mid-2023? dante404 47 13,715 Yesterday, 02:19 AM
Last Post: dragonhospital
  Slarm64 on PinePhone [Unofficial Slackware ARM - 64 bit] acid andy 38 25,396 04-23-2024, 10:29 AM
Last Post: donchurch
  PinePhone app development WhiteHexagon 15 4,101 04-23-2024, 05:19 AM
Last Post: Jonnyc
Wink PINEPHONE not booting Touchwood 2 503 02-23-2024, 07:27 AM
Last Post: Touchwood
  Slack on PinePhone Adam Seline 5 5,465 12-20-2023, 07:20 AM
Last Post: nickolas
  Struggle to install LibreOffice on the PinePhone Peter Gamma 48 24,748 11-24-2023, 07:02 AM
Last Post: Peter Gamma
  Which word processor to choose for the Pinephone? Peter Gamma 8 2,098 11-23-2023, 01:06 AM
Last Post: Peter Gamma
  openSUSE for Pinephone Alefnode 75 102,852 11-17-2023, 08:37 AM
Last Post: Uturn
  Genode- Sculpt OS for the PinePhone (non Linux) Surehand53 1 1,021 11-04-2023, 07:23 PM
Last Post: tllim
  Abiword as a office mobile word processor for the Pinephone? Peter Gamma 11 2,384 10-24-2023, 08:57 AM
Last Post: Peter Gamma

Forum Jump:


Users browsing this thread: 1 Guest(s)