# gs_usb
## IDs
| Vendor | Product | Desc |
|--------|---------|------|
| 0x1d50 | 0x606f | Geschwister Schneider USB2.0 to CAN interface
| 0x1209 | 0x2323 | candleLight
## Endpoints
All CAN communication happens via bulk endpoint (IN = 1, OUT = 2).
Configuration uses the control endpoint.
## Configuration
All control messages use *Vendor* type and *Interface* target.
| Command | Dir | `bRequest` |
|-------------------|-----|------------|
| SET_HOST_FORMAT | OUT | 0
| SET_BITTIMING | OUT | 1
| SET_MODE | OUT | 2
| BERR | ??? | 3
| GET_BT_CONST | IN | 4
| GET_DEVICE_CONFIG | IN | 5
| TIMESTAMP | ??? | 6
| SET_IDENTIFY | OUT | 7
### SET_HOST_FORMAT
Sets the desired byte order. The Linux driver always uses little-endian, regardless of the actual host endianness.
Payload:
```
byte_order: u32
```
`byte_order` is set to `0x0000beef` in the desired byte order.
### SET_BITTIMING
Payload:
```
prop_seg: u32,
phase_seg1: u32,
phase_seg2: u32,
sjw: u32,
brp: u32,
```
* sjw: synchronization jump width
* brp: bit-rate prescaler
### SET_MODE
Payload:
```
mode: u32,
flags: u32,
```
`mode` values:
* `MODE_RESET` = 0
* `MODE_START` = 1
`flags` (only for `MODE_START`):
* `LISTEN_ONLY` = 0b0001
* `LOOP_BACK` = 0b0010
* `TRIPLE_SAMPLE` = 0b0100
* `ONE_SHOT` = 0b1000 (controller is not allowed to retry TX, might be unavailable on some hw)
### GET_BT_CONST
Payload:
```
feature_flags: u32,
fclk_can: u32,
tseg1_min: u32,
tseg1_max: u32,
tseg2_min: u32,
tseg2_max: u32,
swj_max: u32,
brp_min: u32,
brp_max: u32,
brp_inc: u32,
```
`feature_flags` contains any combination of the following bitflags:
Name | Mask
-----|------
`LISTEN_ONLY` | `0b000001`
`LOOP_BACK` | `0b000010`
`TRIPLE_SAMPLE` | `0b000100`
`ONE_SHOT` | `0b001000`
`HW_TIMESTAMP` | `0b010000`
`IDENTIFY` | `0b100000`
### GET_DEVICE_CONFIG
Payload:
```
reserved: [u8; 3],
icount: u8,
sw_version: u32,
hw_version: u32,
```
* `icount`: Number of CAN interfaces provided by the device, minus 1 (so 0 if the device has only one CAN interface)
### SET_IDENTIFY
Turns on/off an LED indicator.
Payload:
```
state: u32,
```
`state` can be 0 or 1 to turn off or on the indicator, respectively.
## CAN Communication
CAN frames are transmitted over the bulk endpoint, with the following format:
```
echo_id: u32,
can_id: u32,
can_dlc: u8,
channel: u8,
flags: u8,
reserved: u8,
data: [u8; 8],
```
Field | Type | Descr
------|------|------
`echo_id` | `u32` | On RX, `-1` for normally received frames