Skip to content

Commit

Permalink
pykitinfo 1.1.2.19 release on PyPI
Browse files Browse the repository at this point in the history
  • Loading branch information
Microchip Technology committed Apr 5, 2024
1 parent 97e0c4b commit 2832d4d
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [1.1.2] - April 2024

### Added
- DSG-7105 added support for Explorer 16/32 kit
- DSG-7181 added support for MCP2221A kits

## [1.0.3] - January 2024

### Added
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pykitinfo currently supports:
- Atmel-ICE, Power Debugger, JTAGICE3
- PICkit3, PKOB
- PICkit4, Snap, PKOB4, PICkit5
- MCP2221A

## Usage
pykitinfo can be used as a library or as a CLI
Expand All @@ -38,13 +39,15 @@ For example:
```bash
pykitinfo
Looking for Microchip kits...
Compatible kits detected: 6
Compatible kits detected: 8
Kit MCHP3349011800000000: 'AVR-IoT WA' (ATmega4808) on COM21
Kit MCHP3280021800000000: 'AVR128DA48 Curiosity Nano' (AVR128DA48) on COM17
Kit ATML2241020200000000: 'SAM L21 Xplained Pro' (ATSAML21J18A) on COM34
Kit J41800000000: 'Atmel-ICE CMSIS-DAP' () on N/A
Kit J50200000000: 'Power Debugger CMSIS-DAP' () on N/A
Kit ATML2323040200000000: 'mEDBG' (ATmega328P) on COM26
Kit BUR180115004: 'Explorer 16/32 PICkit on Board' () on N/A
Kit 020063002RYN000091: 'Curiosity Nano Explorer' (N/A) on COM74
```

#### CLI example - simple list of connected kits with specific serial number
Expand Down
1 change: 1 addition & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ <h2>Python Kit Information<a class="headerlink" href="#python-kit-information" t
<li><p>Atmel-ICE, Power Debugger, JTAGICE3</p></li>
<li><p>PICkit3, PKOB</p></li>
<li><p>PICkit4, Snap, PKOB4, PICkit5</p></li>
<li><p>MCP2221A</p></li>
</ul>
</dd>
</dl>
Expand Down
1 change: 1 addition & 0 deletions docs/pykitinfo.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ <h3>Python Kit Information<a class="headerlink" href="#python-kit-information" t
<li><p>Atmel-ICE, Power Debugger, JTAGICE3</p></li>
<li><p>PICkit3, PKOB</p></li>
<li><p>PICkit4, Snap, PKOB4, PICkit5</p></li>
<li><p>MCP2221A</p></li>
</ul>
</dd>
</dl>
Expand Down
2 changes: 1 addition & 1 deletion docs/searchindex.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions pykitinfo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* Atmel-ICE, Power Debugger, JTAGICE3
* PICkit3, PKOB
* PICkit4, Snap, PKOB4, PICkit5
* MCP2221A
CLI usage example
~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -44,10 +45,10 @@

# Build number part of version will be replaced by build number from Jenkins.
# For local builds the build number is 0 and the 'snapshot' is added as Local Version Identifier
__version__ = "1.0.3.15"
__version__ = "1.1.2.19"

# The GIT commit ID and build date are generated by Jenkins when building the package
COMMIT_ID = '71880defe9ffe393e7e97f160b11154268ece1df'
BUILD_DATE = '2024-01-23 08:01:30'
COMMIT_ID = '5d9404b535b655a65ff0f863591e9c76f5cf5cf7'
BUILD_DATE = '2024-03-22 09:44:32'

