lufa.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Copyright 2012 Jun Wako <wakojun@gmail.com>
  3. * This file is based on:
  4. * LUFA-120219/Demos/Device/Lowlevel/KeyboardMouse
  5. * LUFA-120219/Demos/Device/Lowlevel/GenericHID
  6. */
  7. /*
  8. LUFA Library
  9. Copyright (C) Dean Camera, 2012.
  10. dean [at] fourwalledcubicle [dot] com
  11. www.lufa-lib.org
  12. */
  13. /*
  14. Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)
  15. Copyright 2010 Denver Gingerich (denver [at] ossguy [dot] com)
  16. Permission to use, copy, modify, distribute, and sell this
  17. software and its documentation for any purpose is hereby granted
  18. without fee, provided that the above copyright notice appear in
  19. all copies and that both that the copyright notice and this
  20. permission notice and warranty disclaimer appear in supporting
  21. documentation, and that the name of the author not be used in
  22. advertising or publicity pertaining to distribution of the
  23. software without specific, written prior permission.
  24. The author disclaim all warranties with regard to this
  25. software, including all implied warranties of merchantability
  26. and fitness. In no event shall the author be liable for any
  27. special, indirect or consequential damages or any damages
  28. whatsoever resulting from loss of use, data or profits, whether
  29. in an action of contract, negligence or other tortious action,
  30. arising out of or in connection with the use or performance of
  31. this software.
  32. */
  33. #ifndef _LUFA_H_
  34. #define _LUFA_H_
  35. #include <avr/io.h>
  36. #include <avr/wdt.h>
  37. #include <avr/power.h>
  38. #include <avr/interrupt.h>
  39. #include <stdbool.h>
  40. #include <string.h>
  41. #include <LUFA/Version.h>
  42. #include <LUFA/Drivers/USB/USB.h>
  43. #include "host.h"
  44. #ifdef MIDI_ENABLE
  45. #include "midi.h"
  46. #endif
  47. #ifdef __cplusplus
  48. extern "C" {
  49. #endif
  50. extern host_driver_t lufa_driver;
  51. #ifdef __cplusplus
  52. }
  53. #endif
  54. /* extra report structure */
  55. typedef struct {
  56. uint8_t report_id;
  57. uint16_t usage;
  58. } __attribute__ ((packed)) report_extra_t;
  59. #ifdef MIDI_ENABLE
  60. #define MIDI_SYSEX_BUFFER 16
  61. void MIDI_Task(void);
  62. MidiDevice midi_device;
  63. void sysex_callback(MidiDevice * device, uint16_t start, uint8_t length, uint8_t * data);
  64. void sysex_buffer_callback(MidiDevice * device, uint8_t length, uint8_t * data);
  65. void send_bytes_sysex(uint8_t message_type, uint8_t data_type, uint8_t * bytes, uint8_t length);
  66. void dword_to_bytes(uint32_t dword, uint8_t * bytes);
  67. uint32_t bytes_to_dword(uint8_t * bytes, uint8_t index);
  68. __attribute__ ((weak))
  69. bool sysex_process_quantum(uint8_t length, uint8_t * data);
  70. __attribute__ ((weak))
  71. bool sysex_process_keyboard(uint8_t length, uint8_t * data);
  72. __attribute__ ((weak))
  73. bool sysex_process_user(uint8_t length, uint8_t * data);
  74. enum MESSAGE_TYPE {
  75. MT_GET_DATA = 0x10, // Get data from keyboard
  76. MT_GET_DATA_ACK = 0x11, // returned data to process (ACK)
  77. MT_SET_DATA = 0x20, // Set data on keyboard
  78. MT_SET_DATA_ACK = 0x21, // returned data to confirm (ACK)
  79. MT_SEND_DATA = 0x30, // Sending data/action from keyboard
  80. MT_SEND_DATA_ACK = 0x31, // returned data/action confirmation (ACK)
  81. MT_EXE_ACTION = 0x40, // executing actions on keyboard
  82. MT_EXE_ACTION_ACK =0x41, // return confirmation/value (ACK)
  83. MT_TYPE_ERROR = 0x80 // type not recofgnised (ACK)
  84. };
  85. enum DATA_TYPE {
  86. DT_NONE = 0x00,
  87. DT_HANDSHAKE,
  88. DT_DEFAULT_LAYER,
  89. DT_CURRENT_LAYER,
  90. DT_KEYMAP_OPTIONS,
  91. DT_BACKLIGHT,
  92. DT_RGBLIGHT,
  93. DT_UNICODE,
  94. DT_DEBUG,
  95. DT_AUDIO,
  96. DT_QUANTUM_ACTION,
  97. DT_KEYBOARD_ACTION,
  98. DT_USER_ACTION,
  99. };
  100. #define MT_GET_DATA(data_type, data, length) send_bytes_sysex(MT_GET_DATA, data_type, data, length)
  101. #define MT_GET_DATA_ACK(data_type, data, length) send_bytes_sysex(MT_GET_DATA_ACK, data_type, data, length)
  102. #define MT_SET_DATA(data_type, data, length) send_bytes_sysex(MT_SET_DATA, data_type, data, length)
  103. #define MT_SET_DATA_ACK(data_type, data, length) send_bytes_sysex(MT_SET_DATA_ACK, data_type, data, length)
  104. #define MT_SEND_DATA(data_type, data, length) send_bytes_sysex(MT_SEND_DATA, data_type, data, length)
  105. #define MT_SEND_DATA_ACK(data_type, data, length) send_bytes_sysex(MT_SEND_DATA_ACK, data_type, data, length)
  106. #define MT_EXE_ACTION(data_type, data, length) send_bytes_sysex(MT_EXE_ACTION, data_type, data, length)
  107. #define MT_EXE_ACTION_ACK(data_type, data, length) send_bytes_sysex(MT_EXE_ACTION_ACK, data_type, data, length)
  108. #endif
  109. // #if LUFA_VERSION_INTEGER < 0x120730
  110. // /* old API 120219 */
  111. // #define ENDPOINT_CONFIG(epnum, eptype, epdir, epsize, epbank) Endpoint_ConfigureEndpoint(epnum, eptype, epdir, epsize, epbank)
  112. // #else
  113. /* new API >= 120730 */
  114. #define ENDPOINT_BANK_SINGLE 1
  115. #define ENDPOINT_BANK_DOUBLE 2
  116. #define ENDPOINT_CONFIG(epnum, eptype, epdir, epsize, epbank) Endpoint_ConfigureEndpoint((epdir) | (epnum) , eptype, epsize, epbank)
  117. // #endif
  118. #endif