by John Lauer
Two-board Molecule interferometer with onboard RP2040, USB-C data, 15 V USB-C PD power and a JST stage interface.
main
John Lauer
software/: Pico firmware (500 ksps two-channel ADC over DMA, SYNC on GPIO15, framed delta-packed USB stream), smi-dash…
e09b832
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
// SPDX-License-Identifier: MIT
// USB descriptors: one CDC ACM interface. The serial number string is the
// RP2040 flash unique ID so several Picos can be told apart on one host.
#include <string.h>
#include "tusb.h"
#include "pico/unique_id.h"
#define USBD_VID 0x2E8A // Raspberry Pi
#define USBD_PID 0x000A // Raspberry Pi Pico SDK CDC
#define EPNUM_CDC_NOTIF 0x81
#define EPNUM_CDC_OUT 0x02
#define EPNUM_CDC_IN 0x82
static const tusb_desc_device_t desc_device = {
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
.bcdUSB = 0x0200,
.bDeviceClass = TUSB_CLASS_MISC,
.bDeviceSubClass = MISC_SUBCLASS_COMMON,
.bDeviceProtocol = MISC_PROTOCOL_IAD,
.bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
.idVendor = USBD_VID,
.idProduct = USBD_PID,
.bcdDevice = 0x0100,
.iManufacturer = 1,
.iProduct = 2,
.iSerialNumber = 3,
.bNumConfigurations = 1,
};
const uint8_t *tud_descriptor_device_cb(void) { return (const uint8_t *)&desc_device; }
enum { ITF_NUM_CDC = 0, ITF_NUM_CDC_DATA, ITF_NUM_TOTAL };
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN)
static const uint8_t desc_cfg[] = {
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0, 250),
TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 4, EPNUM_CDC_NOTIF, 8, EPNUM_CDC_OUT, EPNUM_CDC_IN, 64),
};
const uint8_t *tud_descriptor_configuration_cb(uint8_t index) { (void)index; return desc_cfg; }
static const char *strings[] = {
"", // 0: language, handled below
"Adom", // 1: manufacturer
"SMI Interferometer Digitizer", // 2: product
NULL, // 3: serial, from the flash unique ID
"SMI stream", // 4: CDC interface
};
static uint16_t desc_str[33];
const uint16_t *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
(void)langid;
char serial[2 * PICO_UNIQUE_BOARD_ID_SIZE_BYTES + 1];
const char *s;
uint8_t n;
if (index == 0) {
desc_str[1] = 0x0409;
n = 1;
} else {
if (index >= sizeof strings / sizeof strings[0]) return NULL;
if (index == 3) { pico_get_unique_board_id_string(serial, sizeof serial); s = serial; }
else s = strings[index];
n = (uint8_t)strlen(s);
if (n > 32) n = 32;
for (uint8_t i = 0; i < n; i++) desc_str[1 + i] = (uint8_t)s[i];
}
desc_str[0] = (uint16_t)((TUSB_DESC_STRING << 8) | (2 * n + 2));
return desc_str;
}