mirror of
https://github.com/dekuNukem/USB4VC.git
synced 2025-10-31 11:26:46 -07:00
added auto pirority adjustment
This commit is contained in:
@@ -11,6 +11,8 @@ void xtkb_init(GPIO_TypeDef* clk_port, uint16_t clk_pin, GPIO_TypeDef* data_port
|
||||
void xtkb_check_for_softreset(void);
|
||||
uint8_t xtkb_press_key(uint8_t code, uint8_t status);
|
||||
void xtkb_reset_bus(void);
|
||||
void xtkb_release_lines(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
File diff suppressed because one or more lines are too long
Binary file not shown.
@@ -27,19 +27,18 @@ Project File Date: 12/18/2021
|
||||
<h2>Output:</h2>
|
||||
*** Using Compiler 'V5.06 update 6 (build 750)', folder: 'C:\Keil_v5\ARM\ARMCC\Bin'
|
||||
Build target 'ibmpc'
|
||||
compiling xt_kb.c...
|
||||
compiling main.c...
|
||||
../Src/main.c(420): warning: #188-D: enumerated type mixed with another type
|
||||
../Src/main.c(455): warning: #188-D: enumerated type mixed with another type
|
||||
HAL_GPIO_WritePin(GAMEPAD_B1_GPIO_Port, GAMEPAD_B1_Pin, !(this_gamepad_event->button_1));
|
||||
../Src/main.c(421): warning: #188-D: enumerated type mixed with another type
|
||||
../Src/main.c(456): warning: #188-D: enumerated type mixed with another type
|
||||
HAL_GPIO_WritePin(GAMEPAD_B2_GPIO_Port, GAMEPAD_B2_Pin, !(this_gamepad_event->button_2));
|
||||
../Src/main.c(422): warning: #188-D: enumerated type mixed with another type
|
||||
../Src/main.c(457): warning: #188-D: enumerated type mixed with another type
|
||||
HAL_GPIO_WritePin(GAMEPAD_B3_GPIO_Port, GAMEPAD_B3_Pin, !(this_gamepad_event->button_3));
|
||||
../Src/main.c(423): warning: #188-D: enumerated type mixed with another type
|
||||
../Src/main.c(458): warning: #188-D: enumerated type mixed with another type
|
||||
HAL_GPIO_WritePin(GAMEPAD_B4_GPIO_Port, GAMEPAD_B4_Pin, !(this_gamepad_event->button_4));
|
||||
../Src/main.c: 4 warnings, 0 errors
|
||||
linking...
|
||||
Program Size: Code=14224 RO-data=308 RW-data=128 ZI-data=2160
|
||||
Program Size: Code=15856 RO-data=428 RW-data=128 ZI-data=2160
|
||||
FromELF: creating hex file...
|
||||
"ibmpc\ibmpc.axf" - 0 Error(s), 4 Warning(s).
|
||||
|
||||
@@ -64,7 +63,7 @@ Package Vendor: Keil
|
||||
<h2>Collection of Component Files used:</h2>
|
||||
|
||||
* Component: ARM::CMSIS:CORE:5.3.0
|
||||
Build Time Elapsed: 00:00:02
|
||||
Build Time Elapsed: 00:00:01
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -111,7 +111,7 @@ I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_uart_ex.h)(0x5DFA0893)
|
||||
-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 ibmpc\ps2kb.o --omf_browse ibmpc\ps2kb.crf --depend ibmpc\ps2kb.d)
|
||||
I (C:\Keil_v5\ARM\ARMCC\include\stdio.h)(0x5D9B429A)
|
||||
I (C:\Keil_v5\ARM\ARMCC\include\string.h)(0x5D9B4298)
|
||||
@@ -193,7 +193,7 @@ I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_tim_ex.h)(0x5DFA0893)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_pwr_ex.h)(0x5DFA0893)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_spi.h)(0x5DFA0893)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_spi_ex.h)(0x5DFA0893)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_tim.h)(0x5DFA0893)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_tim.h)(0x5DFA0893)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_tim_ex.h)(0x5DFA0893)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_uart.h)(0x5DFA0893)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_uart_ex.h)(0x5DFA0893)
|
||||
@@ -233,7 +233,7 @@ I (../Inc/ps2kb.h)(0x61BC5950)
|
||||
I (../Drivers/CMSIS/Include/core_cmInstr.h)(0x5DFA0892)
|
||||
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 (../Drivers/CMSIS/Device/ST/STM32F0xx/Include/system_stm32f0xx.h)(0x5DFA0880)
|
||||
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)
|
||||
@@ -301,7 +301,7 @@ I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_tim.h)(0x5DFA0893)
|
||||
I (../Inc/helpers.h)(0x61BCFD61)
|
||||
I (../Inc/ps2kb.h)(0x61BC5950)
|
||||
I (C:\Keil_v5\ARM\ARMCC\include\string.h)(0x5D9B4298)
|
||||
I (../Inc/ps2mouse.h)(0x61BC59D5)
|
||||
I (../Inc/ps2mouse.h)(0x61BC59D5)
|
||||
I (../Inc/mcp4451.h)(0x61B64C4C)
|
||||
I (../Inc/xt_kb.h)(0x61BF0387)
|
||||
F (../Src/stm32f0xx_it.c)(0x61BE3FF7)(--c99 -c --cpu Cortex-M0 -D__MICROLIB -g -O3 --apcs=interwork --split_sections -I ../Inc -I ../Drivers/STM32F0xx_HAL_Driver/Inc -I ../Drivers/STM32F0xx_HAL_Driver/Inc/Legacy -I ../Drivers/CMSIS/Device/ST/STM32F0xx/Include -I ../Drivers/CMSIS/Include
|
||||
@@ -338,9 +338,9 @@ I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_tim_ex.h)(0x5DFA0893)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_flash.h)(0x5DFA0893)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_flash_ex.h)(0x5DFA0893)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_i2c.h)(0x5DFA0893)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_i2c_ex.h)(0x5DFA0893)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_i2c_ex.h)(0x5DFA0893)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_pwr.h)(0x5DFA0893)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_pwr_ex.h)(0x5DFA0893)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_pwr_ex.h)(0x5DFA0893)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_spi.h)(0x5DFA0893)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_spi_ex.h)(0x5DFA0893)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_tim.h)(0x5DFA0893)
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -125,6 +125,13 @@ int16_t byte_to_int16_t(uint8_t lsb, uint8_t msb)
|
||||
return (int16_t)((msb << 8) | lsb);
|
||||
}
|
||||
|
||||
uint8_t is_protocol_enabled(uint8_t this_protocol)
|
||||
{
|
||||
if(this_protocol >= PROTOCOL_LOOKUP_SIZE)
|
||||
return 0;
|
||||
return protocol_status_lookup[this_protocol] == PROTOCOL_STATUS_ENABLED;
|
||||
}
|
||||
|
||||
void handle_protocol_switch(uint8_t spi_byte)
|
||||
{
|
||||
uint8_t index = spi_byte & 0x7f;
|
||||
@@ -137,6 +144,31 @@ void handle_protocol_switch(uint8_t spi_byte)
|
||||
return;
|
||||
if(onoff)
|
||||
{
|
||||
switch(index)
|
||||
{
|
||||
case PROTOCOL_AT_PS2_KB:
|
||||
// printf("PS2KB on\n");
|
||||
ps2kb_init(PS2KB_CLK_GPIO_Port, PS2KB_CLK_Pin, PS2KB_DATA_GPIO_Port, PS2KB_DATA_Pin);
|
||||
break;
|
||||
|
||||
case PROTOCOL_XT_KB:
|
||||
// printf("XTKB on\n");
|
||||
xtkb_init(PS2KB_CLK_GPIO_Port, PS2KB_CLK_Pin, PS2KB_DATA_GPIO_Port, PS2KB_DATA_Pin);
|
||||
break;
|
||||
|
||||
case PROTOCOL_PS2_MOUSE:
|
||||
// printf("PS2MOUSE on\n");
|
||||
ps2mouse_init(PS2MOUSE_CLK_GPIO_Port, PS2MOUSE_CLK_Pin, PS2MOUSE_DATA_GPIO_Port, PS2MOUSE_DATA_Pin);
|
||||
break;
|
||||
|
||||
case PROTOCOL_MICROSOFT_SERIAL_MOUSE:
|
||||
// printf("SERMOUSE on\n");
|
||||
break;
|
||||
|
||||
case PROTOCOL_GENERIC_GAMEPORT_GAMEPAD:
|
||||
// printf("GGP on\n");
|
||||
break;
|
||||
}
|
||||
protocol_status_lookup[index] = PROTOCOL_STATUS_ENABLED;
|
||||
}
|
||||
else
|
||||
@@ -152,6 +184,7 @@ void handle_protocol_switch(uint8_t spi_byte)
|
||||
|
||||
case PROTOCOL_XT_KB:
|
||||
// printf("XTKB off\n");
|
||||
xtkb_release_lines();
|
||||
break;
|
||||
|
||||
case PROTOCOL_PS2_MOUSE:
|
||||
@@ -332,7 +365,7 @@ void ps2kb_update(void)
|
||||
// GPIO external interrupt callback
|
||||
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
|
||||
{
|
||||
if(GPIO_Pin == UART3_RTS_Pin)
|
||||
if(GPIO_Pin == UART3_RTS_Pin && is_protocol_enabled(PROTOCOL_MICROSOFT_SERIAL_MOUSE))
|
||||
rts_active = 1;
|
||||
}
|
||||
|
||||
@@ -362,7 +395,7 @@ void serial_mouse_update(void)
|
||||
if(this_mouse_event->button_right)
|
||||
serial_mouse_output_buf[0] |= 0x10;
|
||||
|
||||
uint8_t serial_y = -1 * this_mouse_event->movement_y;
|
||||
int8_t serial_y = -1 * this_mouse_event->movement_y;
|
||||
if(serial_y & 0x80)
|
||||
serial_mouse_output_buf[0] |= 0x8;
|
||||
if(serial_y & 0x40)
|
||||
@@ -374,7 +407,7 @@ void serial_mouse_update(void)
|
||||
|
||||
serial_mouse_output_buf[1] = 0x3f & this_mouse_event->movement_x;
|
||||
serial_mouse_output_buf[2] = 0x3f & serial_y;
|
||||
|
||||
|
||||
mouse_buf_pop(&my_mouse_buf);
|
||||
HAL_UART_Transmit_IT(&huart3, serial_mouse_output_buf, 3);
|
||||
}
|
||||
@@ -399,7 +432,7 @@ void protocol_status_lookup_init(void)
|
||||
{
|
||||
memset(protocol_status_lookup, PROTOCOL_STATUS_NOT_AVAILABLE, PROTOCOL_LOOKUP_SIZE);
|
||||
protocol_status_lookup[PROTOCOL_AT_PS2_KB] = PROTOCOL_STATUS_ENABLED;
|
||||
protocol_status_lookup[PROTOCOL_XT_KB] = PROTOCOL_STATUS_ENABLED;
|
||||
protocol_status_lookup[PROTOCOL_XT_KB] = PROTOCOL_STATUS_DISABLED;
|
||||
protocol_status_lookup[PROTOCOL_PS2_MOUSE] = PROTOCOL_STATUS_ENABLED;
|
||||
protocol_status_lookup[PROTOCOL_MICROSOFT_SERIAL_MOUSE] = PROTOCOL_STATUS_ENABLED;
|
||||
protocol_status_lookup[PROTOCOL_GENERIC_GAMEPORT_GAMEPAD] = PROTOCOL_STATUS_ENABLED;
|
||||
@@ -481,21 +514,28 @@ int main(void)
|
||||
MX_USART1_UART_Init();
|
||||
MX_USART3_UART_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
printf("%s\nrev%d v%d.%d.%d\n", boot_message, hw_revision, version_major, version_minor, version_patch);
|
||||
delay_us_init(&htim2);
|
||||
// ps2kb_init(PS2KB_CLK_GPIO_Port, PS2KB_CLK_Pin, PS2KB_DATA_GPIO_Port, PS2KB_DATA_Pin);
|
||||
xtkb_init(PS2KB_CLK_GPIO_Port, PS2KB_CLK_Pin, PS2KB_DATA_GPIO_Port, PS2KB_DATA_Pin);
|
||||
ps2mouse_init(PS2MOUSE_CLK_GPIO_Port, PS2MOUSE_CLK_Pin, PS2MOUSE_DATA_GPIO_Port, PS2MOUSE_DATA_Pin);
|
||||
protocol_status_lookup_init();
|
||||
|
||||
if(is_protocol_enabled(PROTOCOL_AT_PS2_KB))
|
||||
ps2kb_init(PS2KB_CLK_GPIO_Port, PS2KB_CLK_Pin, PS2KB_DATA_GPIO_Port, PS2KB_DATA_Pin);
|
||||
else if(is_protocol_enabled(PROTOCOL_XT_KB))
|
||||
xtkb_init(PS2KB_CLK_GPIO_Port, PS2KB_CLK_Pin, PS2KB_DATA_GPIO_Port, PS2KB_DATA_Pin);
|
||||
|
||||
if(is_protocol_enabled(PROTOCOL_PS2_MOUSE))
|
||||
ps2mouse_init(PS2MOUSE_CLK_GPIO_Port, PS2MOUSE_CLK_Pin, PS2MOUSE_DATA_GPIO_Port, PS2MOUSE_DATA_Pin);
|
||||
|
||||
kb_buf_init(&my_kb_buf, 16);
|
||||
mouse_buf_init(&my_mouse_buf, 16);
|
||||
gamepad_buf_init(&my_gamepad_buf, 16);
|
||||
protocol_status_lookup_init();
|
||||
memset(spi_transmit_buf, 0, SPI_BUF_SIZE);
|
||||
|
||||
mcp4451_reset();
|
||||
// printf("mia %d\n", mcp4451_is_available());
|
||||
if(mcp4451_is_available() == 0)
|
||||
hw_revision = 1;
|
||||
|
||||
memset(spi_transmit_buf, 0, SPI_BUF_SIZE);
|
||||
HAL_SPI_TransmitReceive_IT(&hspi1, spi_transmit_buf, spi_recv_buf, SPI_BUF_SIZE);
|
||||
printf("%s\nrev%d v%d.%d.%d\n", boot_message, hw_revision, version_major, version_minor, version_patch);
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
@@ -512,17 +552,18 @@ int main(void)
|
||||
/* USER CODE BEGIN 3 */
|
||||
|
||||
// If both enabled, PS2 mouse takes priority
|
||||
if(protocol_status_lookup[PROTOCOL_PS2_MOUSE] == PROTOCOL_STATUS_ENABLED)
|
||||
if(is_protocol_enabled(PROTOCOL_PS2_MOUSE) && IS_PS2MOUSE_PRESENT())
|
||||
ps2mouse_update();
|
||||
else if(protocol_status_lookup[PROTOCOL_MICROSOFT_SERIAL_MOUSE] == PROTOCOL_STATUS_ENABLED)
|
||||
else if(is_protocol_enabled(PROTOCOL_MICROSOFT_SERIAL_MOUSE))
|
||||
serial_mouse_update();
|
||||
|
||||
// if(protocol_status_lookup[PROTOCOL_AT_PS2_KB] == PROTOCOL_STATUS_ENABLED)
|
||||
// ps2kb_update();
|
||||
if(protocol_status_lookup[PROTOCOL_XT_KB] == PROTOCOL_STATUS_ENABLED)
|
||||
// If both enabled, PS2 keyboard takes priority
|
||||
if(is_protocol_enabled(PROTOCOL_AT_PS2_KB) && IS_KB_PRESENT())
|
||||
ps2kb_update();
|
||||
else if(is_protocol_enabled(PROTOCOL_XT_KB) && IS_KB_PRESENT())
|
||||
xtkb_update();
|
||||
|
||||
if(protocol_status_lookup[PROTOCOL_GENERIC_GAMEPORT_GAMEPAD] == PROTOCOL_STATUS_ENABLED)
|
||||
if(is_protocol_enabled(PROTOCOL_GENERIC_GAMEPORT_GAMEPAD))
|
||||
gamepad_update();
|
||||
|
||||
if(spi_error_occured)
|
||||
|
||||
@@ -23,6 +23,12 @@ uint16_t xtkb_data_pin;
|
||||
|
||||
uint32_t last_clk_high, last_typematic;
|
||||
|
||||
void xtkb_release_lines(void)
|
||||
{
|
||||
XTKB_CLK_HI();
|
||||
XTKB_DATA_HI();
|
||||
}
|
||||
|
||||
void xtkb_reset_bus(void)
|
||||
{
|
||||
XTKB_CLK_HI();
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
for (int i = 0; i < SERIAL_MOUSE_BUF_SIZE; ++i)
|
||||
printf("0x%x ", serial_mouse_output_buf[i]);
|
||||
printf("\n");
|
||||
int8_t yyy = serial_mouse_output_buf[2] & 0x3f;
|
||||
yyy = yyy | ((serial_mouse_output_buf[0] & 0xc) << 4);
|
||||
printf("y %d\n", yyy);
|
||||
|
||||
|
||||
printf("%d %d\n", IS_KB_PRESENT(), IS_PS2MOUSE_PRESENT());
|
||||
HAL_Delay(500);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user