forked from progmem/Switch-Fightstick
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Joystick.h
135 lines (117 loc) · 3.95 KB
/
Joystick.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
LUFA Library
Copyright (C) Dean Camera, 2014.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
*/
/*
Copyright 2014 Dean Camera (dean [at] fourwalledcubicle [dot] com)
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
without fee, provided that the above copyright notice appear in
all copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the name of the author not be used in
advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
The author disclaims all warranties with regard to this
software, including all implied warranties of merchantability
and fitness. In no event shall the author be liable for any
special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether
in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of
this software.
*/
/** \file
*
* Header file for Joystick.c.
*/
#ifndef _JOYSTICK_H_
#define _JOYSTICK_H_
/* Includes: */
#include <avr/io.h>
#include <avr/wdt.h>
#include <avr/power.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <string.h>
#include <LUFA/Drivers/USB/USB.h>
#include <LUFA/Drivers/Board/Joystick.h>
#include <LUFA/Drivers/Board/LEDs.h>
#include <LUFA/Drivers/Board/Buttons.h>
#include <LUFA/Platform/Platform.h>
#include "Descriptors.h"
#define I2C_REG_MAX 7
#define I2C_ADDRESS CONFIG_I2C_ADDRESS // put into makefile
void I2C_received(char* buf, uint8_t len);
void I2C_requested(void);
void I2C_setup(void);
/*
// Register map of all buttons. Not needed for this.
typedef union {
struct {
uint16_t Y:1; // 0
uint16_t B:1; // 1
uint16_t A:1; // 2
uint16_t X:1; // 3
uint16_t L:1; // 4
uint16_t R:1; // 5
uint16_t ZL:1; // 6
uint16_t ZR:1; // 7
uint16_t MINUS:1; // 8 - 0
uint16_t PLUS:1; // 9 - 1
uint16_t LCLICK:1; // 10 - 2
uint16_t RCLICK:1; // 11 - 3
uint16_t HOME:1; // 12 - 4
uint16_t CAPTURE:1; // 13 - 5
uint16_t :2; // 14-15 - 6-7 (unknown funcion)
} bit;
uint16_t reg;
} JoystickButtons_t;
*/
#define HAT_TOP 0x00
#define HAT_TOP_RIGHT 0x01
#define HAT_RIGHT 0x02
#define HAT_BOTTOM_RIGHT 0x03
#define HAT_BOTTOM 0x04
#define HAT_BOTTOM_LEFT 0x05
#define HAT_LEFT 0x06
#define HAT_TOP_LEFT 0x07
#define HAT_CENTER 0x08
#define STICK_MIN 0
#define STICK_CENTER 128
#define STICK_MAX 255
// Joystick HID report structure. We have an input and an output.
typedef struct {
uint16_t Button; // 16 buttons; see JoystickButtons_t for bit mapping
uint8_t HAT; // HAT switch; one nibble w/ unused nibble
uint8_t LX; // Left Stick X
uint8_t LY; // Left Stick Y
uint8_t RX; // Right Stick X
uint8_t RY; // Right Stick Y
uint8_t VendorSpec;
} USB_JoystickReport_Input_t;
// The output is structured as a mirror of the input.
// This is based on initial observations of the Pokken Controller.
typedef struct {
uint16_t Button; // 16 buttons; see JoystickButtons_t for bit mapping
uint8_t HAT; // HAT switch; one nibble w/ unused nibble
uint8_t LX; // Left Stick X
uint8_t LY; // Left Stick Y
uint8_t RX; // Right Stick X
uint8_t RY; // Right Stick Y
} USB_JoystickReport_Output_t;
// Function Prototypes
// Setup all necessary hardware, including USB initialization.
void SetupHardware(void);
// Process and deliver data from IN and OUT endpoints.
void HID_Task(void);
// USB device event handlers.
void EVENT_USB_Device_Connect(void);
void EVENT_USB_Device_Disconnect(void);
void EVENT_USB_Device_ConfigurationChanged(void);
void EVENT_USB_Device_ControlRequest(void);
// Prepare the next report for the host.
void GetNextReport(USB_JoystickReport_Input_t* const ReportData);
#endif