pypicoboot 1.1.4__py3-none-any.whl → 1.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
picoboot/_version.py CHANGED
@@ -17,4 +17,4 @@
17
17
  */
18
18
  """
19
19
 
20
- __version__ = "1.1.4"
20
+ __version__ = "1.2"
picoboot/core/enums.py CHANGED
@@ -24,6 +24,11 @@ class NamedIntEnum(enum.IntEnum):
24
24
  def __str__(self):
25
25
  return self.name
26
26
 
27
+ def __format__(self, fmt):
28
+ if any(c in fmt for c in "xXod"):
29
+ return format(self.value, fmt)
30
+ return self.name
31
+
27
32
  @classmethod
28
33
  def from_string(cls, value: Union[str, int]) -> "NamedIntEnum":
29
34
  if not value:
picoboot/core/log.py ADDED
@@ -0,0 +1,58 @@
1
+ """
2
+ /*
3
+ * This file is part of the pypicoboot distribution (https://github.com/polhenarejos/pypicoboot).
4
+ * Copyright (c) 2025 Pol Henarejos.
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU Affero General Public License as published by
8
+ * the Free Software Foundation, version 3.
9
+ *
10
+ * This program is distributed in the hope that it will be useful, but
11
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ * Affero General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Affero General Public License
16
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
17
+ */
18
+ """
19
+
20
+ import os
21
+ import logging
22
+
23
+ TRACE_LEVEL = 5
24
+ logging.addLevelName(TRACE_LEVEL, "TRACE")
25
+
26
+ def trace(self, message, *args, **kwargs):
27
+ if self.isEnabledFor(TRACE_LEVEL):
28
+ self._log(TRACE_LEVEL, message, args, **kwargs)
29
+
30
+ # Afegeix logger.trace()
31
+ logging.Logger.trace = trace
32
+
33
+ def get_logger(name: str):
34
+ env_level = os.getenv("PICOBOOT_LOG", "CRITICAL").upper()
35
+
36
+ valid_levels = {
37
+ "TRACE": TRACE_LEVEL,
38
+ "DEBUG": logging.DEBUG,
39
+ "INFO": logging.INFO,
40
+ "WARNING": logging.WARNING,
41
+ "ERROR": logging.ERROR,
42
+ "CRITICAL": logging.CRITICAL,
43
+ }
44
+
45
+ level = valid_levels.get(env_level, logging.CRITICAL)
46
+
47
+ logger = logging.getLogger(name)
48
+ logger.setLevel(level)
49
+
50
+ if not logger.handlers:
51
+ handler = logging.StreamHandler()
52
+ handler.setFormatter(logging.Formatter(
53
+ fmt="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
54
+ datefmt="%Y-%m-%d %H:%M:%S"
55
+ ))
56
+ logger.addHandler(handler)
57
+
58
+ return logger
picoboot/picoboot.py CHANGED
@@ -16,31 +16,6 @@
16
16
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17
17
  */
18
18
  """
19
- import os
20
- import logging
21
-
22
- def get_logger(name: str):
23
- env_level = os.getenv("PICOBOOT_LOG", "CRITICAL").upper()
24
-
25
- valid_levels = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]
26
- if env_level not in valid_levels:
27
- print(f"[logger] Warning: nivell '{env_level}' invàlid. Usant INFO.")
28
- env_level = "INFO"
29
-
30
- logger = logging.getLogger(name)
31
- logger.setLevel(env_level)
32
-
33
- if not logger.handlers:
34
- handler = logging.StreamHandler()
35
- handler.setFormatter(logging.Formatter(
36
- fmt="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
37
- datefmt="%Y-%m-%d %H:%M:%S"
38
- ))
39
- logger.addHandler(handler)
40
-
41
- return logger
42
-
43
- logger = get_logger("picoboot")
44
19
 
45
20
  from binascii import hexlify
46
21
  from typing import Optional
@@ -51,6 +26,9 @@ import itertools
51
26
  from .utils import uint_to_int
52
27
  from .core.enums import NamedIntEnum
53
28
  from .picobootmonitor import PicoBootMonitor, PicoBootMonitorObserver
29
+ from .core.log import get_logger
30
+
31
+ logger = get_logger("PicoBoot")
54
32
 
55
33
  # Valors per defecte segons el datasheet (es poden canviar via OTP) :contentReference[oaicite:4]{index=4}
56
34
  DEFAULT_VID = 0x2E8A
@@ -369,6 +347,7 @@ class PicoBoot:
369
347
  raise
370
348
  logger.debug(f"Sending command {cmd_id} (0x{cmd_id:02X}) with token {token} (0x{token:08X}) and transfer_length {transfer_length}")
371
349
 
350
+ logger.trace(f"Command header: {hexlify(header).decode()}")
372
351
  self.ep_out.write(header, timeout=timeout)
373
352
  logger.debug(f"Command header sent: {hexlify(header).decode()}")
374
353
 
@@ -386,6 +365,7 @@ class PicoBoot:
386
365
  chunks.append(chunk)
387
366
  remaining -= len(chunk)
388
367
  data_in = b"".join(chunks)
368
+ logger.trace(f"Received data_in: {hexlify(data_in).decode()}")
389
369
  if len(data_in) != transfer_length:
390
370
  logger.error(f"Expected {transfer_length} bytes, got {len(data_in)}")
391
371
  raise PicoBootError(f"Expected {transfer_length} bytes, got {len(data_in)}")
@@ -393,6 +373,7 @@ class PicoBoot:
393
373
  if data_out is None or len(data_out) < transfer_length:
394
374
  logger.error("data_out missing or too short for OUT command")
395
375
  raise ValueError("data_out missing or too short for OUT command")
376
+ logger.trace(f"Sending data_out: {hexlify(data_out[:transfer_length]).decode()}")
396
377
  self.ep_out.write(data_out[:transfer_length], timeout=timeout)
397
378
 
398
379
  try:
@@ -404,6 +385,7 @@ class PicoBoot:
404
385
  except usb.core.USBError:
405
386
  logger.error("No ACK received after command")
406
387
  raise PicoBootError("No ACK received after command")
388
+ logger.debug("ACK received.")
407
389
 
408
390
  return data_in
409
391
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pypicoboot
3
- Version: 1.1.4
3
+ Version: 1.2
4
4
  Summary: Pico Boot for Python
5
5
  Home-page: https://github.com/polhenarejos/pypicoboot
6
6
  Author: Pol Henarejos
@@ -0,0 +1,13 @@
1
+ picoboot/__init__.py,sha256=cQPxH_qPx7ph9SQ-Z4Jc2YCU3SKYnDta6wzU-Q65suc,72
2
+ picoboot/_version.py,sha256=j-dtPcfbhr1IMhFhudY5UZVclyBgMpxp0yoDa7RLwT4,776
3
+ picoboot/picoboot.py,sha256=uzmd9W9JLNXCMSk4U0NzCnMCNAc4xnQg7es1lEJeN9A,24831
4
+ picoboot/picobootmonitor.py,sha256=3msEP2S8ZS7P8QVgKpq9Z9Rcud78XygmG1_0L_OZOvs,2443
5
+ picoboot/utils.py,sha256=SjpAoPZrgyD9Ws7NIFVBHt0zPOb8Lpu2_lsmfeT2rXE,1083
6
+ picoboot/core/__init__.py,sha256=fmoYRI4KbzhLjXblEs_H9zgdCs7oDuSKeNEG_-kMgYo,32
7
+ picoboot/core/enums.py,sha256=ugXS-dbdnusLib_ge0vT1OugHVG9ZjJfpUR073MhwdQ,1353
8
+ picoboot/core/log.py,sha256=XWtN_hgmOtvpDMGDg-9f2BDLUe8elqUAbWti5yCJAA0,1768
9
+ picoboot/tools/picotool.py,sha256=e2xjIxP5UZn9yfjxUWkJXq6KQHyw4YsGbuQbTauo0-Q,94
10
+ pypicoboot-1.2.dist-info/METADATA,sha256=GgnGeLWZEcQDGmvC7stKpgCrMxdlbKXF4h1UxGamc30,41109
11
+ pypicoboot-1.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
12
+ pypicoboot-1.2.dist-info/top_level.txt,sha256=sjegZQO5-kQdFOXXJHm0P7Hg1Nw4Ri0WKHnRYDTsa4I,9
13
+ pypicoboot-1.2.dist-info/RECORD,,
@@ -1,12 +0,0 @@
1
- picoboot/__init__.py,sha256=cQPxH_qPx7ph9SQ-Z4Jc2YCU3SKYnDta6wzU-Q65suc,72
2
- picoboot/_version.py,sha256=txKmvspbYF-uZ89KC9P5WlSJ9yxzTJtHQoWDGcqbpfc,778
3
- picoboot/picoboot.py,sha256=1jmeh8XWI1P3rGqDAsGRUdNcI7DkEVeXov1Siz6Wn74,25206
4
- picoboot/picobootmonitor.py,sha256=3msEP2S8ZS7P8QVgKpq9Z9Rcud78XygmG1_0L_OZOvs,2443
5
- picoboot/utils.py,sha256=SjpAoPZrgyD9Ws7NIFVBHt0zPOb8Lpu2_lsmfeT2rXE,1083
6
- picoboot/core/__init__.py,sha256=fmoYRI4KbzhLjXblEs_H9zgdCs7oDuSKeNEG_-kMgYo,32
7
- picoboot/core/enums.py,sha256=YQnCtiX3XwG5RtAIhTmD37DMZMEGmcPIaTiwsW3ckxw,1211
8
- picoboot/tools/picotool.py,sha256=e2xjIxP5UZn9yfjxUWkJXq6KQHyw4YsGbuQbTauo0-Q,94
9
- pypicoboot-1.1.4.dist-info/METADATA,sha256=zRIdNOpvKdzMObg200_OMOZlByW1ZdvCGqNwkMiTtQw,41111
10
- pypicoboot-1.1.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
- pypicoboot-1.1.4.dist-info/top_level.txt,sha256=sjegZQO5-kQdFOXXJHm0P7Hg1Nw4Ri0WKHnRYDTsa4I,9
12
- pypicoboot-1.1.4.dist-info/RECORD,,