⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usbconf.c

📁 printer usb
💻 C
📖 第 1 页 / 共 3 页
字号:
    /* See section 9.6.5, Rev 2.0 USB specification (page 267). */
    /* (section 9.6.3, Rev 1.0 USB specification, page 185.) */

    /* setup interface descriptors */
#ifdef SCAN_DB_IFACE
    /* interface1.1 */
    9, 4,                   /* bLength, bDescriptorType 4 = INTERFACE */
    SCAN_DB_IFACE,          /* bIfaceNum         interface number */
    0,                      /* bAltSetting       Alternate setting 0 */
    SCANNER_EPS+DEBUG_EPS,  /* bNumEndpoints     EP6 IN/OUT, EP7 IN/OUT */
    0xFF,                   /* bIfaceClass     (vendor specific device class) */
    0xFF,                   /* bIfaceSubClass  (vendor specific) */
    0xFF,                   /* bIfaceProtocol  (vendor specific) */
    4,                      /* iInterface        index to string ("Scan") */

    /* setup endpoint descriptors */
#if SCANNER_EPS
    /* endpoint1.1.1.1, Scan Status and Data from AIO (IN) */
    7, 5,                   /* descriptor length, type */
    0x80+SCN_EP,            /* endpoint address IN */
    2,                      /* attributes - 2 Bulk endpoint */
    LOB(HS_BULK_SIZE),      /* maximum packet size */
    HIB(HS_BULK_SIZE),
    0,                      /* interval - 0 msec. */

    /* setup endpoint descriptors */
    /* endpoint1.1.1.2, Scan Escape Language input to AIO: (OUT) */
    7, 5,                   /* descriptor length, type */
    SCN_EP,                 /* endpoint address OUT */
    2,                      /* attributes - 2 Bulk endpoint */
    LOB(HS_BULK_SIZE),      /* maximum packet size */
    HIB(HS_BULK_SIZE),
    0,                      /* interval - 0 msec. */
#endif /* SCANNER_EPS */

#if DEBUG_EPS
    /* endpoint1.1.1.3, Debug MDM from AIO (IN) */
    7, 5,                   /* descriptor length, type */
    0x80+DBG_EP,            /* endpoint address IN */
    2,                      /* attributes - 2 Bulk endpoint */
    LOB(HS_BULK_SIZE),      /* maximum packet size */
    HIB(HS_BULK_SIZE),
    0,                      /* interval - 0 msec. */

    /* endpoint1.1.1.4, Debug MDM to AIO (OUT) */
    7, 5,                   /* descriptor length, type */
    DBG_EP,                 /* endpoint address OUT */
    2,                      /* attributes - 2 Bulk endpoint */
    LOB(HS_BULK_SIZE),      /* maximum packet size */
    HIB(HS_BULK_SIZE),
    0,                      /* interval - 0 msec. */
