Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add CC2 support #11

Merged
merged 2 commits into from
Mar 29, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 41 additions & 4 deletions charachorder/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@

pid_mapping = {}
vid_mapping = {
0x239A: ("Adafruit", "M0"),
0x303A: ("Espressif", "S2"),
0x239A: "Adafruit",
0x303A: "Espressif",
}


Expand Down Expand Up @@ -84,7 +84,6 @@ class CharaChorder(Device):

bootloader_mode: bool
connection: Serial
chipset: Literal["M0", "S2"]
vendor: Literal["Adafruit", "Espressif"]

def __init__(self, product_id: int, vendor_id: int, port: str):
Expand All @@ -97,7 +96,7 @@ def __init__(self, product_id: int, vendor_id: int, port: str):
raise UnknownProduct(product_id)

if vendor_id in vid_mapping:
self.vendor, self.chipset = vid_mapping[vendor_id]
self.vendor = vid_mapping[vendor_id]
else:
raise UnknownVendor(vendor_id)

Expand Down Expand Up @@ -688,6 +687,35 @@ class CharaChorderOne(CharaChorder):
connected to the system.
"""

chipset: Literal["M0"]

def __init__(self, product_id: int, vendor_id: int, port: str):
super().__init__(product_id, vendor_id, port)
self.chipset = "M0"


@allowed_product_ids(
0x8253, # S3
0x8254, # S3 - UF2 Bootloader
)
class CharaChorderTwo(CharaChorder):
"""
Represents a CharaChorderOne device.

This class inherits from `charachorder.CharaChorder`.

Normally, you wouldn't instantiate this class directly instead use
`CharaChorderTwo.list_devices()` to get a list of CharaChorderTwo devices
connected to the system.
"""

chipset: Literal["S3"]

def __init__(self, product_id: int, vendor_id: int, port: str):
super().__init__(product_id, vendor_id, port)
self.bootloader_mode = self.product_id == 0x8254
self.chipset = "S3"


@allowed_product_ids(
0x801C, # M0
Expand All @@ -705,9 +733,12 @@ class CharaChorderLite(CharaChorder):
connected to the system.
"""

chipset: Literal["M0", "S2"]

def __init__(self, product_id: int, vendor_id: int, port: str):
super().__init__(product_id, vendor_id, port)
self.bootloader_mode = self.product_id == 0x812F
self.chipset = "M0" if self.product_id == 0x801C else "S2"

def is_gui_ctrl_swapped(self) -> bool:
return bool(self.get_parameter(0x13))
Expand Down Expand Up @@ -766,9 +797,12 @@ class CharaChorderX(CharaChorder):
connected to the system.
"""

chipset: Literal["S2"]

def __init__(self, product_id: int, vendor_id: int, port: str):
super().__init__(product_id, vendor_id, port)
self.bootloader_mode = self.product_id in (0x818C, 0x818E)
self.chipset = "S2"


@allowed_product_ids(
Expand All @@ -789,6 +823,9 @@ class CharaChorderEngine(CharaChorder):
devices connected to the system.
"""

chipset: Literal["S2"]

def __init__(self, product_id: int, vendor_id: int, port: str):
super().__init__(product_id, vendor_id, port)
self.bootloader_mode = self.product_id == 0x818A
self.chipset = "S2"