ps2.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright (c) 2019, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2019-08-26 sogwms The first version
  9. */
  10. #ifndef __PS2_H__
  11. #define __PS2_H__
  12. #include <rtthread.h>
  13. #include <rtdevice.h>
  14. #include "command.h"
  15. // COMMAND
  16. #define PS2_CMD_VIBRATE 1
  17. // MODE
  18. #define PS2_NO_MODE 0
  19. #define PS2_GREEN_MODE 0x41
  20. #define PS2_RED_MODE 0x73
  21. // BUTTON
  22. #define PS2_BTN_SELECT (1 << 0)
  23. #define PS2_BTN_L3 (1 << 1)
  24. #define PS2_BTN_R3 (1 << 2)
  25. #define PS2_BTN_START (1 << 3)
  26. #define PS2_BTN_UP (1 << 4)
  27. #define PS2_BTN_RIGHT (1 << 5)
  28. #define PS2_BTN_DOWN (1 << 6)
  29. #define PS2_BTN_LEFT (1 << 7)
  30. #define PS2_BTN_L2 (1 << 8)
  31. #define PS2_BTN_R2 (1 << 9)
  32. #define PS2_BTN_L1 (1 << 10)
  33. #define PS2_BTN_R1 (1 << 11)
  34. #define PS2_BTN_TRIANGLE (1 << 12)
  35. #define PS2_BTN_CICLE (1 << 13)
  36. #define PS2_BTN_FORK (1 << 14)
  37. #define PS2_BTN_SQUARE (1 << 15)
  38. #define PS2_ROCKER_LX (16)
  39. #define PS2_ROCKER_LY (17)
  40. #define PS2_ROCKER_RX (18)
  41. #define PS2_ROCKER_RY (19)
  42. typedef struct ps2_ctrl_data *ps2_ctrl_data_t;
  43. struct ps2_ctrl_data
  44. {
  45. uint16_t button; // 16
  46. uint8_t left_stick_x;
  47. uint8_t left_stick_y;
  48. uint8_t right_stick_x;
  49. uint8_t right_stick_y;
  50. };
  51. void ps2_init(rt_base_t cs_pin, rt_base_t clk_pin, rt_base_t do_pin, rt_base_t di_pin);
  52. int ps2_scan(ps2_ctrl_data_t pt);
  53. int ps2_read_light(void);
  54. command_sender_t ps2_get_sender(void);
  55. rt_err_t ps2_set_target(void *target);
  56. #endif