USB Host Shield 2.0
Loading...
Searching...
No Matches
PS4USB.h
Go to the documentation of this file.
1/* Copyright (C) 2014 Kristian Lauszus, TKJ Electronics. All rights reserved.
2
3 This software may be distributed and modified under the terms of the GNU
4 General Public License version 2 (GPL2) as published by the Free Software
5 Foundation and appearing in the file GPL2.TXT included in the packaging of
6 this file. Please note that GPL2 Section 2[b] requires that all works based
7 on this software must also be made publicly available under the terms of
8 the GPL2 ("Copyleft").
9
10 Contact information
11 -------------------
12
13 Kristian Lauszus, TKJ Electronics
14 Web : http://www.tkjelectronics.com
15 e-mail : kristianl@tkjelectronics.com
16 */
17
18#ifndef _ps4usb_h_
19#define _ps4usb_h_
20
21#include "hiduniversal.h"
22#include "PS4Parser.h"
23
24#define PS4_VID 0x054C // Sony Corporation
25#define PS4_PID 0x05C4 // PS4 Controller
26#define PS4_PID_SLIM 0x09CC // PS4 Slim Controller
27
32class PS4USB : public HIDUniversal, public PS4Parser {
33public:
41 };
42
50
55 void attachOnInit(void (*funcOnInit)(void)) {
56 pFuncOnInit = funcOnInit;
57 };
58
59protected:
72
81 if (pFuncOnInit)
82 pFuncOnInit(); // Call the user function
83 else
84 setLed(Blue);
85 };
86 return 0;
87 };
91 virtual void sendOutputReport(PS4Output *output) { // Source: https://github.com/chrippa/ds4drv
92 uint8_t buf[32];
93 memset(buf, 0, sizeof(buf));
94
95 buf[0] = 0x05; // Report ID
96 buf[1]= 0xFF;
97
98 buf[4] = output->smallRumble; // Small Rumble
99 buf[5] = output->bigRumble; // Big rumble
100
101 buf[6] = output->r; // Red
102 buf[7] = output->g; // Green
103 buf[8] = output->b; // Blue
104
105 buf[9] = output->flashOn; // Time to flash bright (255 = 2.5 seconds)
106 buf[10] = output->flashOff; // Time to flash dark (255 = 2.5 seconds)
107
108 output->reportChanged = false;
109
110 // The PS4 console actually set the four last bytes to a CRC32 checksum, but it seems like it is actually not needed
111
113 };
123 virtual bool VIDPIDOK(uint16_t vid, uint16_t pid) {
124 return (vid == PS4_VID && (pid == PS4_PID || HIDUniversal::PID == PS4_PID_SLIM));
125 };
128private:
129 void (*pFuncOnInit)(void); // Pointer to function called in onInit()
130};
131#endif
@ Blue
Definition AMBXEnums.h:24
#define PS4_PID
Definition PS4USB.h:25
#define PS4_PID_SLIM
Definition PS4USB.h:26
#define PS4_VID
Definition PS4USB.h:24
uint16_t PID
virtual bool isReady()
EpInfo epInfo[totalEndpoints]
uint16_t VID
void Reset()
void setLed(uint8_t r, uint8_t g, uint8_t b)
Definition PS4Parser.h:320
void Parse(uint8_t len, uint8_t *buf)
Definition PS4Parser.cpp:85
PS4USB(USB *p)
Definition PS4USB.h:38
bool connected()
Definition PS4USB.h:47
virtual uint8_t OnInitSuccessful()
Definition PS4USB.h:78
virtual void sendOutputReport(PS4Output *output)
Definition PS4USB.h:91
virtual void ParseHIDData(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
Definition PS4USB.h:68
virtual bool VIDPIDOK(uint16_t vid, uint16_t pid)
Definition PS4USB.h:123
void attachOnInit(void(*funcOnInit)(void))
Definition PS4USB.h:55
uint8_t bAddress
Definition usbhid.h:146
USB * pUsb
Definition usbhid.h:145
static const uint8_t epInterruptOutIndex
Definition usbhid.h:150
Definition UsbCore.h:220
uint8_t outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *data)
Definition Usb.cpp:303