forked from adafruit/Adafruit_Blinka
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboard.py
More file actions
84 lines (64 loc) · 2.74 KB
/
Copy pathboard.py
File metadata and controls
84 lines (64 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""
`board` - Define ids for available pins
=================================================
See `CircuitPython:board` in CircuitPython for more details.
* Author(s): cefn, Melissa LeBlanc-Williams
"""
__version__ = "0.0.0+auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_Blinka.git"
__blinka__ = True
import sys
import json
import adafruit_platformdetect.constants.boards as ap_board
from adafruit_blinka.agnostic import board_id, detector
from adafruit_blinka.importing import import_mod, get_import_file
# pylint: disable=wildcard-import,unused-wildcard-import,ungrouped-imports
# pylint: disable=import-outside-toplevel
SCL = SDA = SCLK = MOSI = MISO = None
# Start with micropython boards as importlib isn't available on those chips:
# Go through the board_list and import the first one that matches
# if the key start with any_ then use detector.board.any_...
with open(get_import_file("board_imports.json", __file__)) as f:
board_imports = json.load(f)
for board_key, board_module in board_imports.items():
if board_key.startswith("any_"):
if getattr(detector.board, board_key):
import_mod(globals(), board_module)
break
else:
if board_id == getattr(ap_board, board_key):
import_mod(globals(), board_module)
break
else:
if "sphinx" in sys.modules:
pass
elif board_id is None:
import platform
from importlib.metadata import version
package_version = version("adafruit_platformdetect")
raise NotImplementedError(
f"""
adafruit-platformdetect version {package_version} was unable to identify the board
and/or microcontroller running the {platform.system()} platform.
Please be sure you have the latest packages by running:
'pip3 install --upgrade adafruit-blinka adafruit-platformdetect'
If you are running the latest package, your board may not yet be supported. Please
open a New Issue on GitHub at https://github.com/adafruit/Adafruit_Blinka/issues and
select New Board Request.
"""
)
else:
raise NotImplementedError(f"Board not supported {board_id}.")
if SCL is not None and SDA is not None:
def I2C():
"""The singleton I2C interface"""
import busio
return busio.I2C(SCL, SDA)
if SCLK is not None and MOSI is not None and MISO is not None:
def SPI():
"""The singleton SPI interface"""
import busio
return busio.SPI(SCLK, MOSI, MISO)