#endif /* DEBUG_EPS */
#endif /* SCAN_DB_IFACE */

    /* setup interface descriptors */
    /* interface1.2 */
    9, 4,                   /* bLength, bDescriptorType 4 = INTERFACE */
    PRINTER_IFACE,          /* bIfaceNum         interface number */
    0,                      /* bAltSetting       Alternate setting 0 */
    2,                      /* bNumEndpoints     EP1 IN, EP1 OUT */
    7,                      /* bIfaceClass     7 base class for printers */
    1,                      /* bIfaceSubClass  1 subclass code for printers */
    2,                      /* bIfaceProtocol  2 bidirectional interface */
    5,                      /* iInterface        index to string ("Print") */

    /* setup endpoint descriptors */
    /* endpoint1.1.2.1, Print status - NPA returns (IN) */
    7, 5,                   /* descriptor length, type */
    0x80+PRN_EP,            /* endpoint address IN */
    2,                      /* attributes - 2 Bulk endpoint */
    LOB(HS_BULK_SIZE),      /* maximum packet size */
    HIB(HS_BULK_SIZE),
    0,                      /* interval - 0 msec. */

    /* endpoint1.1.2.2, Print Cmd/Data from Host (OUT) */
    7, 5,                   /* descriptor length, type */
    PRN_EP,                 /* endpoint address OUT */
    2,                      /* attributes - 2 Bulk endpoint */
    LOB(HS_BULK_SIZE),      /* maximum packet size */
    HIB(HS_BULK_SIZE),
    0,                      /* interval - 0 msec. */

    /* setup interface descriptors */
    /* interface1.3 */
    9, 4,                   /* bLength, bDescriptorType 4 = INTERFACE */
    HID_IFACE,              /* bIfaceNum         interface number */
    0,                      /* bAltSetting       Alternate setting 0 */
    1,                      /* bNumEndpoints     EP3 IN (interrupt) */
    3,                      /* bIfaceClass     (USB specified device class) */
    0,                      /* bIfaceSubClass  0 */
    0,                      /* bIfaceProtocol  0 */
    6,                      /* iInterface        index to string ("Hid") */

    /* HID descriptor */
    9, 0x21,                /* bLength, bDescriptorType 0x21 = HID */
    0, 1,                   /* bcdHID HID Class Spec release no. 1.00  */
    0,                      /* bCountryCode device target country */
    1,                      /* bNumDescriptors to follow */
    0x22,                   /* bDescriptor type - Report */
    0x49, 0,                /* wDescriptorLength - Report length (73 bytes) */

    /* setup endpoint descriptors */
    /* endpoint1.1.3.1, HID Interrupt from AIO (IN) */
    7, 5,                   /* descriptor length, type */
    0x80+HID_EP,            /* endpoint address IN */
    3,                      /* attributes - 3 Interrupt endpoint */
    LOB(INT_BSIZE),         /* maximum packet size (8) */
    HIB(INT_BSIZE),
    11                      /* interval - 128 msec. */

#ifdef MEMORY_CARD_READER
    ,
    /* setup interface descriptors */
    /* interface1.4 */
    9, 4,                   /* bLength, bDescriptorType 4 = INTERFACE */
    CARD_IFACE,             /* bIfaceNum         interface number */
    0,                      /* bAltSetting       Alternate setting 0 */
    2,                      /* bNumEndpoints     EP8 IN, EP8 OUT */
    8,                      /* bIfaceClass     8 Mass Storage class */
    6,                      /* bIfaceSubClass  6 SCSI transparent cmd set */
    0x50,                   /* bIfaceProtocol 50 Bulk-Only transport */
    7,                      /* iInterface        index to string ("MS Class") */

    /* setup endpoint descriptors */
    /* endpoint1.1.4.1, Card Reader Interface (IN) */
    7, 5,                   /* descriptor length, type */
    0x80+MEM_EP,            /* endpoint address IN */
    2,                      /* attributes - 2 Bulk endpoint */
    LOB(HS_BULK_SIZE),      /* maximum packet size */
    HIB(HS_BULK_SIZE),
    0,                      /* interval - 0 msec. */

    /* endpoint1.1.4.2, Card Reader Interface (OUT) */
    7, 5,                   /* descriptor length, type */
    MEM_EP,                 /* endpoint address OUT */
    2,                      /* attributes - 2 Bulk endpoint */
    LOB(HS_BULK_SIZE),      /* maximum packet size */
    HIB(HS_BULK_SIZE),
    0                       /* interval - 0 msec. */
#endif /* MEMORY_CARD_READER */
};

static Uint8 USB_str_0[4] = {
    /* setup language string descriptor(s) */
    4, 3,                   /* descriptor length, type */
    9, 4                    /* language code for English */
};

    /* setup string descriptors */
    /* string descriptor1.1, manufacturer (derived from Device ID string) */
static Uint8 USB_str_1[256];

    /* default string used if Device ID bad */
static Uint8 USB_str_unknown[] = {
    16, 3,      /* descriptor length, type */
    /* 'Unknown'  */
    'U', 0, 'n', 0, 'k', 0, 'n', 0, 'o', 0, 'w', 0, 'n', 0
};

    /* string descriptor1.2, product (derived from Device ID string) */
static Uint8 USB_str_2[256];

    /* string descriptor1.3, serial no */
