Subversion Repositories group.electronics

Rev

Rev 33 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 33 Rev 94
Line 3... Line 3...
3
 * Author: Christian Starkjohann
3
 * Author: Christian Starkjohann
4
 * Creation Date: 2004-12-29
4
 * Creation Date: 2004-12-29
5
 * Tabsize: 4
5
 * Tabsize: 4
6
 * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
6
 * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
7
 * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
7
 * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8
 * This Revision: $Id$
-
 
9
 */
8
 */
10
 
9
 
11
#include "usbportability.h"
-
 
12
#include "usbdrv.h"
10
#include "usbdrv.h"
13
#include "oddebug.h"
11
#include "oddebug.h"
14
 
12
 
15
/*
13
/*
16
General Description:
14
General Description:
Line 43... Line 41...
43
#if USB_CFG_CHECK_DATA_TOGGLING
41
#if USB_CFG_CHECK_DATA_TOGGLING
44
uchar       usbCurrentDataToken;/* when we check data toggling to ignore duplicate packets */
42
uchar       usbCurrentDataToken;/* when we check data toggling to ignore duplicate packets */
45
#endif
43
#endif
46
 
44
 
47
/* USB status registers / not shared with asm code */
45
/* USB status registers / not shared with asm code */
48
uchar               *usbMsgPtr;     /* data to transmit next -- ROM or RAM address */
46
usbMsgPtr_t         usbMsgPtr;      /* data to transmit next -- ROM or RAM address */
49
static usbMsgLen_t  usbMsgLen = USB_NO_MSG; /* remaining number of bytes */
47
static usbMsgLen_t  usbMsgLen = USB_NO_MSG; /* remaining number of bytes */
50
static uchar        usbMsgFlags;    /* flag values see below */
48
static uchar        usbMsgFlags;    /* flag values see below */
51
 
49
 
52
#define USB_FLG_MSGPTR_IS_ROM   (1<<6)
50
#define USB_FLG_MSGPTR_IS_ROM   (1<<6)
53
#define USB_FLG_USE_USER_RW     (1<<7)
51
#define USB_FLG_USE_USER_RW     (1<<7)
Line 65... Line 63...
65
#if USB_CFG_DESCR_PROPS_STRINGS == 0
63
#if USB_CFG_DESCR_PROPS_STRINGS == 0
66
 
64
 
67
#if USB_CFG_DESCR_PROPS_STRING_0 == 0
65
#if USB_CFG_DESCR_PROPS_STRING_0 == 0
68
#undef USB_CFG_DESCR_PROPS_STRING_0
66
#undef USB_CFG_DESCR_PROPS_STRING_0
69
#define USB_CFG_DESCR_PROPS_STRING_0    sizeof(usbDescriptorString0)
67
#define USB_CFG_DESCR_PROPS_STRING_0    sizeof(usbDescriptorString0)
70
PROGMEM char usbDescriptorString0[] = { /* language descriptor */
68
PROGMEM const char usbDescriptorString0[] = { /* language descriptor */
71
    4,          /* sizeof(usbDescriptorString0): length of descriptor in bytes */
69
    4,          /* sizeof(usbDescriptorString0): length of descriptor in bytes */
72
    3,          /* descriptor type */
70
    3,          /* descriptor type */
73
    0x09, 0x04, /* language index (0x0409 = US-English) */
71
    0x09, 0x04, /* language index (0x0409 = US-English) */
74
};
72
};
75
#endif
73
#endif
76
 
74
 
77
#if USB_CFG_DESCR_PROPS_STRING_VENDOR == 0 && USB_CFG_VENDOR_NAME_LEN
75
#if USB_CFG_DESCR_PROPS_STRING_VENDOR == 0 && USB_CFG_VENDOR_NAME_LEN
78
#undef USB_CFG_DESCR_PROPS_STRING_VENDOR
76
#undef USB_CFG_DESCR_PROPS_STRING_VENDOR
79
#define USB_CFG_DESCR_PROPS_STRING_VENDOR   sizeof(usbDescriptorStringVendor)
77
#define USB_CFG_DESCR_PROPS_STRING_VENDOR   sizeof(usbDescriptorStringVendor)
80
PROGMEM int  usbDescriptorStringVendor[] = {
78
PROGMEM const int  usbDescriptorStringVendor[] = {
81
    USB_STRING_DESCRIPTOR_HEADER(USB_CFG_VENDOR_NAME_LEN),
79
    USB_STRING_DESCRIPTOR_HEADER(USB_CFG_VENDOR_NAME_LEN),
82
    USB_CFG_VENDOR_NAME
80
    USB_CFG_VENDOR_NAME
83
};
81
};
84
#endif
82
#endif
85
 
83
 
86
#if USB_CFG_DESCR_PROPS_STRING_PRODUCT == 0 && USB_CFG_DEVICE_NAME_LEN
84
#if USB_CFG_DESCR_PROPS_STRING_PRODUCT == 0 && USB_CFG_DEVICE_NAME_LEN
87
#undef USB_CFG_DESCR_PROPS_STRING_PRODUCT
85
#undef USB_CFG_DESCR_PROPS_STRING_PRODUCT
88
#define USB_CFG_DESCR_PROPS_STRING_PRODUCT   sizeof(usbDescriptorStringDevice)
86
#define USB_CFG_DESCR_PROPS_STRING_PRODUCT   sizeof(usbDescriptorStringDevice)
89
PROGMEM int  usbDescriptorStringDevice[] = {
87
PROGMEM const int  usbDescriptorStringDevice[] = {
90
    USB_STRING_DESCRIPTOR_HEADER(USB_CFG_DEVICE_NAME_LEN),
88
    USB_STRING_DESCRIPTOR_HEADER(USB_CFG_DEVICE_NAME_LEN),
91
    USB_CFG_DEVICE_NAME
89
    USB_CFG_DEVICE_NAME
92
};
90
};
93
#endif
91
#endif
94
 
92
 
95
#if USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER == 0 && USB_CFG_SERIAL_NUMBER_LEN
93
#if USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER == 0 && USB_CFG_SERIAL_NUMBER_LEN
96
#undef USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER
94
#undef USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER
97
#define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER    sizeof(usbDescriptorStringSerialNumber)
95
#define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER    sizeof(usbDescriptorStringSerialNumber)
98
PROGMEM int usbDescriptorStringSerialNumber[] = {
96
PROGMEM const int usbDescriptorStringSerialNumber[] = {
99
    USB_STRING_DESCRIPTOR_HEADER(USB_CFG_SERIAL_NUMBER_LEN),
97
    USB_STRING_DESCRIPTOR_HEADER(USB_CFG_SERIAL_NUMBER_LEN),
100
    USB_CFG_SERIAL_NUMBER
98
    USB_CFG_SERIAL_NUMBER
101
};
99
};
102
#endif
100
#endif
103
 
101
 
Line 106... Line 104...
106
/* --------------------------- Device Descriptor --------------------------- */
104
/* --------------------------- Device Descriptor --------------------------- */
107
 
105
 
