Merge branch 'dev' of https://github.com/Kymkim/modular-kbd into dev
This commit is contained in:
@@ -123,6 +123,11 @@ UARTMessage reportBuff;
|
|||||||
extern USBD_HandleTypeDef hUsbDeviceFS;
|
extern USBD_HandleTypeDef hUsbDeviceFS;
|
||||||
volatile uint8_t MODE = MODE_INACTIVE;
|
volatile uint8_t MODE = MODE_INACTIVE;
|
||||||
|
|
||||||
|
UARTMessage uartBuffer;
|
||||||
|
volatile int uartUpdateFlag = 0;
|
||||||
|
// Encoder state (TIM3 in encoder mode on PA6/PA7)
|
||||||
|
volatile int32_t LAST_ENCODER_COUNT = 0;
|
||||||
|
|
||||||
/* USER CODE END PV */
|
/* USER CODE END PV */
|
||||||
|
|
||||||
/* Private function prototypes -----------------------------------------------*/
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
@@ -133,6 +138,7 @@ void UART_DMA_SendReport(UART_HandleTypeDef *huart);
|
|||||||
void addUSBReport(uint8_t usageID);
|
void addUSBReport(uint8_t usageID);
|
||||||
void handleUARTMessages(uint8_t *data, UART_HandleTypeDef *sender);
|
void handleUARTMessages(uint8_t *data, UART_HandleTypeDef *sender);
|
||||||
void matrixScan(void);
|
void matrixScan(void);
|
||||||
|
void encoderProcess(void);
|
||||||
void resetReport(void);
|
void resetReport(void);
|
||||||
void sendMessage(void);
|
void sendMessage(void);
|
||||||
void findBestParent();
|
void findBestParent();
|
||||||
@@ -188,6 +194,9 @@ int main(void)
|
|||||||
HAL_UART_Receive_DMA(&huart2, (uint8_t*)&RX2Msg, sizeof(UARTMessage));
|
HAL_UART_Receive_DMA(&huart2, (uint8_t*)&RX2Msg, sizeof(UARTMessage));
|
||||||
HAL_UART_Receive_DMA(&huart4, (uint8_t*)&RX4Msg, sizeof(UARTMessage));
|
HAL_UART_Receive_DMA(&huart4, (uint8_t*)&RX4Msg, sizeof(UARTMessage));
|
||||||
HAL_UART_Receive_DMA(&huart5, (uint8_t*)&RX5Msg, sizeof(UARTMessage));
|
HAL_UART_Receive_DMA(&huart5, (uint8_t*)&RX5Msg, sizeof(UARTMessage));
|
||||||
|
// Start TIM3 encoder (PA6/PA7) so we can read encoder delta
|
||||||
|
HAL_TIM_Encoder_Start(&htim3, TIM_CHANNEL_ALL);
|
||||||
|
LAST_ENCODER_COUNT = __HAL_TIM_GET_COUNTER(&htim3);
|
||||||
/* USER CODE END 2 */
|
/* USER CODE END 2 */
|
||||||
|
|
||||||
/* Infinite loop */
|
/* Infinite loop */
|
||||||
@@ -198,6 +207,7 @@ int main(void)
|
|||||||
case MODE_ACTIVE:
|
case MODE_ACTIVE:
|
||||||
resetReport();
|
resetReport();
|
||||||
matrixScan();
|
matrixScan();
|
||||||
|
encoderProcess();
|
||||||
UARTMessage UARTREPORT;
|
UARTMessage UARTREPORT;
|
||||||
UARTREPORT.DEPTH = DEPTH;
|
UARTREPORT.DEPTH = DEPTH;
|
||||||
UARTREPORT.TYPE = 0xEE;
|
UARTREPORT.TYPE = 0xEE;
|
||||||
@@ -229,11 +239,15 @@ int main(void)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case MODE_MAINBOARD:
|
case MODE_MAINBOARD:
|
||||||
resetReport(); //Something related to this making the key stick. Likely due to race conditions
|
resetReport();
|
||||||
matrixScan(); //Removing resetReport() makes the modules inputs works but makes the key stick
|
matrixScan();//Something related to this making the key stick. Likely due to race conditions
|
||||||
//Merge the bufer to the key report
|
encoderProcess();
|
||||||
for(int i = 0; i < sizeof(reportBuff.KEYPRESS); i++){
|
if(uartUpdateFlag){
|
||||||
REPORT.KEYPRESS[i] |= reportBuff.KEYPRESS[i];
|
for(int i = 0; i < 12; i++){
|
||||||
|
REPORT.KEYPRESS[i] |= uartBuffer.KEYPRESS[i];
|
||||||
|
}
|
||||||
|
uartUpdateFlag = 0;
|
||||||
|
memset(uartBuffer.KEYPRESS, 0, 12);
|
||||||
}
|
}
|
||||||
USBD_HID_SendReport(&hUsbDeviceFS, (uint8_t*)&REPORT, sizeof(REPORT));
|
USBD_HID_SendReport(&hUsbDeviceFS, (uint8_t*)&REPORT, sizeof(REPORT));
|
||||||
break;
|
break;
|
||||||
@@ -242,7 +256,7 @@ int main(void)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
HAL_Delay();
|
HAL_Delay(100);
|
||||||
/* USER CODE END WHILE */
|
/* USER CODE END WHILE */
|
||||||
|
|
||||||
/* USER CODE BEGIN 3 */
|
/* USER CODE BEGIN 3 */
|
||||||
@@ -390,9 +404,12 @@ void handleUARTMessages(uint8_t *data, UART_HandleTypeDef *sender) {
|
|||||||
|
|
||||||
case 0xEE:
|
case 0xEE:
|
||||||
//TODO: Append message to the thingy
|
//TODO: Append message to the thingy
|
||||||
if(MODE!=MODE_INACTIVE){
|
if (MODE != MODE_INACTIVE) {
|
||||||
memcpy(msg.KEYPRESS, reportBuff.KEYPRESS, sizeof(reply.KEYPRESS));
|
for (int i = 0; i < sizeof(REPORT.KEYPRESS); i++) {
|
||||||
}
|
uartBuffer.KEYPRESS[i] |= msg.KEYPRESS[i];
|
||||||
|
}
|
||||||
|
uartUpdateFlag = 1;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -423,6 +440,31 @@ void matrixScan(void){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Read TIM3 encoder counter, calculate delta and add corresponding keycodes
|
||||||
|
void encoderProcess(void){
|
||||||
|
int32_t cnt = (int32_t)__HAL_TIM_GET_COUNTER(&htim3);
|
||||||
|
int32_t diff = cnt - LAST_ENCODER_COUNT;
|
||||||
|
// TIM3 configured as 16-bit counter (period 65535). Fix wrap-around.
|
||||||
|
if(diff > 32767) diff -= 65536;
|
||||||
|
if(diff < -32768) diff += 65536;
|
||||||
|
if(diff > 0){
|
||||||
|
int steps = diff;
|
||||||
|
if(steps > 10) steps = 10; // cap bursts
|
||||||
|
for(int i = 0; i < steps; i++){
|
||||||
|
// CW -> KEYCODES[0][0]
|
||||||
|
addUSBReport(KEYCODES[0][0]);
|
||||||
|
}
|
||||||
|
}else if(diff < 0){
|
||||||
|
int steps = -diff;
|
||||||
|
if(steps > 10) steps = 10;
|
||||||
|
for(int i = 0; i < steps; i++){
|
||||||
|
// CCW -> KEYCODES[0][1]
|
||||||
|
addUSBReport(KEYCODES[0][1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LAST_ENCODER_COUNT = cnt;
|
||||||
|
}
|
||||||
|
|
||||||
void resetReport(void){
|
void resetReport(void){
|
||||||
REPORT.MODIFIER = 0;
|
REPORT.MODIFIER = 0;
|
||||||
memset(REPORT.KEYPRESS, 0, sizeof(REPORT.KEYPRESS));
|
memset(REPORT.KEYPRESS, 0, sizeof(REPORT.KEYPRESS));
|
||||||
@@ -460,3 +502,4 @@ void assert_failed(uint8_t *file, uint32_t line)
|
|||||||
/* USER CODE END 6 */
|
/* USER CODE END 6 */
|
||||||
}
|
}
|
||||||
#endif /* USE_FULL_ASSERT */
|
#endif /* USE_FULL_ASSERT */
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
../Core/Src/main.c:150:5:main 7
|
../Core/Src/main.c:153:5:main 8
|
||||||
../Core/Src/main.c:257:6:SystemClock_Config 3
|
../Core/Src/main.c:263:6:SystemClock_Config 3
|
||||||
../Core/Src/main.c:301:6:HAL_UART_RxCpltCallback 5
|
../Core/Src/main.c:307:6:HAL_UART_RxCpltCallback 5
|
||||||
../Core/Src/main.c:320:6:HAL_UART_ErrorCallback 5
|
../Core/Src/main.c:326:6:HAL_UART_ErrorCallback 5
|
||||||
../Core/Src/main.c:338:6:findBestParent 4
|
../Core/Src/main.c:344:6:findBestParent 4
|
||||||
../Core/Src/main.c:359:6:handleUARTMessages 11
|
../Core/Src/main.c:365:6:handleUARTMessages 12
|
||||||
../Core/Src/main.c:405:6:addUSBReport 3
|
../Core/Src/main.c:414:6:addUSBReport 3
|
||||||
../Core/Src/main.c:413:6:matrixScan 4
|
../Core/Src/main.c:422:6:matrixScan 4
|
||||||
../Core/Src/main.c:426:6:resetReport 1
|
../Core/Src/main.c:435:6:resetReport 1
|
||||||
../Core/Src/main.c:437:6:Error_Handler 1
|
../Core/Src/main.c:446:6:Error_Handler 1
|
||||||
|
|||||||
Binary file not shown.
@@ -1,10 +1,10 @@
|
|||||||
../Core/Src/main.c:150:5:main 48 static
|
../Core/Src/main.c:153:5:main 48 static
|
||||||
../Core/Src/main.c:257:6:SystemClock_Config 88 static
|
../Core/Src/main.c:263:6:SystemClock_Config 88 static
|
||||||
../Core/Src/main.c:301:6:HAL_UART_RxCpltCallback 16 static
|
../Core/Src/main.c:307:6:HAL_UART_RxCpltCallback 16 static
|
||||||
../Core/Src/main.c:320:6:HAL_UART_ErrorCallback 16 static
|
../Core/Src/main.c:326:6:HAL_UART_ErrorCallback 16 static
|
||||||
../Core/Src/main.c:338:6:findBestParent 24 static
|
../Core/Src/main.c:344:6:findBestParent 24 static
|
||||||
../Core/Src/main.c:359:6:handleUARTMessages 56 static
|
../Core/Src/main.c:365:6:handleUARTMessages 64 static
|
||||||
../Core/Src/main.c:405:6:addUSBReport 24 static
|
../Core/Src/main.c:414:6:addUSBReport 24 static
|
||||||
../Core/Src/main.c:413:6:matrixScan 16 static
|
../Core/Src/main.c:422:6:matrixScan 16 static
|
||||||
../Core/Src/main.c:426:6:resetReport 8 static
|
../Core/Src/main.c:435:6:resetReport 8 static
|
||||||
../Core/Src/main.c:437:6:Error_Handler 4 static,ignoring_inline_asm
|
../Core/Src/main.c:446:6:Error_Handler 4 static,ignoring_inline_asm
|
||||||
|
|||||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user