Testing keyboard poll
This commit is contained in:
17
firmware/Core/Inc/inputs.h
Normal file
17
firmware/Core/Inc/inputs.h
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* inputs.h
|
||||
*
|
||||
* Created on: Oct 29, 2022
|
||||
* Author: mcfly
|
||||
*/
|
||||
|
||||
#ifndef INC_INPUTS_H_
|
||||
#define INC_INPUTS_H_
|
||||
|
||||
|
||||
#include "stm32g0xx_hal.h"
|
||||
|
||||
//Timers interrupts
|
||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim);
|
||||
|
||||
#endif /* INC_INPUTS_H_ */
|
53
firmware/Core/Src/inputs.c
Normal file
53
firmware/Core/Src/inputs.c
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* inputs.c
|
||||
*
|
||||
* Created on: Oct 29, 2022
|
||||
* Author: mcfly
|
||||
*/
|
||||
#include "inputs.h"
|
||||
#include "st7789.h"
|
||||
|
||||
#define BTNPRT GPIOC
|
||||
#define ENCBTNPRT BGIOB
|
||||
#define ENCBTNPRTMASK 0b11001000
|
||||
#define SCRBTNPRT BGIOD
|
||||
#define SCRBTNPRTMASK 0b1110000
|
||||
|
||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
|
||||
static uint16_t btnbuff = 0xFFFF;
|
||||
static uint16_t btnprev = 0xFFFF;
|
||||
uint8_t i;
|
||||
uint16_t pin;
|
||||
GPIO_TypeDef *port;
|
||||
|
||||
//check if the interrupt comes from TIM6
|
||||
if(htim->Instance == TIM6) {
|
||||
btnbuff = BTNPRT->IDR;
|
||||
for (i=5; i>=2; i--) {
|
||||
if ( !((btnbuff>>i) & 1) && ((btnprev>>i) & 1) ) {
|
||||
switch (i) {
|
||||
case 5:
|
||||
port = CH1_EN_GPIO_Port;
|
||||
pin = CH1_EN_Pin;
|
||||
break;
|
||||
case 4:
|
||||
port = CH2_EN_GPIO_Port;
|
||||
pin = CH2_EN_Pin;
|
||||
break;
|
||||
case 3:
|
||||
port = PWM1_EN_GPIO_Port;
|
||||
pin = PWM1_EN_Pin;
|
||||
break;
|
||||
case 2:
|
||||
port = PWM2_EN_GPIO_Port;
|
||||
pin = PWM2_EN_Pin;
|
||||
break;
|
||||
}
|
||||
HAL_GPIO_TogglePin(port, pin);
|
||||
}
|
||||
}
|
||||
btnprev = btnbuff;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -22,7 +22,7 @@
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include "st7789.h"
|
||||
|
||||
#include "inputs.h"
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
@@ -110,6 +110,7 @@ int main(void)
|
||||
MX_USART3_UART_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
ST7789_Init();
|
||||
HAL_TIM_Base_Start_IT(&htim6);
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
||||
@@ -324,7 +325,7 @@ static void MX_TIM6_Init(void)
|
||||
htim6.Init.Prescaler = 64-1;
|
||||
htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim6.Init.Period = 10000;
|
||||
htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
|
||||
if (HAL_TIM_Base_Init(&htim6) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
|
Reference in New Issue
Block a user