* (c) 2020 Martin Mareš <mj@ucw.cz>
*/
+#define BSB_USB_VENDOR 0x4242
+#define BSB_USB_PRODUCT 0x0003
+#define BSB_USB_VERSION 0x0100
+
+// Status sent on the interrupt endpoint
enum bsb_tx_result {
TX_RESULT_NONE,
TX_RESULT_OK,
u32 tx_ok;
};
+/*
+ * Structure of BSB frames
+ *
+ * start of frame (0xdc)
+ * source address XOR 0x80
+ * destination address
+ * length
+ * operation
+ * <parameters depending on operation>
+ * 16-bit CRC
+ */
+
+enum bsb_address {
+ BSB_ADDR_BOILER = 0,
+ BSB_ADDR_EXT_BOARD = 3,
+ BSB_ADDR_ROOM1 = 6,
+ BSB_ADDR_ROOM2 = 7,
+ BSB_ADDR_GATEWAY = 0x42,
+ BSB_ADDR_BROADCAST = 0x7f,
+};
+
+enum bsb_op {
+ BSB_OP_REQUEST_INFO = 1,
+ BSB_OP_INFO = 2,
+ BSB_OP_SET = 3,
+ BSB_OP_ACK = 4,
+ BSB_OP_NACK = 5,
+ BSB_OP_QUERY = 6,
+ BSB_OP_ANSWER = 7,
+ BSB_OP_ERROR = 8,
+ BSB_OP_QUERY_DEFAULT = 0x0f,
+ BSB_OP_ANSWER_DEFAULT = 0x10,
+};
static usbd_device *usbd_dev;
+enum usb_string {
+ STR_MANUFACTURER = 1,
+ STR_PRODUCT,
+ STR_SERIAL,
+};
+
+static char usb_serial_number[13];
+
+static const char *usb_strings[] = {
+ "United Computer Wizards",
+ "BSB Gateway",
+ usb_serial_number,
+};
+
static const struct usb_device_descriptor device = {
.bLength = USB_DT_DEVICE_SIZE,
.bDescriptorType = USB_DT_DEVICE,
.bDeviceSubClass = 0,
.bDeviceProtocol = 0,
.bMaxPacketSize0 = 64,
- .idVendor = 0x4242,
- .idProduct = 0x0003,
- .bcdDevice = 0x0200,
- .iManufacturer = 1,
- .iProduct = 2,
- .iSerialNumber = 3,
+ .idVendor = BSB_USB_VENDOR,
+ .idProduct = BSB_USB_PRODUCT,
+ .bcdDevice = BSB_USB_VERSION,
+ .iManufacturer = STR_MANUFACTURER,
+ .iProduct = STR_PRODUCT,
+ .iSerialNumber = STR_SERIAL,
.bNumConfigurations = 1,
};
.interface = ifaces,
};
-static char usb_serial_number[13];
-
-static const char *usb_strings[] = {
- "United Computer Wizards",
- "BSB Gateway",
- usb_serial_number,
-};
-
static byte usb_configured;
static byte usb_ep82_pending;
static uint8_t usbd_control_buffer[64];