Skip to content

Conversation

@runger1101001
Copy link

@runger1101001 runger1101001 commented Dec 1, 2024

Support the dual channel devices. This is still a WIP.

This PR is to discuss the necessary changes to the scb_context, which are quite extensive.

Discussion on this topic also in PR #2

pass # TODO verbose output
else:
match(type):
case CyType.UART_CDC: # TODO we could have two of these!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to handle this case a little bit better in this function. I think what would make sense would be to add two DiscoveredDevice entries to the output when we see a dual channel device. Either that, or make DiscoveredDevice able to hold two different channels from one device.

@multiplemonomials
Copy link

I tried running cy_serial_cli scan with your branch, and I got:

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /home/jamie/Mbed/cy_serial_bridge/src/cy_serial_bridge/cli.py:331 in scan                        │
│                                                                                                  │
│   328 │   Scan for candidate USB devices on the system                                           │
│   329 │   """                                                                                    │
│   330 │   scan_filter = None if scan_all else {(global_opt.vid, global_opt.pid)}                 │
│ ❱ 331 │   devices = context.list_devices(scan_filter)                                            │
│   332 │                                                                                          │
│   333 │   if len(devices) == 0:                                                                  │
│   334 │   │   if scan_all:                                                                       │
│                                                                                                  │
│ ╭─────────── locals ────────────╮                                                                │
│ │    scan_all = False           │                                                                │
│ │ scan_filter = {(1204, 57360)} │                                                                │
│ ╰───────────────────────────────╯                                                                │
│                                                                                                  │
│ /home/jamie/Mbed/cy_serial_bridge/src/cy_serial_bridge/cy_scb_context.py:206 in list_devices     │
│                                                                                                  │
│   203 │   │   │   │   │   │   │   scb_interface_settings = cfg[i][0]                             │
│   204 │   │   │   │   │   │   │   curr_cytype = CyType.UART_VENDOR                               │
│   205 │   │   │                                                                                  │
│ ❱ 206 │   │   │   if curr_cytype is None or mfg_interface_settings is None \                     │
│   207 │   │   │   │   or (scb_interface_settings is None and usb_cdc_interface_settings is Non   │
│   208 │   │   │   │   # TODO verbose output                                                      │
│   209 │   │   │   │   continue                                                                   │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │ cdc_data_interface_settings = None                                                           │ │
│ │                         cfg = <usb1.USBConfiguration object at 0x7d84d0df81a0>               │ │
│ │                         dev = <usb1.USBDevice object at 0x7d84d054c110>                      │ │
│ │                 device_list = []                                                             │ │
│ │                even_vid_pid = (1204, 57360)                                                  │ │
│ │                           i = 1                                                              │ │
│ │      mfg_interface_settings = <usb1.USBInterfaceSetting object at 0x7d84d054c290>            │ │
│ │                 odd_vid_pid = (1204, 57361)                                                  │ │
│ │      scb_interface_settings = None                                                           │ │
│ │                        self = <cy_serial_bridge.cy_scb_context.CyScbContext object at        │ │
│ │                               0x7d84d05018b0>                                                │ │
│ │                        type = <CyType.MFG: 5>                                                │ │
│ │  usb_cdc_interface_settings = None                                                           │ │
│ │                    vid_pids = {(1204, 57360)}                                                │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
UnboundLocalError: cannot access local variable 'curr_cytype' where it is not associated with a value

@runger1101001
Copy link
Author

Hmmm - I'll look into this. I have worked on it in the last few days, and it's working on my side. But I have more changes I've done, so probably I've fixed this issue already.

@multiplemonomials
Copy link

Hey! Finally had time to work on this!

I set up a new test suite in the code to test device discovery. This lets you define what the USB descriptors for a device look like, and then test scanning for those descriptors. If you can add entries in there based on your dual channel device (ideally for every combination of interfaces, e.g. UART+UART, UART+I2C, I2C+SPI, etc), then we can test the device discovery code waaay more easily.

To generate the USB descriptor in the test, I am getting data from this script I wrote that dumps all the USB descriptors on the machine. But you could also use something like NirSoft USBTreeView on Windows.

P.S. do you have a Discord account? I can add you to the Mbed CE discord server and we can discuss this more!

P.P.S. I got the tracking email for your package but it still hasn't arrived yet sadly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants