adb.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. Copyright 2011-19 Jun WAKO <wakojun@gmail.com>
  3. This software is licensed with a Modified BSD License.
  4. All of this is supposed to be Free Software, Open Source, DFSG-free,
  5. GPL-compatible, and OK to use in both free and proprietary applications.
  6. Additions and corrections to this file are welcome.
  7. Redistribution and use in source and binary forms, with or without
  8. modification, are permitted provided that the following conditions are met:
  9. * Redistributions of source code must retain the above copyright
  10. notice, this list of conditions and the following disclaimer.
  11. * Redistributions in binary form must reproduce the above copyright
  12. notice, this list of conditions and the following disclaimer in
  13. the documentation and/or other materials provided with the
  14. distribution.
  15. * Neither the name of the copyright holders nor the names of
  16. contributors may be used to endorse or promote products derived
  17. from this software without specific prior written permission.
  18. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  22. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  23. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  24. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  25. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  26. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #pragma once
  31. #include <stdint.h>
  32. #include <stdbool.h>
  33. #if !(defined(ADB_PORT) && defined(ADB_PIN) && defined(ADB_DDR) && defined(ADB_DATA_BIT))
  34. # error "ADB port setting is required in config.h"
  35. #endif
  36. #define ADB_POWER 0x7F
  37. #define ADB_CAPS 0x39
  38. /* ADB commands */
  39. // Default Address
  40. #define ADB_ADDR_0 0
  41. #define ADB_ADDR_DONGLE 1
  42. #define ADB_ADDR_KEYBOARD 2
  43. #define ADB_ADDR_MOUSE 3
  44. #define ADB_ADDR_TABLET 4
  45. #define ADB_ADDR_APPLIANCE 7
  46. #define ADB_ADDR_8 8
  47. #define ADB_ADDR_9 9
  48. #define ADB_ADDR_10 10
  49. #define ADB_ADDR_11 11
  50. #define ADB_ADDR_12 12
  51. #define ADB_ADDR_13 13
  52. #define ADB_ADDR_14 14
  53. #define ADB_ADDR_15 15
  54. // for temporary purpose, do not use for polling
  55. #define ADB_ADDR_TMP 15
  56. #define ADB_ADDR_MOUSE_POLL 10
  57. // Command Type
  58. #define ADB_CMD_RESET 0
  59. #define ADB_CMD_FLUSH 1
  60. #define ADB_CMD_LISTEN 8
  61. #define ADB_CMD_TALK 12
  62. // Register
  63. #define ADB_REG_0 0
  64. #define ADB_REG_1 1
  65. #define ADB_REG_2 2
  66. #define ADB_REG_3 3
  67. /* ADB keyboard handler id */
  68. #define ADB_HANDLER_STD 0x01 /* IIGS, M0116 */
  69. #define ADB_HANDLER_AEK 0x02 /* M0115, M3501 */
  70. #define ADB_HANDLER_AEK_RMOD 0x03 /* M0115, M3501, alternate mode enableing right modifiers */
  71. #define ADB_HANDLER_STD_ISO 0x04 /* M0118, ISO swapping keys */
  72. #define ADB_HANDLER_AEK_ISO 0x05 /* M0115, M3501, ISO swapping keys */
  73. #define ADB_HANDLER_M1242_ANSI 0x10 /* Adjustable keyboard */
  74. #define ADB_HANDLER_CLASSIC1_MOUSE 0x01
  75. #define ADB_HANDLER_CLASSIC2_MOUSE 0x02
  76. #define ADB_HANDLER_EXTENDED_MOUSE 0x04
  77. #define ADB_HANDLER_TURBO_MOUSE 0x32
  78. // ADB host
  79. void adb_host_init(void);
  80. bool adb_host_psw(void);
  81. uint16_t adb_host_talk(uint8_t addr, uint8_t reg);
  82. uint8_t adb_host_talk_buf(uint8_t addr, uint8_t reg, uint8_t *buf, uint8_t len);
  83. void adb_host_listen(uint8_t addr, uint8_t reg, uint8_t data_h, uint8_t data_l);
  84. void adb_host_listen_buf(uint8_t addr, uint8_t reg, uint8_t *buf, uint8_t len);
  85. void adb_host_flush(uint8_t addr);
  86. void adb_host_kbd_led(uint8_t led);
  87. uint16_t adb_host_kbd_recv(void);
  88. uint16_t adb_host_mouse_recv(void);
  89. // ADB Mouse
  90. void adb_mouse_task(void);
  91. void adb_mouse_init(void);