Dependencies:   FATFileSystem

Committer:
nhiro3303
Date:
Tue Aug 22 06:18:15 2017 +0000
Revision:
0:42b8e1bc6235
ps3 test library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nhiro3303 0:42b8e1bc6235 1 /* mbed USBHost Library
nhiro3303 0:42b8e1bc6235 2 * Copyright (c) 2006-2013 ARM Limited
nhiro3303 0:42b8e1bc6235 3 *
nhiro3303 0:42b8e1bc6235 4 * Licensed under the Apache License, Version 2.0 (the "License");
nhiro3303 0:42b8e1bc6235 5 * you may not use this file except in compliance with the License.
nhiro3303 0:42b8e1bc6235 6 * You may obtain a copy of the License at
nhiro3303 0:42b8e1bc6235 7 *
nhiro3303 0:42b8e1bc6235 8 * http://www.apache.org/licenses/LICENSE-2.0
nhiro3303 0:42b8e1bc6235 9 *
nhiro3303 0:42b8e1bc6235 10 * Unless required by applicable law or agreed to in writing, software
nhiro3303 0:42b8e1bc6235 11 * distributed under the License is distributed on an "AS IS" BASIS,
nhiro3303 0:42b8e1bc6235 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
nhiro3303 0:42b8e1bc6235 13 * See the License for the specific language governing permissions and
nhiro3303 0:42b8e1bc6235 14 * limitations under the License.
nhiro3303 0:42b8e1bc6235 15 */
nhiro3303 0:42b8e1bc6235 16
nhiro3303 0:42b8e1bc6235 17 #ifndef USBHOSTPS3DUALSHOCK3_H
nhiro3303 0:42b8e1bc6235 18 #define USBHOSTPS3DUALSHOCK3_H
nhiro3303 0:42b8e1bc6235 19
nhiro3303 0:42b8e1bc6235 20 #include "USBHost/USBHostConf.h"
nhiro3303 0:42b8e1bc6235 21
nhiro3303 0:42b8e1bc6235 22 #if USBHOST_PS3_DUALSHOCK3
nhiro3303 0:42b8e1bc6235 23
nhiro3303 0:42b8e1bc6235 24 #include "USBHost/USBHost.h"
nhiro3303 0:42b8e1bc6235 25
nhiro3303 0:42b8e1bc6235 26 /** Size of the output report buffer for the Dualshock and Navigation controllers */
nhiro3303 0:42b8e1bc6235 27 #define PS3_REPORT_BUFFER_SIZE 48
nhiro3303 0:42b8e1bc6235 28
nhiro3303 0:42b8e1bc6235 29 /**
nhiro3303 0:42b8e1bc6235 30 * A class to communicate a USB ps3ds3
nhiro3303 0:42b8e1bc6235 31 */
nhiro3303 0:42b8e1bc6235 32 class USBHostPS3DualShock3 : public IUSBEnumerator {
nhiro3303 0:42b8e1bc6235 33 public:
nhiro3303 0:42b8e1bc6235 34
nhiro3303 0:42b8e1bc6235 35 /**
nhiro3303 0:42b8e1bc6235 36 * Constructor
nhiro3303 0:42b8e1bc6235 37 */
nhiro3303 0:42b8e1bc6235 38 USBHostPS3DualShock3();
nhiro3303 0:42b8e1bc6235 39
nhiro3303 0:42b8e1bc6235 40 /**
nhiro3303 0:42b8e1bc6235 41 * Try to connect a ps3ds3 device
nhiro3303 0:42b8e1bc6235 42 *
nhiro3303 0:42b8e1bc6235 43 * @return true if connection was successful
nhiro3303 0:42b8e1bc6235 44 */
nhiro3303 0:42b8e1bc6235 45 bool connect();
nhiro3303 0:42b8e1bc6235 46
nhiro3303 0:42b8e1bc6235 47 /**
nhiro3303 0:42b8e1bc6235 48 * Check if a ps3ds3 is connected
nhiro3303 0:42b8e1bc6235 49 *
nhiro3303 0:42b8e1bc6235 50 * @returns true if a ps3ds3 is connected
nhiro3303 0:42b8e1bc6235 51 */
nhiro3303 0:42b8e1bc6235 52 bool connected();
nhiro3303 0:42b8e1bc6235 53
nhiro3303 0:42b8e1bc6235 54 /**
nhiro3303 0:42b8e1bc6235 55 * Attach a callback called when a ps3ds3 event is received
nhiro3303 0:42b8e1bc6235 56 *
nhiro3303 0:42b8e1bc6235 57 * @param ptr function pointer
nhiro3303 0:42b8e1bc6235 58 */
nhiro3303 0:42b8e1bc6235 59 inline void attachEvent(void (*ptr)(uint8_t buttons, int8_t x, int8_t y, int8_t z)) {
nhiro3303 0:42b8e1bc6235 60 if (ptr != NULL) {
nhiro3303 0:42b8e1bc6235 61 onUpdate = ptr;
nhiro3303 0:42b8e1bc6235 62 }
nhiro3303 0:42b8e1bc6235 63 }
nhiro3303 0:42b8e1bc6235 64
nhiro3303 0:42b8e1bc6235 65 /**
nhiro3303 0:42b8e1bc6235 66 * Attach a callback called when the button state changes
nhiro3303 0:42b8e1bc6235 67 *
nhiro3303 0:42b8e1bc6235 68 * @param ptr function pointer
nhiro3303 0:42b8e1bc6235 69 */
nhiro3303 0:42b8e1bc6235 70 inline void attachButtonEvent(void (*ptr)(uint8_t buttons)) {
nhiro3303 0:42b8e1bc6235 71 if (ptr != NULL) {
nhiro3303 0:42b8e1bc6235 72 onButtonUpdate = ptr;
nhiro3303 0:42b8e1bc6235 73 }
nhiro3303 0:42b8e1bc6235 74 }
nhiro3303 0:42b8e1bc6235 75
nhiro3303 0:42b8e1bc6235 76 /**
nhiro3303 0:42b8e1bc6235 77 * Attach a callback called when the X axis value changes
nhiro3303 0:42b8e1bc6235 78 *
nhiro3303 0:42b8e1bc6235 79 * @param ptr function pointer
nhiro3303 0:42b8e1bc6235 80 */
nhiro3303 0:42b8e1bc6235 81 inline void attachXEvent(void (*ptr)(int8_t x)) {
nhiro3303 0:42b8e1bc6235 82 if (ptr != NULL) {
nhiro3303 0:42b8e1bc6235 83 onXUpdate = ptr;
nhiro3303 0:42b8e1bc6235 84 }
nhiro3303 0:42b8e1bc6235 85 }
nhiro3303 0:42b8e1bc6235 86
nhiro3303 0:42b8e1bc6235 87 /**
nhiro3303 0:42b8e1bc6235 88 * Attach a callback called when the Y axis value changes
nhiro3303 0:42b8e1bc6235 89 *
nhiro3303 0:42b8e1bc6235 90 * @param ptr function pointer
nhiro3303 0:42b8e1bc6235 91 */
nhiro3303 0:42b8e1bc6235 92 inline void attachYEvent(void (*ptr)(int8_t y)) {
nhiro3303 0:42b8e1bc6235 93 if (ptr != NULL) {
nhiro3303 0:42b8e1bc6235 94 onYUpdate = ptr;
nhiro3303 0:42b8e1bc6235 95 }
nhiro3303 0:42b8e1bc6235 96 }
nhiro3303 0:42b8e1bc6235 97
nhiro3303 0:42b8e1bc6235 98 /**
nhiro3303 0:42b8e1bc6235 99 * Attach a callback called when the Z axis value changes (scrolling)
nhiro3303 0:42b8e1bc6235 100 *
nhiro3303 0:42b8e1bc6235 101 * @param ptr function pointer
nhiro3303 0:42b8e1bc6235 102 */
nhiro3303 0:42b8e1bc6235 103 inline void attachZEvent(void (*ptr)(int8_t z)) {
nhiro3303 0:42b8e1bc6235 104 if (ptr != NULL) {
nhiro3303 0:42b8e1bc6235 105 onZUpdate = ptr;
nhiro3303 0:42b8e1bc6235 106 }
nhiro3303 0:42b8e1bc6235 107 }
nhiro3303 0:42b8e1bc6235 108
nhiro3303 0:42b8e1bc6235 109 protected:
nhiro3303 0:42b8e1bc6235 110 //From IUSBEnumerator
nhiro3303 0:42b8e1bc6235 111 virtual void setVidPid(uint16_t vid, uint16_t pid);
nhiro3303 0:42b8e1bc6235 112 virtual bool parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol); //Must return true if the interface should be parsed
nhiro3303 0:42b8e1bc6235 113 virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used
nhiro3303 0:42b8e1bc6235 114
nhiro3303 0:42b8e1bc6235 115 private:
nhiro3303 0:42b8e1bc6235 116 USBHost * host;
nhiro3303 0:42b8e1bc6235 117 USBDeviceConnected * dev;
nhiro3303 0:42b8e1bc6235 118 USBEndpoint * int_in;
nhiro3303 0:42b8e1bc6235 119 uint8_t report[PS3_REPORT_BUFFER_SIZE] = {
nhiro3303 0:42b8e1bc6235 120 0x00, 0x00, 0x00, 0x00, 0x00,
nhiro3303 0:42b8e1bc6235 121 0x00, 0x00, 0x00, 0x00, 0x00,
nhiro3303 0:42b8e1bc6235 122 0xff, 0x27, 0x10, 0x00, 0x32,
nhiro3303 0:42b8e1bc6235 123 0xff, 0x27, 0x10, 0x00, 0x32,
nhiro3303 0:42b8e1bc6235 124 0xff, 0x27, 0x10, 0x00, 0x32,
nhiro3303 0:42b8e1bc6235 125 0xff, 0x27, 0x10, 0x00, 0x32,
nhiro3303 0:42b8e1bc6235 126 0x00, 0x00, 0x00, 0x00, 0x00,
nhiro3303 0:42b8e1bc6235 127 0x00, 0x00, 0x00, 0x00, 0x00,
nhiro3303 0:42b8e1bc6235 128 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
nhiro3303 0:42b8e1bc6235 129 };
nhiro3303 0:42b8e1bc6235 130
nhiro3303 0:42b8e1bc6235 131 bool dev_connected;
nhiro3303 0:42b8e1bc6235 132 bool ps3ds3_device_found;
nhiro3303 0:42b8e1bc6235 133 int ps3ds3_intf;
nhiro3303 0:42b8e1bc6235 134
nhiro3303 0:42b8e1bc6235 135 uint8_t buttons;
nhiro3303 0:42b8e1bc6235 136 int8_t x;
nhiro3303 0:42b8e1bc6235 137 int8_t y;
nhiro3303 0:42b8e1bc6235 138 int8_t z;
nhiro3303 0:42b8e1bc6235 139
nhiro3303 0:42b8e1bc6235 140 void rxHandler();
nhiro3303 0:42b8e1bc6235 141 void (*onUpdate)(uint8_t buttons, int8_t x, int8_t y, int8_t z);
nhiro3303 0:42b8e1bc6235 142 void (*onButtonUpdate)(uint8_t buttons);
nhiro3303 0:42b8e1bc6235 143 void (*onXUpdate)(int8_t x);
nhiro3303 0:42b8e1bc6235 144 void (*onYUpdate)(int8_t y);
nhiro3303 0:42b8e1bc6235 145 void (*onZUpdate)(int8_t z);
nhiro3303 0:42b8e1bc6235 146 int report_id;
nhiro3303 0:42b8e1bc6235 147 void init();
nhiro3303 0:42b8e1bc6235 148 };
nhiro3303 0:42b8e1bc6235 149
nhiro3303 0:42b8e1bc6235 150 #endif
nhiro3303 0:42b8e1bc6235 151
nhiro3303 0:42b8e1bc6235 152 #endif