Skip to content

Commit

Permalink
Merge pull request #51 from ej113/variant/shift_4axis_Teensy
Browse files Browse the repository at this point in the history
Variant/shift 4axis teensy
  • Loading branch information
ej113 authored Nov 4, 2023
2 parents 60528f7 + 8cd0342 commit 426fd63
Show file tree
Hide file tree
Showing 5 changed files with 1,106 additions and 31 deletions.
20 changes: 10 additions & 10 deletions Descriptors.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM JoystickReport[] =
HID_RI_COLLECTION(8, 0x00), // Physical
HID_RI_USAGE(8, 0x30), // Usage X
HID_RI_USAGE(8, 0x31), // Usage Y
HID_RI_USAGE(8, 0x32), // Usage Z
//HID_RI_USAGE(8, 0x32), // Usage Z
HID_RI_LOGICAL_MINIMUM(16, -512),
HID_RI_LOGICAL_MAXIMUM(16, 511),
HID_RI_PHYSICAL_MINIMUM(8, 0),
HID_RI_PHYSICAL_MAXIMUM(16, 1023),
HID_RI_REPORT_COUNT(8, 0x03),
HID_RI_REPORT_COUNT(8, 0x02),
HID_RI_REPORT_SIZE(8, 0x10),
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),

Expand All @@ -86,25 +86,25 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM JoystickReport[] =

0x65, 0x00, // UNIT (None)

0x09, 0x33, // USAGE (Rx)
/*0x09, 0x33, // USAGE (Rx)
0x09, 0x34, // USAGE (Ry)
HID_RI_LOGICAL_MINIMUM(8, 0),
HID_RI_LOGICAL_MAXIMUM(8, 255),
HID_RI_PHYSICAL_MAXIMUM(8, 255),
HID_RI_REPORT_SIZE(8, 0x08),
HID_RI_REPORT_SIZE(8, 0x08),
HID_RI_REPORT_COUNT(8, 0x02),
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),*/

HID_RI_END_COLLECTION(0),

0x09, 0x36, // USAGE (Rudder - hmm...actual rudder code 0xBA does not seem to work in Windows - so use slider)
/*0x09, 0x36, // USAGE (Rudder - hmm...actual rudder code 0xBA does not seem to work in Windows - so use slider)
HID_RI_LOGICAL_MINIMUM(8, -128),
HID_RI_LOGICAL_MAXIMUM(8, 127),
HID_RI_PHYSICAL_MAXIMUM(8, 255),
HID_RI_REPORT_SIZE(8, 0x08),
HID_RI_REPORT_COUNT(8, 0x01),
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),*/

0x05, 0x02, // USAGE_PAGE (Simulation Controls)

Expand Down Expand Up @@ -1768,16 +1768,16 @@ const USB_Descriptor_String_t PROGMEM ManufacturerString =
*/
const USB_Descriptor_String_t PROGMEM ProductStringJoystick =
{
.Header = {.Size = USB_STRING_LEN(18), .Type = DTYPE_String},
.Header = {.Size = USB_STRING_LEN(20), .Type = DTYPE_String},

.UnicodeString = L"LUFA Joystick wFFB"
.UnicodeString = L"MS SidewinderPro FFB"
};

const USB_Descriptor_String_t PROGMEM ProductStringWheel =
{
.Header = {.Size = USB_STRING_LEN(15), .Type = DTYPE_String},
.Header = {.Size = USB_STRING_LEN(22), .Type = DTYPE_String},

.UnicodeString = L"LUFA Wheel wFFB"
.UnicodeString = L"MS SidewinderWheel FFB"
};

/** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors"
Expand Down
49 changes: 32 additions & 17 deletions Joystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void Joystick_Init(void)
// ADCSRA |= (1 << ADATE); // free/continous mode
ADMUX |= (1 << ADLAR); // 8-bit resolution to HIGH
ADCSRA |= (1 << ADEN); // Enable ADC
ADCSRA |= (1 << ADIE); // Enable ADC Interrupt
ADCSRA |= (1 << ADIE); // Enable ADC Interrupt

ADCSRA |= (1 << ADSC); // Go ADC
}
Expand Down Expand Up @@ -166,26 +166,26 @@ int Joystick_CreateInputReport(uint8_t inReportId, USB_JoystickReport_Data_t* co
// -------------------------------------------------------------------------------
// *******************************************************************************
// Decode the raw FFP/PP data and store it into sw_report
//
//
// Input:
// Pointer to start of packet to copy
//
//
// FFP/PP data packet structure
// ============================
//
//
// 44444444 33333333 33222222 22221111 11111100 00000000
// 76543210 98765432 10987654 32109876 54321098 76543210
// -------0 -------1 -------2 -------3 -------4 -------5
// ppHHHHRR RRRRTTTT TTTYYYYY YYYYYXXX XXXXXXXB BBBBBBBB
// 321054 32106543 21098765 43210987 65432109 87654321
//
//
// USB report data structure
// =========================
//
//
// -------0 -------1 -------2 -------3 -------4 -------5
// XXXXXXXX YYYYYYXX HHHHYYYY BBRRRRRR TBBBBBBB 00TTTTTT
// 76543210 54321098 32109876 21543210 09876543 654321
//
//
// -------------------------------------------------------------------------------

// Copy the data to the USB report
Expand Down Expand Up @@ -240,13 +240,13 @@ int Joystick_CreateInputReport(uint8_t inReportId, USB_JoystickReport_Data_t* co

/*
5 wwwwwwww
4 aaaaaaww
4 aaaaaaww
3 BAbbbbbb
2 1FLZYXRC
1 p-------
0 --------
*/

// Convert the raw input data to USB report

outReportData->reportId = 1; // Input report ID 1
Expand All @@ -265,24 +265,39 @@ int Joystick_CreateInputReport(uint8_t inReportId, USB_JoystickReport_Data_t* co
outReportData->X = sw_report[0] + ((sw_report[1] & 0x03) << 8);
if (sw_report[1] & 0x02)
outReportData->X |= (0b11111100 << 8);


outReportData->Y = (sw_report[1] >> 2) + ((sw_report[2] & 0x0F) << 6);
if (sw_report[2] & 0x08)
outReportData->Y |= (0b11111100 << 8);
outReportData->Button = ((sw_report[4] & 0x7F) << 2) + ((sw_report[3] & 0xC0) >> 6);
outReportData->Y |= (0b11111100 << 8);

// this part makes Shift act like a shift.
// Btn1-8 will be Btn9-16 when shifted
if ((sw_report[4] & 0b01000000) == 0b01000000)
{
// button 9 (shift) is held down
sw_report[4] &= 0b10111111; // Lift up button 9; it's not to be used alone.
outReportData->Button = ((sw_report[4] & 0x7F) << 10) + ((sw_report[3] & 0xC0) << 2);
}
else
{
// button 9 (shift) is not pressed, just report as usual
outReportData->Button = ((sw_report[4] & 0x7F) << 2) + ((sw_report[3] & 0xC0) >> 6);
}

outReportData->Hat = sw_report[2] >> 4;
outReportData->Rz = (sw_report[3] & 0x3f) - 32;
outReportData->Throttle = ((sw_report[5] & 0x3f) << 1) + (sw_report[4] >> 7);
if (sw_report[5] & 0x20)
outReportData->Throttle |= 0b11000000;

outReportData->Z = 0; // not used at the moment
//outReportData->Z = 0; // not used at the moment

// Get data from additional controls
outReportData->Rudder = (added_controls_adc.pedal2 - added_controls_adc.pedal1) / 2 - 128; // Combine two pedals into a single rudder
/*outReportData->Rudder = (added_controls_adc.pedal2 - added_controls_adc.pedal1) / 2 - 128; // Combine two pedals into a single rudder
outReportData->Rx = added_controls_adc.trim2; // rudder trim
outReportData->Ry = added_controls_adc.trim1; // elevator trim
outReportData->Ry = added_controls_adc.trim1; // elevator trim*/

}

/*
Expand Down Expand Up @@ -337,7 +352,7 @@ int Joystick_CreateInputReport(uint8_t inReportId, USB_JoystickReport_Data_t* co
// the actual data can be read later when there
// is more time. Doing any heavier stuff here
// seems to cause problems reading data from FFP joystick.
ISR(ADC_vect)
ISR(ADC_vect)
{
ADC_is_ready = 1;
}
1 change: 0 additions & 1 deletion Joystick.eep

This file was deleted.

6 changes: 3 additions & 3 deletions Joystick.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ typedef struct
uint8_t reportId; // =1
int16_t X;
int16_t Y;
int16_t Z;
int8_t Rz, Rx, Ry;
uint8_t Rudder;
//int16_t Z;
int8_t Rz; //, Rx, Ry;
//uint8_t Rudder;
uint8_t Throttle;
uint16_t Button;
uint8_t Hat;
Expand Down
Loading

0 comments on commit 426fd63

Please sign in to comment.