Skip to content

Need a way to detect BrickPi and PiStorms on Raspberry Pi #412

Closed

Description

@dlech

This came up in a conversation with @ddemidov in ev3dev/ev3dev-lang@ac9a629#commitcomment-13858910. We want to be able to use the same image file for both BrickPi and PiStorms. Users will have to select which one is attached by changing a setting in config.txt. PiStorms will be easy to detect since is uses a I2C/NXT connection. Basically, it will be automatically detected and everything should "just work". The BrickPi on the other hand uses a tty line discipline. This is attached by a systemd service. So, we need something that can trigger the systemd service rather than the user having to manually enable or disable it. Right now, the presence of the brickpi LED devices is the only thing we have to go off of. It seems like there should be a better way to do this, but I haven't come up with anything yet. Just throwing this out there in case there are any device tree experts listening that may have a better idea.

Activity

  1. added
    BrickPi
    on Oct 19, 2015
  2. added this to the ev3dev-jessie 2015-Q4 milestone on Oct 30, 2015
  3. dlech commented on Nov 4, 2015

    @dlech
    MemberAuthor

    OK. Recommended way to know if you are running on...

    EV3: The file /proc/cpuinfo contains the string LEGO MINDSTORMS EV3 Programmable Brick.

    cat /proc/cpuinfo | grep -q "LEGO MINDSTORMS EV3 Programmable Brick"
    

    BrickPi: The file /sys/class/tty/ttyAMA0/device/of_node/brickpi,status exists and contains okay. (Yes, that is a comma and it is part of the file name.)

    [ -f /sys/class/tty/ttyAMA0/device/of_node/brickpi,status ] && [ "$(cat /sys/class/tty/ttyAMA0/device/of_node/brickpi,status)" == "okay" ]
    

    PiStorms: The directory /sys/bus/i2c/drivers/pistorms exists and contains the symlink (directory) ?-001a (and ?-001b).

    [ -d /sys/bus/i2c/drivers/pistorms ] && [ -L /sys/bus/i2c/drivers/pistorms/?-001a ]
    
  4. added
    fix committed (not released yet)
    on Nov 4, 2015
  5. ddemidov commented on Nov 4, 2015

    @ddemidov
    Member

    Can we introduce a system shell script (ev3dev_platform?) that would return ev3/brickpi/pistorms based on this? The script could be universally used by all the bindings.

  6. rhempel commented on Nov 4, 2015

    @rhempel
    Member

    Can we introduce a more general form of this platform detection? I know that in some cases, the DKMS drivers are all that a user will have, but for the rest of the platforms, we actually have control of the image on the SD card, and therefore we control the kernel.

    Can we not just add a known string to /proc/cpuinfo or create our own /proc/ev3devor/sys/class/ev3dev/platform` that has the version string?

  7. dlech commented on Nov 4, 2015

    @dlech
    MemberAuthor

    Can we introduce a system shell script (ev3dev_platform?) that would return ev3/brickpi/pistorms based on this? The script could be universally used by all the bindings.

    Yes, we can do this.

    Can we introduce a more general form of this platform detection?

    No, we can't. If users are using DKMS drivers, then they just don't have a specific platform. You will never get EV3 LEDs or BrickPi LEDs or PiStorms LEDs using DKMS. These are defined by the board configuration file in the kernel in the case of EV3 and in device-tree overlays in the case of Raspberry Pi. And in fact, your question has made me realize that my proposed detection for the PiStorms is really too general as it is and needs to be revised.

    Can we not just add a known string to /proc/cpuinfo

    This is exactly what has been done in the case of the EV3. But on Raspberry Pi, this can only tell us which model of Raspberry Pi we have. It cannot tell if we have a BrickPi or a PiStorms or neither.

    or create our own /proc/ev3devor/sys/class/ev3dev/platform` that has the version string?

    This is exactly what I have done in the case of the BrickPi. The file /sys/class/tty/ttyAMA0/device/of_node/brickpi,status only exists when the BrickPi overlay is enabled. I'm thinking I should do the same for PiStorms. However it doesn't use the tty. It uses i2c and spi. The i2c can be one of 2 devices depending on which Pi model you have which was the reason for the ?, but perhaps we can attach a custom attribute to the spi instead.

  8. dlech commented on Nov 4, 2015

    @dlech
    MemberAuthor

    Can we introduce a system shell script (ev3dev_platform?) that would return ev3/brickpi/pistorms based on this? The script could be universally used by all the bindings.

    However, as @rhempel mentioned, people can be using ev3dev on non-ev3dev platforms, so depending on an external tool is probably not the best idea.

  9. rhempel commented on Nov 4, 2015

    @rhempel
    Member

    Does each supported platform need a custom kernel?

  10. dlech commented on Nov 4, 2015

    @dlech
    MemberAuthor

    In the case of the EV3, obviously yes. In the case of Raspberry Pi, no. However, on the Raspberry Pi in order to have the full "platform" for BrickPi or PiStorms, you have to have the device-tree overlays (which is sort of like a custom kernel).

  11. rhempel commented on Nov 4, 2015

    @rhempel
    Member

    Sooo - can we put a virtual "thing" in the device tree that forces a kernel module to be required, and all that kernel module does is create a node somewhere in /sys that lets us identify the hardware?

  12. dlech commented on Nov 4, 2015

    @dlech
    MemberAuthor

    I guess what you are getting at is we should have one single place to look for all platforms? That is probably not be possible with device tree without a custom kernel.

  13. dlech commented on Nov 5, 2015

    @dlech
    MemberAuthor

    Well, after thinking about it some more, of course we could do that because we would have the driver in our DKMS package. So, the only problem I see with that is what happens when someone puts their PiStorms on their BrickPi and both overlays try to create the same device node.

  14. 7 remaining items

  15. ddemidov commented on Nov 6, 2015

    @ddemidov
    Member

    I like this. I think we won't loose any functionality this way except for led grouping. I guess there is no generic way to tell that some leds form a group that may be combined to control color? Of course we could put all possible groupings into specification, and only use those that do exist on the current platform.

  16. dlech commented on Nov 6, 2015

    @dlech
    MemberAuthor

    Actually, you can tell led groupings. The standard format for led names is devicename:color:function (comes from https://www.kernel.org/doc/Documentation/leds/leds-class.txt).

    devicename can contain : characters, so when parsing you need to search for the last two :s. For leds that can be controlled by ev3dev, the function will be ev3dev. All other leds should be ignored. Led groups will have the same devicename but a different color.

  17. ddemidov commented on Nov 6, 2015

    @ddemidov
    Member

    These are led names I know about:

    EV3:

    ev3-left0:red:ev3dev
    ev3-left1:green:ev3dev
    ev3-right0:red:ev3dev
    ev3-right1:green:ev3dev
    

    BrickPi:

    brickpi1:blue:ev3dev
    brickpi2:blue:ev3dev
    

    PiStorms:

    pistorms:BA:red:ev3dev
    pistorms:BA:blue:ev3dev
    pistorms:BA:green:ev3dev
    pistorms:BB:red:ev3dev
    pistorms:BB:green:ev3dev
    pistorms:BB:blue:ev3dev 
    

    For BrickPi and PiStorms the group names can be directly mapped to device names (brickpi1/brickpi2 and pistroms:BA/pistorms:BB). For ev3 its not so obvious: each led gets unique device name. We could strip device names of trailing digits (and get ev3-left/ev3-right groups for ev3), but that would also break grouping for brickpi.

    Is it possible to rename leds on ev3 to be

    ev3-left:red:ev3dev
    ev3-left:green:ev3dev
    ev3-right:red:ev3dev
    ev3-right:green:ev3dev
    

    ?

  18. ensonic commented on Nov 6, 2015

    @ensonic

    RIght now the blockly blocks on roberta are quite statically modeled to work for the ev3. We can probably do things to have more dynamic led blocks easilly.

    @dlech on ev3dev, could we drop the numbers? So that we have ev3-{left,right}:{red,green}:ev3dev. To an app that reads like left and right led with r/g controls. The facts that it is two separate leds instead one combined is an impl detail.

  19. rhempel commented on Nov 6, 2015

    @rhempel
    Member

    I agree with @ddemidov and @ensonic - the LED number is an implementation detail.

    Now if the group of LEDs on the left side of the board were arranged in a line (think bars of reception or battery indicator) then an index number would be reasonable.

    Let's think about how to specify LED groups in spec.json in a general way and use the spec to generate platform specific code.

    Actually, even if we don't autogenerate the code, thinking about the LED groups in the spec will probably help us come up with a better naming scheme.

  20. dlech commented on Nov 6, 2015

    @dlech
    MemberAuthor

    Yes. I'm thinking ev3:{left,right}:{red,green}:ev3dev (colon after the ev3 instead of dash) to make it more like the pistorms.

    And the more I'm thinking about this, detecting each component individually makes more sense than trying to define an entire platform from a single property. Not only are there nuances between each platform, there are already nuances within each platform (e.g. color screen on EV3 and BrickPi/BrickPi+). And BrickPi and PiStorms have frimware that can be upgraded, so it is possible there could be even more differences and we would have to look at firmware version too. I gets very complex very quickly. I think just looking at each subsystem individually is going to work better in the long run.

  21. added a commit that references this issue on Nov 6, 2015
  22. ddemidov commented on Nov 6, 2015

    @ddemidov
    Member

    Buttons: /sys/class/input/input*/name. It will tell you the "platform

    It says EV3 buttons and EV3 speaker beep on EV3. Is there a way to know actual buttons supported on the system, or should we keep a database of platform keys?

    In/Out ports.

    If I do cat /sys/class/lego-port/*/port_name on EV3, I get

    in1
    in2
    in3
    in4
    outA
    outB
    outC
    outD
    

    Is lego-port class supported on all platforms, or just ev3?

  23. dlech commented on Nov 6, 2015

    @dlech
    MemberAuthor

    Is there a way to know actual buttons supported on the system

    Yes, /sys/class/input/input0/capabilities/key returns a bitmask of the keys that are present. the EVIOCGBIT(ev,len) ioctl does the same thing.

    or should we keep a database of platform keys?

    If you want the keys available via introspection while developing on a host computer, then probably yes.

    Is lego-port class supported on all platforms, or just ev3?

    The lego-port class is on on all platforms. Additionally, if you have any kind of sensor multiplexer, you will have additional ports, like in1:i2c8:mux2, etc. On BrickPi (for now) the port names are the same (in1, outA), but on PiStorms, they are pistorms:BAS1, pistorms:BAM1.

  24. dlech commented on Nov 9, 2015

    @dlech
    MemberAuthor

    Fix released in kernel cycle 8 (*-8-ev3dev-*).

  25. EricPobot commented on Dec 4, 2015

    @EricPobot

    For your information, I've just received a brand new PiStorms, and the RGB LED on the left side (bank B) is not here any more on the new version of the board (black PCB).
    I firstly suspected my board to be damaged, since not being able to activate it using the provided Python lib, but the support team answered me with this information after asking them.

  26. dlech commented on Dec 4, 2015

    @dlech
    MemberAuthor

    please open a new issue for this.

  27. EricPobot commented on Dec 4, 2015

    @EricPobot

    I was just giving this as an info, since this thread seemed to talk about board identification. It was not an issue in my mind.

  28. removed
    fix committed (not released yet)
    on Mar 20, 2016
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

    BrickPikernelplanning

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions