Skip to content

Instantly share code, notes, and snippets.

@dekuNukem
Last active March 29, 2016 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dekuNukem/34b902f371993f244f4d to your computer and use it in GitHub Desktop.
Save dekuNukem/34b902f371993f244f4d to your computer and use it in GitHub Desktop.
FAP's keyboard interrupt controller
int main(void)
{
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART1_UART_Init();
MX_USART3_UART_Init();
HAL_UART_MspInit(&huart1);
HAL_UART_MspInit(&huart3);
// turn off keyboard data latch
HAL_GPIO_WritePin(PORT_CTRL_PORT, KB_LATCH_H, LOW);
// deselect keyboard interrupt
HAL_GPIO_WritePin(PORT_CTRL_PORT, KB_INT_SEL_L, HIGH);
// deselect Z80 global interrupt
HAL_GPIO_WritePin(PORT_CTRL_PORT, GLOBAL_INT_L, HIGH);
// start receiving data from keyboard
HAL_UART_Receive_IT(&huart1, kb_recv_buf, RECV_BUF_SIZE);
while (1)
{
;
}
}
// UART receive complete
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
// if we received a byte from keyboard...
if(huart->Instance==USART1)
{
// latch keyboard data
CPU_DATA_PORT->ODR = kb_recv_buf[0];
HAL_GPIO_WritePin(PORT_CTRL_PORT, KB_LATCH_H, HIGH);
// select keyboard interrupt
HAL_GPIO_WritePin(PORT_CTRL_PORT, KB_INT_SEL_L, LOW);
HAL_GPIO_WritePin(PORT_CTRL_PORT, GLOBAL_INT_L, LOW);
HAL_UART_Receive_IT(huart, kb_recv_buf, RECV_BUF_SIZE);
}
}
// INTACK interrupt handler, rising edge
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
// when CPU's INTACK' goes from active to inactive...
if(GPIO_Pin == GPIO_PIN_6)
{
// clear interrupt
HAL_GPIO_WritePin(PORT_CTRL_PORT, GLOBAL_INT_L, HIGH);
HAL_GPIO_WritePin(PORT_CTRL_PORT, KB_INT_SEL_L, HIGH);
// turn off latch
HAL_GPIO_WritePin(PORT_CTRL_PORT, KB_LATCH_H, LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment