Rev Author Line No. Line
3331 kaklik 1 // ======================================================================
2 // Common definitions for the USB driver
3 //
4 // Copyright (C) 2006 Dick Streefland
5 //
6 // This is free software, licensed under the terms of the GNU General
7 // Public License as published by the Free Software Foundation.
8 // ======================================================================
9  
10 #ifdef __ASSEMBLER__
11 #define __SFR_OFFSET 0
12 #endif
13 #include <avr/io.h>
14 #include "usbtiny.h"
15  
16 // Preprocessor magic
17 #define CAT2(a,b) CAT2EXP(a, b)
18 #define CAT2EXP(a,b) a ## b
19 #define CAT3(a,b,c) CAT3EXP(a, b, c)
20 #define CAT3EXP(a,b,c) a ## b ## c
21  
22 // I/O Ports
23 #define USB_IN CAT2(PIN, USBTINY_PORT)
24 #define USB_OUT CAT2(PORT, USBTINY_PORT)
25 #define USB_DDR CAT2(DDR, USBTINY_PORT)
26  
27 // I/O bit masks
28 #define USB_MASK_DMINUS (1 << (USBTINY_DMINUS))
29 #define USB_MASK_DPLUS (1 << (USBTINY_DPLUS))
30 #define USB_MASK (USB_MASK_DMINUS | USB_MASK_DPLUS)
31  
32 // Interrupt configuration
33 #if defined EICRA
34 # define USB_INT_CONFIG EICRA
35 #else
36 # define USB_INT_CONFIG MCUCR
37 #endif
38 #define USB_INT_CONFIG_SET ((1 << CAT3(ISC,USBTINY_INT,1)) | (1 << CAT3(ISC,USBTINY_INT,0)))
39 #if defined SIG_INT0
40 # define USB_INT_VECTOR CAT2(SIG_INT, USBTINY_INT)
41 #else
42 # define USB_INT_VECTOR CAT2(SIG_INTERRUPT, USBTINY_INT)
43 #endif
44  
45 // Interrupt enable
46 #if defined GIMSK
47 # define USB_INT_ENABLE GIMSK
48 #elif defined EIMSK
49 # define USB_INT_ENABLE EIMSK
50 #else
51 # define USB_INT_ENABLE GICR
52 #endif
53 #define USB_INT_ENABLE_BIT CAT2(INT,USBTINY_INT)
54  
55 // Interrupt pending bit
56 #if defined EIFR
57 # define USB_INT_PENDING EIFR
58 #else
59 # define USB_INT_PENDING GIFR
60 #endif
61 #define USB_INT_PENDING_BIT CAT2(INTF,USBTINY_INT)
62  
63 // USB PID values
64 #define USB_PID_SETUP 0x2d
65 #define USB_PID_OUT 0xe1
66 #define USB_PID_IN 0x69
67 #define USB_PID_DATA0 0xc3
68 #define USB_PID_DATA1 0x4b
69 #define USB_PID_ACK 0xd2
70 #define USB_PID_NAK 0x5a
71 #define USB_PID_STALL 0x1e
72  
73 // Various constants
74 #define USB_BUFSIZE 11 // PID + data + CRC