ps2.h
 1  #ifndef __PS2_H
 2  #define __PS2_H
 3  
 4  #include <stdio.h>
 5  #include <stdint.h>
 6  
 7  /* clang-format off */
 8  #define CTRL_CLK        10
 9  #define CTRL_CLK_HIGH   10
10  #define CTRL_BYTE_DELAY 5
11  
12  //These are our button constants
13  #define PSB_SELECT      0x0001
14  #define PSB_L3          0x0002
15  #define PSB_R3          0x0004
16  #define PSB_START       0x0008
17  #define PSB_PAD_UP      0x0010
18  #define PSB_PAD_RIGHT   0x0020
19  #define PSB_PAD_DOWN    0x0040
20  #define PSB_PAD_LEFT    0x0080
21  #define PSB_L2          0x0100
22  #define PSB_R2          0x0200
23  #define PSB_L1          0x0400
24  #define PSB_R1          0x0800
25  #define PSB_GREEN       0x1000
26  #define PSB_RED         0x2000
27  #define PSB_BLUE        0x4000
28  #define PSB_PINK        0x8000
29  #define PSB_TRIANGLE    0x1000
30  #define PSB_CIRCLE      0x2000
31  #define PSB_CROSS       0x4000
32  #define PSB_SQUARE      0x8000
33  
34  //Guitar  button constants
35  #define UP_STRUM		0x0010
36  #define DOWN_STRUM		0x0040
37  #define STAR_POWER		0x0100
38  #define GREEN_FRET		0x0200
39  #define YELLOW_FRET		0x1000
40  #define RED_FRET		0x2000
41  #define BLUE_FRET		0x4000
42  #define ORANGE_FRET		0x8000
43  #define WHAMMY_BAR		8
44  
45  //These are stick values
46  #define PSS_RX 5
47  #define PSS_RY 6
48  #define PSS_LX 7
49  #define PSS_LY 8
50  
51  //These are analog buttons
52  #define PSAB_PAD_RIGHT    9
53  #define PSAB_PAD_UP      11
54  #define PSAB_PAD_DOWN    12
55  #define PSAB_PAD_LEFT    10
56  #define PSAB_L2          19
57  #define PSAB_R2          20
58  #define PSAB_L1          17
59  #define PSAB_R1          18
60  #define PSAB_GREEN       13
61  #define PSAB_RED         14
62  #define PSAB_BLUE        15
63  #define PSAB_PINK        16
64  #define PSAB_TRIANGLE    13
65  #define PSAB_CIRCLE      14
66  #define PSAB_CROSS       15
67  #define PSAB_SQUARE      16
68  
69  #define SET(x, y) (x |= (1 << y))
70  #define CLR(x, y) (x &= (~(1 << y)))
71  #define CHK(x, y) (x & (1 << y))
72  #define TOG(x, y) (x ^= (1 << y))
73  
74  /* clang-format on */
75  uint8_t PS2X_Button(uint16_t button);
76  uint8_t PS2X_Analog(uint8_t button);
77  void PS2X_confg_io(uint8_t cs, uint8_t clk, uint8_t mosi, uint8_t miso);
78  uint8_t PS2X_read_gamepad(uint8_t motor1, uint8_t motor2);
79  uint8_t PS2X_config_gamepad(uint8_t pressures, uint8_t rumble);
80  uint8_t PS2X_readType(void);
81  void PS2X_enableRumble(void);
82  void PS2X_enableRumble(void);
83  void PS2X_reconfig_gamepad(void);
84  
85  #endif