Skip to content

Commit 3e1ed05

Browse files
committed
Take input direct from ADC instead of Mixers
1 parent 08dfe4a commit 3e1ed05

File tree

3 files changed

+32
-44
lines changed

3 files changed

+32
-44
lines changed

radio/src/targets/common/arm/stm32/usb_driver.cpp

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ extern "C" {
2828
#endif
2929

3030
#include "opentx.h"
31+
#include "board.h"
3132
#include "debug.h"
3233

3334
static bool usbDriverStarted = false;
@@ -162,6 +163,8 @@ bool usbStarted()
162163
}
163164

164165
#if !defined(BOOT)
166+
167+
#define PACKET_SIZE 7
165168
/*
166169
Prepare and send new USB data packet
167170
@@ -171,7 +174,7 @@ bool usbStarted()
171174
*/
172175
void usbJoystickUpdate()
173176
{
174-
static uint8_t HID_Buffer[HID_IN_PACKET];
177+
static uint8_t HID_Buffer[PACKET_SIZE];
175178

176179
// test to see if TX buffer is free
177180
#if defined(STM32F0)
@@ -181,36 +184,28 @@ void usbJoystickUpdate()
181184
#endif
182185

183186
// 4 axes
184-
for (int i = 0; i < 8; ++i) {
185-
int16_t value = channelOutputs[i] + 1024;
186-
if ( value > 2047 ) value = 2047;
187-
else if ( value < 0 ) value = 0;
188-
HID_Buffer[i*2 + 0] = uint8_t(value);
189-
HID_Buffer[i*2 + 1] = uint8_t(value >> 8);
190-
}
191-
// 2 sliders
192-
// 4 switches
187+
HID_Buffer[0] = uint8_t(adcValues[STICK1] >> 4) - 0x80;
188+
HID_Buffer[1] = uint8_t(adcValues[STICK2] >> 4) - 0x80;
189+
HID_Buffer[2] = uint8_t(adcValues[STICK3] >> 4) - 0x80;
190+
HID_Buffer[3] = uint8_t(adcValues[STICK4] >> 4) - 0x80;
193191

194-
// buttons
195-
HID_Buffer[8*2+1] = 0;
196-
HID_Buffer[8*2+2] = 0;
197-
HID_Buffer[8*2+3] = 0;
198-
for (int i = 0; i < 8; ++i) {
199-
if (channelOutputs[i+8] > 0) {
200-
HID_Buffer[8*2+1] |= 1 << i;
201-
}
202-
if (channelOutputs[i+16] > 0) {
203-
HID_Buffer[8*2+2] |= 1 << i;
204-
}
205-
if (channelOutputs[i+24] > 0) {
206-
HID_Buffer[8*2+3] |= 1 << i;
207-
}
208-
}
192+
// 2 pots
193+
HID_Buffer[4] = uint8_t(adcValues[POT1] >> 4) - 0x80;
194+
HID_Buffer[5] = uint8_t(adcValues[POT2] >> 4) - 0x80;
195+
196+
// 4 switches
197+
// up: 10
198+
// mid: 00
199+
// dn: 01
200+
HID_Buffer[6] = (~(uint8_t(adcValues[SW_A] >> 10) - 2) & 0x03)
201+
| (~(uint8_t(adcValues[SW_C] >> 10) - 2) & 0x03) << 2
202+
| (~(uint8_t(adcValues[SW_C] >> 10) - 2) & 0x03) << 4
203+
| (~(uint8_t(adcValues[SW_D] >> 10) - 2) & 0x03) << 6;
209204

210205
#if defined(STM32F0)
211-
USBD_HID_SendReport(&USB_Device_dev, HID_Buffer, HID_IN_PACKET);
206+
USBD_HID_SendReport(&USB_Device_dev, HID_Buffer, PACKET_SIZE);
212207
#else
213-
USBD_HID_SendReport(&USB_OTG_dev, HID_Buffer, HID_IN_PACKET);
208+
USBD_HID_SendReport(&USB_OTG_dev, HID_Buffer, PACKET_SIZE);
214209
#endif
215210
}
216211
}

radio/src/targets/common/arm/stm32/usbd_hid_joystick.c

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -112,34 +112,27 @@ __ALIGN_BEGIN static const uint8_t HID_JOYSTICK_ReportDesc[] __ALIGN_END =
112112
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
113113
0x09, 0x04, // USAGE (Joystick)
114114
0xa1, 0x01, // COLLECTION (Application)
115-
0xa1, 0x00, // COLLECTION (Physical)
116-
117115
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
118116
0x09, 0x30, // USAGE (X)
119117
0x09, 0x31, // USAGE (Y)
120118
0x09, 0x32, // USAGE (Z)
121119
0x09, 0x33, // USAGE (Rx)
122120
0x09, 0x34, // USAGE (Ry)
123121
0x09, 0x35, // USAGE (Rz)
124-
0x09, 0x36, // USAGE (Slider)
125-
0x09, 0x37, // USAGE (Slider)
126-
0x16, 0x00, 0x00, // LOGICAL_MINIMUM (0)
127-
0x26, 0xFF, 0x07, // LOGICAL_MAXIMUM (2047)
128-
0x75, 0x10, // REPORT_SIZE (16)
129-
0x95, 0x08, // REPORT_COUNT (8)
122+
0x15, 0x81, // LOGICAL_MINIMUM (-127)
123+
0x25, 0x7F, // LOGICAL_MAXIMUM (127)
124+
0x75, 0x08, // REPORT_SIZE (8)
125+
0x95, 0x06, // REPORT_COUNT (6)
130126
0x81, 0x02, // INPUT (Data,Var,Abs)
131-
132127
0x05, 0x09, // USAGE_PAGE (Button)
133128
0x19, 0x01, // USAGE_MINIMUM (Button 1)
134-
0x29, 0x10, // USAGE_MAXIMUM (Button 16)
129+
0x29, 0x08, // USAGE_MAXIMUM (Button 8)
135130
0x15, 0x00, // LOGICAL_MINIMUM (0)
136131
0x25, 0x01, // LOGICAL_MAXIMUM (1)
137-
0x95, 0x10, // REPORT_COUNT (16)
138132
0x75, 0x01, // REPORT_SIZE (1)
133+
0x95, 0x08, // REPORT_COUNT (8)
139134
0x81, 0x02, // INPUT (Data,Var,Abs)
140-
141-
0xc0, // END_COLLECTION
142-
0xc0 // END_COLLECTION
135+
0xc0, // END_COLLECTION
143136
};
144137

145138

@@ -248,7 +241,7 @@ __ALIGN_BEGIN static const uint8_t USBD_HID_CfgDesc[USB_HID_CONFIG_DESC_SIZ] __A
248241

249242
HID_IN_EP, /*bEndpointAddress: Endpoint Address (IN)*/
250243
0x03, /*bmAttributes: Interrupt endpoint*/
251-
HID_IN_PACKET, /*wMaxPacketSize: 4 Byte max */
244+
0x40, /*wMaxPacketSize: 4 Byte max */
252245
0x00,
253246
0x07, /*bInterval: Polling Interval (7 ms)*/
254247
/* 34 */

radio/src/targets/flysky/board.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,12 +335,12 @@ enum Analogs {
335335
STICK4,
336336
SW_A,
337337
SW_B,
338-
SW_C,
339-
SW_D,
340338
POT_FIRST,
341339
POT1 = POT_FIRST,
342340
POT2,
343341
POT_LAST = POT2,
342+
SW_C,
343+
SW_D,
344344
TX_VOLTAGE,
345345
NUM_ANALOGS
346346
};

0 commit comments

Comments
 (0)