Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added 3rd endpoint #1

Merged
merged 9 commits into from
Aug 16, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions usbdrv/asmcommon.inc
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,17 @@ handleData:
breq doReturn ;[21]
lds x2, usbRxLen ;[22]
tst x2 ;[24]
brne sendNakAndReti ;[25]
; 2020-05-04 Following change is used to overcome branch +/- 64 word limit.
breq noBranchSendNakAndReti ; [25]
rjmp sendNakAndReti
noBranchSendNakAndReti:
; 2006-03-11: The following two lines fix a problem where the device was not
; recognized if usbPoll() was called less frequently than once every 4 ms.
cpi cnt, 4 ;[26] zero sized data packets are status phase only -- ignore and ack
brmi sendAckAndReti ;[27] keep rx buffer clean -- we must not NAK next SETUP
; 2020-05-04 Following change is used to overcome branch +/- 64 word limit.
brpl noBranchSendAckAndReti ;[27] keep rx buffer clean -- we must not NAK next SETUP
rjmp sendAckAndReti
noBranchSendAckAndReti:
#if USB_CFG_CHECK_DATA_TOGGLING
sts usbCurrentDataToken, token ; store for checking by C code
#endif
Expand Down Expand Up @@ -165,6 +171,10 @@ handleIn1: ;[38]
; 2006-06-10 as suggested by O.Tamura: support second INTR IN / BULK IN endpoint
cpi x3, USB_CFG_EP3_NUMBER;[38]
breq handleIn3 ;[39]
#endif
#if USB_CFG_HAVE_INTRIN_ENDPOINT4
cpi x3, USB_CFG_EP4_NUMBER;[38]
breq handleIn4 ;[39]
#endif
lds cnt, usbTxLen1 ;[40]
sbrc cnt, 4 ;[42] all handshake tokens have bit 4 set
Expand All @@ -184,4 +194,16 @@ handleIn3:
ldi YH, hi8(usbTxBuf3) ;[48]
rjmp usbSendAndReti ;[49] 51 + 12 = 63 until SOP
#endif

#if USB_CFG_HAVE_INTRIN_ENDPOINT4
handleIn4:
lds cnt, usbTxLen4 ;[41]
sbrc cnt, 4 ;[43]
rjmp sendCntAndReti ;[44] 49 + 16 = 65 until SOP
sts usbTxLen4, x1 ;[45] x1 == USBPID_NAK from above
ldi YL, lo8(usbTxBuf4) ;[47]
ldi YH, hi8(usbTxBuf4) ;[48]
rjmp usbSendAndReti ;[49] 51 + 12 = 63 until SOP
#endif

