mirror of
https://github.com/dekuNukem/USB4VC.git
synced 2025-10-31 11:26:46 -07:00
adding BUSY signal to IBM card
This commit is contained in:
@@ -6,11 +6,11 @@
|
||||
******************************************************************************
|
||||
** This notice applies to any and all portions of this file
|
||||
* that are not between comment pairs USER CODE BEGIN and
|
||||
* USER CODE END. Other portions of this file, whether
|
||||
* USER CODE END. Other portions of this file, whether
|
||||
* inserted by the user or by software development tools
|
||||
* are owned by their respective copyright owners.
|
||||
*
|
||||
* COPYRIGHT(c) 2022 STMicroelectronics
|
||||
* COPYRIGHT(c) 2023 STMicroelectronics
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
@@ -241,6 +241,7 @@ void handle_protocol_switch(uint8_t spi_byte)
|
||||
This is called when a new SPI packet is received
|
||||
This is part of an ISR, so keep it short!
|
||||
*/
|
||||
uint32_t ACT_LED_off_ts;
|
||||
void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi)
|
||||
{
|
||||
HAL_GPIO_WritePin(ACT_LED_GPIO_Port, ACT_LED_Pin, GPIO_PIN_SET);
|
||||
@@ -320,7 +321,7 @@ void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi)
|
||||
}
|
||||
}
|
||||
HAL_SPI_TransmitReceive_IT(&hspi1, spi_transmit_buf, spi_recv_buf, SPI_BUF_SIZE);
|
||||
HAL_GPIO_WritePin(ACT_LED_GPIO_Port, ACT_LED_Pin, GPIO_PIN_RESET);
|
||||
ACT_LED_off_ts = micros() + 10000;
|
||||
}
|
||||
|
||||
void cap_to_127(int32_t *number)
|
||||
@@ -404,16 +405,17 @@ void ps2mouse_update(void)
|
||||
// HAL_GPIO_WritePin(ERR_LED_GPIO_Port, ERR_LED_Pin, GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
void ps2kb_update(void)
|
||||
uint8_t ps2kb_update(void)
|
||||
{
|
||||
ps2kb_bus_status = ps2kb_get_bus_status();
|
||||
if(ps2kb_bus_status == PS2_BUS_INHIBIT)
|
||||
{
|
||||
ps2kb_release_lines();
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
else if(ps2kb_bus_status == PS2_BUS_REQ_TO_SEND)
|
||||
if(ps2kb_bus_status == PS2_BUS_REQ_TO_SEND)
|
||||
{
|
||||
PCARD_BUSY_HI();
|
||||
uint8_t ps2kb_leds = 0xff;
|
||||
ps2kb_read(&ps2kb_host_cmd, 10);
|
||||
keyboard_reply(ps2kb_host_cmd, &ps2kb_leds);
|
||||
@@ -434,17 +436,13 @@ void ps2kb_update(void)
|
||||
}
|
||||
else if(ps2kb_bus_status == PS2_BUS_IDLE && (kb_buf_peek(&my_kb_buf, &buffered_code, &buffered_value) == 0))
|
||||
{
|
||||
PCARD_BUSY_HI();
|
||||
if(ps2kb_press_key(buffered_code, buffered_value) == PS2_ERROR_HOST_INHIBIT) // host inhibited line during transmission
|
||||
{
|
||||
// HAL_GPIO_WritePin(ERR_LED_GPIO_Port, ERR_LED_Pin, GPIO_PIN_SET);
|
||||
HAL_Delay(1);
|
||||
// HAL_GPIO_WritePin(ERR_LED_GPIO_Port, ERR_LED_Pin, GPIO_PIN_RESET);
|
||||
}
|
||||
else
|
||||
{
|
||||
kb_buf_pop(&my_kb_buf);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
// GPIO external interrupt callback
|
||||
@@ -690,7 +688,10 @@ int main(void)
|
||||
|
||||
while (1)
|
||||
{
|
||||
// HAL_GPIO_TogglePin(PCARD_BUSY_GPIO_Port, PCARD_BUSY_Pin);
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
if(micros() > ACT_LED_off_ts)
|
||||
HAL_GPIO_WritePin(ACT_LED_GPIO_Port, ACT_LED_Pin, GPIO_PIN_RESET);
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
@@ -704,7 +705,10 @@ int main(void)
|
||||
mousesystems_serial_mouse_update();
|
||||
// If both enabled, PS2 keyboard takes priority
|
||||
if(is_protocol_enabled(PROTOCOL_AT_PS2_KB) && IS_KB_PRESENT())
|
||||
ps2kb_update();
|
||||
{
|
||||
if(ps2kb_update())
|
||||
PCARD_BUSY_LOW();
|
||||
}
|
||||
else if(is_protocol_enabled(PROTOCOL_XT_KB) && IS_KB_PRESENT())
|
||||
xtkb_update();
|
||||
|
||||
@@ -729,7 +733,7 @@ void SystemClock_Config(void)
|
||||
RCC_ClkInitTypeDef RCC_ClkInitStruct;
|
||||
RCC_PeriphCLKInitTypeDef PeriphClkInit;
|
||||
|
||||
/**Initializes the CPU, AHB and APB busses clocks
|
||||
/**Initializes the CPU, AHB and APB busses clocks
|
||||
*/
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48|RCC_OSCILLATORTYPE_LSI;
|
||||
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
|
||||
@@ -740,7 +744,7 @@ void SystemClock_Config(void)
|
||||
_Error_Handler(__FILE__, __LINE__);
|
||||
}
|
||||
|
||||
/**Initializes the CPU, AHB and APB busses clocks
|
||||
/**Initializes the CPU, AHB and APB busses clocks
|
||||
*/
|
||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||
|RCC_CLOCKTYPE_PCLK1;
|
||||
@@ -760,11 +764,11 @@ void SystemClock_Config(void)
|
||||
_Error_Handler(__FILE__, __LINE__);
|
||||
}
|
||||
|
||||
/**Configure the Systick interrupt time
|
||||
/**Configure the Systick interrupt time
|
||||
*/
|
||||
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
|
||||
|
||||
/**Configure the Systick
|
||||
/**Configure the Systick
|
||||
*/
|
||||
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
|
||||
|
||||
@@ -790,14 +794,14 @@ static void MX_I2C2_Init(void)
|
||||
_Error_Handler(__FILE__, __LINE__);
|
||||
}
|
||||
|
||||
/**Configure Analogue filter
|
||||
/**Configure Analogue filter
|
||||
*/
|
||||
if (HAL_I2CEx_ConfigAnalogFilter(&hi2c2, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
|
||||
{
|
||||
_Error_Handler(__FILE__, __LINE__);
|
||||
}
|
||||
|
||||
/**Configure Digital filter
|
||||
/**Configure Digital filter
|
||||
*/
|
||||
if (HAL_I2CEx_ConfigDigitalFilter(&hi2c2, 0) != HAL_OK)
|
||||
{
|
||||
@@ -885,8 +889,6 @@ static void MX_USART1_UART_Init(void)
|
||||
|
||||
huart1.Instance = USART1;
|
||||
huart1.Init.BaudRate = 115200;
|
||||
if(flash_size != 64)
|
||||
huart1.Init.BaudRate = 195134;
|
||||
huart1.Init.WordLength = UART_WORDLENGTH_8B;
|
||||
huart1.Init.StopBits = UART_STOPBITS_1;
|
||||
huart1.Init.Parity = UART_PARITY_NONE;
|
||||
@@ -908,10 +910,7 @@ static void MX_USART3_UART_Init(void)
|
||||
|
||||
huart3.Instance = USART3;
|
||||
huart3.Init.BaudRate = 1200;
|
||||
if(flash_size != 64)
|
||||
huart3.Init.BaudRate = 2032;
|
||||
huart3.Init.StopBits = UART_STOPBITS_1;
|
||||
huart3.Init.WordLength = UART_WORDLENGTH_7B;
|
||||
huart3.Init.Parity = UART_PARITY_NONE;
|
||||
huart3.Init.Mode = UART_MODE_TX_RX;
|
||||
huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
||||
@@ -927,9 +926,9 @@ static void MX_USART3_UART_Init(void)
|
||||
|
||||
}
|
||||
|
||||
/** Configure pins as
|
||||
* Analog
|
||||
* Input
|
||||
/** Configure pins as
|
||||
* Analog
|
||||
* Input
|
||||
* Output
|
||||
* EVENT_OUT
|
||||
* EXTI
|
||||
@@ -955,11 +954,11 @@ static void MX_GPIO_Init(void)
|
||||
HAL_GPIO_WritePin(GPIOF, GAMEPAD_B3_Pin|GAMEPAD_B1_Pin, GPIO_PIN_SET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOB, POT_RESET_Pin|PS2MOUSE_DATA_Pin|PS2MOUSE_CLK_Pin|PS2KB_DATA_Pin
|
||||
|PS2KB_CLK_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(GPIOA, PCARD_BUSY_Pin|ACT_LED_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(ACT_LED_GPIO_Port, ACT_LED_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(GPIOB, POT_RESET_Pin|PS2MOUSE_DATA_Pin|PS2MOUSE_CLK_Pin|PS2KB_DATA_Pin
|
||||
|PS2KB_CLK_Pin, GPIO_PIN_SET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(ERR_LED_GPIO_Port, ERR_LED_Pin, GPIO_PIN_RESET);
|
||||
@@ -985,15 +984,22 @@ static void MX_GPIO_Init(void)
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : PCARD_BUSY_Pin ACT_LED_Pin */
|
||||
GPIO_InitStruct.Pin = PCARD_BUSY_Pin|ACT_LED_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : UART3_RTS_Pin */
|
||||
GPIO_InitStruct.Pin = UART3_RTS_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(UART3_RTS_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : POT_RESET_Pin PS2MOUSE_DATA_Pin PS2MOUSE_CLK_Pin PS2KB_DATA_Pin
|
||||
/*Configure GPIO pins : POT_RESET_Pin PS2MOUSE_DATA_Pin PS2MOUSE_CLK_Pin PS2KB_DATA_Pin
|
||||
PS2KB_CLK_Pin */
|
||||
GPIO_InitStruct.Pin = POT_RESET_Pin|PS2MOUSE_DATA_Pin|PS2MOUSE_CLK_Pin|PS2KB_DATA_Pin
|
||||
GPIO_InitStruct.Pin = POT_RESET_Pin|PS2MOUSE_DATA_Pin|PS2MOUSE_CLK_Pin|PS2KB_DATA_Pin
|
||||
|PS2KB_CLK_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
@@ -1012,13 +1018,6 @@ static void MX_GPIO_Init(void)
|
||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||
HAL_GPIO_Init(KB_DETECT_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : ACT_LED_Pin */
|
||||
GPIO_InitStruct.Pin = ACT_LED_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(ACT_LED_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : ERR_LED_Pin */
|
||||
GPIO_InitStruct.Pin = ERR_LED_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
@@ -1061,7 +1060,7 @@ void _Error_Handler(char *file, int line)
|
||||
* @retval None
|
||||
*/
|
||||
void assert_failed(uint8_t* file, uint32_t line)
|
||||
{
|
||||
{
|
||||
/* USER CODE BEGIN 6 */
|
||||
/* User can add his own implementation to report the file name and line number,
|
||||
tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||
|
||||
@@ -153,8 +153,9 @@ uint8_t ps2mouse_read(uint8_t* result, uint8_t timeout_ms)
|
||||
|
||||
uint8_t ps2mouse_wait_for_idle(uint8_t timeout_ms)
|
||||
{
|
||||
uint32_t ps2mouse_wait_start;
|
||||
ps2mouse_idle_check:
|
||||
uint32_t ps2mouse_wait_start = HAL_GetTick();
|
||||
ps2mouse_wait_start = HAL_GetTick();
|
||||
while(ps2mouse_get_bus_status() != PS2_BUS_IDLE)
|
||||
{
|
||||
if(HAL_GetTick() - ps2mouse_wait_start >= timeout_ms)
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* File Name : stm32f0xx_hal_msp.c
|
||||
* Description : This file provides code for the MSP Initialization
|
||||
* Description : This file provides code for the MSP Initialization
|
||||
* and de-Initialization codes.
|
||||
******************************************************************************
|
||||
** This notice applies to any and all portions of this file
|
||||
* that are not between comment pairs USER CODE BEGIN and
|
||||
* USER CODE END. Other portions of this file, whether
|
||||
* USER CODE END. Other portions of this file, whether
|
||||
* inserted by the user or by software development tools
|
||||
* are owned by their respective copyright owners.
|
||||
*
|
||||
* COPYRIGHT(c) 2022 STMicroelectronics
|
||||
* COPYRIGHT(c) 2023 STMicroelectronics
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
@@ -76,10 +76,10 @@ void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c)
|
||||
/* USER CODE BEGIN I2C2_MspInit 0 */
|
||||
|
||||
/* USER CODE END I2C2_MspInit 0 */
|
||||
|
||||
/**I2C2 GPIO Configuration
|
||||
|
||||
/**I2C2 GPIO Configuration
|
||||
PB13 ------> I2C2_SCL
|
||||
PB14 ------> I2C2_SDA
|
||||
PB14 ------> I2C2_SDA
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_14;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
|
||||
@@ -107,12 +107,14 @@ void HAL_I2C_MspDeInit(I2C_HandleTypeDef* hi2c)
|
||||
/* USER CODE END I2C2_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_I2C2_CLK_DISABLE();
|
||||
|
||||
/**I2C2 GPIO Configuration
|
||||
|
||||
/**I2C2 GPIO Configuration
|
||||
PB13 ------> I2C2_SCL
|
||||
PB14 ------> I2C2_SDA
|
||||
PB14 ------> I2C2_SDA
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_13|GPIO_PIN_14);
|
||||
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_13);
|
||||
|
||||
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_14);
|
||||
|
||||
/* USER CODE BEGIN I2C2_MspDeInit 1 */
|
||||
|
||||
@@ -132,12 +134,12 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
|
||||
/* USER CODE END SPI1_MspInit 0 */
|
||||
/* Peripheral clock enable */
|
||||
__HAL_RCC_SPI1_CLK_ENABLE();
|
||||
|
||||
/**SPI1 GPIO Configuration
|
||||
|
||||
/**SPI1 GPIO Configuration
|
||||
PA4 ------> SPI1_NSS
|
||||
PA5 ------> SPI1_SCK
|
||||
PA6 ------> SPI1_MISO
|
||||
PA7 ------> SPI1_MOSI
|
||||
PA7 ------> SPI1_MOSI
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
@@ -166,12 +168,12 @@ void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
|
||||
/* USER CODE END SPI1_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_SPI1_CLK_DISABLE();
|
||||
|
||||
/**SPI1 GPIO Configuration
|
||||
|
||||
/**SPI1 GPIO Configuration
|
||||
PA4 ------> SPI1_NSS
|
||||
PA5 ------> SPI1_SCK
|
||||
PA6 ------> SPI1_MISO
|
||||
PA7 ------> SPI1_MOSI
|
||||
PA7 ------> SPI1_MOSI
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7);
|
||||
|
||||
@@ -229,10 +231,10 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart)
|
||||
/* USER CODE END USART1_MspInit 0 */
|
||||
/* Peripheral clock enable */
|
||||
__HAL_RCC_USART1_CLK_ENABLE();
|
||||
|
||||
/**USART1 GPIO Configuration
|
||||
|
||||
/**USART1 GPIO Configuration
|
||||
PA9 ------> USART1_TX
|
||||
PA10 ------> USART1_RX
|
||||
PA10 ------> USART1_RX
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
@@ -252,10 +254,10 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart)
|
||||
/* USER CODE END USART3_MspInit 0 */
|
||||
/* Peripheral clock enable */
|
||||
__HAL_RCC_USART3_CLK_ENABLE();
|
||||
|
||||
/**USART3 GPIO Configuration
|
||||
|
||||
/**USART3 GPIO Configuration
|
||||
PB10 ------> USART3_TX
|
||||
PB11 ------> USART3_RX
|
||||
PB11 ------> USART3_RX
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
@@ -284,10 +286,10 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
|
||||
/* USER CODE END USART1_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_USART1_CLK_DISABLE();
|
||||
|
||||
/**USART1 GPIO Configuration
|
||||
|
||||
/**USART1 GPIO Configuration
|
||||
PA9 ------> USART1_TX
|
||||
PA10 ------> USART1_RX
|
||||
PA10 ------> USART1_RX
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10);
|
||||
|
||||
@@ -302,10 +304,10 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
|
||||
/* USER CODE END USART3_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_USART3_CLK_DISABLE();
|
||||
|
||||
/**USART3 GPIO Configuration
|
||||
|
||||
/**USART3 GPIO Configuration
|
||||
PB10 ------> USART3_TX
|
||||
PB11 ------> USART3_RX
|
||||
PB11 ------> USART3_RX
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_10|GPIO_PIN_11);
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* @brief Interrupt Service Routines.
|
||||
******************************************************************************
|
||||
*
|
||||
* COPYRIGHT(c) 2022 STMicroelectronics
|
||||
* COPYRIGHT(c) 2023 STMicroelectronics
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
@@ -44,7 +44,7 @@ extern SPI_HandleTypeDef hspi1;
|
||||
extern UART_HandleTypeDef huart3;
|
||||
|
||||
/******************************************************************************/
|
||||
/* Cortex-M0 Processor Interruption and Exception Handlers */
|
||||
/* Cortex-M0 Processor Interruption and Exception Handlers */
|
||||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user