dma sending stuff thru uart
This commit is contained in:
@@ -117,6 +117,7 @@ uint16_t DEPTH = 0;
|
||||
uint16_t PORT_DEPTH[] = {0xFF, 0xFF, 0xFF, 0xFF};
|
||||
UART_HandleTypeDef* PARENT;
|
||||
UART_HandleTypeDef* PORTS[] = {&huart5, &huart1, &huart2, &huart4};
|
||||
//North East South West
|
||||
|
||||
extern USBD_HandleTypeDef hUsbDeviceFS;
|
||||
volatile uint8_t MODE = MODE_INACTIVE;
|
||||
@@ -129,6 +130,7 @@ void SystemClock_Config(void);
|
||||
void handleUARTMessages(uint8_t *data, UART_HandleTypeDef *huart);
|
||||
void UART_DMA_SendReport(UART_HandleTypeDef *huart);
|
||||
void addUSBReport(uint8_t usageID);
|
||||
void handleUARTMessages(uint8_t *data, UART_HandleTypeDef *sender);
|
||||
void matrixScan(void);
|
||||
void resetReport(void);
|
||||
void sendMessage(void);
|
||||
@@ -282,27 +284,27 @@ void SystemClock_Config(void)
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 4 */
|
||||
//UART Message Requests Goes Here
|
||||
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart){
|
||||
//Parse recieved message
|
||||
if (huart->Instance == USART1) {
|
||||
handleUARTMessage(&RX1Msg);
|
||||
HAL_UART_Receive_DMA(&huart1, (uint8_t*)&RX1Msg, sizeof(UARTMessage));
|
||||
}
|
||||
else if (huart->Instance == USART2) {
|
||||
handleUARTMessage(&RX2Msg);
|
||||
HAL_UART_Receive_DMA(&huart2, (uint8_t*)&RX2Msg, sizeof(UARTMessage));
|
||||
}
|
||||
else if (huart->Instance == USART4) {
|
||||
handleUARTMessage(&RX4Msg);
|
||||
HAL_UART_Receive_DMA(&huart4, (uint8_t*)&RX4Msg, sizeof(UARTMessage));
|
||||
}
|
||||
else if (huart->Instance == USART5) {
|
||||
handleUARTMessage(&RX5Msg);
|
||||
HAL_UART_Receive_DMA(&huart5, (uint8_t*)&RX5Msg, sizeof(UARTMessage));
|
||||
}
|
||||
// UART Message Requests Goes Here
|
||||
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) {
|
||||
if (huart->Instance == USART1) {
|
||||
handleUARTMessages((uint8_t*)&RX1Msg, huart);
|
||||
HAL_UART_Receive_DMA(&huart1, (uint8_t*)&RX1Msg, sizeof(UARTMessage));
|
||||
}
|
||||
else if (huart->Instance == USART2) {
|
||||
handleUARTMessages((uint8_t*)&RX2Msg, huart);
|
||||
HAL_UART_Receive_DMA(&huart2, (uint8_t*)&RX2Msg, sizeof(UARTMessage));
|
||||
}
|
||||
else if (huart->Instance == UART4) {
|
||||
handleUARTMessages((uint8_t*)&RX4Msg, huart);
|
||||
HAL_UART_Receive_DMA(&huart4, (uint8_t*)&RX4Msg, sizeof(UARTMessage));
|
||||
}
|
||||
else if (huart->Instance == UART5) {
|
||||
handleUARTMessages((uint8_t*)&RX5Msg, huart);
|
||||
HAL_UART_Receive_DMA(&huart5, (uint8_t*)&RX5Msg, sizeof(UARTMessage));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void findBestParent(){
|
||||
//Find least depth parent
|
||||
uint16_t least_val = 0xFF;
|
||||
@@ -321,11 +323,42 @@ void findBestParent(){
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: A function that gets called by RX Interrupt to handle messages that get sent
|
||||
void handleUARTMessages(uint8_t *data, UART_HandleTypeDef *sender){
|
||||
//TODO: Handle messages coming from devices based on the message type.
|
||||
// Called when UART RX interrupt completes
|
||||
void handleUARTMessages(uint8_t *data, UART_HandleTypeDef *sender) {
|
||||
UARTMessage msg;
|
||||
UARTMessage reply;
|
||||
|
||||
// Parse incoming message into struct
|
||||
memcpy(&msg, data, sizeof(UARTMessage));
|
||||
|
||||
switch(msg.TYPE) {
|
||||
|
||||
// Parent request reply
|
||||
case 0xAA:
|
||||
if(sender == &huart5) {
|
||||
PORT_DEPTH[0] = msg.DEPTH;
|
||||
} else if(sender == &huart1) {
|
||||
PORT_DEPTH[1] = msg.DEPTH;
|
||||
} else if(sender == &huart2) {
|
||||
PORT_DEPTH[2] = msg.DEPTH;
|
||||
} else if(sender == &huart4) {
|
||||
PORT_DEPTH[3] = msg.DEPTH;
|
||||
}
|
||||
break;
|
||||
|
||||
// Requested to be a parent
|
||||
case 0xFF:
|
||||
reply.TYPE = 0xAA;
|
||||
reply.DEPTH = DEPTH; // use your local DEPTH
|
||||
memset(reply.KEYPRESS, 0, sizeof(reply.KEYPRESS));
|
||||
|
||||
HAL_UART_Transmit(sender, (uint8_t*)&reply, sizeof(reply), HAL_MAX_DELAY);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void addUSBReport(uint8_t usageID){
|
||||
if(usageID < 0x04 || usageID > 0x73) return; //Usage ID is out of bounds
|
||||
uint16_t bit_index = usageID - 0x04; //Offset, UsageID starts with 0x04. Gives us the actual value of the bit
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
../Core/Src/main.c:149:5:main 6
|
||||
../Core/Src/main.c:244:6:SystemClock_Config 3
|
||||
../Core/Src/main.c:288:6:HAL_UART_RxCpltCallback 5
|
||||
../Core/Src/main.c:308:6:findBestParent 4
|
||||
../Core/Src/main.c:327:6:handleUARTMessages 7
|
||||
../Core/Src/main.c:362:6:addUSBReport 3
|
||||
../Core/Src/main.c:370:6:matrixScan 4
|
||||
../Core/Src/main.c:383:6:resetReport 1
|
||||
../Core/Src/main.c:394:6:Error_Handler 1
|
||||
|
||||
BIN
firmware/modularkbd/Debug/Core/Src/main.o
Normal file
BIN
firmware/modularkbd/Debug/Core/Src/main.o
Normal file
Binary file not shown.
@@ -0,0 +1,9 @@
|
||||
../Core/Src/main.c:149:5:main 24 static
|
||||
../Core/Src/main.c:244:6:SystemClock_Config 88 static
|
||||
../Core/Src/main.c:288:6:HAL_UART_RxCpltCallback 16 static
|
||||
../Core/Src/main.c:308:6:findBestParent 24 static
|
||||
../Core/Src/main.c:327:6:handleUARTMessages 48 static
|
||||
../Core/Src/main.c:362:6:addUSBReport 24 static
|
||||
../Core/Src/main.c:370:6:matrixScan 16 static
|
||||
../Core/Src/main.c:383:6:resetReport 8 static
|
||||
../Core/Src/main.c:394:6:Error_Handler 4 static,ignoring_inline_asm
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:279:16:USBD_HID_Init 3
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:326:16:USBD_HID_DeInit 2
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:357:16:USBD_HID_Setup 18
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:489:9:USBD_HID_SendReport 4
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:522:10:USBD_HID_GetPollingInterval 2
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:552:17:USBD_HID_GetFSCfgDesc 2
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:572:17:USBD_HID_GetHSCfgDesc 2
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:592:17:USBD_HID_GetOtherSpeedCfgDesc 2
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:613:16:USBD_HID_DataIn 1
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:630:17:USBD_HID_GetDeviceQualifierDesc 1
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:304:16:USBD_HID_Init 3
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:351:16:USBD_HID_DeInit 2
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:382:16:USBD_HID_Setup 18
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:514:9:USBD_HID_SendReport 4
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:547:10:USBD_HID_GetPollingInterval 2
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:577:17:USBD_HID_GetFSCfgDesc 2
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:597:17:USBD_HID_GetHSCfgDesc 2
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:617:17:USBD_HID_GetOtherSpeedCfgDesc 2
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:638:16:USBD_HID_DataIn 1
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:655:17:USBD_HID_GetDeviceQualifierDesc 1
|
||||
|
||||
Binary file not shown.
@@ -1,10 +1,10 @@
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:279:16:USBD_HID_Init 24 static
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:326:16:USBD_HID_DeInit 16 static
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:357:16:USBD_HID_Setup 32 static
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:489:9:USBD_HID_SendReport 32 static
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:522:10:USBD_HID_GetPollingInterval 24 static
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:552:17:USBD_HID_GetFSCfgDesc 24 static
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:572:17:USBD_HID_GetHSCfgDesc 24 static
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:592:17:USBD_HID_GetOtherSpeedCfgDesc 24 static
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:613:16:USBD_HID_DataIn 16 static
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:630:17:USBD_HID_GetDeviceQualifierDesc 16 static
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:304:16:USBD_HID_Init 24 static
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:351:16:USBD_HID_DeInit 16 static
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:382:16:USBD_HID_Setup 32 static
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:514:9:USBD_HID_SendReport 32 static
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:547:10:USBD_HID_GetPollingInterval 24 static
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:577:17:USBD_HID_GetFSCfgDesc 24 static
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:597:17:USBD_HID_GetHSCfgDesc 24 static
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:617:17:USBD_HID_GetOtherSpeedCfgDesc 24 static
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:638:16:USBD_HID_DataIn 16 static
|
||||
../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c:655:17:USBD_HID_GetDeviceQualifierDesc 16 static
|
||||
|
||||
Binary file not shown.
Binary file not shown.
BIN
firmware/modularkbd/Debug/modularkbd.elf
Executable file
BIN
firmware/modularkbd/Debug/modularkbd.elf
Executable file
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