TestAndMeasurement.h 4.6 KB

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