static Uint8 USB_str_3[50];
/* filled with unicode for "17K005000151805" */

    /* string descriptor1.4, Interface string */
static Uint8 USB_str_4[] = {
    10, 3,       /* descriptor length, type */
    /* 'Scan'  */
    'S', 0, 'c', 0, 'a', 0, 'n', 0
};

    /* string descriptor1.5, Interface string */
static Uint8 USB_str_5[] = {
    12, 3,      /* descriptor length, type */
    /* 'Print'  */
    'P', 0, 'r', 0, 'i', 0, 'n', 0, 't', 0
};

    /* string descriptor1.6, Interface string */
static Uint8 USB_str_6[] = {
     8, 3,      /* descriptor length, type */
    /* 'Hid'  */
    'H', 0, 'i', 0, 'd', 0,
};

    /* string descriptor1.7, Interface string */
static Uint8 USB_str_7[] = {
     38, 3,     /* descriptor length, type */
    /* 'Mass Storage Class'  */
    'M', 0, 'a', 0, 's', 0, 's', 0, ' ', 0,
    'S', 0, 't', 0, 'o', 0, 'r', 0, 'a', 0, 'g', 0, 'e', 0, ' ', 0,
    'C', 0, 'l', 0, 'a', 0, 's', 0, 's', 0
};

    /* string descriptor1.x, error */
static Uint8 USB_str_n[] = {
    28, 3,      /* descriptor length, type */
    /* 'Illegal Index' */
    'I', 0, 'l', 0, 'l', 0, 'e', 0, 'g', 0, 'a', 0, 'l', 0, ' ', 0,
    'I', 0, 'n', 0, 'd', 0, 'e', 0, 'x', 0
};

static Uint8 USB_str_lerr[] = {
    /* setup language error string descriptor */
    30, 3,      /* descriptor length, type */
    /* 'Language Error' */
    'L', 0, 'a', 0, 'n', 0, 'g', 0, 'u', 0, 'a', 0, 'g', 0, 'e', 0, ' ', 0,
    'E', 0, 'r', 0, 'r', 0, 'o', 0, 'r', 0
};

    /* HID Class Report Descriptor */
static Uint8 HIDClassReportDesc[] = {
    0x06, 0x00, 0x01,     /* Usage Page (Reserved)              */
            0x09, 0x01,   /* Usage (Reserved)                   */
            0xA1, 0x01,   /* Collection (Application)           */
            0x09, 0x02,   /*   Usage (Reserved)                 */
    0x15, 0x00,           /*   Logical Minimum (0)              */
    0x26, 0xFF, 0x00,     /*   Logical Maximum (255)            */
            0x75, 0x08,   /*   Report Size (8)                  */
            0x95, 0x01,   /*   Report Count (1)                 */
    0x85, 0x01,           /*   Report ID (1)                    */

            0x09, 0x03,   /*   Usage (Reserved)                 */
            0x81, 0x02,   /*   Input (Data, Variable, Absolute) */
            0x75, 0x08,   /*   Report Size (8)                  */
            0x95, 0x01,   /*   Report Count (1)                 */

            0x09, 0x04,   /*   Usage (Reserved)                 */
            0x81, 0x02,   /*   Input (Data, Variable, Absolute) */
            0x75, 0x08,   /*   Report Size (8)                  */
            0x95, 0x01,   /*   Report Count (1)                 */

            0x09, 0x05,   /*   Usage (Reserved)                 */
            0x81, 0x02,   /*   Input (Data, Variable, Absolute) */
            0x75, 0x08,   /*   Report Size (8)                  */
            0x95, 0x01,   /*   Report Count (1)                 */

            0x09, 0x06,   /*   Usage (Reserved)                 */
            0x81, 0x02,   /*   Input (Data, Variable, Absolute) */
            0x75, 0x08,   /*   Report Size (8)                  */
            0x95, 0x01,   /*   Report Count (1)                 */

            0x09, 0x07,   /*   Usage (Reserved)                 */
            0x81, 0x02,   /*   Input (Data, Variable, Absolute) */
            0x75, 0x08,   /*   Report Size (8)                  */
            0x95, 0x01,   /*   Report Count (1)                 */

            0x09, 0x08,   /*   Usage (Reserved)                 */
            0x81, 0x02,   /*   Input (Data, Variable, Absolute) */
            0x75, 0x08,   /*   Report Size (8)                  */
            0x95, 0x01,   /*   Report Count (1)                 */

            0x09, 0x09,   /*   Usage (Reserved)                 */
            0x81, 0x02,   /*   Input (Data, Variable, Absolute) */
    0xC0};                /* End Collection                     */