#endif
20 changes: 15 additions & 5 deletions usbdrv/usbconfig-prototype.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,19 @@ section at the end of this file).
/* If the so-called endpoint 3 is used, it can now be configured to any other
* endpoint number (except 0) with this macro. Default if undefined is 3.
*/
#define USB_CFG_HAVE_INTRIN_ENDPOINT4 0
/* Define this to 1 if you want to compile a version with three endpoints: The
* default control endpoint 0, an interrupt-in endpoint 4 (or the number
* configured below) and a catch-all default interrupt-in endpoint as above.
* You must also define USB_CFG_HAVE_INTRIN_ENDPOINT to 1 for this feature.
*/
#define USB_CFG_EP4_NUMBER 4
/* If the so-called endpoint 4 is used, it can now be configured to any other
* endpoint number (except 0) with this macro. Default if undefined is 4.
*/
/* #define USB_INITIAL_DATATOKEN USBPID_DATA1 */
/* The above macro defines the startup condition for data toggling on the
* interrupt/bulk endpoints 1 and 3. Defaults to USBPID_DATA1.
* interrupt/bulk endpoints 1, 3 and 4. Defaults to USBPID_DATA1.
* Since the token is toggled BEFORE sending any data, the first packet is
* sent with the oposite value of this configuration!
*/
Expand All @@ -104,10 +114,10 @@ section at the end of this file).
#define USB_CFG_SUPPRESS_INTR_CODE 0
/* Define this to 1 if you want to declare interrupt-in endpoints, but don't
* want to send any data over them. If this macro is defined to 1, functions
* usbSetInterrupt() and usbSetInterrupt3() are omitted. This is useful if
* you need the interrupt-in endpoints in order to comply to an interface
* (e.g. HID), but never want to send any data. This option saves a couple
* of bytes in flash memory and the transmit buffers in RAM.
* usbSetInterrupt(), usbSetInterrupt3() and usbSetInterrupt4() are omitted.
* This is useful if you need the interrupt-in endpoints in order to comply
* to an interface (e.g. HID), but never want to send any data. This option
* saves a couple of bytes in flash memory and the transmit buffers in RAM.
*/
#define USB_CFG_INTR_POLL_INTERVAL 10
/* If you compile a version with endpoint 1 (interrupt-in), this is the poll
Expand Down
29 changes: 28 additions & 1 deletion usbdrv/usbdrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ usbTxStatus_t usbTxStatus1;
# if USB_CFG_HAVE_INTRIN_ENDPOINT3
usbTxStatus_t usbTxStatus3;
# endif
# if USB_CFG_HAVE_INTRIN_ENDPOINT4
usbTxStatus_t usbTxStatus4;
# endif
#endif
#if USB_CFG_CHECK_DATA_TOGGLING
uchar usbCurrentDataToken;/* when we check data toggling to ignore duplicate packets */
Expand Down Expand Up @@ -140,7 +143,7 @@ PROGMEM const char usbDescriptorConfiguration[] = { /* USB configuration desc
9, /* sizeof(usbDescriptorConfiguration): length of descriptor in bytes */
USBDESCR_CONFIG, /* descriptor type */
18 + 7 * USB_CFG_HAVE_INTRIN_ENDPOINT + 7 * USB_CFG_HAVE_INTRIN_ENDPOINT3 +
yiancar marked this conversation as resolved.
Show resolved Hide resolved
(USB_CFG_DESCR_PROPS_HID & 0xff), 0,
7 * USB_CFG_HAVE_INTRIN_ENDPOINT4 +(USB_CFG_DESCR_PROPS_HID & 0xff), 0,
yiancar marked this conversation as resolved.
Show resolved Hide resolved
/* total length of data returned (including inlined descriptors) */
1, /* number of interfaces in this configuration */
1, /* index of this configuration */
Expand Down Expand Up @@ -187,6 +190,14 @@ PROGMEM const char usbDescriptorConfiguration[] = { /* USB configuration desc
8, 0, /* maximum packet size */
USB_CFG_INTR_POLL_INTERVAL, /* in ms */
#endif
#if USB_CFG_HAVE_INTRIN_ENDPOINT4 /* endpoint descriptor for endpoint 3 */
yiancar marked this conversation as resolved.
Show resolved Hide resolved
7, /* sizeof(usbDescrEndpoint) */
USBDESCR_ENDPOINT, /* descriptor type = endpoint */
(char)(0x80 | USB_CFG_EP4_NUMBER), /* IN endpoint number 3 */
yiancar marked this conversation as resolved.
Show resolved Hide resolved
0x03, /* attrib: Interrupt endpoint */
8, 0, /* maximum packet size */
USB_CFG_INTR_POLL_INTERVAL, /* in ms */
#endif
};
#endif

Expand All @@ -199,6 +210,9 @@ static inline void usbResetDataToggling(void)
# if USB_CFG_HAVE_INTRIN_ENDPOINT3
USB_SET_DATATOKEN3(USB_INITIAL_DATATOKEN); /* reset data toggling for interrupt endpoint */
# endif
# if USB_CFG_HAVE_INTRIN_ENDPOINT4
USB_SET_DATATOKEN4(USB_INITIAL_DATATOKEN); /* reset data toggling for interrupt endpoint */
# endif
#endif
}

Expand All @@ -209,6 +223,9 @@ static inline void usbResetStall(void)
#if USB_CFG_HAVE_INTRIN_ENDPOINT3
usbTxLen3 = USBPID_NAK;
#endif
#if USB_CFG_HAVE_INTRIN_ENDPOINT4
usbTxLen4 = USBPID_NAK;
#endif
#endif
}

Expand Down Expand Up @@ -252,6 +269,13 @@ USB_PUBLIC void usbSetInterrupt3(uchar *data, uchar len)
usbGenericSetInterrupt(data, len, &usbTxStatus3);
}
#endif

#if USB_CFG_HAVE_INTRIN_ENDPOINT4
USB_PUBLIC void usbSetInterrupt4(uchar *data, uchar len)
{
usbGenericSetInterrupt(data, len, &usbTxStatus4);
}
#endif
#endif /* USB_CFG_SUPPRESS_INTR_CODE */

/* ------------------ utilities for code following below ------------------- */
Expand Down Expand Up @@ -628,6 +652,9 @@ USB_PUBLIC void usbInit(void)
#if USB_CFG_HAVE_INTRIN_ENDPOINT3
usbTxLen3 = USBPID_NAK;
#endif
#if USB_CFG_HAVE_INTRIN_ENDPOINT4
usbTxLen4 = USBPID_NAK;
#endif
#endif
}

Expand Down
20 changes: 18 additions & 2 deletions usbdrv/usbdrv.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ USB_PUBLIC void usbSetInterrupt3(uchar *data, uchar len);
#define usbInterruptIsReady3() (usbTxLen3 & 0x10)
/* Same as above for endpoint 3 */
#endif
#if USB_CFG_HAVE_INTRIN_ENDPOINT4
USB_PUBLIC void usbSetInterrupt4(uchar *data, uchar len);
#define usbInterruptIsReady4() (usbTxLen4 & 0x10)
/* Same as above for endpoint 4 */
#endif
#endif /* USB_CFG_HAVE_INTRIN_ENDPOINT */
#if USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH /* simplified interface for backward compatibility */
#define usbHidReportDescriptor usbDescriptorHidReport
Expand Down Expand Up @@ -408,8 +413,9 @@ extern volatile schar usbRxLen;

