Skip to content

Commit 035b5bd

Browse files
authored
Merge pull request #217 from RaspberryPiFoundation/changes-for-open-firmware
Changes for open source / custom firmware
2 parents 78c0c69 + 6a763de commit 035b5bd

File tree

8 files changed

+56
-7
lines changed

8 files changed

+56
-7
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[flake8]
22
docstring_style=sphinx
33
max-line-length = 127
4-
ignore = D400, Q000, S311, PLW, PLC, PLR
4+
ignore = D400, Q000, S311, W503, PLW, PLC, PLR
55
per-file-ignores =
66
buildhat/__init__.py:F401
77
exclude = docs/conf.py, docs/sphinxcontrib/cmtinc-buildhat.py, docs/sphinx_selective_exclude/*.py

buildhat/data/firmware.bin

-2.84 KB
Binary file not shown.

buildhat/data/signature.bin

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Q#�E]��]-.T~�駶�e[yE�V}A5�L��}���A�$I!�u�9Nzw`��l�@eK��;�{E
1+
��N�.2�wSm�Q/I�Ӎm�)io\�~��I�Az4�ĘɅ�P��w�>\w��L�V

buildhat/data/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1674818421
1+
1737564117

buildhat/devices.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,15 @@ def __init__(self, port):
7272
def _setup(**kwargs):
7373
if Device._instance:
7474
return
75-
data = os.path.join(os.path.dirname(sys.modules["buildhat"].__file__), "data/")
75+
if (
76+
os.path.isdir(os.path.join(os.getcwd(), "data/"))
77+
and os.path.isfile(os.path.join(os.getcwd(), "data", "firmware.bin"))
78+
and os.path.isfile(os.path.join(os.getcwd(), "data", "signature.bin"))
79+
and os.path.isfile(os.path.join(os.getcwd(), "data", "version"))
80+
):
81+
data = os.path.join(os.getcwd(), "data/")
82+
else:
83+
data = os.path.join(os.path.dirname(sys.modules["buildhat"].__file__), "data/")
7684
firm = os.path.join(data, "firmware.bin")
7785
sig = os.path.join(data, "signature.bin")
7886
ver = os.path.join(data, "version")

buildhat/serinterface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ def loop(self, cond, uselist, q, listevt):
378378
def runit():
379379
with cond:
380380
cond.notify()
381-
t = Timer(8.0, runit)
381+
t = Timer(11.0, runit)
382382
t.start()
383383

384384
if line[0] == "P" and (line[2] == "C" or line[2] == "M"):

docs/buildhat/index.rst

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,51 @@ power supply. For best results, use the `official Raspberry Pi Build HAT power s
2828

2929
.. _official Raspberry Pi Build HAT power supply: http://raspberrypi.com/products/build-hat-power-supply
3030

31+
It is now possible to use custom firmware with the library. To do this you can follow the steps below.
32+
33+
.. code-block::
34+
:caption: Using custom firmware
35+
36+
sudo apt install cmake python3 build-essential gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib
37+
38+
git clone https://github.com/raspberrypi/pico-sdk.git --recursive
39+
git clone https://github.com/raspberrypi/buildhat.git --recursive
40+
41+
cd buildhat
42+
export PICO_SDK_PATH="$(pwd)/../pico-sdk/"
43+
make
44+
45+
cd ..
46+
mkdir test
47+
cd test
48+
mkdir data
49+
50+
cp ../buildhat/firmware-pico/build/main.bin data/firmware.bin
51+
cp ../buildhat/bhbl-pico/signature.bin data/signature.bin
52+
cat ../buildhat/firmware-pico/version.h | sed 's/#define FWVERSION "//g; s/ .*//g' > data/version
53+
54+
Then place your script, such as the following, within the test/ directory.
55+
56+
.. code-block::
57+
:caption: Create test.py in test directory
58+
59+
import time
60+
from buildhat import Motor
61+
62+
m = Motor('A')
63+
m.start()
64+
65+
time.sleep(5)
66+
67+
Then use: ``python test.py`` in the test directory, to run your script with your custom firmware.
68+
69+
Note if you want python to always reload the firmware from your **data/** directory each time
70+
you run your script, simply write the value: -1 to **data/version**.
71+
3172
.. warning::
3273

3374
The API for the Build HAT is undergoing active development and is subject
34-
to change.
75+
to change.
3576

3677
.. toctree::
3778
:maxdepth: 2

test/color.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def test_caching(self):
3434
"""Test to make sure we're not reading cached data"""
3535
color = ColorSensor('A')
3636
color.avg_reads = 1
37-
color.interval = 1
37+
color.interval = 10
3838

3939
for _ in range(100):
4040
color.mode(2)

0 commit comments

Comments
 (0)