Skip to content

Commit 18c9682

Browse files
authored
Merge pull request #52 from yeyeto2788/master
Initial addition for Pine64 devices
2 parents eab68f0 + 869b151 commit 18c9682

File tree

3 files changed

+66
-21
lines changed

3 files changed

+66
-21
lines changed

adafruit_platformdetect/board.py

+46-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Detect boards."""
22
import os
33
import re
4+
45
import adafruit_platformdetect.chip as ap_chip
56

67
# Allow for aligned constant definitions:
@@ -74,6 +75,10 @@
7475
ONION_OMEGA = "ONION_OMEGA"
7576
ONION_OMEGA2 = "ONION_OMEGA2"
7677

78+
PINE64 = "PINE64"
79+
PINEBOOK = "PINEBOOK"
80+
PINEPHONE = "PINEPHONE"
81+
7782
# pylint: enable=bad-whitespace
7883

7984
#OrangePI
@@ -249,44 +254,44 @@
249254
),
250255
RASPBERRY_PI_ZERO: (
251256
'900092', '920092', '900093', '920093',
252-
'1900092', '1920092', '1900093', '1920093', # warranty bit 24
253-
'2900092', '2920092', '2900093', '2920093', # warranty bit 25
257+
'1900092', '1920092', '1900093', '1920093', # warranty bit 24
258+
'2900092', '2920092', '2900093', '2920093', # warranty bit 25
254259
),
255260
RASPBERRY_PI_ZERO_W: (
256261
'9000c1',
257-
'19000c1', '29000c1', # warranty bits
262+
'19000c1', '29000c1', # warranty bits
258263
),
259264
RASPBERRY_PI_2B: (
260265
'a01040', 'a01041', 'a21041', 'a22042',
261-
'1a01040', '1a01041', '1a21041', '1a22042', # warranty bit 24
262-
'2a01040', '2a01041', '2a21041', '2a22042', # warranty bit 25
266+
'1a01040', '1a01041', '1a21041', '1a22042', # warranty bit 24
267+
'2a01040', '2a01041', '2a21041', '2a22042', # warranty bit 25
263268
),
264269
RASPBERRY_PI_3B: (
265270
'a02082', 'a22082', 'a32082', 'a52082',
266-
'1a02082', '1a22082', '1a32082', '1a52082', # warranty bit 24
267-
'2a02082', '2a22082', '2a32082', '2a52082', # warranty bit 25
271+
'1a02082', '1a22082', '1a32082', '1a52082', # warranty bit 24
272+
'2a02082', '2a22082', '2a32082', '2a52082', # warranty bit 25
268273
),
269274
RASPBERRY_PI_3B_PLUS: (
270275
'a020d3',
271-
'1a020d3', '2a020d3', # warranty bits
276+
'1a020d3', '2a020d3', # warranty bits
272277
),
273278
RASPBERRY_PI_CM3: (
274279
'a020a0', 'a220a0',
275-
'1a020a0', '2a020a0', # warranty bits
280+
'1a020a0', '2a020a0', # warranty bits
276281
'1a220a0', '2a220a0',
277282
),
278283
RASPBERRY_PI_3A_PLUS: (
279284
'9020e0',
280-
'19020e0', '29020e0', # warranty bits
285+
'19020e0', '29020e0', # warranty bits
281286
),
282287
RASPBERRY_PI_CM3_PLUS: (
283288
'a02100',
284-
'1a02100', '2a02100', # warranty bits
289+
'1a02100', '2a02100', # warranty bits
285290
),
286291
RASPBERRY_PI_4B: (
287292
'a03111', 'b03111', 'c03111',
288293
'a03112', 'b03112', 'c03112',
289-
'1a03111', '2a03111', '1b03111', '2b03111', # warranty bits
294+
'1a03111', '2a03111', '1b03111', '2b03111', # warranty bits
290295
'1c03111', '2c03111', '1a03112', '2a03112',
291296
'1b03112', '2b03112', '1c03112', '2c03112',
292297
),
@@ -298,6 +303,13 @@
298303
ONION_OMEGA2,
299304
)
300305

306+
# Pine64 boards and devices
307+
_PINE64_DEV_IDS = (
308+
PINE64,
309+
PINEBOOK,
310+
PINEPHONE
311+
)
312+
301313
class Board:
302314
"""Attempt to detect specific boards."""
303315
def __init__(self, detector):
@@ -357,6 +369,8 @@ def id(self):
357369
board_id = ONION_OMEGA
358370
elif chip_id == ap_chip.MIPS24KEC:
359371
board_id = ONION_OMEGA2
372+
elif chip_id == ap_chip.A64:
373+
board_id = self._pine64_id()
360374
return board_id
361375
# pylint: enable=invalid-name
362376

@@ -435,6 +449,8 @@ def _armbian_id(self):
435449
return ORANGE_PI_R1
436450
if board_value == "orangepizero":
437451
return ORANGE_PI_ZERO
452+
if board_value == "pinebook-a64":
453+
return PINEBOOK
438454
return None
439455

440456
def _sama5_id(self):
@@ -472,6 +488,18 @@ def _sifive_id(self):
472488
return SIFIVE_UNLEASHED
473489
return None
474490

491+
def _pine64_id(self):
492+
"""Try to detect the id for Pine64 board or device."""
493+
board_value = self.detector.get_device_model()
494+
board = None
495+
if 'pine64' in board_value.lower():
496+
board = PINE64
497+
elif 'pinebook' in board_value.lower():
498+
board = PINEBOOK
499+
elif 'pinephone' in board_value.lower():
500+
board = PINEPHONE
501+
return board
502+
475503
@property
476504
def any_96boards(self):
477505
"""Check whether the current board is any 96boards board."""
@@ -532,13 +560,18 @@ def any_onion_omega_board(self):
532560
"""Check whether the current board is any defined OpenWRT board."""
533561
return self.id in _ONION_OMEGA_BOARD_IDS
534562

563+
@property
564+
def any_pine64_board(self):
565+
"""Check whether the current board is any Pine64 device."""
566+
return self.id in _PINE64_DEV_IDS
567+
535568
@property
536569
def any_embedded_linux(self):
537570
"""Check whether the current board is any embedded Linux device."""
538571
return self.any_raspberry_pi or self.any_beaglebone or \
539572
self.any_orange_pi or self.any_giant_board or self.any_jetson_board or \
540573
self.any_coral_board or self.any_odroid_40_pin or self.any_96boards or \
541-
self.any_sifive_board or self.any_onion_omega_board
574+
self.any_sifive_board or self.any_onion_omega_board or self.any_pine64_board
542575

543576
@property
544577
def ftdi_ft232h(self):

adafruit_platformdetect/chip.py

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Attempt detection of current chip / CPU."""
2-
import sys
32
import os
3+
import sys
44

