mirror of
https://github.com/dekuNukem/USB4VC.git
synced 2025-10-31 11:26:46 -07:00
refractoring quad encoder code
This commit is contained in:
@@ -110,8 +110,8 @@
|
||||
<MDIClientArea>
|
||||
<RegID>0</RegID>
|
||||
<MDITabState>
|
||||
<Len>673</Len>
|
||||
<Data>01000000040000000100000001000000010000000100000000000000020000000000000001000000010000000000000028000000280000000100000004000000000000000100000042433A5C55736572735C616C6C656E5C4465736B746F705C7265706F735C757362327073325C6669726D776172655C6170706C655F616C6C5C5372635C6D61696E2E6300000000066D61696E2E6300000000C5D4F200FFFFFFFF6C433A5C55736572735C616C6C656E5C4465736B746F705C7265706F735C757362327073325C6669726D776172655C6170706C655F616C6C5C447269766572735C53544D3332463078785F48414C5F4472697665725C496E635C73746D3332663078785F68616C5F74696D2E68000000001373746D3332663078785F68616C5F74696D2E6800000000FFDC7800FFFFFFFF6F433A5C55736572735C616C6C656E5C4465736B746F705C7265706F735C757362327073325C6669726D776172655C6170706C655F616C6C5C447269766572735C434D5349535C4465766963655C53545C53544D3332463078785C496E636C7564655C73746D33326630373278622E68000000000D73746D33326630373278622E6800000000BECEA100FFFFFFFF55433A5C55736572735C616C6C656E5C4465736B746F705C7265706F735C757362327073325C6669726D776172655C6170706C655F616C6C5C4D444B2D41524D5C737461727475705F73746D33326630373278622E730000000015737461727475705F73746D33326630373278622E7300000000F0A0A100FFFFFFFF0100000010000000C5D4F200FFDC7800BECEA100F0A0A100BCA8E1009CC1B600F7B88600D9ADC200A5C2D700B3A6BE00EAD6A300F6FA7D00B5E99D005FC3CF00C1838300CACAD500010000000000000002000000F4000000660000008007000004030000</Data>
|
||||
<Len>779</Len>
|
||||
<Data>01000000040000000100000001000000010000000100000000000000020000000000000001000000010000000000000028000000280000000100000005000000040000000100000042433A5C55736572735C616C6C656E5C4465736B746F705C7265706F735C757362327073325C6669726D776172655C6170706C655F616C6C5C5372635C6D61696E2E6300000000066D61696E2E6300000000C5D4F200FFFFFFFF6C433A5C55736572735C616C6C656E5C4465736B746F705C7265706F735C757362327073325C6669726D776172655C6170706C655F616C6C5C447269766572735C53544D3332463078785F48414C5F4472697665725C496E635C73746D3332663078785F68616C5F74696D2E68000000001373746D3332663078785F68616C5F74696D2E6800000000FFDC7800FFFFFFFF6F433A5C55736572735C616C6C656E5C4465736B746F705C7265706F735C757362327073325C6669726D776172655C6170706C655F616C6C5C447269766572735C434D5349535C4465766963655C53545C53544D3332463078785C496E636C7564655C73746D33326630373278622E68000000000D73746D33326630373278622E6800000000BECEA100FFFFFFFF55433A5C55736572735C616C6C656E5C4465736B746F705C7265706F735C757362327073325C6669726D776172655C6170706C655F616C6C5C4D444B2D41524D5C737461727475705F73746D33326630373278622E730000000015737461727475705F73746D33326630373278622E7300000000F0A0A100FFFFFFFF4A433A5C55736572735C616C6C656E5C4465736B746F705C7265706F735C757362327073325C6669726D776172655C6170706C655F616C6C5C5372635C717561645F656E636F6465722E63000000000E717561645F656E636F6465722E6300000000BCA8E100FFFFFFFF0100000010000000C5D4F200FFDC7800BECEA100F0A0A100BCA8E1009CC1B600F7B88600D9ADC200A5C2D700B3A6BE00EAD6A300F6FA7D00B5E99D005FC3CF00C1838300CACAD500010000000000000002000000F4000000660000008007000004030000</Data>
|
||||
</MDITabState>
|
||||
</MDIClientArea>
|
||||
<ViewEx>
|
||||
@@ -3603,12 +3603,12 @@
|
||||
<ActiveMDIGroup>0</ActiveMDIGroup>
|
||||
<MDIGroup>
|
||||
<Size>100</Size>
|
||||
<ActiveTab>0</ActiveTab>
|
||||
<ActiveTab>4</ActiveTab>
|
||||
<Doc>
|
||||
<Name>../Src/main.c</Name>
|
||||
<ColumnNumber>0</ColumnNumber>
|
||||
<ColumnNumber>48</ColumnNumber>
|
||||
<TopLine>314</TopLine>
|
||||
<CurrentLine>336</CurrentLine>
|
||||
<CurrentLine>343</CurrentLine>
|
||||
<Folding>1</Folding>
|
||||
<ContractedFolders></ContractedFolders>
|
||||
<PaneID>0</PaneID>
|
||||
@@ -3640,6 +3640,15 @@
|
||||
<ContractedFolders></ContractedFolders>
|
||||
<PaneID>0</PaneID>
|
||||
</Doc>
|
||||
<Doc>
|
||||
<Name>..\Src\quad_encoder.c</Name>
|
||||
<ColumnNumber>0</ColumnNumber>
|
||||
<TopLine>22</TopLine>
|
||||
<CurrentLine>49</CurrentLine>
|
||||
<Folding>1</Folding>
|
||||
<ContractedFolders></ContractedFolders>
|
||||
<PaneID>0</PaneID>
|
||||
</Doc>
|
||||
</MDIGroup>
|
||||
</MDIGroups>
|
||||
|
||||
|
||||
Binary file not shown.
@@ -27,11 +27,43 @@ Project File Date: 04/29/2022
|
||||
<h2>Output:</h2>
|
||||
*** Using Compiler 'V5.06 update 6 (build 750)', folder: 'C:\Keil_v5\ARM\ARMCC\Bin'
|
||||
Build target 'apple_all'
|
||||
compiling quad_encoder.c...
|
||||
..\Src\quad_encoder.c(47): error: #147-D: declaration is incompatible with "void quad_init(quad_output *, GPIO_TypeDef *, uint16_t, GPIO_TypeDef *, uint16_t)" (declared at line 19 of "../Inc/quad_encoder.h")
|
||||
void quad_init(TIM_HandleTypeDef* avg_tim, TIM_HandleTypeDef* arr_tim, GPIO_TypeDef* x1_port, uint16_t x1_pin, GPIO_TypeDef* x2_port, uint16_t x2_pin)//, GPIO_TypeDef* y1_port, uint16_t y1_pin, GPIO_TypeDef* y2_port, uint16_t y2_pin)
|
||||
..\Src\quad_encoder.c(49): error: #44: expression must have pointer type
|
||||
quad_x->A_port = x1_port;
|
||||
..\Src\quad_encoder.c(50): error: #44: expression must have pointer type
|
||||
quad_x->A_pin = x1_pin;
|
||||
..\Src\quad_encoder.c(51): error: #44: expression must have pointer type
|
||||
quad_x->B_port = x2_port;
|
||||
..\Src\quad_encoder.c(52): error: #44: expression must have pointer type
|
||||
quad_x->B_pin = x2_pin;
|
||||
..\Src\quad_encoder.c(55): error: #20: identifier "qo" is undefined
|
||||
quad_reset(qo);
|
||||
..\Src\quad_encoder.c: 0 warnings, 6 errors
|
||||
compiling main.c...
|
||||
linking...
|
||||
Program Size: Code=9300 RO-data=408 RW-data=40 ZI-data=2096
|
||||
FromELF: creating hex file...
|
||||
"apple_all\apple_all.axf" - 0 Error(s), 0 Warning(s).
|
||||
../Src/main.c(220): error: #20: identifier "ARR_LOOKUP_SIZE" is undefined
|
||||
if(speed_val <= 0 || speed_val >= ARR_LOOKUP_SIZE)
|
||||
../Src/main.c(222): error: #20: identifier "arr_lookup" is undefined
|
||||
return arr_lookup[speed_val];
|
||||
../Src/main.c(245): error: #20: identifier "avg_speed" is undefined
|
||||
avg_speed = get_buf_avg();
|
||||
../Src/main.c(249): error: #20: identifier "avg_speed" is undefined
|
||||
if(htim == &htim16 && avg_speed != 0)
|
||||
../Src/main.c(308): error: #167: argument of type "TIM_HandleTypeDef *" is incompatible with parameter of type "quad_output *"
|
||||
quad_init(&htim17, &htim16, GPIOB, GPIO_PIN_13, GPIOB, GPIO_PIN_12);
|
||||
../Src/main.c(308): error: #167: argument of type "TIM_HandleTypeDef *" is incompatible with parameter of type "GPIO_TypeDef *"
|
||||
quad_init(&htim17, &htim16, GPIOB, GPIO_PIN_13, GPIOB, GPIO_PIN_12);
|
||||
../Src/main.c(308): error: #167: argument of type "GPIO_TypeDef *" is incompatible with parameter of type "uint16_t"
|
||||
quad_init(&htim17, &htim16, GPIOB, GPIO_PIN_13, GPIOB, GPIO_PIN_12);
|
||||
../Src/main.c(308): error: #167: argument of type "uint16_t" is incompatible with parameter of type "GPIO_TypeDef *"
|
||||
quad_init(&htim17, &htim16, GPIOB, GPIO_PIN_13, GPIOB, GPIO_PIN_12);
|
||||
../Src/main.c(308): error: #167: argument of type "GPIO_TypeDef *" is incompatible with parameter of type "uint16_t"
|
||||
quad_init(&htim17, &htim16, GPIOB, GPIO_PIN_13, GPIOB, GPIO_PIN_12);
|
||||
../Src/main.c(308): error: #140: too many arguments in function call
|
||||
quad_init(&htim17, &htim16, GPIOB, GPIO_PIN_13, GPIOB, GPIO_PIN_12);
|
||||
../Src/main.c: 0 warnings, 10 errors
|
||||
"apple_all\apple_all.axf" - 16 Error(s), 0 Warning(s).
|
||||
|
||||
<h2>Software Packages used:</h2>
|
||||
|
||||
@@ -54,6 +86,7 @@ Package Vendor: Keil
|
||||
<h2>Collection of Component Files used:</h2>
|
||||
|
||||
* Component: ARM::CMSIS:CORE:5.3.0
|
||||
Target not created.
|
||||
Build Time Elapsed: 00:00:01
|
||||
</pre>
|
||||
</body>
|
||||
|
||||
@@ -35,7 +35,7 @@ I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_tim_ex.h)(0x5DFA0893)
|
||||
I (../Drivers/CMSIS/Include/cmsis_armcc.h)(0x5DFA0892)
|
||||
I (../Drivers/CMSIS/Include/core_cmFunc.h)(0x5DFA0892)
|
||||
I (../Drivers/CMSIS/Device/ST/STM32F0xx/Include/system_stm32f0xx.h)(0x5DFA0880)
|
||||
I (C:\Keil_v5\ARM\ARMCC\include\stdio.h)(0x5D9B429A)
|
||||
I (C:\Keil_v5\ARM\ARMCC\include\stdio.h)(0x5D9B429A)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_rcc_ex.h)(0x5DFA0893)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_gpio.h)(0x5DFA0893)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_gpio_ex.h)(0x5DFA0893)
|
||||
@@ -113,7 +113,7 @@ I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_tim_ex.h)(0x5DFA0893)
|
||||
-IC:\Users\allen\AppData\Local\Arm\Packs\ARM\CMSIS\5.6.0\CMSIS\Core\Include
|
||||
|
||||
-IC:\Users\allen\AppData\Local\Arm\Packs\Keil\STM32F0xx_DFP\2.0.0\Drivers\CMSIS\Device\ST\STM32F0xx\Include
|
||||
|
||||
|
||||
-D__UVISION_VERSION="529" -D_RTE_ -DSTM32F072xB -DUSE_HAL_DRIVER -DSTM32F072xB
|
||||
|
||||
-o apple_all\helpers.o --omf_browse apple_all\helpers.crf --depend apple_all\helpers.d)
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -213,8 +213,6 @@ make sure to enable autoreload preload to prevent glitches
|
||||
ARR = Auto Reload Register
|
||||
value = us
|
||||
*/
|
||||
#define ARR_LOOKUP_SIZE 40
|
||||
const uint16_t arr_lookup[ARR_LOOKUP_SIZE] = {500, 12500, 10245, 8926, 7990, 7264, 6671, 6170, 5735, 5352, 5010, 4699, 4416, 4156, 3915, 3691, 3481, 3283, 3098, 2922, 2755, 2596, 2445, 2300, 2162, 2029, 1901, 1779, 1660, 1546, 1436, 1329, 1226, 1126, 1029, 934, 843, 754, 667, 582};
|
||||
|
||||
uint16_t calc_arr(int32_t speed_val)
|
||||
{
|
||||
@@ -224,10 +222,6 @@ uint16_t calc_arr(int32_t speed_val)
|
||||
return arr_lookup[speed_val];
|
||||
}
|
||||
|
||||
quad_output quad_x;
|
||||
quad_output quad_y;
|
||||
int32_t avg_speed;
|
||||
|
||||
/*
|
||||
this gets called every 10ms, fetches mouse event and put them into a running buffer
|
||||
a window average is calculated, used to adjust the timer autoreload register
|
||||
@@ -255,10 +249,10 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
||||
if(htim == &htim16 && avg_speed != 0)
|
||||
{
|
||||
HAL_GPIO_TogglePin(MX2_GPIO_Port, MX2_Pin);
|
||||
if(avg_speed > 0)
|
||||
quad_increment(&quad_x);
|
||||
else
|
||||
quad_decrement(&quad_x);
|
||||
// if(avg_speed > 0)
|
||||
// quad_increment(&quad_x);
|
||||
// else
|
||||
// quad_decrement(&quad_x);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -311,10 +305,7 @@ int main(void)
|
||||
then every 50ms for example the average movement is calculated
|
||||
and that is used to update quad encoder?
|
||||
*/
|
||||
quad_init(&quad_x, MY2_GPIO_Port, MY2_Pin, MOUSE_BUTTON_GPIO_Port, MOUSE_BUTTON_Pin);
|
||||
// quad_init(&quad_y, MY1_GPIO_Port, MY1_Pin, MY2_GPIO_Port, MY2_Pin);
|
||||
HAL_TIM_Base_Start_IT(&htim17);
|
||||
HAL_TIM_Base_Start_IT(&htim16);
|
||||
quad_init(&htim17, &htim16, GPIOB, GPIO_PIN_13, GPIOB, GPIO_PIN_12);
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
|
||||
@@ -4,6 +4,16 @@
|
||||
#include "quad_encoder.h"
|
||||
#include "shared.h"
|
||||
|
||||
|
||||
quad_output quad_x;
|
||||
quad_output quad_y;
|
||||
|
||||
TIM_HandleTypeDef* avg_timer;
|
||||
TIM_HandleTypeDef* arr_timer;
|
||||
|
||||
int32_t avg_speed;
|
||||
#define ARR_LOOKUP_SIZE 40
|
||||
const uint16_t arr_lookup[ARR_LOOKUP_SIZE] = {500, 12500, 10245, 8926, 7990, 7264, 6671, 6170, 5735, 5352, 5010, 4699, 4416, 4156, 3915, 3691, 3481, 3283, 3098, 2922, 2755, 2596, 2445, 2300, 2162, 2029, 1901, 1779, 1660, 1546, 1436, 1329, 1226, 1126, 1029, 934, 843, 754, 667, 582};
|
||||
const uint8_t grey_code_lookup[4] = {0, 1, 3, 2};
|
||||
|
||||
void quad_write(quad_output *qo)
|
||||
@@ -25,13 +35,26 @@ void quad_reset(quad_output *qo)
|
||||
quad_write(qo);
|
||||
}
|
||||
|
||||
void quad_init(quad_output *qo, GPIO_TypeDef* this_A_port, uint16_t this_A_pin, GPIO_TypeDef* this_B_port, uint16_t this_B_pin)
|
||||
// void quad_init(quad_output *qo, GPIO_TypeDef* this_A_port, uint16_t this_A_pin, GPIO_TypeDef* this_B_port, uint16_t this_B_pin)
|
||||
// {
|
||||
// qo->A_port = this_A_port;
|
||||
// qo->A_pin = this_A_pin;
|
||||
// qo->B_port = this_B_port;
|
||||
// qo->B_pin = this_B_pin;
|
||||
// quad_reset(qo);
|
||||
// }
|
||||
|
||||
void quad_init(TIM_HandleTypeDef* avg_tim, TIM_HandleTypeDef* arr_tim, GPIO_TypeDef* x1_port, uint16_t x1_pin, GPIO_TypeDef* x2_port, uint16_t x2_pin)//, GPIO_TypeDef* y1_port, uint16_t y1_pin, GPIO_TypeDef* y2_port, uint16_t y2_pin)
|
||||
{
|
||||
qo->A_port = this_A_port;
|
||||
qo->A_pin = this_A_pin;
|
||||
qo->B_port = this_B_port;
|
||||
qo->B_pin = this_B_pin;
|
||||
quad_x->A_port = x1_port;
|
||||
quad_x->A_pin = x1_pin;
|
||||
quad_x->B_port = x2_port;
|
||||
quad_x->B_pin = x2_pin;
|
||||
avg_timer = avg_tim;
|
||||
arr_timer = arr_tim;
|
||||
quad_reset(qo);
|
||||
HAL_TIM_Base_Start_IT(avg_timer);
|
||||
HAL_TIM_Base_Start_IT(arr_timer);
|
||||
}
|
||||
|
||||
void quad_increment(quad_output *qo)
|
||||
|
||||
@@ -72,8 +72,7 @@ PA6.Mode=Full_Duplex_Slave
|
||||
PA6.Signal=SPI1_MISO
|
||||
PA7.Mode=Full_Duplex_Slave
|
||||
PA7.Signal=SPI1_MOSI
|
||||
PA8.GPIOParameters=PinState,GPIO_Label,GPIO_ModeDefaultOutputPP
|
||||
PA8.GPIO_Label=MX1
|
||||
PA8.GPIOParameters=PinState,GPIO_ModeDefaultOutputPP
|
||||
PA8.GPIO_ModeDefaultOutputPP=GPIO_MODE_OUTPUT_OD
|
||||
PA8.Locked=true
|
||||
PA8.PinState=GPIO_PIN_SET
|
||||
@@ -92,28 +91,24 @@ PB1.GPIO_ModeDefaultOutputPP=GPIO_MODE_OUTPUT_OD
|
||||
PB1.Locked=true
|
||||
PB1.PinState=GPIO_PIN_SET
|
||||
PB1.Signal=GPIO_Output
|
||||
PB12.GPIOParameters=PinState,GPIO_Label,GPIO_ModeDefaultOutputPP
|
||||
PB12.GPIO_Label=MOUSE_BUTTON
|
||||
PB12.GPIOParameters=PinState,GPIO_ModeDefaultOutputPP
|
||||
PB12.GPIO_ModeDefaultOutputPP=GPIO_MODE_OUTPUT_OD
|
||||
PB12.Locked=true
|
||||
PB12.PinState=GPIO_PIN_SET
|
||||
PB12.Signal=GPIO_Output
|
||||
PB13.GPIOParameters=GPIO_Speed,PinState,GPIO_Label,GPIO_ModeDefaultOutputPP
|
||||
PB13.GPIO_Label=MY2
|
||||
PB13.GPIOParameters=GPIO_Speed,PinState,GPIO_ModeDefaultOutputPP
|
||||
PB13.GPIO_ModeDefaultOutputPP=GPIO_MODE_OUTPUT_OD
|
||||
PB13.GPIO_Speed=GPIO_SPEED_FREQ_LOW
|
||||
PB13.Locked=true
|
||||
PB13.PinState=GPIO_PIN_SET
|
||||
PB13.Signal=GPIO_Output
|
||||
PB14.GPIOParameters=GPIO_Speed,PinState,GPIO_Label,GPIO_ModeDefaultOutputPP
|
||||
PB14.GPIO_Label=MY1
|
||||
PB14.GPIOParameters=GPIO_Speed,PinState,GPIO_ModeDefaultOutputPP
|
||||
PB14.GPIO_ModeDefaultOutputPP=GPIO_MODE_OUTPUT_OD
|
||||
PB14.GPIO_Speed=GPIO_SPEED_FREQ_LOW
|
||||
PB14.Locked=true
|
||||
PB14.PinState=GPIO_PIN_SET
|
||||
PB14.Signal=GPIO_Output
|
||||
PB15.GPIOParameters=GPIO_Speed,PinState,GPIO_Label,GPIO_ModeDefaultOutputPP
|
||||
PB15.GPIO_Label=MX2
|
||||
PB15.GPIOParameters=GPIO_Speed,PinState,GPIO_ModeDefaultOutputPP
|
||||
PB15.GPIO_ModeDefaultOutputPP=GPIO_MODE_OUTPUT_OD
|
||||
PB15.GPIO_Speed=GPIO_SPEED_FREQ_LOW
|
||||
PB15.Locked=true
|
||||
|
||||
Reference in New Issue
Block a user