mirror of
https://github.com/dekuNukem/USB4VC.git
synced 2025-10-31 11:26:46 -07:00
mouse systems serial mouse prototype working
This commit is contained in:
@@ -64,6 +64,7 @@ typedef struct
|
||||
uint8_t button_right;
|
||||
uint8_t button_side;
|
||||
uint8_t button_extra;
|
||||
uint8_t has_button_transition;
|
||||
} mouse_event;
|
||||
|
||||
typedef struct
|
||||
|
||||
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -27,11 +27,20 @@ Project File Date: 03/28/2022
|
||||
<h2>Output:</h2>
|
||||
*** Using Compiler 'V5.06 update 6 (build 750)', folder: 'C:\Keil_v5\ARM\ARMCC\Bin'
|
||||
Build target 'ibmpc'
|
||||
compiling ps2kb.c...
|
||||
compiling main.c...
|
||||
../Src/main.c(489): 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(490): 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(491): 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(492): 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=16912 RO-data=768 RW-data=128 ZI-data=2320
|
||||
Program Size: Code=11596 RO-data=764 RW-data=136 ZI-data=2320
|
||||
FromELF: creating hex file...
|
||||
"ibmpc\ibmpc.axf" - 0 Error(s), 0 Warning(s).
|
||||
"ibmpc\ibmpc.axf" - 0 Error(s), 4 Warning(s).
|
||||
|
||||
<h2>Software Packages used:</h2>
|
||||
|
||||
|
||||
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
@@ -40,7 +40,7 @@ F (..\Src\helpers.c)(0x61BCF9FD)(--c99 -c --cpu Cortex-M0 -D__MICROLIB -g -O3 --
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_gpio.h)(0x5DFA0893)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_gpio_ex.h)(0x5DFA0893)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_dma.h)(0x5DFA0893)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_dma_ex.h)(0x5DFA0893)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_dma_ex.h)(0x5DFA0893)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_cortex.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)
|
||||
@@ -78,7 +78,7 @@ F (..\Src\ps2kb.c)(0x627582A5)(--c99 -c --cpu Cortex-M0 -D__MICROLIB -g -O3 --ap
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_def.h)(0x5DFA0893)
|
||||
I (../Drivers/CMSIS/Device/ST/STM32F0xx/Include/stm32f0xx.h)(0x5DFA0880)
|
||||
I (../Drivers/CMSIS/Device/ST/STM32F0xx/Include/stm32f072xb.h)(0x5DFA0880)
|
||||
I (../Drivers/CMSIS/Include/core_cm0.h)(0x5DFA0892)
|
||||
I (../Drivers/CMSIS/Include/core_cm0.h)(0x5DFA0892)
|
||||
I (C:\Keil_v5\ARM\ARMCC\include\stdint.h)(0x5D9B4298)
|
||||
I (../Drivers/CMSIS/Include/core_cmInstr.h)(0x5DFA0892)
|
||||
I (../Drivers/CMSIS/Include/cmsis_armcc.h)(0x5DFA0892)
|
||||
@@ -118,7 +118,7 @@ F (..\Src\ps2mouse.c)(0x62757D48)(--c99 -c --cpu Cortex-M0 -D__MICROLIB -g -O3 -
|
||||
I (C:\Keil_v5\ARM\ARMCC\include\stdio.h)(0x5D9B429A)
|
||||
I (C:\Keil_v5\ARM\ARMCC\include\string.h)(0x5D9B4298)
|
||||
I (C:\Keil_v5\ARM\ARMCC\include\stdlib.h)(0x5D9B429A)
|
||||
I (../Inc/helpers.h)(0x62757D10)
|
||||
I (../Inc/helpers.h)(0x62783C99)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal.h)(0x5DFA0893)
|
||||
I (../Inc/stm32f0xx_hal_conf.h)(0x62423606)
|
||||
I (../Inc/main.h)(0x62423606)
|
||||
@@ -155,7 +155,7 @@ I (../Inc/shared.h)(0x61B61A00)
|
||||
I (../Inc/ps2kb.h)(0x6274FBAF)
|
||||
I (../Inc/delay_us.h)(0x617487C7)
|
||||
F (..\Src\ps2mouse.c)(0x62757D48)(--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
|
||||
|
||||
|
||||
-I.\RTE\_ibmpc
|
||||
|
||||
-IC:\Users\allen\AppData\Local\Arm\Packs\ARM\CMSIS\5.6.0\CMSIS\Core\Include
|
||||
@@ -202,7 +202,7 @@ F (..\Src\xt_kb.c)(0x626F0101)(--c99 -c --cpu Cortex-M0 -D__MICROLIB -g -O3 --ap
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_uart.h)(0x5DFA0893)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_uart_ex.h)(0x5DFA0893)
|
||||
I (../Inc/shared.h)(0x61B61A00)
|
||||
I (../Inc/ps2mouse.h)(0x62757D20)
|
||||
I (../Inc/ps2mouse.h)(0x62757D20)
|
||||
I (../Inc/delay_us.h)(0x617487C7)
|
||||
F (..\Inc\delay_us.h)(0x617487C7)()
|
||||
F (..\Inc\helpers.h)(0x62783C99)()
|
||||
@@ -239,7 +239,7 @@ I (../Inc/shared.h)(0x61B61A00)
|
||||
I (../Drivers/CMSIS/Include/core_cmFunc.h)(0x5DFA0892)
|
||||
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.h)(0x5DFA0893)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_gpio_ex.h)(0x5DFA0893)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_dma.h)(0x5DFA0893)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_dma_ex.h)(0x5DFA0893)
|
||||
@@ -275,7 +275,7 @@ I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_uart.h)(0x5DFA0893)
|
||||
I (../Inc/helpers.h)(0x62783C99)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal.h)(0x5DFA0893)
|
||||
I (../Inc/stm32f0xx_hal_conf.h)(0x62423606)
|
||||
I (../Inc/main.h)(0x62423606)
|
||||
I (../Inc/main.h)(0x62423606)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_rcc.h)(0x5DFA0893)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_def.h)(0x5DFA0893)
|
||||
I (../Drivers/CMSIS/Device/ST/STM32F0xx/Include/stm32f0xx.h)(0x5DFA0880)
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -84,8 +84,11 @@ uint8_t ps2kb_host_cmd, ps2mouse_host_cmd, buffered_code, buffered_value, ps2mou
|
||||
mouse_event latest_mouse_event;
|
||||
gamepad_event latest_gamepad_event;
|
||||
ps2_outgoing_buf my_ps2_outbuf;
|
||||
#define SERIAL_MOUSE_BUF_SIZE 3
|
||||
uint8_t serial_mouse_output_buf[SERIAL_MOUSE_BUF_SIZE];
|
||||
#define MICROSOFT_SERIAL_MOUSE_BUF_SIZE 3
|
||||
uint8_t microsoft_serial_mouse_output_buf[MICROSOFT_SERIAL_MOUSE_BUF_SIZE];
|
||||
#define MOUSESYSTEMS_SERIAL_MOUSE_BUF_SIZE 5
|
||||
uint8_t mousesystems_serial_mouse_output_buf[MOUSESYSTEMS_SERIAL_MOUSE_BUF_SIZE];
|
||||
|
||||
uint8_t serial_mouse_rts_response;
|
||||
volatile uint8_t rts_active;
|
||||
uint8_t spi_error_occured;
|
||||
@@ -212,6 +215,9 @@ void handle_protocol_switch(uint8_t spi_byte)
|
||||
}
|
||||
}
|
||||
|
||||
#define MOUSE_BUTTON_HISTORY_SIZE 5
|
||||
uint8_t mouse_button_history[MOUSE_BUTTON_HISTORY_SIZE];
|
||||
|
||||
/*
|
||||
This is called when a new SPI packet is received
|
||||
This is part of an ISR, so keep it short!
|
||||
@@ -240,6 +246,10 @@ void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi)
|
||||
latest_mouse_event.button_middle = backup_spi1_recv_buf[15];
|
||||
latest_mouse_event.button_side = backup_spi1_recv_buf[16];
|
||||
latest_mouse_event.button_extra = backup_spi1_recv_buf[17];
|
||||
latest_mouse_event.has_button_transition = 0;
|
||||
if(memcmp(mouse_button_history, &backup_spi1_recv_buf[13], MOUSE_BUTTON_HISTORY_SIZE))
|
||||
latest_mouse_event.has_button_transition = 1;
|
||||
memcpy(mouse_button_history, &backup_spi1_recv_buf[13], MOUSE_BUTTON_HISTORY_SIZE);
|
||||
mouse_buf_add(&my_mouse_buf, &latest_mouse_event);
|
||||
}
|
||||
else if(backup_spi1_recv_buf[SPI_BUF_INDEX_MSG_TYPE] == SPI_MOSI_MSG_TYPE_GAMEPAD_EVENT_MAPPED_IBMPC)
|
||||
@@ -405,34 +415,37 @@ void microsoft_serial_mouse_update(void)
|
||||
|
||||
if(serial_mouse_is_tx_in_progress)
|
||||
{
|
||||
mouse_buf_pop(&my_mouse_buf);
|
||||
if(this_mouse_event->has_button_transition == 0)
|
||||
mouse_buf_pop(&my_mouse_buf);
|
||||
return;
|
||||
}
|
||||
|
||||
memset(serial_mouse_output_buf, 0, SERIAL_MOUSE_BUF_SIZE);
|
||||
serial_mouse_output_buf[0] = 0xc0;
|
||||
memset(microsoft_serial_mouse_output_buf, 0, MICROSOFT_SERIAL_MOUSE_BUF_SIZE);
|
||||
microsoft_serial_mouse_output_buf[0] = 0xc0;
|
||||
if(this_mouse_event->button_left)
|
||||
serial_mouse_output_buf[0] |= 0x20;
|
||||
microsoft_serial_mouse_output_buf[0] |= 0x20;
|
||||
if(this_mouse_event->button_right)
|
||||
serial_mouse_output_buf[0] |= 0x10;
|
||||
microsoft_serial_mouse_output_buf[0] |= 0x10;
|
||||
|
||||
int16_t serial_x = this_mouse_event->movement_x;
|
||||
int16_t serial_y = -1* this_mouse_event->movement_y;
|
||||
|
||||
if(serial_y & 0x80)
|
||||
serial_mouse_output_buf[0] |= 0x8;
|
||||
microsoft_serial_mouse_output_buf[0] |= 0x8;
|
||||
if(serial_y & 0x40)
|
||||
serial_mouse_output_buf[0] |= 0x4;
|
||||
microsoft_serial_mouse_output_buf[0] |= 0x4;
|
||||
if(serial_x & 0x80)
|
||||
serial_mouse_output_buf[0] |= 0x2;
|
||||
microsoft_serial_mouse_output_buf[0] |= 0x2;
|
||||
if(serial_x & 0x40)
|
||||
serial_mouse_output_buf[0] |= 0x1;
|
||||
microsoft_serial_mouse_output_buf[0] |= 0x1;
|
||||
|
||||
serial_mouse_output_buf[1] = 0x3f & serial_x;
|
||||
serial_mouse_output_buf[2] = 0x3f & serial_y;
|
||||
microsoft_serial_mouse_output_buf[1] = 0x3f & serial_x;
|
||||
microsoft_serial_mouse_output_buf[2] = 0x3f & serial_y;
|
||||
mouse_buf_pop(&my_mouse_buf);
|
||||
HAL_UART_Transmit_IT(&huart3, serial_mouse_output_buf, 3);
|
||||
HAL_UART_Transmit_IT(&huart3, microsoft_serial_mouse_output_buf, MICROSOFT_SERIAL_MOUSE_BUF_SIZE);
|
||||
serial_mouse_is_tx_in_progress = 1;
|
||||
if(this_mouse_event->has_button_transition)
|
||||
HAL_Delay(10);
|
||||
}
|
||||
|
||||
void spi_error_dump_reboot(void)
|
||||
@@ -514,6 +527,50 @@ huart3.Init.WordLength = UART_WORDLENGTH_7B;
|
||||
!!!!!!!!!!!!!!!!!!!!!!
|
||||
*/
|
||||
|
||||
void mouse_uart_switch_to_8bit(void)
|
||||
{
|
||||
huart3.Init.WordLength = UART_WORDLENGTH_8B;
|
||||
HAL_UART_Init(&huart3);
|
||||
}
|
||||
|
||||
void mouse_uart_switch_to_7bit(void)
|
||||
{
|
||||
huart3.Init.WordLength = UART_WORDLENGTH_7B;
|
||||
HAL_UART_Init(&huart3);
|
||||
}
|
||||
|
||||
void mousesystem_update(void)
|
||||
{
|
||||
mouse_event* this_mouse_event = mouse_buf_peek(&my_mouse_buf);
|
||||
if(this_mouse_event == NULL)
|
||||
return;
|
||||
|
||||
if(serial_mouse_is_tx_in_progress)
|
||||
{
|
||||
if(this_mouse_event->has_button_transition == 0)
|
||||
mouse_buf_pop(&my_mouse_buf);
|
||||
return;
|
||||
}
|
||||
|
||||
memset(mousesystems_serial_mouse_output_buf, 0, MOUSESYSTEMS_SERIAL_MOUSE_BUF_SIZE);
|
||||
mousesystems_serial_mouse_output_buf[0] = 0x87;
|
||||
if(this_mouse_event->button_left)
|
||||
mousesystems_serial_mouse_output_buf[0] &= 0xfb;
|
||||
if(this_mouse_event->button_middle)
|
||||
mousesystems_serial_mouse_output_buf[0] &= 0xfd;
|
||||
if(this_mouse_event->button_right)
|
||||
mousesystems_serial_mouse_output_buf[0] &= 0xfe;
|
||||
mousesystems_serial_mouse_output_buf[1] = (int8_t)(this_mouse_event->movement_x);
|
||||
mousesystems_serial_mouse_output_buf[2] = (int8_t)(this_mouse_event->movement_y);
|
||||
mousesystems_serial_mouse_output_buf[3] = (int8_t)(this_mouse_event->movement_x);
|
||||
mousesystems_serial_mouse_output_buf[4] = (int8_t)(this_mouse_event->movement_y);
|
||||
mouse_buf_pop(&my_mouse_buf);
|
||||
HAL_UART_Transmit_IT(&huart3, mousesystems_serial_mouse_output_buf, MOUSESYSTEMS_SERIAL_MOUSE_BUF_SIZE);
|
||||
serial_mouse_is_tx_in_progress = 1;
|
||||
if(this_mouse_event->has_button_transition)
|
||||
HAL_Delay(10);
|
||||
}
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/**
|
||||
@@ -589,30 +646,32 @@ int main(void)
|
||||
HAL_GPIO_WritePin(ERR_LED_GPIO_Port, ERR_LED_Pin, GPIO_PIN_SET);
|
||||
}
|
||||
|
||||
ps2mouse_send_bat(25);
|
||||
mouse_uart_switch_to_8bit();
|
||||
while (1)
|
||||
{
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
mousesystem_update();
|
||||
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
|
||||
// If both enabled, PS2 mouse takes priority
|
||||
if(is_protocol_enabled(PROTOCOL_PS2_MOUSE) && IS_PS2MOUSE_PRESENT())
|
||||
ps2mouse_update();
|
||||
else if(is_protocol_enabled(PROTOCOL_MICROSOFT_SERIAL_MOUSE))
|
||||
microsoft_serial_mouse_update();
|
||||
// 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 both enabled, PS2 mouse takes priority
|
||||
// if(is_protocol_enabled(PROTOCOL_PS2_MOUSE) && IS_PS2MOUSE_PRESENT())
|
||||
// ps2mouse_update();
|
||||
// else if(is_protocol_enabled(PROTOCOL_MICROSOFT_SERIAL_MOUSE))
|
||||
// microsoft_serial_mouse_update();
|
||||
// // 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(is_protocol_enabled(PROTOCOL_GENERIC_GAMEPORT_GAMEPAD))
|
||||
gamepad_update();
|
||||
// if(is_protocol_enabled(PROTOCOL_GENERIC_GAMEPORT_GAMEPAD))
|
||||
// gamepad_update();
|
||||
|
||||
if(spi_error_occured)
|
||||
spi_error_dump_reboot();
|
||||
// if(spi_error_occured)
|
||||
// spi_error_dump_reboot();
|
||||
}
|
||||
/* USER CODE END 3 */
|
||||
|
||||
|
||||
@@ -1,3 +1,37 @@
|
||||
uint8_t payload = 0x4D;
|
||||
mouse_uart_switch_to_8bit();
|
||||
HAL_UART_Transmit(&huart3, (unsigned char *)&payload, 1, 100);
|
||||
HAL_Delay(100);
|
||||
mouse_uart_switch_to_7bit();
|
||||
HAL_UART_Transmit(&huart3, (unsigned char *)&payload, 1, 100);
|
||||
HAL_Delay(100);
|
||||
HAL_GPIO_TogglePin(ERR_LED_GPIO_Port, ERR_LED_Pin);
|
||||
|
||||
|
||||
void mouse_uart_switch_to_8bit(void)
|
||||
{
|
||||
huart3.Init.WordLength = UART_WORDLENGTH_8B;
|
||||
printf("8 %d", HAL_UART_Init(&huart3));
|
||||
}
|
||||
|
||||
void mouse_uart_switch_to_7bit(void)
|
||||
{
|
||||
huart3.Init.WordLength = UART_WORDLENGTH_7B;
|
||||
// HAL_UART_Init(&huart3);
|
||||
printf("7 %d", HAL_UART_Init(&huart3));
|
||||
}
|
||||
while (1)
|
||||
{
|
||||
uint8_t payload = 0xaa;
|
||||
// mouse_uart_switch_to_8bit();
|
||||
HAL_UART_Transmit(&huart3, (unsigned char *)&payload, 1, 100);
|
||||
HAL_Delay(100);
|
||||
// mouse_uart_switch_to_7bit();
|
||||
// payload = 0xaa;
|
||||
// HAL_UART_Transmit(&huart3, (unsigned char *)&payload, 1, 100);
|
||||
// HAL_Delay(100);
|
||||
HAL_GPIO_TogglePin(ERR_LED_GPIO_Port, ERR_LED_Pin);
|
||||
|
||||
uint8_t is_ps2_mouse_connected_prev;
|
||||
|
||||
void ps2mouse_update(void)
|
||||
|
||||
Reference in New Issue
Block a user