Skip to content

Commit

Permalink
Encoders to matrix buttons, swapped matrix row and columns
Browse files Browse the repository at this point in the history
  • Loading branch information
Yury Vostrenkov committed Feb 21, 2020
1 parent eb39341 commit d9e629b
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Inc/common_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ typedef struct

typedef struct
{
uint8_t dummy;
uint8_t dummy; // alighning
uint8_t id;
int16_t raw_axis_data[MAX_AXIS_NUM];
uint8_t raw_button_data[9];
Expand Down
Binary file modified MDK-ARM/FreeJoy.bin
Binary file not shown.
32 changes: 6 additions & 26 deletions MDK-ARM/FreeJoy.uvoptx
Original file line number Diff line number Diff line change
Expand Up @@ -148,24 +148,7 @@
<Name>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128 -FS08000000 -FL020000 -FP0($$Device:STM32F103C8$Flash\STM32F10x_128.FLM))</Name>
</SetRegEntry>
</TargetDriverDllRegistry>
<Breakpoint>
<Bp>
<Number>0</Number>
<Type>0</Type>
<LineNumber>150</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>134223878</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>..\Src\usb_prop.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\FreeJoy\../Src/usb_prop.c\150</Expression>
</Bp>
</Breakpoint>
<Breakpoint/>
<WatchWindow1>
<Ww>
<count>0</count>
Expand All @@ -192,15 +175,12 @@
<WinNumber>1</WinNumber>
<ItemText>physical_buttons_data</ItemText>
</Ww>
</WatchWindow1>
<MemoryWindow1>
<Mm>
<Ww>
<count>5</count>
<WinNumber>1</WinNumber>
<SubType>0</SubType>
<ItemText>0x8007000</ItemText>
<AccSizeX>0</AccSizeX>
</Mm>
</MemoryWindow1>
<ItemText>buttons_data</ItemText>
</Ww>
</WatchWindow1>
<Tracepoint>
<THDelay>0</THDelay>
</Tracepoint>
Expand Down
23 changes: 12 additions & 11 deletions Src/buttons.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,21 +446,21 @@ void MaxtrixButtonsGet (uint8_t * raw_button_data_buf, dev_config_t * p_dev_conf
// get matrix buttons
for (int i=0; i<USED_PINS_NUM; i++)
{
if ((p_dev_config->pins[i] == BUTTON_COLUMN) && ((*pos) < MAX_BUTTONS_NUM))
if ((p_dev_config->pins[i] == BUTTON_ROW) && ((*pos) < MAX_BUTTONS_NUM))
{
// tie Column pin to ground
// tie Row pin to ground
GPIO_WriteBit(pin_config[i].port, pin_config[i].pin, Bit_RESET);

// get states at Rows
// get states at Columns
for (int k=0; k<USED_PINS_NUM; k++)
{
if (p_dev_config->pins[k] == BUTTON_ROW && (*pos) < MAX_BUTTONS_NUM)
if (p_dev_config->pins[k] == BUTTON_COLUMN && (*pos) < MAX_BUTTONS_NUM)
{
raw_button_data_buf[*pos] = DirectButtonGet(k, p_dev_config);
(*pos)++;
}
}
// return Column pin to Hi-Z state
// return Row pin to Hi-Z state
GPIO_WriteBit(pin_config[i].port, pin_config[i].pin, Bit_SET);
}
}
Expand Down Expand Up @@ -654,15 +654,11 @@ void ButtonsReadLogical (dev_config_t * p_dev_config)
}
}


// prevent not atomic read
NVIC_DisableIRQ(TIM1_UP_IRQn);
// convert data to report format
uint8_t k = 0;
for (int i=0;i<MAX_BUTTONS_NUM;i++)
{
uint8_t is_hidden = 0;
buttons_data[(i & 0xF8)>>3] &= ~(1 << (i & 0x07));

// buttons is mapped to shift
if (i == p_dev_config->shift_config[0].button ||
Expand Down Expand Up @@ -701,8 +697,15 @@ void ButtonsReadLogical (dev_config_t * p_dev_config)

if (!is_hidden)
{
// prevent not atomic read
NVIC_DisableIRQ(TIM1_UP_IRQn);

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

// resume IRQ
NVIC_EnableIRQ(TIM1_UP_IRQn);
}
}

Expand Down Expand Up @@ -740,8 +743,6 @@ void ButtonsReadLogical (dev_config_t * p_dev_config)
break;
}
}
// resume IRQ
NVIC_EnableIRQ(TIM1_UP_IRQn);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions Src/periphery.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,14 @@ void IO_Init (dev_config_t * p_dev_config)
GPIO_InitStructure.GPIO_Pin = pin_config[i].pin;
GPIO_Init(pin_config[i].port, &GPIO_InitStructure);
}
else if (p_dev_config->pins[i] == BUTTON_ROW)
else if (p_dev_config->pins[i] == BUTTON_COLUMN)
{
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Pin = pin_config[i].pin;
GPIO_Init(pin_config[i].port, &GPIO_InitStructure);
}
else if (p_dev_config->pins[i] == BUTTON_COLUMN)
else if (p_dev_config->pins[i] == BUTTON_ROW)
{
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
Expand Down
3 changes: 1 addition & 2 deletions Src/stm32f10x_it.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ void TIM3_IRQHandler(void)

void TIM1_UP_IRQHandler(void)
{
uint8_t report_buf[64];
app_config_t tmp_app_config;

if (TIM_GetITStatus(TIM1, TIM_IT_Update))
Expand Down Expand Up @@ -233,7 +232,7 @@ void TIM1_UP_IRQHandler(void)

joy_report.id = REPORT_ID_JOY;

USB_CUSTOM_HID_SendReport((uint8_t *)&(joy_report.id), sizeof(joy_report)-sizeof(joy_report.dummy));
USB_CUSTOM_HID_SendReport((uint8_t *)&joy_report.id, sizeof(joy_report) - sizeof(joy_report.dummy));
}

EncoderProcess(buttons_state, &dev_config);
Expand Down

0 comments on commit d9e629b

Please sign in to comment.