usbMsgLen_t usbFunctionDescriptor(usbRequest_t *rq) { usbMsgLen_t len = 0; if (rq->wValue.bytes[1] == USBDESCR_STRING && rq->wValue.bytes[0] == 3 /*SERIAL_NUMBER*/) { #if 1 int i; for (i = 0; i < SERIAL_NUMBER_LEN; i++) { uchar c = eeprom_read_byte(EEPROM_SERIAL_NUMBER + i); serial_number_buf[i] = c; } len = serial_number_buf[0] * 2 + 2; serial_number_buf[0] = USB_STRING_DESCRIPTOR_HEADER(serial_number_buf[0]); #else serial_number_buf[0] = USB_STRING_DESCRIPTOR_HEADER(4); serial_number_buf[1] = '1'; serial_number_buf[2] = '2'; serial_number_buf[3] = '3'; serial_number_buf[4] = '4'; len = 4 * 2 + 2; #endif usbMsgPtr = (uchar *)serial_number_buf; } return len; }
/** * Reads the serial number from flash and stores it in RAM where USB can read * it from. */ static void readSerial() { unsigned char i; serialNumberDescriptor[0] = USB_STRING_DESCRIPTOR_HEADER(SERIAL_NUMBER_LENGTH); for (i = 0; i < SERIAL_NUMBER_LENGTH; ++i) serialNumberDescriptor[i + 1] = pgm_read_byte(0x2000 - SERIAL_NUMBER_LENGTH + i); }
0x81, /* IN endpoint number 1 */ 0x03, /* attrib: Interrupt endpoint */ 8, 0, /* maximum packet size */ USB_CFG_INTR_POLL_INTERVAL, /* in ms */ #endif }; static PROGMEM char usbDescrString0[] = { /* language descriptor */ 4, /* sizeof(usbDescrString0): length of descriptor in bytes */ 3, /* descriptor type */ 0x09, 0x04, /* language index (0x0409 = US-English) */ }; #if USB_CFG_VENDOR_NAME_LEN static PROGMEM int usbDescrString1[] = { USB_STRING_DESCRIPTOR_HEADER(USB_CFG_VENDOR_NAME_LEN), USB_CFG_VENDOR_NAME }; #endif #if USB_CFG_DEVICE_NAME_LEN static PROGMEM int usbDescrString2[] = { USB_STRING_DESCRIPTOR_HEADER(USB_CFG_DEVICE_NAME_LEN), USB_CFG_DEVICE_NAME }; #endif /* We don't use prog_int or prog_int16_t for compatibility with various libc * versions. Here's an other compatibility hack: */ #ifndef PRG_RDB #define PRG_RDB(addr) pgm_read_byte(addr)
#if USB_CFG_DESCR_PROPS_STRING_0 == 0 #undef USB_CFG_DESCR_PROPS_STRING_0 #define USB_CFG_DESCR_PROPS_STRING_0 sizeof(usbDescriptorString0) PROGMEM char usbDescriptorString0[] = { /* language descriptor */ 4, /* sizeof(usbDescriptorString0): length of descriptor in bytes */ 3, /* descriptor type */ 0x09, 0x04, /* language index (0x0409 = US-English) */ }; #endif #if USB_CFG_DESCR_PROPS_STRING_VENDOR == 0 && USB_CFG_VENDOR_NAME_LEN #undef USB_CFG_DESCR_PROPS_STRING_VENDOR #define USB_CFG_DESCR_PROPS_STRING_VENDOR sizeof(usbDescriptorStringVendor) PROGMEM int usbDescriptorStringVendor[] = { USB_STRING_DESCRIPTOR_HEADER(USB_CFG_VENDOR_NAME_LEN), USB_CFG_VENDOR_NAME }; #endif #if USB_CFG_DESCR_PROPS_STRING_DEVICE == 0 && USB_CFG_DEVICE_NAME_LEN #undef USB_CFG_DESCR_PROPS_STRING_DEVICE #define USB_CFG_DESCR_PROPS_STRING_DEVICE sizeof(usbDescriptorStringDevice) PROGMEM int usbDescriptorStringDevice[] = { USB_STRING_DESCRIPTOR_HEADER(USB_CFG_DEVICE_NAME_LEN), USB_CFG_DEVICE_NAME }; #endif #if USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER == 0 && USB_CFG_SERIAL_NUMBER_LEN #undef USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER
0, // protocol 8, // max packet size // the following two casts affect the first byte of the constant only, but // that's sufficient to avoid a warning with the default values. (char)USB_CFG_VENDOR_ID, (char)USB_CFG_DEVICE_ID, USB_CFG_DEVICE_VERSION, 1, // manufacturer string index 2, // product string index 3, // serial number string index 1, // number of configurations }; #define SERIAL_NUMBER_BYTE_COUNT (EEPROM_SERIAL_LENGTH * sizeof(int)) const int webUsbDescriptorStringSerialNumber[EEPROM_SERIAL_LENGTH + 1] = { USB_STRING_DESCRIPTOR_HEADER(EEPROM_SERIAL_LENGTH) }; USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(usbRequest_t *rq) { switch (rq->wValue.bytes[1]) { case USBDESCR_STRING: switch (rq->wValue.bytes[0]) { case 3: usbMsgPtr = (usbMsgPtr_t)(webUsbDescriptorStringSerialNumber); return sizeof(webUsbDescriptorStringSerialNumber); } break; case USB_BOS_DESCRIPTOR_TYPE: usbMsgPtr = (usbMsgPtr_t)(BOS_DESCRIPTOR); return sizeof(BOS_DESCRIPTOR); default:
0x10, 0x01, /* USB version supported */ USB_CFG_DEVICE_CLASS, USB_CFG_DEVICE_SUBCLASS, 0, /* protocol */ 8, /* max packet size */ 0xc0, 0x16, /* Objective Development */ 0xdf, 0x05, /* Shared USB HID ID */ USB_CFG_DEVICE_VERSION, /* 2 bytes */ 1, /* manufacturer string index */ 2, /* product string index */ 0, /* serial number string index */ 1, /* number of configurations */ }; PROGMEM int usbDescriptorStringVendorMT[] = { USB_STRING_DESCRIPTOR_HEADER(20), 'p', 'o', 'h', 'l', '-', 'm', 'i', 'c', 'h', 'a', 'e', 'l', '@', 'g', 'm', 'x', '.', 'b', 'i', 'z' }; PROGMEM int usbDescriptorStringDeviceMT[] = { USB_STRING_DESCRIPTOR_HEADER(10), 'M', 'e', 'm', 'o', 'r', 'y', 'T', 'o', 'o', 'l' }; #define EEPROM_SIZE_QUERY_REPORT_ID 1 #define EEPROM_PROGRAMMING_REPORT_ID 2 #define EEPROM_SET_ADDRESS_REPORT_ID 3 #define EEPROM_READING_REPORT_ID 4 #define FLASH_SIZE_QUERY_REPORT_ID 5 #define FLASH_SET_ADDRESS_REPORT_ID 6 #define FLASH_READING_REPORT_ID 7
#include "bitbang_i2c.h" /*---------------------------------------------------------------------------*/ #define VERSION 0x04 /*---------------------------------------------------------------------------*/ void timer_init(); void initSerialNumber(); /*---------------------------------------------------------------------------*/ uint8_t debug[3]; volatile uint8_t gainSetting; uint8_t thermocoupleReadout[4]; uint8_t coldJunctionReadout[4]; uint8_t* EE_addr = (uint8_t*)32; volatile uint16_t timer0_counter; /*---------------------------------------------------------------------------*/ int usbDescriptorStringSerialNumber[] = { USB_STRING_DESCRIPTOR_HEADER(USB_CFG_SERIAL_NUMBER_LEN), USB_CFG_SERIAL_NUMBER }; /*---------------------------------------------------------------------------*/ void handleMessage() { switch(msgbuf[1]) { case 0: /* Version reading */ { msgbuf[2] = 0xBB; msgbuf[3] = 0x66; msgbuf[4] = VERSION; break; } case 1: /* ADC reading */
USBDESCR_HID_REPORT, // descriptor type: HID report sizeof consumer_report_descriptor, 0, // total length of report descriptor // Endpoint descriptor 7, // sizeof(usbDescrEndpoint) USBDESCR_ENDPOINT, // descriptor type = endpoint (char) (0x80 | USB_CFG_EP3_NUMBER), // IN endpoint number 3 0x03, // attrib: Interrupt endpoint 8, 0, // maximum packet size USB_CFG_INTR_POLL_INTERVAL, // must be at least 10ms }; const PROGMEM uint16_t keyboard_interface_name[] = { USB_STRING_DESCRIPTOR_HEADER( CFG_INTERFACE_KEYBOARD_SZ ), CFG_INTERFACE_KEYBOARD_NAME }, consumer_interface_name[] = { USB_STRING_DESCRIPTOR_HEADER( CFG_INTERFACE_CONSUMER_SZ ), CFG_INTERFACE_CONSUMER_NAME }; void vusb_init(void) { // inits the timer used for idle rate // a rate of 12M/(1024 * 256) = 45.78 Hz (period = 21845us) TCCR0B = _BV(CS02) | _BV(CS00); #define TMR1US 21845L