Skip to content

new display driver in kernel 4.14.x #455

Closed

Description

@dlech

I just released a new ev3dev kernel on ev3dev-stretch that updates from 4.9.x to 4.14.x. This comes with a new display driver for the EV3 from the mainline kernel.

The new driver still provides a fbdev device (/dev/fb0) however, the memory layout is different. Because of limitations in the mainline kernel, there is no monochome. Instead it uses a 32-bit XRGB pixel format.

This causes an error with ev3dev-lang-python. See ev3dev/ev3dev#1022 (comment)

Activity

  1. dlech commented on Apr 15, 2018

    @dlech
    MemberAuthor

    In reality, though, the display will now use 2-bit (4 color) grayscale 😮

  2. ddemidov commented on Apr 16, 2018

    @ddemidov
    Member

    So it looks like we should add a case for self.var_info.bits_per_pixel == 32 here with an appropriate encoder:

    if self.var_info.bits_per_pixel == 1:
    self.mmap[:] = self._img.tobytes("raw", "1;IR")
    elif self.var_info.bits_per_pixel == 16:
    self.mmap[:] = self._img_to_rgb565_bytes()
    else:
    raise Exception("Not supported")

  3. ddemidov commented on Apr 22, 2018

    @ddemidov
    Member

    3b34f78 might help, but I did not have time to update to the 4.14 kernel and actually test it.

  4. ndward commented on Apr 24, 2018

    @ndward

    It's not clear to me whether the update() function in the 22 April Stretch image has been fixed. Is there something different I should be doing to be able to update the LCD? Should I expect a fix for this any time soon? Am I right in thinking that all the Stretch images released so far for the EV3 suffer either from the brickd hyperactivity bug or the update() function not working?

  5. dlech commented on Apr 25, 2018

    @dlech
    MemberAuthor

    given the fact that this issue is still marked as open, I don't see why one would expect that it has been fixed.

    in the meantime, if you want an older kernel with fixed brickd, I would suggest using an image older than 14 April and just upgrade the brickd package, but not the kernel (sudo apt update && sudo apt install brickd).

  6. ddemidov commented on Apr 25, 2018

    @ddemidov
    Member

    @ndward, you can help by testing if 3b34f78 works. You can do it by doing something like this in the EV3 command line:

    git clone -b display-4.14 https://github.com/ev3dev/ev3dev-lang-python test-display-fix
    cd ./test-display-fix
    # test display by running some script from this directory,
    # or interactively by opening python3

    If you run any script while in test-display-fix directory, then this version of ev3dev should be picked up instead of the one installed system-wide.

  7. ndward commented on Apr 25, 2018

    @ndward

    I followed your instructions, then put this script in the test-display-fix folder (specifically, I used SFTP Net Drive to copy this script from another folder, which caused the copy to no longer be executable, so I then made it executable with chmod). Is it correct that I put the script directly in the test-display-fix folder and not in a subfolder?

    #!/usr/bin/env python3
    from ev3dev.ev3 import *
    from time import sleep
    lcd = Screen()
    lcd.clear()
    lcd.update()
    sleep(5)
    

    When I ran that script (right-click + Run in the EV3 browser) I got

    Starting: brickrun --directory=/home/robot/test-display-fix /home/robot/test-display-fix/lcdtestshort.py
    Started.
    ----------
    Traceback (most recent call last):
      File "/home/robot/test-display-fix/lcdtestshort.py", line 6, in <module>
        lcd.update()
      File "/usr/lib/python3/dist-packages/ev3dev/core.py", line 3325, in update
        raise Exception("Not supported")
    Exception: Not supported
    ----------
    Exited with error code 1.
    

    I got the same result using python3 interactively.

    If the font is large in the above paragraph then that is not deliberate.

    Image file:         ev3dev-stretch-ev3-generic-2018-04-22
    Kernel version:     4.14.34-ev3dev-1.6.1-ev3
    Brickman:           0.10.0
    ev3devKit:          0.5.2
    Board:              board0
    BOARD_INFO_HW_REV=7
    BOARD_INFO_MODEL=LEGO MINDSTORMS EV3
    BOARD_INFO_ROM_REV=6
    BOARD_INFO_SERIAL_NUM=00165340377E
    BOARD_INFO_TYPE=main
    
  8. ddemidov commented on Apr 25, 2018

    @ddemidov
    Member

    The main module is now named ev3dev2 I think. Can you change the line

    from ev3dev.ev3 import *

    to

    from ev3dev2.auto import *

    ?

  9. ddemidov commented on Apr 25, 2018

    @ddemidov
    Member

    Also, the Screen class is now called Display. There was some big restructuring recently in the stretch branch.

  10. ndward commented on Apr 25, 2018

    @ndward

    When I ran this script

    #!/usr/bin/env python3
    from ev3dev2.auto import *
    from time import sleep
    lcd = Display()
    lcd.clear()
    lcd.update()
    sleep(5)
    

    I got
    Starting: brickrun --directory=/home/robot/test-display-fix /home/robot/test-display-fix/lcdtestshort.py

    Started.
    ----------
    Traceback (most recent call last):
      File "/home/robot/test-display-fix/lcdtestshort.py", line 6, in <module>
        lcd.update()
      File "/home/robot/test-display-fix/ev3dev2/display.py", line 290, in update
        self.mmap[:] = self._img_to_xrgb_bytes()
      File "/home/robot/test-display-fix/ev3dev2/display.py", line 277, in _img_to_xrgb_bytes
        return pack('H' * len(pixels), *pixels)
    struct.error: ushort format requires 0 <= number <= (0x7fff * 2 + 1)
    ----------
    Exited with error code 1.
    

    Apart from Screen() becoming Display(), are there many other changes that need to be made in scripts? Is there a list of necessary changes somewhere?

  11. jabrena commented on Apr 25, 2018

    @jabrena

    This is an important point, not only for Python library and users related. We should announce and track all changes to synchronize the changes or at least try. For Java, I will have to see how to solve the Display issue too, and it is complex. :(

  12. ddemidov commented on Apr 25, 2018

    @ddemidov
    Member

    @ndward, thanks for testing! I've pushed a fix that should address the problem. You can get it by doing git pull from inside test-display-fix directory. Can you try if that works?

  13. ddemidov commented on Apr 25, 2018

    @ddemidov
    Member

    The branch is yet to be released (this is a development branch). When that happens, I guess there will be a list of changes.

  14. ndward commented on Apr 25, 2018

    @ndward

    Same simple script now gives:

    Starting: brickrun --directory=/home/robot/test-display-fix /home/robot/test-display-fix/lcdtestshort.py
    Started.
    ----------
    ----------
    Completed successfully.
    
  15. ndward commented on Apr 25, 2018

    @ndward

    I added a line to draw text:

    #!/usr/bin/env python3
    from ev3dev2.auto import *
    from time import sleep
    lcd = Display()
    lcd.clear()
    lcd.draw.text((10,10), 'Hello World!')
    lcd.update()
    sleep(5)
    

    The script completed after 1m8s but no text was drawn.

  16. ddemidov commented on Apr 25, 2018

    @ddemidov
    Member

    @dlech, does this look correct to you?

    def _color_xrgb(self, r, g, b):
    """Convert red, green, blue components to a 32-bit XRGB value. Components
    should be values 0 to 255.
    """
    return ((r << 16) | (g << 8) | b)
    def _img_to_xrgb_bytes(self):
    pixels = [self._color_xrgb(r, g, b) for (r, g, b) in self._img.getdata()]
    return pack('I' * len(pixels), *pixels)

    The only idea I have is to try and switch the byte order: now it is 0RGB, the other options to try are RGB0 or BGR0.

  17. ndward commented on Apr 25, 2018

    @ndward
  18. dlech commented on Apr 25, 2018

    @dlech
    MemberAuthor

    @dlech, does this look correct to you?

    Hmm... I think I would add a special case for EV3 int Display.__init__(). If platform == EV3 and self.var_info.bits_per_pixel != 1 then create an 8-bit grayscale (PIL type 'L') image.

    Then, for the conversion function, take the 'L' image one byte at a time and expand it to a 32 bit value, making R, G and B each having the same value.

    def _gray_xrgb(self, value): 
             """Convert grayscale to a 32-bit XRGB value. Value
             should be values 0 to 255. 
             """ 
    return ((value << 16) | (value << 8) | value) 
  19. ndward commented on Apr 25, 2018

    @ndward
  20. added a commit that references this issue on Apr 30, 2018
    4c2e21d
  21. ddemidov commented on Apr 30, 2018

    @ddemidov
    Member

    #462 is tested and works on stretch.

  22. dlech commented on May 5, 2018

    @dlech
    MemberAuthor

    Fix released in v1.2.0

  23. added a commit that references this issue on May 20, 2018
    70b7b44
  24. dwalton76 commented on Nov 10, 2018

    @dwalton76
    Collaborator

    Can we close this one?

  25. WasabiFan commented on Nov 11, 2018

    @WasabiFan
    Member

    I think so. #501 covers the remaining work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions