Skip to content

Commit

Permalink
Params report
Browse files Browse the repository at this point in the history
  • Loading branch information
Yury Vostrenkov committed Jan 23, 2021
1 parent 721c1bf commit 7385bea
Show file tree
Hide file tree
Showing 14 changed files with 186 additions and 146 deletions.
4 changes: 2 additions & 2 deletions application/Inc/analog.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ typedef struct



void AxesInit (dev_config_t * p_dev_config);
void AxisInit (dev_config_t * p_dev_config);
void ADC_Conversion (void);
void AxesProcess (dev_config_t * p_dev_config);
void AxisProcess (dev_config_t * p_dev_config);
void AxisResetCalibration (dev_config_t * p_dev_config, uint8_t axis_num);
void AnalogGet (analog_data_t * out_data, analog_data_t * scaled_data, analog_data_t * raw_data);

Expand Down
2 changes: 1 addition & 1 deletion application/Inc/axis_to_buttons.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "analog.h"


void AxesToButtonsGet (uint8_t * raw_button_data_buf, dev_config_t * p_dev_config, uint8_t * pos);
void AxisToButtonsGet (uint8_t * raw_button_data_buf, dev_config_t * p_dev_config, uint8_t * pos);

#endif /* __AXIS_TO_BUTTONS_H__ */

6 changes: 4 additions & 2 deletions application/Inc/buttons.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
#include "shift_registers.h"
#include "axis_to_buttons.h"

extern logical_buttons_state_t logical_buttons_state[MAX_BUTTONS_NUM];
extern uint8_t raw_buttons_data[MAX_BUTTONS_NUM];
extern logical_buttons_state_t logical_buttons_state[MAX_BUTTONS_NUM];
extern uint8_t phy_buttons_data[MAX_BUTTONS_NUM/8];
extern uint8_t log_buttons_data[MAX_BUTTONS_NUM/8];
extern uint8_t shifts_state;

typedef uint8_t button_data_t;
Expand All @@ -27,7 +29,7 @@ void RadioButtons_Init (dev_config_t * p_dev_config);
void SequentialButtons_Init (dev_config_t * p_dev_config);
uint8_t ButtonsReadPhysical(dev_config_t * p_dev_config, uint8_t * p_buf);
void ButtonsReadLogical (dev_config_t * p_dev_config);
void ButtonsGet (uint8_t * raw_data, button_data_t * data, uint8_t * shift_data);
void ButtonsGet (uint8_t * out_data, uint8_t * log_data, uint8_t * phy_data, uint8_t * shift_data);
void POVsGet (pov_data_t * data);


Expand Down
6 changes: 3 additions & 3 deletions application/Inc/common_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "common_defines.h"


/******************** AXES **********************/
/******************** AXIS **********************/
enum
{
FILTER_NO = 0,
Expand Down Expand Up @@ -295,7 +295,7 @@ typedef struct
} encode_stater_t;


/******************** AXES TO BUTTONS **********************/
/******************** AXIS TO BUTTONS **********************/
typedef struct
{
uint8_t points[13];
Expand Down Expand Up @@ -388,7 +388,7 @@ typedef struct
uint16_t a2b_debounce_ms; // config packet 9

// config 12-13-14
axis_to_buttons_t axes_to_buttons[MAX_AXIS_NUM];
axis_to_buttons_t axis_to_buttons[MAX_AXIS_NUM];

// config 14
shift_reg_config_t shift_registers[4];
Expand Down
52 changes: 26 additions & 26 deletions application/Inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ static const dev_config_t init_config =
.pins[29] = NOT_USED, // PC15

/*
Configuration of analog axes
Configuration of analog axis
*/
.axis_config[0].calib_min = AXIS_MIN_VALUE,
.axis_config[0].calib_center = AXIS_CENTER_VALUE,
Expand Down Expand Up @@ -661,39 +661,39 @@ static const dev_config_t init_config =
.buttons[127].type = BUTTON_NORMAL,

/*
AxesToButtons configuration
AxisToButtons configuration
*/
.axes_to_buttons[0].points[0] = 0,
.axes_to_buttons[0].points[1] = 255,
.axes_to_buttons[0].buttons_cnt = 0,
.axis_to_buttons[0].points[0] = 0,
.axis_to_buttons[0].points[1] = 255,
.axis_to_buttons[0].buttons_cnt = 0,

.axes_to_buttons[1].points[0] = 0,
.axes_to_buttons[1].points[1] = 255,
.axes_to_buttons[1].buttons_cnt = 0,
.axis_to_buttons[1].points[0] = 0,
.axis_to_buttons[1].points[1] = 255,
.axis_to_buttons[1].buttons_cnt = 0,

.axes_to_buttons[2].points[0] = 0,
.axes_to_buttons[2].points[1] = 255,
.axes_to_buttons[2].buttons_cnt = 0,
.axis_to_buttons[2].points[0] = 0,
.axis_to_buttons[2].points[1] = 255,
.axis_to_buttons[2].buttons_cnt = 0,

.axes_to_buttons[3].points[0] = 0,
.axes_to_buttons[3].points[1] = 255,
.axes_to_buttons[3].buttons_cnt = 0,
.axis_to_buttons[3].points[0] = 0,
.axis_to_buttons[3].points[1] = 255,
.axis_to_buttons[3].buttons_cnt = 0,

.axes_to_buttons[4].points[0] = 0,
.axes_to_buttons[4].points[1] = 255,
.axes_to_buttons[4].buttons_cnt = 0,
.axis_to_buttons[4].points[0] = 0,
.axis_to_buttons[4].points[1] = 255,
.axis_to_buttons[4].buttons_cnt = 0,

.axes_to_buttons[5].points[0] = 0,
.axes_to_buttons[5].points[1] = 255,
.axes_to_buttons[5].buttons_cnt = 0,
.axis_to_buttons[5].points[0] = 0,
.axis_to_buttons[5].points[1] = 255,
.axis_to_buttons[5].buttons_cnt = 0,

.axes_to_buttons[6].points[0] = 0,
.axes_to_buttons[6].points[1] = 255,
.axes_to_buttons[6].buttons_cnt = 0,
.axis_to_buttons[6].points[0] = 0,
.axis_to_buttons[6].points[1] = 255,
.axis_to_buttons[6].buttons_cnt = 0,

.axes_to_buttons[7].points[0] = 0,
.axes_to_buttons[7].points[1] = 255,
.axes_to_buttons[7].buttons_cnt = 0,
.axis_to_buttons[7].points[0] = 0,
.axis_to_buttons[7].points[1] = 255,
.axis_to_buttons[7].buttons_cnt = 0,


.shift_config[0].button = -1,
Expand Down
2 changes: 1 addition & 1 deletion application/Inc/periphery.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ extern pin_config_t pin_config[USED_PINS_NUM];

void SysTick_Init(void);
void Timers_Init(dev_config_t * p_dev_config);
void PWM_SetFromAxes(dev_config_t * p_dev_config, analog_data_t * axes_data);
void PWM_SetFromAxis(dev_config_t * p_dev_config, analog_data_t * axis_data);

uint64_t GetTick(void);

Expand Down
122 changes: 61 additions & 61 deletions application/Src/analog.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ analog_data_t FILTER_LEVEL_7_COEF[FILTER_BUF_SIZE] = {8, 8, 7, 7, 7, 6, 6, 6, 6,
analog_data_t filter_buffer[MAX_AXIS_NUM][FILTER_BUF_SIZE];
analog_data_t deadband_buffer[MAX_AXIS_NUM][DEADBAND_BUF_SIZE];

logical_buttons_state_t axes_buttons[MAX_AXIS_NUM][3];
int32_t axes_trim_value[MAX_AXIS_NUM];
logical_buttons_state_t axis_buttons[MAX_AXIS_NUM][3];
int32_t axis_trim_value[MAX_AXIS_NUM];

uint8_t adc_cnt = 0;
uint8_t sensors_cnt = 0;
Expand Down Expand Up @@ -400,11 +400,11 @@ analog_data_t ShapeFunc (axis_config_t * p_axis_cfg, analog_data_t value, uint8
}

/**
* @brief Axes initialization after startup
* @brief Axis initialization after startup
* @param p_dev_config: Pointer to device configuration structure
* @retval None
*/
void AxesInit (dev_config_t * p_dev_config)
void AxisInit (dev_config_t * p_dev_config)
{
ADC_InitTypeDef ADC_InitStructure;
DMA_InitTypeDef DMA_InitStructure;
Expand Down Expand Up @@ -713,11 +713,11 @@ void ADC_Conversion (void)
}

/**
* @brief Axes data processing routine
* @brief Axis data processing routine
* @param p_dev_config: Pointer to device configuration structure
* @retval None
*/
void AxesProcess (dev_config_t * p_dev_config)
void AxisProcess (dev_config_t * p_dev_config)
{

int32_t tmp[MAX_AXIS_NUM];
Expand Down Expand Up @@ -1016,11 +1016,11 @@ void AxesProcess (dev_config_t * p_dev_config)
(p_dev_config->axis_config[i].button2 < 0 || p_dev_config->axis_config[i].button2_type != AXIS_BUTTON_PRESCALER_EN) &&
(p_dev_config->axis_config[i].button3 < 0 || p_dev_config->axis_config[i].button3_type != AXIS_BUTTON_PRESCALER_EN)) ||
// or defined and pressed
((p_dev_config->axis_config[i].button1 >=0 && axes_buttons[i][0].current_state &&
((p_dev_config->axis_config[i].button1 >=0 && axis_buttons[i][0].current_state &&
p_dev_config->axis_config[i].button1_type == AXIS_BUTTON_PRESCALER_EN) ||
(p_dev_config->axis_config[i].button2 >=0 && axes_buttons[i][1].current_state &&
(p_dev_config->axis_config[i].button2 >=0 && axis_buttons[i][1].current_state &&
p_dev_config->axis_config[i].button2_type == AXIS_BUTTON_PRESCALER_EN) ||
(p_dev_config->axis_config[i].button3 >=0 && axes_buttons[i][2].current_state &&
(p_dev_config->axis_config[i].button3 >=0 && axis_buttons[i][2].current_state &&
p_dev_config->axis_config[i].button3_type == AXIS_BUTTON_PRESCALER_EN))
)
{
Expand Down Expand Up @@ -1062,107 +1062,107 @@ void AxesProcess (dev_config_t * p_dev_config)
if (p_dev_config->axis_config[i].button3 >= 0 &&
p_dev_config->axis_config[i].button3_type == AXIS_BUTTON_CENTER) cent_button_num |= 1<<2;

axes_buttons[i][0].prev_physical_state = axes_buttons[i][0].current_state;
axes_buttons[i][1].prev_physical_state = axes_buttons[i][1].current_state;
axes_buttons[i][2].prev_physical_state = axes_buttons[i][2].current_state;
axis_buttons[i][0].prev_physical_state = axis_buttons[i][0].current_state;
axis_buttons[i][1].prev_physical_state = axis_buttons[i][1].current_state;
axis_buttons[i][2].prev_physical_state = axis_buttons[i][2].current_state;

// get new button's states
if (p_dev_config->axis_config[i].button1 >= 0)
{
axes_buttons[i][0].current_state = logical_buttons_state[p_dev_config->axis_config[i].button1].current_state;
axis_buttons[i][0].current_state = logical_buttons_state[p_dev_config->axis_config[i].button1].current_state;
}
if (p_dev_config->axis_config[i].button2 >= 0)
{
axes_buttons[i][1].current_state = logical_buttons_state[p_dev_config->axis_config[i].button2].current_state;
axis_buttons[i][1].current_state = logical_buttons_state[p_dev_config->axis_config[i].button2].current_state;
}
if (p_dev_config->axis_config[i].button3 >= 0)
{
axes_buttons[i][2].current_state = logical_buttons_state[p_dev_config->axis_config[i].button3].current_state;
axis_buttons[i][2].current_state = logical_buttons_state[p_dev_config->axis_config[i].button3].current_state;
}

// Trimming by buttons
if (inc_button_num > 0 || rst_button_num > 0 || dec_button_num > 0)
{
// increment
if ((inc_button_num & 0x01) && axes_buttons[i][0].current_state > axes_buttons[i][0].prev_physical_state)
if ((inc_button_num & 0x01) && axis_buttons[i][0].current_state > axis_buttons[i][0].prev_physical_state)
{
axes_buttons[i][0].time_last = millis + 500;
axes_trim_value[i] += (AXIS_FULLSCALE)/p_dev_config->axis_config[i].divider;
axis_buttons[i][0].time_last = millis + 500;
axis_trim_value[i] += (AXIS_FULLSCALE)/p_dev_config->axis_config[i].divider;
}
else if ((inc_button_num & 0x01) && axes_buttons[i][0].prev_physical_state && millis - axes_buttons[i][0].time_last > 50)
else if ((inc_button_num & 0x01) && axis_buttons[i][0].prev_physical_state && millis - axis_buttons[i][0].time_last > 50)
{
axes_buttons[i][0].time_last = millis;
axes_trim_value[i] += (AXIS_FULLSCALE)/p_dev_config->axis_config[i].divider;
axis_buttons[i][0].time_last = millis;
axis_trim_value[i] += (AXIS_FULLSCALE)/p_dev_config->axis_config[i].divider;
}
else if ((inc_button_num & 0x04) && axes_buttons[i][2].current_state > axes_buttons[i][2].prev_physical_state)
else if ((inc_button_num & 0x04) && axis_buttons[i][2].current_state > axis_buttons[i][2].prev_physical_state)
{
axes_buttons[i][2].time_last = millis + 500;
axes_trim_value[i] += (AXIS_FULLSCALE)/p_dev_config->axis_config[i].divider;
axis_buttons[i][2].time_last = millis + 500;
axis_trim_value[i] += (AXIS_FULLSCALE)/p_dev_config->axis_config[i].divider;
}
else if ((inc_button_num & 0x04) && axes_buttons[i][2].prev_physical_state && millis - axes_buttons[i][2].time_last > 50)
else if ((inc_button_num & 0x04) && axis_buttons[i][2].prev_physical_state && millis - axis_buttons[i][2].time_last > 50)
{
axes_buttons[i][2].time_last = millis;
axes_trim_value[i] += (AXIS_FULLSCALE)/p_dev_config->axis_config[i].divider;
axis_buttons[i][2].time_last = millis;
axis_trim_value[i] += (AXIS_FULLSCALE)/p_dev_config->axis_config[i].divider;
}

// decrement
if ((dec_button_num & 0x01) && axes_buttons[i][0].current_state > axes_buttons[i][0].prev_physical_state)
if ((dec_button_num & 0x01) && axis_buttons[i][0].current_state > axis_buttons[i][0].prev_physical_state)
{
axes_buttons[i][0].time_last = millis + 500;
axes_trim_value[i] -= (AXIS_FULLSCALE)/p_dev_config->axis_config[i].divider;
axis_buttons[i][0].time_last = millis + 500;
axis_trim_value[i] -= (AXIS_FULLSCALE)/p_dev_config->axis_config[i].divider;
}
else if ((dec_button_num & 0x01) && axes_buttons[i][0].prev_physical_state && millis - axes_buttons[i][0].time_last > 50)
else if ((dec_button_num & 0x01) && axis_buttons[i][0].prev_physical_state && millis - axis_buttons[i][0].time_last > 50)
{
axes_buttons[i][0].time_last = millis;
axes_trim_value[i] -= (AXIS_FULLSCALE)/p_dev_config->axis_config[i].divider;
axis_buttons[i][0].time_last = millis;
axis_trim_value[i] -= (AXIS_FULLSCALE)/p_dev_config->axis_config[i].divider;
}
else if ((dec_button_num & 0x04) && axes_buttons[i][2].current_state > axes_buttons[i][2].prev_physical_state)
else if ((dec_button_num & 0x04) && axis_buttons[i][2].current_state > axis_buttons[i][2].prev_physical_state)
{
axes_buttons[i][2].time_last = millis + 500;
axes_trim_value[i] -= (AXIS_FULLSCALE)/p_dev_config->axis_config[i].divider;
axis_buttons[i][2].time_last = millis + 500;
axis_trim_value[i] -= (AXIS_FULLSCALE)/p_dev_config->axis_config[i].divider;
}
else if ((dec_button_num & 0x04) && axes_buttons[i][2].prev_physical_state && millis - axes_buttons[i][2].time_last > 50)
else if ((dec_button_num & 0x04) && axis_buttons[i][2].prev_physical_state && millis - axis_buttons[i][2].time_last > 50)
{
axes_buttons[i][2].time_last = millis;
axes_trim_value[i] -= (AXIS_FULLSCALE)/p_dev_config->axis_config[i].divider;
axis_buttons[i][2].time_last = millis;
axis_trim_value[i] -= (AXIS_FULLSCALE)/p_dev_config->axis_config[i].divider;
}

// reset
if ((rst_button_num & 0x01) && axes_buttons[i][0].current_state)
if ((rst_button_num & 0x01) && axis_buttons[i][0].current_state)
{
axes_trim_value[i] = 0;
axis_trim_value[i] = 0;
}
else if ((rst_button_num & 0x02) && axes_buttons[i][1].current_state)
else if ((rst_button_num & 0x02) && axis_buttons[i][1].current_state)
{
axes_trim_value[i] = 0;
axis_trim_value[i] = 0;
}
else if ((rst_button_num & 0x04) && axes_buttons[i][2].current_state)
else if ((rst_button_num & 0x04) && axis_buttons[i][2].current_state)
{
axes_trim_value[i] = 0;
axis_trim_value[i] = 0;
}
}

// Centering
if (cent_button_num > 0)
{
if ((cent_button_num & 0x01) && axes_buttons[i][0].current_state)
if ((cent_button_num & 0x01) && axis_buttons[i][0].current_state)
{
axes_trim_value[i] = -tmp[i];
axis_trim_value[i] = -tmp[i];
}
else if ((cent_button_num & 0x02) && axes_buttons[i][1].current_state)
else if ((cent_button_num & 0x02) && axis_buttons[i][1].current_state)
{
axes_trim_value[i] = -tmp[i];
axis_trim_value[i] = -tmp[i];
}
else if ((cent_button_num & 0x04) && axes_buttons[i][2].current_state)
else if ((cent_button_num & 0x04) && axis_buttons[i][2].current_state)
{
axes_trim_value[i] = -tmp[i];
axis_trim_value[i] = -tmp[i];
}
}

if (axes_trim_value[i] > AXIS_FULLSCALE) axes_trim_value[i] = AXIS_FULLSCALE;
if (axes_trim_value[i] < -AXIS_FULLSCALE) axes_trim_value[i] = -AXIS_FULLSCALE;
if (axis_trim_value[i] > AXIS_FULLSCALE) axis_trim_value[i] = AXIS_FULLSCALE;
if (axis_trim_value[i] < -AXIS_FULLSCALE) axis_trim_value[i] = -AXIS_FULLSCALE;

tmp[i] += axes_trim_value[i];
tmp[i] += axis_trim_value[i];

if (tmp[i] > AXIS_MAX_VALUE) tmp[i] = AXIS_MAX_VALUE;
if (tmp[i] < AXIS_MIN_VALUE) tmp[i] = AXIS_MIN_VALUE;
Expand All @@ -1175,9 +1175,9 @@ void AxesProcess (dev_config_t * p_dev_config)
{

// check axis function activation
if(((axes_buttons[i][0].current_state && p_dev_config->axis_config[i].button1_type == AXIS_BUTTON_FUNC_EN) ||
(axes_buttons[i][1].current_state && p_dev_config->axis_config[i].button2_type == AXIS_BUTTON_FUNC_EN) ||
(axes_buttons[i][2].current_state && p_dev_config->axis_config[i].button3_type == AXIS_BUTTON_FUNC_EN) ||
if(((axis_buttons[i][0].current_state && p_dev_config->axis_config[i].button1_type == AXIS_BUTTON_FUNC_EN) ||
(axis_buttons[i][1].current_state && p_dev_config->axis_config[i].button2_type == AXIS_BUTTON_FUNC_EN) ||
(axis_buttons[i][2].current_state && p_dev_config->axis_config[i].button3_type == AXIS_BUTTON_FUNC_EN) ||
(p_dev_config->axis_config[i].button1_type != AXIS_BUTTON_FUNC_EN &&
p_dev_config->axis_config[i].button2_type != AXIS_BUTTON_FUNC_EN &&
p_dev_config->axis_config[i].button3_type != AXIS_BUTTON_FUNC_EN)) &&
Expand Down Expand Up @@ -1250,10 +1250,10 @@ void AxisResetCalibration (dev_config_t * p_dev_config, uint8_t axis_num)
}

/**
* @brief Getting axes data in report format
* @param out_data: Pointer to target buffer of axes output data (may be disabled in configuration)
* @param scaled_data: Pointer to target buffer of axes scaled output data
* @param raw_data: Pointer to target buffer of axes raw output data
* @brief Getting axis data in report format
* @param out_data: Pointer to target buffer of axis output data (may be disabled in configuration)
* @param scaled_data: Pointer to target buffer of axis scaled output data
* @param raw_data: Pointer to target buffer of axis raw output data
* @retval None
*/
void AnalogGet (analog_data_t * out_data, analog_data_t * scaled_data, analog_data_t * raw_data)
Expand Down
Loading

0 comments on commit 7385bea

Please sign in to comment.