Skip to content

Commit

Permalink
Dynamic/static HID config selection, fixed axes order in Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Yury Vostrenkov committed Feb 22, 2020
1 parent d9e629b commit 16896e5
Show file tree
Hide file tree
Showing 19 changed files with 325 additions and 91 deletions.
7 changes: 4 additions & 3 deletions Inc/analog.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
#include "common_types.h"
#include "periphery.h"

#define FILTER_LOW_SIZE 5
#define FILTER_MED_SIZE 10
#define FILTER_HIGH_SIZE 20
#define FILTER_LOW_SIZE 5
#define FILTER_MED_SIZE 10
#define FILTER_HIGH_SIZE 20
#define FILTER_VERY_HIGH_SIZE 20

extern tle_t sensors[MAX_AXIS_NUM];

Expand Down
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 0x1340 // v1.3.4b0
#define FIRMWARE_VERSION 0x1341 // v1.3.4b1
#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
7 changes: 4 additions & 3 deletions Inc/common_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ enum
FILTER_LOW,
FILTER_MEDIUM,
FILTER_HIGH,

FILTER_VERY_HIGH,
};
typedef uint8_t filter_t;

Expand Down Expand Up @@ -230,12 +230,13 @@ typedef struct
shift_modificator_t shift_config[5];
uint16_t vid;
uint16_t pid;
uint8_t reserved_10[27];
uint8_t is_dynamic_config;
uint8_t reserved_10[26];
}dev_config_t;

typedef struct
{
uint8_t axes_cnt;
uint8_t axes;
uint8_t buttons_cnt;
uint8_t povs;

Expand Down
3 changes: 2 additions & 1 deletion 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 = 0x1340, // do not change
.firmware_version = 0x1341, // do not change

/*
Name of device in devices dispatcher
Expand Down Expand Up @@ -667,6 +667,7 @@ static const dev_config_t init_config =

.vid = 0x0483,
.pid = 0x5750,
.is_dynamic_config = 0,

};

Expand Down
Binary file modified MDK-ARM/FreeJoy.bin
Binary file not shown.
43 changes: 31 additions & 12 deletions Src/analog.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@
******************************************************************************
* @file : analog.c
* @brief : Analog axis driver implementation
FreeJoy software for game device controllers
Copyright (C) 2020 Yury Vostrenkov (yuvostrenkov@gmail.com)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
******************************************************************************
*/

Expand All @@ -20,9 +37,10 @@ analog_data_t out_axis_data[MAX_AXIS_NUM];

analog_data_t FILTER_LOW_COEFF[FILTER_LOW_SIZE] = {40, 30, 15, 10, 5};
analog_data_t FILTER_MED_COEFF[FILTER_MED_SIZE] = {30, 20, 10, 10, 10, 6, 6, 4, 2, 2};
analog_data_t FILTER_HIGH_COEFF[FILTER_HIGH_SIZE] = {20, 20, 10, 10, 5, 5, 5, 5, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1};
analog_data_t FILTER_HIGH_COEFF[FILTER_HIGH_SIZE] = {25, 20, 10, 5, 5, 5, 5, 5, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1};
analog_data_t FILTER_VERY_HIGH_COEFF[FILTER_VERY_HIGH_SIZE] = {15, 15, 10, 10, 10, 10, 5, 4, 3, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1};

analog_data_t filter_buffer[MAX_AXIS_NUM][FILTER_HIGH_SIZE];
analog_data_t filter_buffer[MAX_AXIS_NUM][FILTER_VERY_HIGH_SIZE];

buttons_state_t axes_buttons[MAX_AXIS_NUM][3];

Expand All @@ -34,16 +52,6 @@ adc_channel_config_t channel_config[MAX_AXIS_NUM] =
{ADC_Channel_6, 6}, {ADC_Channel_7, 7},
};

///**
// * @brief Returns absolute value of input parameter
// * @param x: Input value
// * @retval Absolute value
// */
//static int32_t abs (int32_t x)
//{
// return (x > 0) ? x : -x;
//}

/**
* @brief Transform value from input range to value in output range
* @param x: Value to transform
Expand Down Expand Up @@ -215,6 +223,17 @@ analog_data_t Filter (analog_data_t value, analog_data_t * filter_buf, filter_t

tmp32 += filter_buf[i] * FILTER_HIGH_COEFF[i];
}
break;

case FILTER_VERY_HIGH:

tmp32 = value * FILTER_VERY_HIGH_COEFF[0];
for (uint8_t i=FILTER_VERY_HIGH_SIZE-1; i>0; i--)
{
filter_buf[i] = filter_buf[i-1];

tmp32 += filter_buf[i] * FILTER_VERY_HIGH_COEFF[i];
}

break;
}
Expand Down
17 changes: 17 additions & 0 deletions Src/axis_to_buttons.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@
******************************************************************************
* @file : axis_to_buttons.c
* @brief : Axis to buttons driver implementation
FreeJoy software for game device controllers
Copyright (C) 2020 Yury Vostrenkov (yuvostrenkov@gmail.com)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
******************************************************************************
*/

Expand Down
24 changes: 24 additions & 0 deletions Src/bootloader.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
/**
******************************************************************************
* @file : bootloader.c
* @brief : Application bootloader
FreeJoy software for game device controllers
Copyright (C) 2020 Yury Vostrenkov (yuvostrenkov@gmail.com)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
******************************************************************************
*/

#include "bootloader.h"


Expand Down
17 changes: 17 additions & 0 deletions Src/buttons.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@
******************************************************************************
* @file : buttons.c
* @brief : Buttons driver implementation
FreeJoy software for game device controllers
Copyright (C) 2020 Yury Vostrenkov (yuvostrenkov@gmail.com)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
******************************************************************************
*/

Expand Down
147 changes: 86 additions & 61 deletions Src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@
******************************************************************************
* @file : config.c
* @brief : Config management implementation
FreeJoy software for game device controllers
Copyright (C) 2020 Yury Vostrenkov (yuvostrenkov@gmail.com)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
******************************************************************************
*/

Expand Down Expand Up @@ -49,75 +66,83 @@ void DevConfigGet (dev_config_t * p_dev_config)

void AppConfigInit (dev_config_t * p_dev_config)
{
app_config.axes_cnt = 0;
app_config.axes = 0;
app_config.buttons_cnt = 0;
app_config.povs = 0;

for (uint8_t i=0; i<MAX_AXIS_NUM; i++)
if (p_dev_config->is_dynamic_config)
{
if (p_dev_config->axis_config[i].out_enabled) app_config.axes_cnt++;
}

for (uint8_t i=0; i<MAX_BUTTONS_NUM; i++)
{
uint8_t is_hidden = 0;

if (i == p_dev_config->shift_config[0].button ||
i == p_dev_config->shift_config[1].button ||
i == p_dev_config->shift_config[2].button ||
i == p_dev_config->shift_config[3].button ||
i == p_dev_config->shift_config[4].button) continue;

if (p_dev_config->buttons[i].type == POV1_DOWN ||
p_dev_config->buttons[i].type == POV1_UP ||
p_dev_config->buttons[i].type == POV1_LEFT ||
p_dev_config->buttons[i].type == POV1_RIGHT)
for (uint8_t i=0; i<MAX_AXIS_NUM; i++)
{
app_config.povs |= 0x01;
continue;
}
if (p_dev_config->buttons[i].type == POV2_DOWN ||
p_dev_config->buttons[i].type == POV2_UP ||
p_dev_config->buttons[i].type == POV2_LEFT ||
p_dev_config->buttons[i].type == POV2_RIGHT)
{
app_config.povs |= 0x02;
continue;
}
if (p_dev_config->buttons[i].type == POV3_DOWN ||
p_dev_config->buttons[i].type == POV3_UP ||
p_dev_config->buttons[i].type == POV3_LEFT ||
p_dev_config->buttons[i].type == POV3_RIGHT)
{
app_config.povs |= 0x04;
continue;
}
if (p_dev_config->buttons[i].type == POV4_DOWN ||
p_dev_config->buttons[i].type == POV4_UP ||
p_dev_config->buttons[i].type == POV4_LEFT ||
p_dev_config->buttons[i].type == POV4_RIGHT)
{
app_config.povs |= 0x08;
continue;
if (p_dev_config->axis_config[i].out_enabled) app_config.axes |= (1<<i);
}

for (uint8_t j=0; j<MAX_AXIS_NUM; j++)
{
// button is mapped to axis
if (i == p_dev_config->axis_config[j].decrement_button ||
i == p_dev_config->axis_config[j].increment_button)
{
is_hidden = 1;
break;
}
}

if (!is_hidden && p_dev_config->buttons[i].physical_num >=0)
for (uint8_t i=0; i<MAX_BUTTONS_NUM; i++)
{
app_config.buttons_cnt++;
}
}

uint8_t is_hidden = 0;

if (i == p_dev_config->shift_config[0].button ||
i == p_dev_config->shift_config[1].button ||
i == p_dev_config->shift_config[2].button ||
i == p_dev_config->shift_config[3].button ||
i == p_dev_config->shift_config[4].button) continue;

if (p_dev_config->buttons[i].type == POV1_DOWN ||
p_dev_config->buttons[i].type == POV1_UP ||
p_dev_config->buttons[i].type == POV1_LEFT ||
p_dev_config->buttons[i].type == POV1_RIGHT)
{
app_config.povs |= 0x01;
continue;
}
if (p_dev_config->buttons[i].type == POV2_DOWN ||
p_dev_config->buttons[i].type == POV2_UP ||
p_dev_config->buttons[i].type == POV2_LEFT ||
p_dev_config->buttons[i].type == POV2_RIGHT)
{
app_config.povs |= 0x02;
continue;
}
if (p_dev_config->buttons[i].type == POV3_DOWN ||
p_dev_config->buttons[i].type == POV3_UP ||
p_dev_config->buttons[i].type == POV3_LEFT ||
p_dev_config->buttons[i].type == POV3_RIGHT)
{
app_config.povs |= 0x04;
continue;
}
if (p_dev_config->buttons[i].type == POV4_DOWN ||
p_dev_config->buttons[i].type == POV4_UP ||
p_dev_config->buttons[i].type == POV4_LEFT ||
p_dev_config->buttons[i].type == POV4_RIGHT)
{
app_config.povs |= 0x08;
continue;
}

for (uint8_t j=0; j<MAX_AXIS_NUM; j++)
{
// button is mapped to axis
if (i == p_dev_config->axis_config[j].decrement_button ||
i == p_dev_config->axis_config[j].increment_button)
{
is_hidden = 1;
break;
}
}

if (!is_hidden && p_dev_config->buttons[i].physical_num >=0)
{
app_config.buttons_cnt++;
}
}
}
else
{
app_config.axes = 0xFF;
app_config.buttons_cnt = MAX_BUTTONS_NUM;
app_config.povs = 0x0F;
}

}

Expand Down
Loading

0 comments on commit 16896e5

Please sign in to comment.