#define USB_SET_DATATOKEN1(token) usbTxBuf1[0] = token
#define USB_SET_DATATOKEN3(token) usbTxBuf3[0] = token
#define USB_SET_DATATOKEN4(token) usbTxBuf4[0] = token
/* These two macros can be used by application software to reset data toggling
* for interrupt-in endpoints 1 and 3. Since the token is toggled BEFORE
* for interrupt-in endpoints 1, 3 and 4. Since the token is toggled BEFORE
* sending data, you must set the opposite value of the token which should come
* first.
*/
Expand Down Expand Up @@ -592,10 +598,18 @@ int usbDescriptorStringSerialNumber[];
#define USB_CFG_EP3_NUMBER 3
#endif

#ifndef USB_CFG_EP4_NUMBER /* if not defined in usbconfig.h */
#define USB_CFG_EP4_NUMBER 4
#endif

#ifndef USB_CFG_HAVE_INTRIN_ENDPOINT3
#define USB_CFG_HAVE_INTRIN_ENDPOINT3 0
#endif

#ifndef USB_CFG_HAVE_INTRIN_ENDPOINT4
#define USB_CFG_HAVE_INTRIN_ENDPOINT4 0
#endif

#define USB_BUFSIZE 11 /* PID, 8 bytes data, 2 bytes CRC */

/* ----- Try to find registers and bits responsible for ext interrupt 0 ----- */
Expand Down Expand Up @@ -683,11 +697,13 @@ typedef struct usbTxStatus{
uchar buffer[USB_BUFSIZE];
}usbTxStatus_t;

extern usbTxStatus_t usbTxStatus1, usbTxStatus3;
extern usbTxStatus_t usbTxStatus1, usbTxStatus3, usbTxStatus4;
#define usbTxLen1 usbTxStatus1.len
#define usbTxBuf1 usbTxStatus1.buffer
#define usbTxLen3 usbTxStatus3.len
#define usbTxBuf3 usbTxStatus3.buffer
#define usbTxLen4 usbTxStatus4.len
#define usbTxBuf4 usbTxStatus4.buffer


typedef union usbWord{
Expand Down
12 changes: 7 additions & 5 deletions usbdrv/usbdrvasm.S
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ the file appropriate for the given clock rate.
#ifdef __IAR_SYSTEMS_ASM__
extern usbRxBuf, usbDeviceAddr, usbNewDeviceAddr, usbInputBufOffset
extern usbCurrentTok, usbRxLen, usbRxToken, usbTxLen
extern usbTxBuf, usbTxStatus1, usbTxStatus3
extern usbTxBuf, usbTxStatus1, usbTxStatus3, usbTxStatus4
# if USB_COUNT_SOF
extern usbSofCount
# endif
Expand Down Expand Up @@ -82,6 +82,8 @@ the file appropriate for the given clock rate.
#define usbTxBuf1 (usbTxStatus1 + 1)
#define usbTxLen3 usbTxStatus3
#define usbTxBuf3 (usbTxStatus3 + 1)
#define usbTxLen4 usbTxStatus4
#define usbTxBuf4 (usbTxStatus4 + 1)


;----------------------------------------------------------------------------
Expand Down Expand Up @@ -117,7 +119,7 @@ RTMODEL "__rt_version", "3"
# define polyH r21
# define scratch r23

#else /* __IAR_SYSTEMS_ASM__ */
#else /* __IAR_SYSTEMS_ASM__ */
yiancar marked this conversation as resolved.
Show resolved Hide resolved
/* Register assignments for usbCrc16 on gcc */
/* Calling conventions on gcc:
* First parameter passed in r24/r25, second in r22/23 and so on.
Expand Down Expand Up @@ -151,7 +153,7 @@ RTMODEL "__rt_version", "3"
; unsigned table(unsigned char x)
; {
; unsigned value;
;
;
yiancar marked this conversation as resolved.
Show resolved Hide resolved
; value = (unsigned)x << 6;
; value ^= (unsigned)x << 7;
; if(parity(x))
Expand All @@ -161,7 +163,7 @@ RTMODEL "__rt_version", "3"
; unsigned usbCrc16(unsigned char *argPtr, unsigned char argLen)
; {
; unsigned crc = 0xffff;
;
;
yiancar marked this conversation as resolved.
Show resolved Hide resolved
; while(argLen--)
; crc = table(lo8(crc) ^ *argPtr++) ^ hi8(crc);
; return ~crc;
Expand Down Expand Up @@ -293,7 +295,7 @@ usbCrc16Append:
# define cnt16H r31
# define cntH r18

#else /* __IAR_SYSTEMS_ASM__ */
#else /* __IAR_SYSTEMS_ASM__ */
yiancar marked this conversation as resolved.
Show resolved Hide resolved
/* Register assignments for usbMeasureFrameLength on gcc */
/* Calling conventions on gcc:
* First parameter passed in r24/r25, second in r22/23 and so on.
Expand Down