mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-21 07:15:18 +03:00
Fixes from review.
This commit is contained in:
parent
444e5c43a5
commit
48ed3d0b15
4 changed files with 25 additions and 20 deletions
|
@ -24,6 +24,8 @@
|
||||||
|
|
||||||
#include "common/maths.h"
|
#include "common/maths.h"
|
||||||
|
|
||||||
|
#include "fc/rc_controls.h"
|
||||||
|
|
||||||
#include "rx/rx.h"
|
#include "rx/rx.h"
|
||||||
|
|
||||||
//TODO: Make it platform independent in the future
|
//TODO: Make it platform independent in the future
|
||||||
|
@ -32,39 +34,45 @@
|
||||||
#include "usbd_hid_core.h"
|
#include "usbd_hid_core.h"
|
||||||
#elif defined(STM32F7)
|
#elif defined(STM32F7)
|
||||||
#include "usbd_cdc_interface.h"
|
#include "usbd_cdc_interface.h"
|
||||||
|
#include "usbd_def.h"
|
||||||
#include "usbd_hid.h"
|
#include "usbd_hid.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define USB_CDC_HID_NUM_AXES 8
|
#define USB_CDC_HID_NUM_AXES 8
|
||||||
|
|
||||||
// In the windows joystick driver, the axes are defined as shown in the third column.
|
#define USB_CDC_HID_RANGE_MIN -127
|
||||||
|
#define USB_CDC_HID_RANGE_MAX 127
|
||||||
|
|
||||||
|
// In the windows joystick driver, the axes are defined as shown in the second column.
|
||||||
|
|
||||||
const uint8_t hidChannelMapping[] = {
|
const uint8_t hidChannelMapping[] = {
|
||||||
0, // X, ROLL
|
ROLL, // X
|
||||||
1, // Y, PITCH
|
PITCH, // Y
|
||||||
6, // , AUX3
|
AUX3,
|
||||||
3, // Y Rotation, THROTTLE
|
YAW, // X Rotation
|
||||||
4, // Z Rotation, AUX1
|
AUX1, // Z Rotation
|
||||||
2, // X Rotation, YAW
|
THROTTLE, // Y Rotation
|
||||||
7, // , AUX4
|
AUX4,
|
||||||
5, // Wheel, AUX2
|
AUX2, // Wheel
|
||||||
};
|
};
|
||||||
|
|
||||||
void sendRcDataToHid(void)
|
void sendRcDataToHid(void)
|
||||||
{
|
{
|
||||||
int8_t report[8];
|
int8_t report[8];
|
||||||
for (unsigned i = 0; i < USB_CDC_HID_NUM_AXES; i++) {
|
for (unsigned i = 0; i < USB_CDC_HID_NUM_AXES; i++) {
|
||||||
const uint8_t channel = getMappedChannel(hidChannelMapping[i]);
|
const uint8_t channel = hidChannelMapping[i];
|
||||||
report[i] = scaleRange(constrain(rcData[channel], 1000, 2000), 1000, 2000, -127, 127);
|
report[i] = scaleRange(constrain(rcData[channel], PWM_RANGE_MIN, PWM_RANGE_MAX), PWM_RANGE_MIN, PWM_RANGE_MAX, USB_CDC_HID_RANGE_MIN, USB_CDC_HID_RANGE_MAX);
|
||||||
if (i == 1 || i == 2) {
|
if (i == 1) {
|
||||||
report[i] = -report[i];
|
// For some reason ROLL is inverted in Windows
|
||||||
}
|
report[i] = -report[i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#ifdef STM32F4
|
#ifdef STM32F4
|
||||||
USBD_HID_SendReport(&USB_OTG_dev, (uint8_t*)report, sizeof(report));
|
USBD_HID_SendReport(&USB_OTG_dev, (uint8_t*)report, sizeof(report));
|
||||||
#elif defined(STM32F7)
|
#elif defined(STM32F7)
|
||||||
extern USBD_HandleTypeDef USBD_Device;
|
|
||||||
USBD_HID_SendReport(&USBD_Device, (uint8_t*)report, sizeof(report));
|
USBD_HID_SendReport(&USBD_Device, (uint8_t*)report, sizeof(report));
|
||||||
|
#else
|
||||||
|
# error "MCU does not support USB HID."
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -466,7 +466,7 @@ STATIC_UNIT_TESTED uint16_t applyRxChannelRangeConfiguraton(int sample, const rx
|
||||||
return sample;
|
return sample;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t getMappedChannel(uint8_t channel)
|
static uint8_t getMappedChannel(uint8_t channel)
|
||||||
{
|
{
|
||||||
return channel < RX_MAPPABLE_CHANNEL_COUNT ? rxConfig()->rcmap[channel] : channel;
|
return channel < RX_MAPPABLE_CHANNEL_COUNT ? rxConfig()->rcmap[channel] : channel;
|
||||||
}
|
}
|
||||||
|
|
|
@ -173,5 +173,3 @@ void suspendRxSignal(void);
|
||||||
void resumeRxSignal(void);
|
void resumeRxSignal(void);
|
||||||
|
|
||||||
uint16_t rxGetRefreshRate(void);
|
uint16_t rxGetRefreshRate(void);
|
||||||
|
|
||||||
uint8_t getMappedChannel(uint8_t channel);
|
|
||||||
|
|
|
@ -48,6 +48,7 @@
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "stm32f7xx_hal.h"
|
#include "stm32f7xx_hal.h"
|
||||||
#include "usbd_core.h"
|
#include "usbd_core.h"
|
||||||
|
#include "usbd_def.h"
|
||||||
#include "usbd_desc.h"
|
#include "usbd_desc.h"
|
||||||
#include "usbd_cdc.h"
|
#include "usbd_cdc.h"
|
||||||
#include "usbd_cdc_interface.h"
|
#include "usbd_cdc_interface.h"
|
||||||
|
@ -82,8 +83,6 @@ uint8_t* rxBuffPtr = NULL;
|
||||||
|
|
||||||
/* TIM handler declaration */
|
/* TIM handler declaration */
|
||||||
TIM_HandleTypeDef TimHandle;
|
TIM_HandleTypeDef TimHandle;
|
||||||
/* USB handler declaration */
|
|
||||||
extern USBD_HandleTypeDef USBD_Device;
|
|
||||||
|
|
||||||
static void (*ctrlLineStateCb)(void *context, uint16_t ctrlLineState);
|
static void (*ctrlLineStateCb)(void *context, uint16_t ctrlLineState);
|
||||||
static void *ctrlLineStateCbContext;
|
static void *ctrlLineStateCbContext;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue