Hanna
Sourcecode Kontrollplatine
usb_ep.h
gehe zur Dokumentation dieser Datei
1 
15 #ifndef _USB_EP_H
16 #define _USB_EP_H
17 
18 #include "usb_defaults.h"
19 
20 // Callback for incomming data from usb (host to device).
21 // this functions have to handle the databuffer pointet with the void-ptr
22 // the data-len is given in le;
23 // return-value not used (return 0)
24 
25 // callback for outgoing data to usb (device to host).
26 // this functions have to handle the databuffer pointer with the void-ptr
27 // the data-max-len is given in le; it has to return the len of data in buffer
28 // if nothing to send, return 0
29 
30 typedef unsigned int (*USBDataCallback) ( void *, unsigned int ); // pointer to Callback-Function
31 
32 typedef struct ep_data
33 {
34  unsigned char ep;
35  unsigned char type;
36  unsigned char bank;
37  unsigned char *buf;
38  unsigned int len;
39 
40  USBDataCallback handler;
41 
42 } EP_data;
43 
44 #define USB_EP_size_to_gc(x) ((x <= 8 )?USB_EP_BUFSIZE_8_gc:\
45  (x <= 16 )?USB_EP_BUFSIZE_16_gc:\
46  (x <= 32 )?USB_EP_BUFSIZE_32_gc:\
47  (x <= 64 )?USB_EP_BUFSIZE_64_gc:\
48  (x <= 128 )?USB_EP_BUFSIZE_128_gc:\
49  (x <= 256 )?USB_EP_BUFSIZE_256_gc:\
50  (x <= 512 )?USB_EP_BUFSIZE_512_gc:\
51  USB_EP_BUFSIZE_1023_gc)
52 
53 #define USB_EP_IN 0x80
54 
55 // Flag in the endpoint address to indicate that the endpoint should use
56 // PingPong (double buffer) mode. This is not actually part of the endpoint
57 // address as seen by the host. If PP is enabled, this flag needs to be part
58 // of the address passed to all USB_EP_* functions.
59 #define USB_EP_PP 0x40
60 
61 extern USB_Request_Header_t USB_ControlRequest;
62 
63 typedef union USB_EP_pair
64 {
65  union
66  {
67  struct
68  {
69  USB_EP_t out;
70  USB_EP_t in;
71  };
72  USB_EP_t ep[2];
73  };
75 
76 #define EP_DEF(NAME, EPNO, TYPE, PACKET_SIZE,HANDLER) \
77  extern unsigned char NAME##_buf[((EPNO)&USB_EP_PP)?PACKET_SIZE*2:PACKET_SIZE ]; \
78  extern EP_data NAME##_data; \
79  unsigned char NAME##_buf[((EPNO)&USB_EP_PP)?PACKET_SIZE*2:PACKET_SIZE ]; \
80  EP_data NAME##_data = { \
81  .ep = (EPNO), \
82  .type = (TYPE), \
83  .bank = 0, \
84  .buf = NAME##_buf, \
85  .len = PACKET_SIZE, \
86  .handler = HANDLER, \
87  };
88 
89 #define EP_DEF_init(NAME) ep_def_init(&(NAME##_data))
90 #define EP_DEF_init_buffer(NAME) ep_def_init_buffer(&(NAME##_data))
91 #define EP_DEF_in(NAME) ep_def_in(&(NAME##_data))
92 #define EP_DEF_out(NAME) ep_def_out(&(NAME##_data))
93 
94 #define EP_NOTE_IDLE 0
95 #define EP_NOTE_SET_DCD 1
96 #define EP_NOTE_CLR_DCD 2
97 #define EP_NOTE_SEND 0x80
98 
99 extern uint8_t ep0_buf_in[USB_DEF_EP0_SIZE];
100 extern uint8_t ep0_buf_out[USB_DEF_EP0_SIZE];
101 extern USB_EP_pair_t endpoints[USB_DEF_EP_MAX];
102 
104 // endpoint-prototypes
106 void ep_def_init_buffer ( EP_data *p );
107 void ep_def_init ( EP_data *p );
108 void ep_def_in ( EP_data *p );
109 void ep_def_out ( EP_data *p );
110 
111 #endif
Bibliothek zur USB-Kommunikation von Jürgen W.
Definition: usb_ep.h:32