55
AM33XX = "AM33XX"
66
IMX8MX = "IMX8MX"
@@ -24,36 +24,39 @@
2424
BINHO = "BINHO"
2525
MIPS24KC = "MIPS24KC"
2626
MIPS24KEC = "MIPS24KEC"
27+
A64 = "A64"
2728

2829
BCM_RANGE = {'BCM2708', 'BCM2709', 'BCM2835', 'BCM2837', 'bcm2708', 'bcm2709',
2930
'bcm2835', 'bcm2837'}
3031

32+
3133
class Chip:
3234
"""Attempt detection of current chip / CPU."""
35+
3336
def __init__(self, detector):
3437
self.detector = detector
3538

3639
@property
37-
def id(self): # pylint: disable=invalid-name,too-many-branches,too-many-return-statements
40+
def id(self): # pylint: disable=invalid-name,too-many-branches,too-many-return-statements
3841
"""Return a unique id for the detected chip, if any."""
3942
# There are some times we want to trick the platform detection
4043
# say if a raspberry pi doesn't have the right ID, or for testing
4144
try:
4245
return os.environ['BLINKA_FORCECHIP']
43-
except KeyError: # no forced chip, continue with testing!
46+
except KeyError: # no forced chip, continue with testing!
4447
pass
4548

4649
# Special cases controlled by environment var
4750
if os.environ.get('BLINKA_FT232H'):
48-
from pyftdi.usbtools import UsbTools # pylint: disable=import-error
51+
from pyftdi.usbtools import UsbTools # pylint: disable=import-error
4952
# look for it based on PID/VID
5053
count = len(UsbTools.find_all([(0x0403, 0x6014)]))
5154
if count == 0:
5255
raise RuntimeError('BLINKA_FT232H environment variable ' + \
5356
'set, but no FT232H device found')
5457
return FT232H
5558
if os.environ.get('BLINKA_MCP2221'):
56-
import hid # pylint: disable=import-error
59+
import hid # pylint: disable=import-error
5760
# look for it based on PID/VID
5861
for dev in hid.enumerate():
5962
if dev['vendor_id'] == 0x04D8 and dev['product_id'] == 0x00DD:
@@ -74,9 +77,10 @@ def id(self): # pylint: disable=invalid-name,too-many-branches,too-many-return-s
7477
return STM32
7578
# nothing found!
7679
return None
80+
7781
# pylint: enable=invalid-name
7882

79-
def _linux_id(self): # pylint: disable=too-many-branches
83+
def _linux_id(self): # pylint: disable=too-many-branches,too-many-statements
8084
"""Attempt to detect the CPU on a computer running the Linux kernel."""
8185

8286
if self.detector.check_dt_compatible_value('qcom,apq8016'):
@@ -109,6 +113,7 @@ def _linux_id(self): # pylint: disable=too-many-branches
109113
linux_id = S922X
110114

111115
cpu_model = self.detector.get_cpuinfo_field("cpu model")
116+
112117
if cpu_model is not None:
113118
if "MIPS 24Kc" in cpu_model:
114119
linux_id = MIPS24KC
@@ -136,6 +141,10 @@ def _linux_id(self): # pylint: disable=too-many-branches
136141
linux_id = S922X
137142
elif 'SAMA5' in hardware:
138143
linux_id = SAMA5
144+
elif "Pinebook" in hardware:
145+
linux_id = A64
146+
elif "sun50iw1p1" in hardware:
147+
linux_id = A64
139148
else:
140149
if isinstance(hardware, str):
141150
if hardware in BCM_RANGE:

bin/detect.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
print("Is this a SiFive Unleashed? ", detector.board.SIFIVE_UNLEASHED)
2020
print("Is this an embedded Linux system?", detector.board.any_embedded_linux)
2121
print("Is this a generic Linux PC?", detector.board.GENERIC_LINUX_PC)
22-
print("Is this an OS environment variable special case?", detector.board.FTDI_FT232H |
23-
detector.board.MICROCHIP_MCP2221 )
22+
print("Is this an OS environment variable special case?", detector.board.FTDI_FT232H |
23+
detector.board.MICROCHIP_MCP2221)
2424

2525
if detector.board.any_raspberry_pi:
2626
print("Raspberry Pi detected.")
@@ -36,3 +36,6 @@
3636

3737
if detector.board.any_onion_omega_board:
3838
print("Onion Omega detected.")
39+
40+
if detector.board.any_pine64_board:
41+
print("Pine64 device detected.")

0 commit comments

Comments
 (0)