Skip to content

Commit

Permalink
Fixed copying joystick buttons data to HID report
Browse files Browse the repository at this point in the history
  • Loading branch information
Yury Vostrenkov committed Feb 21, 2020
1 parent 5b7ec4e commit b7c24ca
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion 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 0x1334 // v1.3.3b4
#define FIRMWARE_VERSION 0x1335 // v1.3.3b5
#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 Inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

static const app_config_t init_config =
{
.firmware_version = 0x1334, // do not change
.firmware_version = 0x1335, // do not change

/*
Name of device in devices dispatcher
Expand Down
Binary file modified MDK-ARM/FreeJoy.bin
Binary file not shown.
6 changes: 3 additions & 3 deletions MDK-ARM/FreeJoy.uvoptx
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,16 @@
<Type>2</Type>
<LineNumber>0</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>536875064</Address>
<ByteObject>1</ByteObject>
<Address>536874876</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>1</ManyObjects>
<SizeOfObject>1</SizeOfObject>
<BreakByAccess>2</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename></Filename>
<ExecCommand></ExecCommand>
<Expression>&amp;buttons_data[0]</Expression>
<Expression>buttons_data[4]==0</Expression>
</Bp>
</Breakpoint>
<WatchWindow1>
Expand Down
10 changes: 6 additions & 4 deletions Src/analog.c
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,7 @@ void AxesProcess (app_config_t * p_config)
}
}

// disable data updating from IRQ
NVIC_DisableIRQ(TIM1_UP_IRQn);

for (uint8_t i=0; i<MAX_AXIS_NUM; i++)
{
// Multi-axis process
Expand Down Expand Up @@ -546,16 +545,19 @@ void AxesProcess (app_config_t * p_config)
else if (tmp[i] < AXIS_MIN_VALUE) tmp[i] = AXIS_MIN_VALUE;
}

// disable data updating from IRQ
NVIC_DisableIRQ(TIM1_UP_IRQn);

// setting technical axis data
scaled_axis_data[i] = tmp[i];
// setting output axis data
if (p_config->axis_config[i].out_enabled) out_axis_data[i] = tmp[i];
else out_axis_data[i] = 0;

// restore IRQ
NVIC_EnableIRQ(TIM1_UP_IRQn);
}
// restore IRQ
NVIC_EnableIRQ(TIM1_UP_IRQn);


}

Expand Down
14 changes: 8 additions & 6 deletions Src/buttons.c
Original file line number Diff line number Diff line change
Expand Up @@ -654,14 +654,11 @@ void ButtonsReadLogical (app_config_t * p_config)
}
}

// disable data updating from IRQ
NVIC_DisableIRQ(TIM1_UP_IRQn);
// convert data to report format
for (int i=0;i<MAX_BUTTONS_NUM;i++)
{
uint8_t is_button_to_axis = 0;
buttons_data[(i & 0xF8)>>3] &= ~(1 << (i & 0x07));


// buttons is mapped to shift
if (i == p_config->shift_config[0].button ||
i == p_config->shift_config[1].button ||
Expand All @@ -682,7 +679,14 @@ void ButtonsReadLogical (app_config_t * p_config)

if (!is_button_to_axis)
{
// disable data updating from IRQ
NVIC_DisableIRQ(TIM1_UP_IRQn);

buttons_data[(i & 0xF8)>>3] &= ~(1 << (i & 0x07));
buttons_data[(i & 0xF8)>>3] |= (buttons_state[i].current_state << (i & 0x07));

// restore IRQ
NVIC_EnableIRQ(TIM1_UP_IRQn);
}
}

Expand Down Expand Up @@ -720,8 +724,6 @@ void ButtonsReadLogical (app_config_t * p_config)
break;
}
}
// restore IRQ
NVIC_EnableIRQ(TIM1_UP_IRQn);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions Src/stm32f10x_it.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@
/* Private variables ---------------------------------------------------------*/
volatile int32_t millis =0, joy_millis=0;
extern app_config_t config;
joy_report_t joy_report;
uint8_t btn_num = 0;
uint8_t physical_buttons_data[MAX_BUTTONS_NUM];
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

Expand Down Expand Up @@ -201,6 +198,9 @@ void TIM3_IRQHandler(void)

void TIM1_UP_IRQHandler(void)
{
uint8_t btn_num = 0;
uint8_t physical_buttons_data[MAX_BUTTONS_NUM];
joy_report_t joy_report;

if (TIM_GetITStatus(TIM1, TIM_IT_Update))
{
Expand Down

0 comments on commit b7c24ca

Please sign in to comment.