static Uint8 HIDDescriptor[9] = {
    9, 0x21,                /* bLength, bDescriptorType 0x21 = HID */
    0, 1,                   /* bcdHID HID Class Spec release no. 1.00  */
    0,                      /* bCountryCode device target country */
    1,                      /* bNumDescriptors to follow */
    0x22,                   /* bDescriptor type - Report */
    0x49, 0                 /* wDescriptorLength - Report length (73 bytes) */
};

static Uint8 DeviceID[256];

#ifdef BOOTCODE

#define FLASH_PAGE_SIZE 512

static Uint32 nvram_page[FLASH_PAGE_SIZE/sizeof(Uint32)];

static Boolean nvram_invalid=FALSE;

#define FLASH_PAGE_COUNT    4096
#define N_NVRAM_PAGES          8
#define USB_CONFIG_PAGE_OFFSET 1

#define USB_CONFIG_PAGE (FLASH_PAGE_COUNT - N_NVRAM_PAGES + USB_CONFIG_PAGE_OFFSET)

static void get_nvflash_page(void)
{
    int failure;

    LockSPIMode(TRUE);

    failure = SPI_ReadPage(USB_CONFIG_PAGE, 1, nvram_page);

    UnlockSPIMode();
}

#define OMgetString(prop,lev,pval,len) get_nv_string(prop, pval, len)
#define OMgetInt(prop,lev,pval) get_nv_int(prop, pval)

enum
{
    omUSBVendorID,
    omUSBProductID,
    omUSBSerialNumberActive,
    omSerialNumber,
    omManufacturerName,
    omUSBCommandString,
    omPrinterModel,
    omMetaDataPage2Id,

    N_USB_PROPS
};

static struct
{
    int size;
    int offset;
} g_properties[N_USB_PROPS] =
{
    { 2,  4640 } /* omUSBVendorID */,
    { 2,  4656 } /* omUSBProductID */,
    { 1,  4688 } /* omUSBSerialNumberActive */,
    { 16, 4256 } /* omSerialNumber */,
    { 20, 4096 } /* omManufacturerName */,
    { 32, 4776 } /* omUSBCommandString */,
    { 32, 4384 } /* omPrinterModel */,
    { 2,  8128 } /* omMetaDataPage2Id */,
};

static void get_nv_int(int prop, int *val)
{
    Uint8 *page = (Uint8 *)nvram_page;
    int offset = g_properties[prop].offset/8 - 512;

    ASSERT(prop < N_USB_PROPS);

    switch (g_properties[prop].size)
    {
        case 1:
            *val = page[offset];
            break;

        case 2:
            *val = page[offset + 1];
            *val <<= 8;
            *val |= page[offset];
            break;

        default:
            ASSERT(0);
    }
}

static void get_nv_string(int prop, char *val, int max_len)
{
    Uint8 *page = (Uint8 *)nvram_page;
    int len = page[g_properties[prop].offset/8 - 512];

    ASSERT(prop < N_USB_PROPS);

    if (len > max_len) len = 0;

    memcpy(val, page + (g_properties[prop].offset/8 - 512 + 1), len);
    val[len] = '\0';
}
#endif

/**************************************************************************
*
*  Function Name  : USBConfigurationInit
*  Returned Value : None
*  Comments       :
*    Initialize USB configuration data structures.
*
**************************************************************************/
void USBConfigurationInit(void)
{
    int i, n;
    Uint8 c, serial_no[50], *key;
    Uint16 Vid, Pid;

#ifdef BOOTCODE
    {
        int page_id=0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -