Skip to content

Commit c32a24d

Browse files
authored
feat: CC2 support
This involves some restructuring as the chipset is not a one-to-one mapping with the vendor ids anymore.
1 parent c11ca09 commit c32a24d

File tree

1 file changed

+41
-4
lines changed

1 file changed

+41
-4
lines changed

charachorder/device.py

+41-4
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828

2929
pid_mapping = {}
3030
vid_mapping = {
31-
0x239A: ("Adafruit", "M0"),
32-
0x303A: ("Espressif", "S2"),
31+
0x239A: "Adafruit",
32+
0x303A: "Espressif",
3333
}
3434

3535

@@ -84,7 +84,6 @@ class CharaChorder(Device):
8484

8585
bootloader_mode: bool
8686
connection: Serial
87-
chipset: Literal["M0", "S2"]
8887
vendor: Literal["Adafruit", "Espressif"]
8988

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

9998
if vendor_id in vid_mapping:
100-
self.vendor, self.chipset = vid_mapping[vendor_id]
99+
self.vendor = vid_mapping[vendor_id]
101100
else:
102101
raise UnknownVendor(vendor_id)
103102

@@ -688,6 +687,35 @@ class CharaChorderOne(CharaChorder):
688687
connected to the system.
689688
"""
690689

690+
chipset: Literal["M0"]
691+
692+
def __init__(self, product_id: int, vendor_id: int, port: str):
693+
super().__init__(product_id, vendor_id, port)
694+
self.chipset = "M0"
695+
696+
697+
@allowed_product_ids(
698+
0x8253, # S3
699+
0x8254, # S3 - UF2 Bootloader
700+
)
701+
class CharaChorderTwo(CharaChorder):
702+
"""
703+
Represents a CharaChorderOne device.
704+
705+
This class inherits from `charachorder.CharaChorder`.
706+
707+
Normally, you wouldn't instantiate this class directly instead use
708+
`CharaChorderTwo.list_devices()` to get a list of CharaChorderTwo devices
709+
connected to the system.
710+
"""
711+
712+
chipset: Literal["S3"]
713+
714+
def __init__(self, product_id: int, vendor_id: int, port: str):
715+
super().__init__(product_id, vendor_id, port)
716+
self.bootloader_mode = self.product_id == 0x8254
717+
self.chipset = "S3"
718+
691719

692720
@allowed_product_ids(
693721
0x801C, # M0
@@ -705,9 +733,12 @@ class CharaChorderLite(CharaChorder):
705733
connected to the system.
706734
"""
707735

736+
chipset: Literal["M0", "S2"]
737+
708738
def __init__(self, product_id: int, vendor_id: int, port: str):
709739
super().__init__(product_id, vendor_id, port)
710740
self.bootloader_mode = self.product_id == 0x812F
741+
self.chipset = "M0" if self.product_id == 0x801C else "S2"
711742

712743
def is_gui_ctrl_swapped(self) -> bool:
713744
return bool(self.get_parameter(0x13))
@@ -766,9 +797,12 @@ class CharaChorderX(CharaChorder):
766797
connected to the system.
767798
"""
768799

800+
chipset: Literal["S2"]
801+
769802
def __init__(self, product_id: int, vendor_id: int, port: str):
770803
super().__init__(product_id, vendor_id, port)
771804
self.bootloader_mode = self.product_id in (0x818C, 0x818E)
805+
self.chipset = "S2"
772806

773807

774808
@allowed_product_ids(
@@ -789,6 +823,9 @@ class CharaChorderEngine(CharaChorder):
789823
devices connected to the system.
790824
"""
791825

826+
chipset: Literal["S2"]
827+
792828
def __init__(self, product_id: int, vendor_id: int, port: str):
793829
super().__init__(product_id, vendor_id, port)
794830
self.bootloader_mode = self.product_id == 0x818A
831+
self.chipset = "S2"

0 commit comments

Comments
 (0)