From fc022452f588e50697939f3c2dce15b312391dc4 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Tue, 7 Nov 2023 00:26:51 -0600 Subject: [PATCH] replace most references to pico with RP2040 --- gp2040ce_bintools/builder.py | 4 +- gp2040ce_bintools/gui.py | 4 +- gp2040ce_bintools/{pico.py => rp2040.py} | 24 ++++----- gp2040ce_bintools/storage.py | 4 +- tests/{test_pico.py => test_rp2040.py} | 64 ++++++++++++------------ 5 files changed, 50 insertions(+), 50 deletions(-) rename gp2040ce_bintools/{pico.py => rp2040.py} (91%) rename tests/{test_pico.py => test_rp2040.py} (82%) diff --git a/gp2040ce_bintools/builder.py b/gp2040ce_bintools/builder.py index 69db8e1..5342062 100644 --- a/gp2040ce_bintools/builder.py +++ b/gp2040ce_bintools/builder.py @@ -6,7 +6,7 @@ import logging from google.protobuf.message import Message from gp2040ce_bintools import core_parser -from gp2040ce_bintools.pico import get_bootsel_endpoints, read, write +from gp2040ce_bintools.rp2040 import get_bootsel_endpoints, read, write from gp2040ce_bintools.storage import (STORAGE_BINARY_LOCATION, STORAGE_MEMORY_ADDRESS, STORAGE_SIZE, pad_config_to_storage_size, serialize_config_with_footer) @@ -149,7 +149,7 @@ def write_new_config_to_usb(config: Message, endpoint_out: object, endpoint_in: """Serialize the provided config to a device over USB, in the proper location for a GP2040-CE board. Args: - config: the Protobuf configuration to write to a Pico board in BOOTSEL mode + config: the Protobuf configuration to write to a RP2040 board in BOOTSEL mode endpoint_out: the USB endpoint to write to endpoint_in: the USB endpoint to read from """ diff --git a/gp2040ce_bintools/gui.py b/gp2040ce_bintools/gui.py index b37104a..816c3a7 100644 --- a/gp2040ce_bintools/gui.py +++ b/gp2040ce_bintools/gui.py @@ -17,7 +17,7 @@ from textual.widgets.tree import TreeNode from gp2040ce_bintools import core_parser, handler from gp2040ce_bintools.builder import write_new_config_to_filename, write_new_config_to_usb -from gp2040ce_bintools.pico import get_bootsel_endpoints, read +from gp2040ce_bintools.rp2040 import get_bootsel_endpoints, read from gp2040ce_bintools.storage import (STORAGE_MEMORY_ADDRESS, STORAGE_SIZE, ConfigReadError, get_config, get_config_from_file, get_new_config) @@ -390,7 +390,7 @@ def edit_config(): parser.add_argument('--new-if-not-found', action='store_true', default=True, help="if the file/USB device doesn't have a config section, start a new one (default: enabled)") group = parser.add_mutually_exclusive_group(required=True) - group.add_argument('--usb', action='store_true', help="retrieve the config from a Pico board connected over USB " + group.add_argument('--usb', action='store_true', help="retrieve the config from a RP2040 board connected over USB " "and in BOOTSEL mode") group.add_argument('--filename', help=".bin file of a GP2040-CE board's config + footer or entire storage section, " "or of a GP2040-CE's whole board dump if --whole-board is specified") diff --git a/gp2040ce_bintools/pico.py b/gp2040ce_bintools/rp2040.py similarity index 91% rename from gp2040ce_bintools/pico.py rename to gp2040ce_bintools/rp2040.py index f6a08c7..dd30169 100644 --- a/gp2040ce_bintools/pico.py +++ b/gp2040ce_bintools/rp2040.py @@ -1,4 +1,4 @@ -"""Methods to interact with the Raspberry Pi Pico directly. +"""Methods to interact with the Raspberry Pi RP2040 directly. Much of this code is a partial Python implementation of picotool. """ @@ -37,12 +37,12 @@ PICO_COMMANDS = { ################# -class PicoAlignmentError(ValueError): +class RP2040AlignmentError(ValueError): """Exception raised when the address provided for an operation is invalid.""" def get_bootsel_endpoints() -> tuple[usb.core.Endpoint, usb.core.Endpoint]: - """Retrieve the USB endpoint for purposes of interacting with a Pico in BOOTSEL mode. + """Retrieve the USB endpoint for purposes of interacting with a RP2040 in BOOTSEL mode. Returns: the out and in endpoints for the BOOTSEL interface @@ -51,7 +51,7 @@ def get_bootsel_endpoints() -> tuple[usb.core.Endpoint, usb.core.Endpoint]: pico_device = usb.core.find(idVendor=PICO_VENDOR, idProduct=PICO_PRODUCT) if not pico_device: - raise ValueError("Pico board in BOOTSEL mode could not be found!") + raise ValueError("RP2040 board in BOOTSEL mode could not be found!") if pico_device.is_kernel_driver_active(0): pico_device.detach_kernel_driver(0) @@ -71,7 +71,7 @@ def get_bootsel_endpoints() -> tuple[usb.core.Endpoint, usb.core.Endpoint]: def exclusive_access(out_end: usb.core.Endpoint, in_end: usb.core.Endpoint, is_exclusive: bool = True) -> None: - """Enable exclusive access mode on a Pico in BOOTSEL. + """Enable exclusive access mode on a RP2040 in BOOTSEL. Args: out_endpoint: the out direction USB endpoint to write to @@ -91,7 +91,7 @@ def exclusive_access(out_end: usb.core.Endpoint, in_end: usb.core.Endpoint, is_e def erase(out_end: usb.core.Endpoint, in_end: usb.core.Endpoint, location: int, size: int) -> None: - """Erase a section of flash memory on a Pico in BOOTSEL mode. + """Erase a section of flash memory on a RP2040 in BOOTSEL mode. Args: out_endpoint: the out direction USB endpoint to write to @@ -113,7 +113,7 @@ def erase(out_end: usb.core.Endpoint, in_end: usb.core.Endpoint, location: int, def exit_xip(out_end: usb.core.Endpoint, in_end: usb.core.Endpoint) -> None: - """Exit XIP on a Pico in BOOTSEL. + """Exit XIP on a RP2040 in BOOTSEL. Args: out_endpoint: the out direction USB endpoint to write to @@ -131,7 +131,7 @@ def exit_xip(out_end: usb.core.Endpoint, in_end: usb.core.Endpoint) -> None: def read(out_end: usb.core.Endpoint, in_end: usb.core.Endpoint, location: int, size: int) -> bytearray: - """Read a requested number of bytes from a Pico in BOOTSEL, starting from the specified location. + """Read a requested number of bytes from a RP2040 in BOOTSEL, starting from the specified location. This also prepares the USB device for reading, so it expects to be able to grab exclusive access. @@ -172,7 +172,7 @@ def read(out_end: usb.core.Endpoint, in_end: usb.core.Endpoint, location: int, s def reboot(out_end: usb.core.Endpoint) -> None: - """Reboot a Pico in BOOTSEL mode.""" + """Reboot a RP2040 in BOOTSEL mode.""" # set up the data pico_token = 1 command_size = 12 @@ -187,7 +187,7 @@ def reboot(out_end: usb.core.Endpoint) -> None: def write(out_end: usb.core.Endpoint, in_end: usb.core.Endpoint, location: int, content: bytes) -> None: - """Write content to a Pico in BOOTSEL, starting from the specified location. + """Write content to a RP2040 in BOOTSEL, starting from the specified location. This also prepares the USB device for writing, so it expects to be able to grab exclusive access. @@ -203,8 +203,8 @@ def write(out_end: usb.core.Endpoint, in_end: usb.core.Endpoint, location: int, write_size = 0 if (location % chunk_size) != 0: - raise PicoAlignmentError(f"writes must start at {chunk_size} byte boundaries, " - f"please pad or align as appropriate!") + raise RP2040AlignmentError(f"writes must start at {chunk_size} byte boundaries, " + f"please pad or align as appropriate!") # set up the data command_size = 8 diff --git a/gp2040ce_bintools/storage.py b/gp2040ce_bintools/storage.py index a0e8604..e33ef7a 100644 --- a/gp2040ce_bintools/storage.py +++ b/gp2040ce_bintools/storage.py @@ -7,7 +7,7 @@ from google.protobuf.json_format import MessageToJson from google.protobuf.message import Message from gp2040ce_bintools import core_parser, get_config_pb2 -from gp2040ce_bintools.pico import get_bootsel_endpoints, read +from gp2040ce_bintools.rp2040 import get_bootsel_endpoints, read logger = logging.getLogger(__name__) @@ -229,7 +229,7 @@ def visualize(): parser.add_argument('--whole-board', action='store_true', help="indicate the binary file is a whole board dump") parser.add_argument('--json', action='store_true', help="print the config out as a JSON document") group = parser.add_mutually_exclusive_group(required=True) - group.add_argument('--usb', action='store_true', help="retrieve the config from a Pico board connected over USB " + group.add_argument('--usb', action='store_true', help="retrieve the config from a RP2040 board connected over USB " "and in BOOTSEL mode") group.add_argument('--filename', help=".bin file of a GP2040-CE board's storage section, bytes " "101FC000-10200000, or of a GP2040-CE's whole board dump " diff --git a/tests/test_pico.py b/tests/test_rp2040.py similarity index 82% rename from tests/test_pico.py rename to tests/test_rp2040.py index fe470a6..d2853e4 100644 --- a/tests/test_pico.py +++ b/tests/test_rp2040.py @@ -8,7 +8,7 @@ from array import array import pytest from decorator import decorator -import gp2040ce_bintools.pico as pico +import gp2040ce_bintools.rp2040 as rp2040 HERE = os.path.dirname(os.path.abspath(__file__)) @@ -34,9 +34,9 @@ def test_get_bootsel_endpoints(): mock_interface = mock.MagicMock(name='mock_interface') with mock.patch('usb.core.find', return_value=mock_device) as mock_find: with mock.patch('usb.util.find_descriptor', return_value=mock_interface) as mock_find_descriptor: - _, _ = pico.get_bootsel_endpoints() + _, _ = rp2040.get_bootsel_endpoints() - mock_find.assert_called_with(idVendor=pico.PICO_VENDOR, idProduct=pico.PICO_PRODUCT) + mock_find.assert_called_with(idVendor=rp2040.PICO_VENDOR, idProduct=rp2040.PICO_PRODUCT) mock_device.is_kernel_driver_active.assert_called_with(0) mock_device.detach_kernel_driver.assert_not_called() mock_device.get_active_configuration.assert_called_once() @@ -54,9 +54,9 @@ def test_get_bootsel_endpoints_with_kernel_disconnect(): mock_interface = mock.MagicMock(name='mock_interface') with mock.patch('usb.core.find', return_value=mock_device) as mock_find: with mock.patch('usb.util.find_descriptor', return_value=mock_interface) as mock_find_descriptor: - _, _ = pico.get_bootsel_endpoints() + _, _ = rp2040.get_bootsel_endpoints() - mock_find.assert_called_with(idVendor=pico.PICO_VENDOR, idProduct=pico.PICO_PRODUCT) + mock_find.assert_called_with(idVendor=rp2040.PICO_VENDOR, idProduct=rp2040.PICO_PRODUCT) mock_device.is_kernel_driver_active.assert_called_with(0) mock_device.detach_kernel_driver.assert_called_with(0) mock_device.get_active_configuration.assert_called_once() @@ -68,7 +68,7 @@ def test_get_bootsel_endpoints_with_kernel_disconnect(): def test_exclusive_access(): """Test that we can get exclusive access to a BOOTSEL board.""" end_out, end_in = mock.MagicMock(), mock.MagicMock() - pico.exclusive_access(end_out, end_in) + rp2040.exclusive_access(end_out, end_in) payload = struct.pack('