adafruit / Adafruit_Python_PlatformDetect

MIT License
59 stars 238 forks source link

orangepipc2 detection is wrong #352

Closed nopnop2002 closed 5 months ago

nopnop2002 commented 5 months ago

Thanks for your support.

For orangepipc2:

board_value = self.detector.get_armbian_release_field("BOARD")
print("_armbian_id board_value={}".format(board_value))

get_armbian_release_field("BOARD") reads the BOARD of the next file.

$ cat /etc/armbian-release
# PLEASE DO NOT EDIT THIS FILE
BOARD=orangepipc2
BOARD_NAME="Orange Pi PC2"
BOARDFAMILY=sun50iw2
BUILD_REPOSITORY_URL=git@github.com:armbian/build
BUILD_REPOSITORY_COMMIT=aec64805a
DISTRIBUTION_CODENAME=buster
DISTRIBUTION_STATUS=supported
VERSION=21.08.1
LINUXFAMILY=sunxi64
ARCH=arm64
IMAGE_TYPE=stable
BOARD_TYPE=conf
INITRD_ARCH=arm64
KERNEL_IMAGE_TYPE=Image
BRANCH=current

_armbian_id board_value=orangepipc2

Current code:

elif board_value == "orangepi2":
    board = boards.ORANGE_PI_2

name order: Orangepi -> Orangepi 2 -> Orangepi PC -> Orangepi PC2 -> Orangepi 3 -> Orangepi 4 -> Orangepi 5. Before Orangepi PC was released (around 2015), there was a model called Orangepi 2.

Orangepi 2 is an older board than Orangepi PC. This library does not support boards older than orangepipc, so this is clearly a mistake.

    # pylint: disable=too-many-return-statements
    def _armbian_id(self) -> Optional[str]:
        """Get the current board via the ARMBIAN release field."""
        board_value = self.detector.get_armbian_release_field("BOARD")
        print("_armbian_id board_value={}".format(board_value))
        board = None

        if board_value == "orangepipc":
            board = boards.ORANGE_PI_PC
        elif board_value == "orangepi-r1":
            board = boards.ORANGE_PI_R1

The correct name for the definition of boards.ORANGE_PI_2 is boards.ORANGE_PI_PC2.

        #elif board_value == "orangepi2":
        #    board = boards.ORANGE_PI_2
        elif board_value == "orangepipc2":
            board = boards.ORANGE_PI_PC2

This is also wrong. https://github.com/adafruit/Adafruit_Blinka/blob/main/src/board.py#L118

OrangePi PC2 is H5, not H3. So GPIO assignment is different from orangepipc.

#elif board_id == ap_board.ORANGE_PI_2:
#    from adafruit_blinka.board.orangepi.orangepipc import *
elif board_id == ap_board.ORANGE_PI_PC2:
    from adafruit_blinka.board.orangepi.orangepipc2 import *

There is no H5(orangepipc2) pin information in the orangepi directory. https://linux-sunxi.org/Xunlong_Orange_Pi_PC_2

makermelissa commented 5 months ago

Makes sense. Would you like to submit a PR to update it?

nopnop2002 commented 5 months ago

If I changed boards.ORANGE_PI_2 to boards.ORANGE_PI_PC2, Adafruit_Python_PlatformDetect and Adafruit_Blinka must be changed at the same time.

Therefore, I think it is better to leave boards.ORANGE_PI_2 and add new boards.ORANGE_PI_PC2.

https://github.com/adafruit/Adafruit_Python_PlatformDetect/blob/main/adafruit_platformdetect/constants/boards.py#L257

# OrangePI
_ORANGE_PI_IDS = (
    ORANGE_PI_PC,
    ORANGE_PI_R1,
    ORANGE_PI_ZERO,
    ORANGE_PI_ONE,
    ORANGE_PI_LITE,
    ORANGE_PI_PC_PLUS,
    ORANGE_PI_PLUS_2E,
    ORANGE_PI_2,
    ORANGE_PI_PC2, // add new board
    ORANGE_PI_ZERO_PLUS_2H5,
    ORANGE_PI_ZERO_PLUS,
    ORANGE_PI_ZERO_2,
    ORANGE_PI_3,
    ORANGE_PI_3B,
    ORANGE_PI_3_LTS,
    ORANGE_PI_4,
    ORANGE_PI_4_LTS,
    ORANGE_PI_5,
    ORANGE_PI_5_PLUS,
)

I'm thinking of the following steps.

Step1 Add ORANGE_PI_PC2 to Adafruit_Python_PlatformDetect.

Step2 Once Step1 is merged, add ORANGE_PI_PC2 to Adafruit_Blinka.

What do you think?

nopnop2002 commented 5 months ago

I added orangepi pc2.