Skip to content

Commit

Permalink
Fixed sequence of params reports
Browse files Browse the repository at this point in the history
  • Loading branch information
Yury Vostrenkov committed Mar 23, 2021
2 parents de17fb7 + e9ea1f2 commit 4dfb23f
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Drivers/STM32_USB-FS-Device_Driver/inc/usb_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
extern __IO uint8_t EP1_PrevXferComplete;
extern __IO uint8_t EP2_PrevXferComplete;

void USB_CUSTOM_HID_SendReport(uint8_t EP_num, uint8_t * data, uint8_t length);
int8_t USB_CUSTOM_HID_SendReport(uint8_t EP_num, uint8_t * data, uint8_t length);

#endif /* __USB_LIB_H */

Expand Down
10 changes: 5 additions & 5 deletions MDK-ARM/FreeJoy.uvoptx
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@
</OPTFL>
<CpuCode>18</CpuCode>
<DebugOpt>
<uSim>0</uSim>
<uTrg>1</uTrg>
<uSim>1</uSim>
<uTrg>0</uTrg>
<sLdApp>1</sLdApp>
<sGomain>1</sGomain>
<sRbreak>1</sRbreak>
Expand All @@ -89,7 +89,7 @@
<sRfunc>1</sRfunc>
<sRbox>1</sRbox>
<tLdApp>1</tLdApp>
<tGomain>1</tGomain>
<tGomain>0</tGomain>
<tRbreak>1</tRbreak>
<tRwatch>1</tRwatch>
<tRmem>1</tRmem>
Expand Down Expand Up @@ -930,7 +930,7 @@

<Group>
<GroupName>Bootloader</GroupName>
<tvExp>1</tvExp>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel>
<RteFlg>0</RteFlg>
Expand Down Expand Up @@ -1206,7 +1206,7 @@

<Group>
<GroupName>USB-FS-Device_Driver</GroupName>
<tvExp>1</tvExp>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel>
<RteFlg>0</RteFlg>
Expand Down
2 changes: 1 addition & 1 deletion application/Inc/common_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

//#define DEBUG

#define FIRMWARE_VERSION 0x1702 // v1.7.0b2
#define FIRMWARE_VERSION 0x1703 // v1.7.0b3
#define USED_PINS_NUM 30 // constant for BluePill and BlackPill boards
#define MAX_AXIS_NUM 8 // max 8
#define MAX_BUTTONS_NUM 128 // power of 2, max 128
Expand Down
2 changes: 1 addition & 1 deletion application/Inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

static const dev_config_t init_config =
{
.firmware_version = 0x1702, // do not change
.firmware_version = 0x1703, // do not change

/*
Name of device in devices dispatcher
Expand Down
14 changes: 8 additions & 6 deletions application/Src/stm32f10x_it.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ void TIM2_IRQHandler(void)
params_report.phy_button_data,
&params_report.shift_button_data);
AnalogGet(joy_report.axis_data, NULL, params_report.raw_axis_data);
memcpy(params_report.axis_data, joy_report.axis_data, sizeof(params_report.axis_data));
POVsGet(joy_report.pov_data);

// fill joystick report buffer
Expand Down Expand Up @@ -235,23 +234,26 @@ void TIM2_IRQHandler(void)
USB_CUSTOM_HID_SendReport(1, report_buf, pos);

// fill params report buffer
static uint8_t test = 0;
static uint8_t report = 0;
report_buf[0] = REPORT_ID_PARAM;
if (test == 0)
memcpy(params_report.axis_data, joy_report.axis_data, sizeof(params_report.axis_data));

if (report == 0)
{
report_buf[1] = 0;
test = 1;
memcpy(&report_buf[2], (uint8_t *)&(params_report), 62);
}
else
{
report_buf[1] = 1;
test = 0;
memcpy(&report_buf[2], (uint8_t *)&(params_report) + 62, sizeof(params_report_t) - 62);
}

// send params report
USB_CUSTOM_HID_SendReport(2, report_buf, 64);
if (USB_CUSTOM_HID_SendReport(2, report_buf, 64) == 0)
{
report = !report;
}
}

// digital inputs polling
Expand Down
12 changes: 11 additions & 1 deletion application/Src/usb_endp.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,20 +237,30 @@ void EP2_IN_Callback(void)
EP2_PrevXferComplete = 1;
}

void USB_CUSTOM_HID_SendReport(uint8_t EP_num, uint8_t * data, uint8_t length)
/*******************************************************************************
* Function Name : USB_CUSTOM_HID_SendReport.
* Description :
* Input : None.
* Output : None.
* Return : 1 if success otherwise 0.
*******************************************************************************/
int8_t USB_CUSTOM_HID_SendReport(uint8_t EP_num, uint8_t * data, uint8_t length)
{
if ((EP_num == 1) && (EP1_PrevXferComplete) && (bDeviceState == CONFIGURED))
{
USB_SIL_Write(EP1_IN, data, length);
SetEPTxValid(ENDP1);
EP1_PrevXferComplete = 0;
return 0;
}
else if ((EP_num == 2) && (EP2_PrevXferComplete) && (bDeviceState == CONFIGURED))
{
USB_SIL_Write(EP2_IN, data, length);
SetEPTxValid(ENDP2);
EP2_PrevXferComplete = 0;
return 0;
}
return -1;
}
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

0 comments on commit 4dfb23f

Please sign in to comment.