logging.getLogger(__name__).addHandler(logging.NullHandler())
2 changes: 1 addition & 1 deletion pykitinfo/detect_legacy_pickit3_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def detect_pickit3s(serialnumber=None):
"""
logger = getLogger(__name__)
logger.debug("Looking for PKoB/PICkit 3 kits")
PICKIT3_PRODUCT_NAMES = ["PICkit 3", "Curiosity"]
PICKIT3_PRODUCT_NAMES = ["PICkit 3", "Curiosity", "Explorer 16/32 PICkit on Board"]
pickit_list = []
devices = hid.enumerate(MICROCHIP_VID)
for candidate in devices:
Expand Down
96 changes: 96 additions & 0 deletions pykitinfo/detect_mcp2221a_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
from logging import getLogger
from .tools import MICROCHIP_VID
import hid
import serial.tools.list_ports

MCP2221A_PID = 0x00DD

def detect_mcp2221a_kits(serial_number=None):
"""
Look for all compatible MCP2221A kits
:param serial_number: (partial) serial number to use
:type serial_number: str
:return: List of detected tools
:rtype: list
"""

logger = getLogger(__name__)
logger.debug("Looking for MCP2221A kits")

devices = hid.enumerate(MICROCHIP_VID, MCP2221A_PID)
port_map = map_mcp2221a_to_serial_port(devices)
kits = []

for device in devices:
if serial_number and device['serial_number'] and not device['serial_number'].endswith(serial_number):
continue

mapped_port = list(filter(lambda dev: dev['tool'] == device, port_map))

usb_info = {
"interface": "hid",
"packet_size": 0,
"product_id": device['product_id'],
"product_string": device['product_string'],
"serial_number": device['serial_number'],
"vendor_id": device['vendor_id']
}

debugger = {
'device': 'N/A',
'serial_number': device['serial_number'],
'protocol': 'N/A',
# Use product name as kit name
'kitname' : device['product_string'],
'serial_port': 'N/A' if len(mapped_port) == 0 else mapped_port[0]['port'],
}

kit = {
'usb': usb_info,
'debugger': debugger
}

kits.append(kit)

return kits

def map_mcp2221a_to_serial_port(devices):
"""Map MCP2221A devices to serial ports
:param devices: List of MCP2221A devices
:type devices: list(dict)
:return: List containing mapped serial ports to devices
:rtype: list(dict)
"""

logger = getLogger(__name__)

portmap = []
available_comports = serial.tools.list_ports.comports()

usbports = set([p for p in available_comports if "USB" in p.hwid and MICROCHIP_VID == p.vid and p.pid == MCP2221A_PID])
used_comports = set()
devices_missing_serial_number = []

for dev in devices:
if not dev['serial_number'] or dev['serial_number'] == "":
devices_missing_serial_number.append(dev)
else:
remaining_comports = usbports.symmetric_difference(used_comports)

for port in remaining_comports:
if dev['serial_number'] == port.serial_number:
portmap.append({"tool": dev, "port": port.device})
used_comports.add(port)
break

# Now we should have left only the devices and ports from MCP2221A devices that don't have serial number
# Here we can only map a single device

if len(devices_missing_serial_number) > 1:
logger.debug("Too many MCP2221 devices without serial number connected. Cannot map these to serial ports")
elif len(devices_missing_serial_number) > 0 and len(usbports) > 0:
portmap.append({"tool": devices_missing_serial_number[0], "port": list(usbports)[0].device})

return portmap
3 changes: 3 additions & 0 deletions pykitinfo/pykitinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .detect_microchip_tools import detect_microchip_tools
from .detect_edbg_tools import detect_edbg_kits
from .detect_legacy_pickit3_tools import detect_pickit3s
from .detect_mcp2221a_tools import detect_mcp2221a_kits

STATUS_SUCCESS = 0
STATUS_FAILURE = 1
Expand Down Expand Up @@ -62,4 +63,6 @@ def detect_all_kits(serialnumber=None):
kit_list += detect_edbg_kits(serialnumber)
kit_list += detect_pickit3s(serialnumber)
kit_list += detect_microchip_tools(serialnumber)
kit_list += detect_mcp2221a_kits(serialnumber)

return kit_list
5 changes: 4 additions & 1 deletion pypi.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pykitinfo currently supports:
* Atmel-ICE, Power Debugger, JTAGICE3
* PICkit3, PKOB
* PICkit4, Snap, PKOB4, PICkit5
* MCP2221A

## Usage
pykitinfo can be used as a library or as a CLI
Expand All @@ -30,13 +31,15 @@ For example:
```bash
pykitinfo
Looking for Microchip kits...
Compatible kits detected: 6
Compatible kits detected: 8
Kit MCHP3349011800000000: 'AVR-IoT WA' (ATmega4808) on COM21
Kit MCHP3280021800000000: 'AVR128DA48 Curiosity Nano' (AVR128DA48) on COM17
Kit ATML2241020200000000: 'SAM L21 Xplained Pro' (ATSAML21J18A) on COM34
Kit J41800000000: 'Atmel-ICE CMSIS-DAP' () on N/A
Kit J50200000000: 'Power Debugger CMSIS-DAP' () on N/A
Kit ATML2323040200000000: 'mEDBG' (ATmega328P) on COM26
Kit BUR180115004: 'Explorer 16/32 PICkit on Board' () on N/A
Kit 020063002RYN000091: 'Curiosity Nano Explorer' (N/A) on COM74
```

## Example - simple list of connected kits with specific serial number
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ authors = [
]
description = "A provider of information about connected Microchip development kits"
license = {text = "MIT"}
keywords = ["Microchip", "Xplained Pro", "EDBG", "nEDBG", "Curiosity Nano", "PKOB nano", "debugger"]
keywords = ["Microchip", "Xplained Pro", "EDBG", "nEDBG", "Curiosity Nano", "PKOB nano", "debugger", "MCP2221A"]
requires-python = ">=3.8"
classifiers = [
"Development Status :: 5 - Production/Stable",
Expand Down

0 comments on commit 2832d4d

Please sign in to comment.