Announcement

Collapse
No announcement yet.

Armadillo-43T and Pygame

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Armadillo-43T and Pygame

    Hi,

    I'm trying to build a small GUI on the Armadillo without X11, using Pygame instead.

    I've written a few working demos on the Armadillo-70T, but when migrating over to a 43T today I came across a strange problem.

    I'm using image "Armadillo-43T_armadillian-jessie_R_1_4.zip", hand-installed the firmware required for my USB-WLAN stick (are there any WLAN sticks recommended that work out of the box?) and did a apt-get update/upgrade/dist-upgrade. Then I installed python3-pygame and my demos.

    When launching the demos, only about 1/4th of the screen is used, there is a large black border around that I cannot seem to get rid off, my Pygame application uses only the center quarter (or so). I start pygame in the FULLSCREEN mode, so it should grab the whole screen. I get the same effect with our without X11 running. Strangely, the X11 server does not have this problenm, it fills the entire screen.

    What could be the reason for this diverging behaviour on the 70T and the 43T?

    Please see attached a minimal example, it should run on both 70T (ok) and 43T (buggy) after installing package python3-pygame.

    Thanks,
    Christian
    Attached Files

  • #2
    Hi again,

    I took a screenshot using

    $ cat /dev/fb0 > screenshot.data

    and then used GIMP to turn that into a PNG, please see attached screenshot file. When transforming the image I noticed that it has a resoultion of 640 x 480 x 3 instead of the 480 x 272 x 3. Turnes out that pyGame does not support the required screen resolution of 480 x 272:

    >>> import pygame
    >>> pygame.display.init()
    >>> for mode in pygame.display.list_modes():
    ... print(mode)
    ...
    (1600, 1200)
    (1280, 1024)
    (1024, 1024)
    (1280, 960)
    (1152, 864)
    (1024, 768)
    (800, 600)
    (768, 576)
    (640, 480)
    >>>

    So pyGame's supports ends with 640x480, and the pyGame documentation is clear about this:

    When requesting fullscreen display modes, sometimes an exact match for the requested resolution cannot be made. In these situations pygame will select the closest compatible match. The returned surface will still always match the requested resolution.
    This explains it, but what can I do about it?

    I tried directly writing to /dev/fb0 and I verified that I can access the whole screen in 420 x 272, but this is a bit of a dire route, I'd rather not do that.

    I tried using libSDL2 with C/C++, it supports no fbcon but only X11 and thus needs the X11 server (not what I want), and it is also extremly slow (like 0.3 FPS even with very simple graphics). Still, it manages the whole screen normally.. When trying to compile libSDL 2.0.5 it failed because bcm_host.h is missing (in fact, all of /opt/vc/include is missing, I couldn't find it, where did it go?). So I think I couldn't compile because of http://forum.4dsystems.com.au/forum/...-libarmadillo0 - any news on this?

    Maybe recompiling pyGame is an option, but I could not find out if I can force it to support 480 x 272, and also I'm not sure if I can compile it without the system headers in /opt/vc/include.

    Should I try to build pyGame myself?

    Thanks!
    Christian
    Attached Files

    Comment


    • #3
      Hello Christian,

      I was also looking for a solution to this screen resolution but drawn a blank. Any kind of post image scaling from the lowest supported resolution of pyGame to 480 x 272 is going to cause a performance issue and in this case the best option would be trying to create pyGame in the native 480 x 272.

      I hope this helps

      Best regards

      Paul

      Comment


      • #4
        Hello Paul,

        thanks for looking into this.

        I was able to compile pyGame on the 43T, but that won't help. pyGame internally uses SDL (1.2) to access /dev/fb0 and asks SDL for the supported screen resolutions. I've made a small sample in C that uses SDL, and it suffers from the exact same problem of using 640 x 480 instead of 480 x 272.

        I am not sure yet what limits the set of screen resolutions in SDL 1.2. In case it is hard-compiled in I'd need to build my own with appropriate screen resolutions. Since I wasn't able to build SDL2, I'm concerned that it will fail for the same reason. So please, is there any chance to get a copy of /opt/vc/include? I do not understand why they are missing, could you please shed some light on this?

        I guess if all fails I could give directfb a shot.

        Thanks and best regards,
        Christian

        Comment


        • #5
          It is solved.

          The frame buffer device only accepts video modes listed in /etc/fb.modes, and the settings for 480x272 are missing in the Armadillian 43T distribution.

          Fortunately, the fbset utility lists the currently active video settings in the format required for /etc/fb.modes:

          $ fbset

          mode "480x272"
          geometry 480 272 480 272 24
          timings 0 0 0 0 0 0 0
          rgba 8/0,8/8,8/16,0/24
          endmode

          So the fix is simple, just run:

          $ sudo bash -c "fbset > /etc/fb.modes"

          and then reboot (note that I'm overwriting /etc/fb.modes, this is because we only need that single mode on the 43T). Everything works! directfb was suffering from the same misconfiguration, but now it works as expected:

          Code:
          $ sudo dfbdump
          
             ~~~~~~~~~~~~~~~~~~~~~~~~~~| DirectFB 1.2.10 |~~~~~~~~~~~~~~~~~~~~~~~~~~
                  (c) 2001-2008  The world wide DirectFB Open Source Community
                  (c) 2000-2004  Convergence (integrated media) GmbH
                ----------------------------------------------------------------
          
          (*) DirectFB/Core: Single Application Core. (2014-11-01 05:58)
          (*) Direct/Thread: Started 'VT Switcher' (-1) [CRITICAL OTHER/OTHER 0/0] <8388608>...
          (*) Direct/Thread: Started 'Linux Input' (-1) [INPUT OTHER/OTHER 0/0] <8388608>...
          (*) DirectFB/Input: HID 046a:0023 (1) 0.1 (directfb.org)
          (*) Direct/Thread: Started 'Linux Input' (-1) [INPUT OTHER/OTHER 0/0] <8388608>...
          (*) DirectFB/Input: HID 046a:0023 (2) 0.1 (directfb.org)
          (*) Direct/Thread: Started 'Linux Input' (-1) [INPUT OTHER/OTHER 0/0] <8388608>...
          (*) DirectFB/Input: AR1020 Touchscreen (3) 0.1 (directfb.org)
          (*) Direct/Thread: Started 'PS/2 Input' (-1) [INPUT OTHER/OTHER 0/0] <8388608>...
          (*) DirectFB/Input: IMPS/2 Mouse 1.0 (directfb.org)
          (*) Direct/Thread: Started 'Keyboard Input' (-1) [INPUT OTHER/OTHER 0/0] <8388608>...
          (*) DirectFB/Input: Keyboard 0.9 (directfb.org)
          (*) DirectFB/Graphics: Generic Software Rasterizer 0.6 (directfb.org)
          (*) DirectFB/Core/WM: Default 0.3 (directfb.org)
          (*) FBDev/Surface: Allocated 480x272 24 bit RGB24 buffer (index 0) at offset 0 and pitch 1440.
          
          DirectFB uptime: 00:00:00
          
          -----------------------------[ Surfaces ]-------------------------------------
          Reference   FID  . Refs  Width Height  Format     Video   System  Capabilities
          ------------------------------------------------------------------------------
          N/A              :   2    480 x  272      RGB24   382k*    382k*  video only   double
                                                          ------   ------
                                                            382k     382k   -> 765k total
          
          ----------------------------------[ Contexts of Layer 0 ]----------------------------------------
          Reference   FID  . Refs  Width Height Format   Location on screen  Regions  Active  Info    Level
          -------------------------------------------------------------------------------------------------
          N/A              :   3    480 x  272  RGB24    0.0, 0.0 -> 1.0, 1.0    1     (*)    SHARED   N/A
          Code:
          $ sudo dfbinfo
          
             ~~~~~~~~~~~~~~~~~~~~~~~~~~| DirectFB 1.2.10 |~~~~~~~~~~~~~~~~~~~~~~~~~~
                  (c) 2001-2008  The world wide DirectFB Open Source Community
                  (c) 2000-2004  Convergence (integrated media) GmbH
                ----------------------------------------------------------------
          
          (*) DirectFB/Core: Single Application Core. (2014-11-01 05:58)
          (*) Direct/Thread: Started 'VT Switcher' (-1) [CRITICAL OTHER/OTHER 0/0] <8388608>...
          (*) Direct/Thread: Started 'Linux Input' (-1) [INPUT OTHER/OTHER 0/0] <8388608>...
          (*) DirectFB/Input: HID 046a:0023 (1) 0.1 (directfb.org)
          (*) Direct/Thread: Started 'Linux Input' (-1) [INPUT OTHER/OTHER 0/0] <8388608>...
          (*) DirectFB/Input: HID 046a:0023 (2) 0.1 (directfb.org)
          (*) Direct/Thread: Started 'Linux Input' (-1) [INPUT OTHER/OTHER 0/0] <8388608>...
          (*) DirectFB/Input: AR1020 Touchscreen (3) 0.1 (directfb.org)
          (*) Direct/Thread: Started 'PS/2 Input' (-1) [INPUT OTHER/OTHER 0/0] <8388608>...
          (*) DirectFB/Input: IMPS/2 Mouse 1.0 (directfb.org)
          (*) Direct/Thread: Started 'Keyboard Input' (-1) [INPUT OTHER/OTHER 0/0] <8388608>...
          (*) DirectFB/Input: Keyboard 0.9 (directfb.org)
          (*) DirectFB/Graphics: Generic Software Rasterizer 0.6 (directfb.org)
          (*) DirectFB/Core/WM: Default 0.3 (directfb.org)
          (*) FBDev/Surface: Allocated 480x272 24 bit RGB24 buffer (index 0) at offset 0 and pitch 1440.
          
          
          Screen (00) FBDev Primary Screen            (primary screen)
             Caps: VSYNC POWER_MANAGEMENT
          
               Layer (00) FBDev Primary Layer             (primary layer)
                  Type:    GRAPHICS
                  Caps:    SURFACE BRIGHTNESS CONTRAST SATURATION
          
          
          Input (00) HID 046a:0023                   (primary keyboard)
             Type: KEYBOARD
             Caps: KEYS
             Min. Keycode: 0
             Max. Keycode: 127
          
          Input (03) HID 046a:0023                   (primary remote control)
             Type: REMOTE
             Caps: KEYS AXES
             Min. Keycode: -1
             Max. Keycode: -1
             Max. Axis: 0
          
          Input (01) AR1020 Touchscreen              (primary mouse)
             Type: MOUSE
             Caps: AXES
             Max. Axis: 1
          
          Input (10) IMPS/2 Mouse
             Type: MOUSE
             Caps: AXES BUTTONS
             Max. Axis: 2
             Max. Button: 2
          
          Input (11) Keyboard
             Type: KEYBOARD
             Caps: KEYS
             Min. Keycode: 0
             Max. Keycode: 127
          Code:
          $ fbset -i
          
          mode "480x272"
              geometry 480 272 480 272 24
              timings 0 0 0 0 0 0 0
              rgba 8/0,8/8,8/16,0/24
          endmode
          
          Frame buffer device information:
              Name        : BCM2708 FB
              Address     : 0x18052000
              Size        : 391680
              Type        : PACKED PIXELS
              Visual      : TRUECOLOR
              XPanStep    : 1
              YPanStep    : 1
              YWrapStep   : 0
              LineLength  : 1440
              Accelerator : No
          Last edited by cschnell; 4th July 2017, 05:53 PM. Reason: Clarification

          Comment


          • #6
            Hello Christian,

            Thank you for sharing this on the forum. I am so glad you found a solution without a major re-write. Awesome =)

            Best regards

            Paul

            Comment

            Working...
            X