mirror of
https://github.com/dekuNukem/USB4VC.git
synced 2025-10-31 11:26:46 -07:00
implemented protocol turning on and off
This commit is contained in:
@@ -88,7 +88,7 @@ uint8_t spi_error_occured;
|
||||
#define PROTOCOL_STATUS_DISABLED 2
|
||||
|
||||
#define PROTOCOL_LOOKUP_SIZE 16
|
||||
uint8_t protocol_lookup[PROTOCOL_LOOKUP_SIZE];
|
||||
uint8_t protocol_status_lookup[PROTOCOL_LOOKUP_SIZE];
|
||||
|
||||
/* USER CODE END PV */
|
||||
|
||||
@@ -118,40 +118,49 @@ int16_t byte_to_int16_t(uint8_t lsb, uint8_t msb)
|
||||
return (int16_t)((msb << 8) | lsb);
|
||||
}
|
||||
|
||||
void handle_protocol_switch(uint8_t before, uint8_t after)
|
||||
void handle_protocol_switch(uint8_t spi_byte)
|
||||
{
|
||||
if(before == after)
|
||||
uint8_t index = spi_byte & 0x7f;
|
||||
uint8_t onoff = spi_byte & 0x80;
|
||||
|
||||
if(index >= PROTOCOL_LOOKUP_SIZE)
|
||||
return;
|
||||
if((before & 0x7f) != (after & 0x7f))
|
||||
// trying to change a protocol that is not available on this board
|
||||
if(protocol_status_lookup[index] == PROTOCOL_STATUS_NOT_AVAILABLE)
|
||||
return;
|
||||
if((before & 0x80) > (after & 0x80)) // switching off
|
||||
if(onoff)
|
||||
{
|
||||
switch(after & 0x7f)
|
||||
protocol_status_lookup[index] = PROTOCOL_STATUS_ENABLED;
|
||||
}
|
||||
else
|
||||
{
|
||||
protocol_status_lookup[index] = PROTOCOL_STATUS_DISABLED;
|
||||
switch(index)
|
||||
{
|
||||
case PROTOCOL_AT_PS2_KB:
|
||||
printf("PS2KB off\n");
|
||||
// printf("PS2KB off\n");
|
||||
ps2kb_release_lines();
|
||||
ps2kb_reset();
|
||||
break;
|
||||
|
||||
// case PROTOCOL_XT_KB:
|
||||
// printf("XTKB off\n");
|
||||
// break;
|
||||
case PROTOCOL_XT_KB:
|
||||
// printf("XTKB off\n");
|
||||
break;
|
||||
|
||||
case PROTOCOL_PS2_MOUSE:
|
||||
printf("PS2MOUSE off\n");
|
||||
// printf("PS2MOUSE off\n");
|
||||
ps2mouse_reset();
|
||||
ps2mouse_release_lines();
|
||||
break;
|
||||
|
||||
// case PROTOCOL_MICROSOFT_SERIAL_MOUSE:
|
||||
// printf("SERMOUSE off\n");
|
||||
// break;
|
||||
case PROTOCOL_MICROSOFT_SERIAL_MOUSE:
|
||||
// printf("SERMOUSE off\n");
|
||||
break;
|
||||
|
||||
// case PROTOCOL_GENERIC_GAMEPORT_GAMEPAD:
|
||||
// printf("GGP off\n");
|
||||
// release all buttons, reset digital pot to middle
|
||||
// break;
|
||||
case PROTOCOL_GENERIC_GAMEPORT_GAMEPAD:
|
||||
// printf("GGP off\n");
|
||||
// release all buttons, reset digital pot to middle
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -203,12 +212,12 @@ void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi)
|
||||
uint8_t curr_index = 8;
|
||||
for (int i = 0; i < PROTOCOL_LOOKUP_SIZE; i++)
|
||||
{
|
||||
if(protocol_lookup[i] == PROTOCOL_STATUS_NOT_AVAILABLE)
|
||||
if(protocol_status_lookup[i] == PROTOCOL_STATUS_NOT_AVAILABLE)
|
||||
continue;
|
||||
else if(protocol_lookup[i] == PROTOCOL_STATUS_DISABLED)
|
||||
else if(protocol_status_lookup[i] == PROTOCOL_STATUS_DISABLED)
|
||||
spi_transmit_buf[curr_index] = i;
|
||||
else if(protocol_lookup[i] == PROTOCOL_STATUS_ENABLED)
|
||||
spi_transmit_buf[curr_index] = i & 0x80;
|
||||
else if(protocol_status_lookup[i] == PROTOCOL_STATUS_ENABLED)
|
||||
spi_transmit_buf[curr_index] = i | 0x80;
|
||||
curr_index++;
|
||||
}
|
||||
}
|
||||
@@ -218,9 +227,7 @@ void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi)
|
||||
{
|
||||
if(backup_spi1_recv_buf[i] == 0)
|
||||
break;
|
||||
uint8_t protocol_index = backup_spi1_recv_buf[i] & 0x7f;
|
||||
if(protocol_index < PROTOCOL_LOOKUP_SIZE)
|
||||
handle_protocol_switch(protocol_lookup[protocol_index], backup_spi1_recv_buf[i]);
|
||||
handle_protocol_switch(backup_spi1_recv_buf[i]);
|
||||
}
|
||||
}
|
||||
HAL_SPI_TransmitReceive_IT(&hspi1, spi_transmit_buf, spi_recv_buf, SPI_BUF_SIZE);
|
||||
@@ -360,14 +367,14 @@ void spi_error_dump_reboot(void)
|
||||
|
||||
const char boot_message[] = "USB4VC Protocol Board\nIBM PC Compatible\ndekuNukem 2022";
|
||||
|
||||
void protocol_lookup_init(void)
|
||||
void protocol_status_lookup_init(void)
|
||||
{
|
||||
memset(protocol_lookup, PROTOCOL_STATUS_NOT_AVAILABLE, PROTOCOL_LOOKUP_SIZE);
|
||||
protocol_lookup[PROTOCOL_AT_PS2_KB] = PROTOCOL_STATUS_ENABLED;
|
||||
protocol_lookup[PROTOCOL_XT_KB] = PROTOCOL_STATUS_ENABLED;
|
||||
protocol_lookup[PROTOCOL_PS2_MOUSE] = PROTOCOL_STATUS_ENABLED;
|
||||
protocol_lookup[PROTOCOL_MICROSOFT_SERIAL_MOUSE] = PROTOCOL_STATUS_ENABLED;
|
||||
protocol_lookup[PROTOCOL_GENERIC_GAMEPORT_GAMEPAD] = PROTOCOL_STATUS_ENABLED;
|
||||
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_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;
|
||||
}
|
||||
|
||||
/* USER CODE END 0 */
|
||||
@@ -412,6 +419,7 @@ int main(void)
|
||||
ps2mouse_init(PS2MOUSE_CLK_GPIO_Port, PS2MOUSE_CLK_Pin, PS2MOUSE_DATA_GPIO_Port, PS2MOUSE_DATA_Pin);
|
||||
ps2kb_buf_init(&my_ps2kb_buf, 16);
|
||||
ps2mouse_buf_init(&my_ps2mouse_buf, 16);
|
||||
protocol_status_lookup_init();
|
||||
memset(spi_transmit_buf, 0, SPI_BUF_SIZE);
|
||||
mcp4451_reset();
|
||||
if(mcp4451_is_available() == 0)
|
||||
@@ -432,10 +440,11 @@ int main(void)
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
// if()
|
||||
ps2mouse_update();
|
||||
if(protocol_status_lookup[PROTOCOL_PS2_MOUSE] == PROTOCOL_STATUS_ENABLED)
|
||||
ps2mouse_update();
|
||||
// serial_mouse_update();
|
||||
ps2kb_update();
|
||||
if(protocol_status_lookup[PROTOCOL_AT_PS2_KB] == PROTOCOL_STATUS_ENABLED)
|
||||
ps2kb_update();
|
||||
if(spi_error_occured)
|
||||
spi_error_dump_reboot();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user