6161 * Later changes can be tracked in SCM.
6262 */
6363
64+ #include <linux/bits.h>
6465#include <linux/kernel.h>
6566#include <linux/input.h>
6667#include <linux/rcupdate.h>
@@ -709,10 +710,10 @@ static void xpad_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *d
709710 /* digital pad */
710711 if (xpad -> mapping & MAP_DPAD_TO_BUTTONS ) {
711712 /* dpad as buttons (left, right, up, down) */
712- input_report_key (dev , BTN_TRIGGER_HAPPY1 , data [2 ] & 0x04 );
713- input_report_key (dev , BTN_TRIGGER_HAPPY2 , data [2 ] & 0x08 );
714- input_report_key (dev , BTN_TRIGGER_HAPPY3 , data [2 ] & 0x01 );
715- input_report_key (dev , BTN_TRIGGER_HAPPY4 , data [2 ] & 0x02 );
713+ input_report_key (dev , BTN_TRIGGER_HAPPY1 , data [2 ] & BIT ( 2 ) );
714+ input_report_key (dev , BTN_TRIGGER_HAPPY2 , data [2 ] & BIT ( 3 ) );
715+ input_report_key (dev , BTN_TRIGGER_HAPPY3 , data [2 ] & BIT ( 0 ) );
716+ input_report_key (dev , BTN_TRIGGER_HAPPY4 , data [2 ] & BIT ( 1 ) );
716717 } else {
717718 input_report_abs (dev , ABS_HAT0X ,
718719 !!(data [2 ] & 0x08 ) - !!(data [2 ] & 0x04 ));
@@ -721,10 +722,10 @@ static void xpad_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *d
721722 }
722723
723724 /* start/back buttons and stick press left/right */
724- input_report_key (dev , BTN_START , data [2 ] & 0x10 );
725- input_report_key (dev , BTN_SELECT , data [2 ] & 0x20 );
726- input_report_key (dev , BTN_THUMBL , data [2 ] & 0x40 );
727- input_report_key (dev , BTN_THUMBR , data [2 ] & 0x80 );
725+ input_report_key (dev , BTN_START , data [2 ] & BIT ( 4 ) );
726+ input_report_key (dev , BTN_SELECT , data [2 ] & BIT ( 5 ) );
727+ input_report_key (dev , BTN_THUMBL , data [2 ] & BIT ( 6 ) );
728+ input_report_key (dev , BTN_THUMBR , data [2 ] & BIT ( 7 ) );
728729
729730 /* "analog" buttons A, B, X, Y */
730731 input_report_key (dev , BTN_A , data [4 ]);
@@ -759,10 +760,10 @@ static void xpad360_process_packet(struct usb_xpad *xpad, struct input_dev *dev,
759760 /* digital pad */
760761 if (xpad -> mapping & MAP_DPAD_TO_BUTTONS ) {
761762 /* dpad as buttons (left, right, up, down) */
762- input_report_key (dev , BTN_TRIGGER_HAPPY1 , data [2 ] & 0x04 );
763- input_report_key (dev , BTN_TRIGGER_HAPPY2 , data [2 ] & 0x08 );
764- input_report_key (dev , BTN_TRIGGER_HAPPY3 , data [2 ] & 0x01 );
765- input_report_key (dev , BTN_TRIGGER_HAPPY4 , data [2 ] & 0x02 );
763+ input_report_key (dev , BTN_TRIGGER_HAPPY1 , data [2 ] & BIT ( 2 ) );
764+ input_report_key (dev , BTN_TRIGGER_HAPPY2 , data [2 ] & BIT ( 3 ) );
765+ input_report_key (dev , BTN_TRIGGER_HAPPY3 , data [2 ] & BIT ( 0 ) );
766+ input_report_key (dev , BTN_TRIGGER_HAPPY4 , data [2 ] & BIT ( 1 ) );
766767 }
767768
768769 /*
@@ -780,21 +781,21 @@ static void xpad360_process_packet(struct usb_xpad *xpad, struct input_dev *dev,
780781 }
781782
782783 /* start/back buttons */
783- input_report_key (dev , BTN_START , data [2 ] & 0x10 );
784- input_report_key (dev , BTN_SELECT , data [2 ] & 0x20 );
784+ input_report_key (dev , BTN_START , data [2 ] & BIT ( 4 ) );
785+ input_report_key (dev , BTN_SELECT , data [2 ] & BIT ( 5 ) );
785786
786787 /* stick press left/right */
787- input_report_key (dev , BTN_THUMBL , data [2 ] & 0x40 );
788- input_report_key (dev , BTN_THUMBR , data [2 ] & 0x80 );
788+ input_report_key (dev , BTN_THUMBL , data [2 ] & BIT ( 6 ) );
789+ input_report_key (dev , BTN_THUMBR , data [2 ] & BIT ( 7 ) );
789790
790791 /* buttons A,B,X,Y,TL,TR and MODE */
791- input_report_key (dev , BTN_A , data [3 ] & 0x10 );
792- input_report_key (dev , BTN_B , data [3 ] & 0x20 );
793- input_report_key (dev , BTN_X , data [3 ] & 0x40 );
794- input_report_key (dev , BTN_Y , data [3 ] & 0x80 );
795- input_report_key (dev , BTN_TL , data [3 ] & 0x01 );
796- input_report_key (dev , BTN_TR , data [3 ] & 0x02 );
797- input_report_key (dev , BTN_MODE , data [3 ] & 0x04 );
792+ input_report_key (dev , BTN_A , data [3 ] & BIT ( 4 ) );
793+ input_report_key (dev , BTN_B , data [3 ] & BIT ( 5 ) );
794+ input_report_key (dev , BTN_X , data [3 ] & BIT ( 6 ) );
795+ input_report_key (dev , BTN_Y , data [3 ] & BIT ( 7 ) );
796+ input_report_key (dev , BTN_TL , data [3 ] & BIT ( 0 ) );
797+ input_report_key (dev , BTN_TR , data [3 ] & BIT ( 1 ) );
798+ input_report_key (dev , BTN_MODE , data [3 ] & BIT ( 2 ) );
798799
799800 if (!(xpad -> mapping & MAP_STICKS_TO_NULL )) {
800801 /* left stick */
@@ -832,7 +833,7 @@ static void xpad360_process_packet(struct usb_xpad *xpad, struct input_dev *dev,
832833 }
833834
834835 /* mode button down/up */
835- if (data [3 ] & 0x04 )
836+ if (data [3 ] & BIT ( 2 ) )
836837 xpad -> mode_btn_down_ts = ktime_get_seconds ();
837838 else
838839 xpad -> mode_btn_down_ts = 0 ;
@@ -928,7 +929,7 @@ static void xpadone_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char
928929 if (data [1 ] == 0x30 )
929930 xpadone_ack_mode_report (xpad , data [2 ]);
930931
931- input_report_key (dev , BTN_MODE , data [4 ] & 0x01 );
932+ input_report_key (dev , BTN_MODE , data [4 ] & BIT ( 0 ) );
932933
933934 do_sync = true;
934935 } else if (data [0 ] == 0X0C ) {
@@ -942,33 +943,33 @@ static void xpadone_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char
942943 data [18 ] = 0 ;
943944
944945 /* Elite Series 2 split packet paddle bits */
945- input_report_key (dev , BTN_TRIGGER_HAPPY5 , data [18 ] & 0x01 );
946- input_report_key (dev , BTN_TRIGGER_HAPPY6 , data [18 ] & 0x02 );
947- input_report_key (dev , BTN_TRIGGER_HAPPY7 , data [18 ] & 0x04 );
948- input_report_key (dev , BTN_TRIGGER_HAPPY8 , data [18 ] & 0x08 );
946+ input_report_key (dev , BTN_TRIGGER_HAPPY5 , data [18 ] & BIT ( 0 ) );
947+ input_report_key (dev , BTN_TRIGGER_HAPPY6 , data [18 ] & BIT ( 1 ) );
948+ input_report_key (dev , BTN_TRIGGER_HAPPY7 , data [18 ] & BIT ( 2 ) );
949+ input_report_key (dev , BTN_TRIGGER_HAPPY8 , data [18 ] & BIT ( 3 ) );
949950
950951 do_sync = true;
951952 }
952953 } else if (data [0 ] == 0X20 ) { /* The main valid packet type for inputs */
953954 /* menu/view buttons */
954- input_report_key (dev , BTN_START , data [4 ] & 0x04 );
955- input_report_key (dev , BTN_SELECT , data [4 ] & 0x08 );
955+ input_report_key (dev , BTN_START , data [4 ] & BIT ( 2 ) );
956+ input_report_key (dev , BTN_SELECT , data [4 ] & BIT ( 3 ) );
956957 if (xpad -> mapping & MAP_SELECT_BUTTON )
957- input_report_key (dev , KEY_RECORD , data [22 ] & 0x01 );
958+ input_report_key (dev , KEY_RECORD , data [22 ] & BIT ( 0 ) );
958959
959960 /* buttons A,B,X,Y */
960- input_report_key (dev , BTN_A , data [4 ] & 0x10 );
961- input_report_key (dev , BTN_B , data [4 ] & 0x20 );
962- input_report_key (dev , BTN_X , data [4 ] & 0x40 );
963- input_report_key (dev , BTN_Y , data [4 ] & 0x80 );
961+ input_report_key (dev , BTN_A , data [4 ] & BIT ( 4 ) );
962+ input_report_key (dev , BTN_B , data [4 ] & BIT ( 5 ) );
963+ input_report_key (dev , BTN_X , data [4 ] & BIT ( 6 ) );
964+ input_report_key (dev , BTN_Y , data [4 ] & BIT ( 7 ) );
964965
965966 /* digital pad */
966967 if (xpad -> mapping & MAP_DPAD_TO_BUTTONS ) {
967968 /* dpad as buttons (left, right, up, down) */
968- input_report_key (dev , BTN_TRIGGER_HAPPY1 , data [5 ] & 0x04 );
969- input_report_key (dev , BTN_TRIGGER_HAPPY2 , data [5 ] & 0x08 );
970- input_report_key (dev , BTN_TRIGGER_HAPPY3 , data [5 ] & 0x01 );
971- input_report_key (dev , BTN_TRIGGER_HAPPY4 , data [5 ] & 0x02 );
969+ input_report_key (dev , BTN_TRIGGER_HAPPY1 , data [5 ] & BIT ( 2 ) );
970+ input_report_key (dev , BTN_TRIGGER_HAPPY2 , data [5 ] & BIT ( 3 ) );
971+ input_report_key (dev , BTN_TRIGGER_HAPPY3 , data [5 ] & BIT ( 0 ) );
972+ input_report_key (dev , BTN_TRIGGER_HAPPY4 , data [5 ] & BIT ( 1 ) );
972973 } else {
973974 input_report_abs (dev , ABS_HAT0X ,
974975 !!(data [5 ] & 0x08 ) - !!(data [5 ] & 0x04 ));
@@ -977,12 +978,12 @@ static void xpadone_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char
977978 }
978979
979980 /* TL/TR */
980- input_report_key (dev , BTN_TL , data [5 ] & 0x10 );
981- input_report_key (dev , BTN_TR , data [5 ] & 0x20 );
981+ input_report_key (dev , BTN_TL , data [5 ] & BIT ( 4 ) );
982+ input_report_key (dev , BTN_TR , data [5 ] & BIT ( 5 ) );
982983
983984 /* stick press left/right */
984- input_report_key (dev , BTN_THUMBL , data [5 ] & 0x40 );
985- input_report_key (dev , BTN_THUMBR , data [5 ] & 0x80 );
985+ input_report_key (dev , BTN_THUMBL , data [5 ] & BIT ( 6 ) );
986+ input_report_key (dev , BTN_THUMBR , data [5 ] & BIT ( 7 ) );
986987
987988 if (!(xpad -> mapping & MAP_STICKS_TO_NULL )) {
988989 /* left stick */
@@ -1023,10 +1024,10 @@ static void xpadone_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char
10231024 data [32 ] = 0 ;
10241025
10251026 /* OG Elite Series Controller paddle bits */
1026- input_report_key (dev , BTN_TRIGGER_HAPPY5 , data [32 ] & 0x02 );
1027- input_report_key (dev , BTN_TRIGGER_HAPPY6 , data [32 ] & 0x08 );
1028- input_report_key (dev , BTN_TRIGGER_HAPPY7 , data [32 ] & 0x01 );
1029- input_report_key (dev , BTN_TRIGGER_HAPPY8 , data [32 ] & 0x04 );
1027+ input_report_key (dev , BTN_TRIGGER_HAPPY5 , data [32 ] & BIT ( 1 ) );
1028+ input_report_key (dev , BTN_TRIGGER_HAPPY6 , data [32 ] & BIT ( 3 ) );
1029+ input_report_key (dev , BTN_TRIGGER_HAPPY7 , data [32 ] & BIT ( 0 ) );
1030+ input_report_key (dev , BTN_TRIGGER_HAPPY8 , data [32 ] & BIT ( 2 ) );
10301031 } else if (xpad -> packet_type == PKT_XBE2_FW_OLD ) {
10311032 /* Mute paddles if controller has a custom mapping applied.
10321033 * Checked by comparing the current mapping
@@ -1036,10 +1037,10 @@ static void xpadone_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char
10361037 data [18 ] = 0 ;
10371038
10381039 /* Elite Series 2 4.x firmware paddle bits */
1039- input_report_key (dev , BTN_TRIGGER_HAPPY5 , data [18 ] & 0x01 );
1040- input_report_key (dev , BTN_TRIGGER_HAPPY6 , data [18 ] & 0x02 );
1041- input_report_key (dev , BTN_TRIGGER_HAPPY7 , data [18 ] & 0x04 );
1042- input_report_key (dev , BTN_TRIGGER_HAPPY8 , data [18 ] & 0x08 );
1040+ input_report_key (dev , BTN_TRIGGER_HAPPY5 , data [18 ] & BIT ( 0 ) );
1041+ input_report_key (dev , BTN_TRIGGER_HAPPY6 , data [18 ] & BIT ( 1 ) );
1042+ input_report_key (dev , BTN_TRIGGER_HAPPY7 , data [18 ] & BIT ( 2 ) );
1043+ input_report_key (dev , BTN_TRIGGER_HAPPY8 , data [18 ] & BIT ( 3 ) );
10431044 } else if (xpad -> packet_type == PKT_XBE2_FW_5_EARLY ) {
10441045 /* Mute paddles if controller has a custom mapping applied.
10451046 * Checked by comparing the current mapping
@@ -1051,10 +1052,10 @@ static void xpadone_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char
10511052 /* Elite Series 2 5.x firmware paddle bits
10521053 * (before the packet was split)
10531054 */
1054- input_report_key (dev , BTN_TRIGGER_HAPPY5 , data [22 ] & 0x01 );
1055- input_report_key (dev , BTN_TRIGGER_HAPPY6 , data [22 ] & 0x02 );
1056- input_report_key (dev , BTN_TRIGGER_HAPPY7 , data [22 ] & 0x04 );
1057- input_report_key (dev , BTN_TRIGGER_HAPPY8 , data [22 ] & 0x08 );
1055+ input_report_key (dev , BTN_TRIGGER_HAPPY5 , data [22 ] & BIT ( 0 ) );
1056+ input_report_key (dev , BTN_TRIGGER_HAPPY6 , data [22 ] & BIT ( 1 ) );
1057+ input_report_key (dev , BTN_TRIGGER_HAPPY7 , data [22 ] & BIT ( 2 ) );
1058+ input_report_key (dev , BTN_TRIGGER_HAPPY8 , data [22 ] & BIT ( 3 ) );
10581059 }
10591060 }
10601061
0 commit comments