108
#if USB_CFG_DESCR_PROPS_DEVICE == 0
106
#if USB_CFG_DESCR_PROPS_DEVICE == 0
109
#undef USB_CFG_DESCR_PROPS_DEVICE
107
#undef USB_CFG_DESCR_PROPS_DEVICE
110
#define USB_CFG_DESCR_PROPS_DEVICE  sizeof(usbDescriptorDevice)
108
#define USB_CFG_DESCR_PROPS_DEVICE  sizeof(usbDescriptorDevice)
111
PROGMEM char usbDescriptorDevice[] = {    /* USB device descriptor */
109
PROGMEM const char usbDescriptorDevice[] = {    /* USB device descriptor */
112
    18,         /* sizeof(usbDescriptorDevice): length of descriptor in bytes */
110
    18,         /* sizeof(usbDescriptorDevice): length of descriptor in bytes */
113
    USBDESCR_DEVICE,        /* descriptor type */
111
    USBDESCR_DEVICE,        /* descriptor type */
114
    0x10, 0x01,             /* USB version supported */
112
    0x10, 0x01,             /* USB version supported */
115
    USB_CFG_DEVICE_CLASS,
113
    USB_CFG_DEVICE_CLASS,
116
    USB_CFG_DEVICE_SUBCLASS,
114
    USB_CFG_DEVICE_SUBCLASS,
Line 137... Line 135...
137
#endif
135
#endif
138
 
136
 
139
#if USB_CFG_DESCR_PROPS_CONFIGURATION == 0
137
#if USB_CFG_DESCR_PROPS_CONFIGURATION == 0
140
#undef USB_CFG_DESCR_PROPS_CONFIGURATION
138
#undef USB_CFG_DESCR_PROPS_CONFIGURATION
141
#define USB_CFG_DESCR_PROPS_CONFIGURATION   sizeof(usbDescriptorConfiguration)
139
#define USB_CFG_DESCR_PROPS_CONFIGURATION   sizeof(usbDescriptorConfiguration)
142
PROGMEM char usbDescriptorConfiguration[] = {    /* USB configuration descriptor */
140
PROGMEM const char usbDescriptorConfiguration[] = {    /* USB configuration descriptor */
143
    9,          /* sizeof(usbDescriptorConfiguration): length of descriptor in bytes */
141
    9,          /* sizeof(usbDescriptorConfiguration): length of descriptor in bytes */
144
    USBDESCR_CONFIG,    /* descriptor type */
142
    USBDESCR_CONFIG,    /* descriptor type */
145
    18 + 7 * USB_CFG_HAVE_INTRIN_ENDPOINT + 7 * USB_CFG_HAVE_INTRIN_ENDPOINT3 +
143
    18 + 7 * USB_CFG_HAVE_INTRIN_ENDPOINT + 7 * USB_CFG_HAVE_INTRIN_ENDPOINT3 +
146
                (USB_CFG_DESCR_PROPS_HID & 0xff), 0,
144
                (USB_CFG_DESCR_PROPS_HID & 0xff), 0,
147
                /* total length of data returned (including inlined descriptors) */
145
                /* total length of data returned (including inlined descriptors) */
Line 299... Line 297...
299
            flags = 0;                              \
297
            flags = 0;                              \
300
        if((cfgProp) & USB_PROP_IS_DYNAMIC){        \
298
        if((cfgProp) & USB_PROP_IS_DYNAMIC){        \
301
            len = usbFunctionDescriptor(rq);        \
299
            len = usbFunctionDescriptor(rq);        \
302
        }else{                                      \
300
        }else{                                      \
303
            len = USB_PROP_LENGTH(cfgProp);         \
301
            len = USB_PROP_LENGTH(cfgProp);         \
304
            usbMsgPtr = (uchar *)(staticName);      \
302
            usbMsgPtr = (usbMsgPtr_t)(staticName);  \
305
        }                                           \
303
        }                                           \
306
    }
304
    }
307
 
305
 
308
/* usbDriverDescriptor() is similar to usbFunctionDescriptor(), but used
306
/* usbDriverDescriptor() is similar to usbFunctionDescriptor(), but used
309
 * internally for all types of descriptors.
307
 * internally for all types of descriptors.
Line 407... Line 405...
407
        usbResetStall();
405
        usbResetStall();
408
#endif
406
#endif
409
    SWITCH_DEFAULT                          /* 7=SET_DESCRIPTOR, 12=SYNC_FRAME */
407
    SWITCH_DEFAULT                          /* 7=SET_DESCRIPTOR, 12=SYNC_FRAME */
410
        /* Should we add an optional hook here? */
408
        /* Should we add an optional hook here? */
411
    SWITCH_END
409
    SWITCH_END
412
    usbMsgPtr = dataPtr;
410
    usbMsgPtr = (usbMsgPtr_t)dataPtr;
413
skipMsgPtrAssignment:
411
skipMsgPtrAssignment:
414
    return len;
412
    return len;
415
}
413
}
416
 
414
 
417
/* ------------------------------------------------------------------------- */
415
/* ------------------------------------------------------------------------- */
Line 497... Line 495...
497
        if(usbMsgFlags & USB_FLG_USE_USER_RW){
495
        if(usbMsgFlags & USB_FLG_USE_USER_RW){
498
            len = usbFunctionRead(data, len);
496
            len = usbFunctionRead(data, len);
499
        }else
497
        }else
500
#endif
498
#endif
501
        {
499
        {
-
 
500
            uchar i = len;
502
            uchar i = len, *r = usbMsgPtr;
501
            usbMsgPtr_t r = usbMsgPtr;
503
            if(usbMsgFlags & USB_FLG_MSGPTR_IS_ROM){    /* ROM data */
502
            if(usbMsgFlags & USB_FLG_MSGPTR_IS_ROM){    /* ROM data */
504
                do{
503
                do{
505
                    uchar c = USB_READ_FLASH(r);    /* assign to char size variable to enforce byte ops */
504
                    uchar c = USB_READ_FLASH(r);    /* assign to char size variable to enforce byte ops */
506
                    *data++ = c;
505
                    *data++ = c;
507
                    r++;
506
                    r++;
508
                }while(--i);
507
                }while(--i);
509
            }else{  /* RAM data */
508
            }else{  /* RAM data */
510
                do{
509
                do{
511
                    *data++ = *r++;
510
                    *data++ = *((uchar *)r);
-
 
511
                    r++;
512
                }while(--i);
512
                }while(--i);
513
            }
513
            }
514
            usbMsgPtr = r;
514
            usbMsgPtr = r;
515
        }
515
        }
516
    }
516
    }