Tag for the LUFA-120730-BETA release.
[pub/USBasp.git] / Demos / Device / Incomplete / TestAndMeasurement / TestAndMeasurement.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2012.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7 */
8
9 /*
10 Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
20
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
28 this software.
29 */
30
31 #ifndef _TESTANDMEASUREMENT_H_
32 #define _TESTANDMEASUREMENT_H_
33
34 /* Includes: */
35 #include <avr/io.h>
36 #include <avr/wdt.h>
37 #include <avr/power.h>
38 #include <avr/interrupt.h>
39
40 #include "Descriptors.h"
41
42 #include <LUFA/Drivers/USB/USB.h>
43 #include <LUFA/Drivers/Board/LEDs.h>
44
45 /* Macros: */
46 /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */
47 #define LEDMASK_USB_NOTREADY LEDS_LED1
48
49 /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */
50 #define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3)
51
52 /** LED mask for the library LED driver, to indicate that the USB interface is ready. */
53 #define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4)
54
55 /** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */
56 #define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3)
57
58 /** LED mask for the library LED driver, to indicate that the USB interface is busy. */
59 #define LEDMASK_USB_BUSY LEDS_LED2
60
61 #define Req_InitiateAbortBulkOut 0x01
62 #define Req_CheckAbortBulkOutStatus 0x02
63 #define Req_InitiateAbortBulkIn 0x03
64 #define Req_CheckAbortBulkInStatus 0x04
65 #define Req_InitiateClear 0x05
66 #define Req_CheckClearStatus 0x06
67 #define Req_GetCapabilities 0x07
68 #define Req_IndicatorPulse 0x40
69
70 #define TMC_STATUS_SUCCESS 0x01
71 #define TMC_STATUS_PENDING 0x02
72 #define TMC_STATUS_FAILED 0x80
73 #define TMC_STATUS_TRANSFER_NOT_IN_PROGRESS 0x81
74 #define TMC_STATUS_SPLIT_NOT_IN_PROGRESS 0x82
75 #define TMC_STATUS_SPLIT_IN_PROGRESS 0x83
76
77 #define TMC_MESSAGEID_DEV_DEP_MSG_OUT 0x01
78 #define TMC_MESSAGEID_DEV_DEP_MSG_IN 0x02
79 #define TMC_MESSAGEID_DEV_VENDOR_OUT 0x7E
80 #define TMC_MESSAGEID_DEV_VENDOR_IN 0x7F
81
82 /* Type Defines */
83 typedef struct
84 {
85 uint8_t Status;
86 uint8_t Reserved;
87
88 uint16_t TMCVersion;
89
90 struct
91 {
92 unsigned ListenOnly : 1;
93 unsigned TalkOnly : 1;
94 unsigned PulseIndicateSupported : 1;
95 unsigned Reserved : 5;
96 } Interface;
97
98 struct
99 {
100 unsigned SupportsAbortINOnMatch : 1;
101 unsigned Reserved : 7;
102 } Device;
103
104 uint8_t Reserved2[6];
105 uint8_t Reserved3[12];
106 } TMC_Capabilities_t;
107
108 typedef struct
109 {
110 uint8_t LastMessageTransaction;
111 uint8_t TermChar;
112 uint8_t Reserved[2];
113 } TMC_DevOUTMessageHeader_t;
114
115 typedef struct
116 {
117 uint8_t LastMessageTransaction;
118 uint8_t Reserved[3];
119 } TMC_DevINMessageHeader_t;
120
121 typedef struct
122 {
123 uint8_t MessageID;
124 uint8_t Tag;
125 uint8_t InverseTag;
126 uint8_t Reserved;
127 uint32_t TransferSize;
128
129 union
130 {
131 TMC_DevOUTMessageHeader_t DeviceOUT;
132 TMC_DevINMessageHeader_t DeviceIN;
133 uint32_t VendorSpecific;
134 } MessageIDSpecific;
135 } TMC_MessageHeader_t;
136
137 /* Function Prototypes: */
138 void SetupHardware(void);
139 void TMC_Task(void);
140 bool ReadTMCHeader(TMC_MessageHeader_t* const MessageHeader);
141 bool WriteTMCHeader(TMC_MessageHeader_t* const MessageHeader);
142
143 void EVENT_USB_Device_Connect(void);
144 void EVENT_USB_Device_Disconnect(void);
145 void EVENT_USB_Device_ConfigurationChanged(void);
146 void EVENT_USB_Device_ControlRequest(void);
147
148 #endif
149