UART STUFF
This commit is contained in:
@@ -31,7 +31,7 @@
|
|||||||
typedef struct{
|
typedef struct{
|
||||||
uint8_t MODIFIER;
|
uint8_t MODIFIER;
|
||||||
uint8_t RESERVED;
|
uint8_t RESERVED;
|
||||||
uint8_t KEYPRESS[13];
|
uint8_t KEYPRESS[12];
|
||||||
}HIDReport;
|
}HIDReport;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -39,13 +39,11 @@ typedef struct {
|
|||||||
uint16_t PIN;
|
uint16_t PIN;
|
||||||
}SwitchPins;
|
}SwitchPins;
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t buffer[256];
|
uint16_t depth;
|
||||||
uint16_t head;
|
uint16_t msgType;
|
||||||
uint16_t tail;
|
uint8_t keypress[12];
|
||||||
uint16_t count;
|
}UARTMessage;
|
||||||
} HIDQueue;
|
|
||||||
/* USER CODE END PTD */
|
/* USER CODE END PTD */
|
||||||
|
|
||||||
/* Private define ------------------------------------------------------------*/
|
/* Private define ------------------------------------------------------------*/
|
||||||
@@ -63,6 +61,8 @@ typedef struct {
|
|||||||
#define MODE_MAINBOARD 1
|
#define MODE_MAINBOARD 1
|
||||||
#define MODE_ACTIVE 2
|
#define MODE_ACTIVE 2
|
||||||
#define MODE_DEBUG 3
|
#define MODE_DEBUG 3
|
||||||
|
|
||||||
|
#define UART_RX_BUFF_SIZE 64
|
||||||
/* USER CODE END PM */
|
/* USER CODE END PM */
|
||||||
|
|
||||||
/* Private variables ---------------------------------------------------------*/
|
/* Private variables ---------------------------------------------------------*/
|
||||||
@@ -78,6 +78,17 @@ UART_HandleTypeDef huart1;
|
|||||||
UART_HandleTypeDef huart2;
|
UART_HandleTypeDef huart2;
|
||||||
UART_HandleTypeDef huart3;
|
UART_HandleTypeDef huart3;
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t UART1_RX_BUFF[UART_RX_BUFF_SIZE];
|
||||||
|
uint8_t UART2_RX_BUFF[UART_RX_BUFF_SIZE];
|
||||||
|
uint8_t UART4_RX_BUFF[UART_RX_BUFF_SIZE];
|
||||||
|
uint8_t UART5_RX_BUFF[UART_RX_BUFF_SIZE];
|
||||||
|
|
||||||
|
uint16_t UART1_BUFF_LASTPOS = 0;
|
||||||
|
uint16_t UART2_BUFF_LASTPOS = 0;
|
||||||
|
uint16_t UART4_BUFF_LASTPOS = 0;
|
||||||
|
uint16_t UART5_BUFF_LASTPOS = 0;
|
||||||
|
|
||||||
// Initialize HID report properly
|
// Initialize HID report properly
|
||||||
HIDReport REPORT = {0, 0, {0}};
|
HIDReport REPORT = {0, 0, {0}};
|
||||||
|
|
||||||
@@ -99,11 +110,11 @@ uint8_t KEYCODES[2][2] = {
|
|||||||
{KEY_K, KEY_U} // 'K', 'U'
|
{KEY_K, KEY_U} // 'K', 'U'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
uint16_t DEPTH = 0;
|
||||||
|
|
||||||
extern USBD_HandleTypeDef hUsbDeviceFS;
|
extern USBD_HandleTypeDef hUsbDeviceFS;
|
||||||
|
volatile uint8_t MODE = MODE_INACTIVE;
|
||||||
|
|
||||||
volatile uint8_t MODE = MODE_MAINBOARD;
|
|
||||||
/* USER CODE END PV */
|
/* USER CODE END PV */
|
||||||
|
|
||||||
/* Private function prototypes -----------------------------------------------*/
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
@@ -119,13 +130,8 @@ static void MX_USART2_UART_Init(void);
|
|||||||
static void MX_I2C1_Init(void);
|
static void MX_I2C1_Init(void);
|
||||||
static void MX_USART3_UART_Init(void);
|
static void MX_USART3_UART_Init(void);
|
||||||
|
|
||||||
//Queue Functions (move this later as a separate c/h file)
|
void handleUARTMessages(uint8_t *data, UART_HandleTypeDef *huart);
|
||||||
uint8_t Q_IsEmpty(HIDQueue* q);
|
void UART_DMA_SendReport(UART_HandleTypeDef *huart);
|
||||||
uint8_t Q_IsMax(HIDQueue*q);
|
|
||||||
uint8_t Q_Enqueue(HIDQueue* q);
|
|
||||||
uint8_t Q_Dequeue(HIDQueue* q);
|
|
||||||
uint8_t Q_Peek(HIDQueue* q);
|
|
||||||
|
|
||||||
void addUSBReport(uint8_t usageID);
|
void addUSBReport(uint8_t usageID);
|
||||||
void matrixScan(void);
|
void matrixScan(void);
|
||||||
void resetReport(void);
|
void resetReport(void);
|
||||||
@@ -176,6 +182,9 @@ int main(void)
|
|||||||
MX_USB_DEVICE_Init();
|
MX_USB_DEVICE_Init();
|
||||||
/* USER CODE BEGIN 2 */
|
/* USER CODE BEGIN 2 */
|
||||||
|
|
||||||
|
//Enable UART RX DMA for all ports
|
||||||
|
|
||||||
|
|
||||||
/* USER CODE END 2 */
|
/* USER CODE END 2 */
|
||||||
|
|
||||||
/* Infinite loop */
|
/* Infinite loop */
|
||||||
@@ -186,15 +195,22 @@ int main(void)
|
|||||||
//Reset Report
|
//Reset Report
|
||||||
resetReport();
|
resetReport();
|
||||||
|
|
||||||
//TODO: Append Child Module Reports
|
//Query Neighbors
|
||||||
|
UARTMessage query;
|
||||||
|
query.depth = DEPTH;
|
||||||
|
query.msgType = 0x01;
|
||||||
|
memset(query.keypress, 0,sizeof(query.keypress));
|
||||||
|
HAL_UART_Transmit_DMA(&huart1, (uint8_t*)&query, sizeof(query));
|
||||||
|
HAL_UART_Transmit_DMA(&huart2, (uint8_t*)&query, sizeof(query));
|
||||||
|
HAL_UART_Transmit_DMA(&huart4, (uint8_t*)&query, sizeof(query));
|
||||||
|
HAL_UART_Transmit_DMA(&huart5, (uint8_t*)&query, sizeof(query));
|
||||||
|
|
||||||
matrixScan();
|
matrixScan();
|
||||||
|
|
||||||
switch (MODE){
|
switch (MODE){
|
||||||
|
|
||||||
case MODE_ACTIVE:
|
case MODE_ACTIVE:
|
||||||
//TODO: Send to parent
|
//TODO: Detect if a request is recieved
|
||||||
//TODO: Check heartbeat signal from parent.
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MODE_MAINBOARD:
|
case MODE_MAINBOARD:
|
||||||
@@ -202,9 +218,22 @@ int main(void)
|
|||||||
USBD_HID_SendReport(&hUsbDeviceFS, (uint8_t*)&REPORT, sizeof(REPORT));
|
USBD_HID_SendReport(&hUsbDeviceFS, (uint8_t*)&REPORT, sizeof(REPORT));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Send heartbeat signal to child nodes
|
//TODO: Send heartbeat signal to child nodes
|
||||||
|
|
||||||
|
|
||||||
}else{ //INACTIVE Mode
|
}else{ //INACTIVE Mode
|
||||||
//TODO: Request parents
|
//Check if the USB is enumerated/connected.
|
||||||
|
if (hUsbDeviceFS.dev_state == USBD_STATE_CONFIGURED) {
|
||||||
|
MODE = MODE_MAINBOARD;
|
||||||
|
//Enable DMA RX
|
||||||
|
HAL_UART_Receive_DMA(&huart1, UART1_RX_BUFF, UART_RX_BUFF_SIZE);
|
||||||
|
HAL_UART_Receive_DMA(&huart2, UART2_RX_BUFF, UART_RX_BUFF_SIZE);
|
||||||
|
HAL_UART_Receive_DMA(&huart4, UART4_RX_BUFF, UART_RX_BUFF_SIZE);
|
||||||
|
HAL_UART_Receive_DMA(&huart5, UART5_RX_BUFF, UART_RX_BUFF_SIZE);
|
||||||
|
}else{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
HAL_Delay(USBD_HID_GetPollingInterval(&hUsbDeviceFS));
|
HAL_Delay(USBD_HID_GetPollingInterval(&hUsbDeviceFS));
|
||||||
}
|
}
|
||||||
@@ -611,27 +640,41 @@ static void MX_GPIO_Init(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* USER CODE BEGIN 4 */
|
/* USER CODE BEGIN 4 */
|
||||||
/**
|
//UART Message Requests Goes Here
|
||||||
* @brief Returns whether the HID Queue is Full
|
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart){
|
||||||
* @retval uint8_t; 1 for full, 0 otherwise
|
if(huart->Instance == USART1){
|
||||||
* @param HIDQueue
|
handleUARTMessages(UART1_RX_BUFF, huart);
|
||||||
*/
|
HAL_UART_Receive_DMA(huart, UART1_RX_BUFF, UART_RX_BUFF_SIZE);
|
||||||
uint8_t Q_IsEmpty(HIDQueue* q){
|
}
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
uint8_t Q_IsMax(HIDQueue*q){
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
uint8_t Q_Enqueue(HIDQueue* q){
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
uint8_t Q_Dequeue(HIDQueue* q){
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
uint8_t Q_Peek(HIDQueue* q){
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void handleUARTMessages(uint8_t *data, UART_HandleTypeDef *sender){
|
||||||
|
UARTMessage msg;
|
||||||
|
UARTMessage res;
|
||||||
|
|
||||||
|
// Parse incoming message
|
||||||
|
msg.depth = (data[0]<<8) | data[1];
|
||||||
|
msg.msgType = (data[2]<<8) | data[3];
|
||||||
|
memcpy(msg.keypress, &data[4], 12);
|
||||||
|
|
||||||
|
switch(msg.msgType){
|
||||||
|
case 0x01: // Request keypress
|
||||||
|
if (sender->gState == HAL_UART_STATE_READY) {
|
||||||
|
res.depth = DEPTH;
|
||||||
|
res.msgType = 0x10;
|
||||||
|
memcpy(res.keypress, &REPORT.KEYPRESS, sizeof(REPORT.KEYPRESS));
|
||||||
|
// Send safely using DMA
|
||||||
|
HAL_UART_Transmit_DMA(sender, (uint8_t *)&res, sizeof(res));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 0x10: //Keypress recieved
|
||||||
|
//Merge keypresses
|
||||||
|
for (int i = 0; i < 12; i++) {
|
||||||
|
REPORT.KEYPRESS[i] |= msg.keypress[i];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
void addUSBReport(uint8_t usageID){
|
void addUSBReport(uint8_t usageID){
|
||||||
if(usageID < 0x04 || usageID > 0x73) return; //Usage ID is out of bounds
|
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
|
uint16_t bit_index = usageID - 0x04; //Offset, UsageID starts with 0x04. Gives us the actual value of the bit
|
||||||
|
|||||||
@@ -1,20 +1,17 @@
|
|||||||
../Core/Src/main.c:143:5:main 3
|
../Core/Src/main.c:149:5:main 4
|
||||||
../Core/Src/main.c:218:6:SystemClock_Config 3
|
../Core/Src/main.c:247:6:SystemClock_Config 3
|
||||||
../Core/Src/main.c:265:13:MX_I2C1_Init 2
|
../Core/Src/main.c:294:13:MX_I2C1_Init 2
|
||||||
../Core/Src/main.c:299:13:MX_TIM2_Init 4
|
../Core/Src/main.c:328:13:MX_TIM2_Init 4
|
||||||
../Core/Src/main.c:348:13:MX_TIM3_Init 3
|
../Core/Src/main.c:377:13:MX_TIM3_Init 3
|
||||||
../Core/Src/main.c:397:13:MX_UART4_Init 2
|
../Core/Src/main.c:426:13:MX_UART4_Init 2
|
||||||
../Core/Src/main.c:430:13:MX_UART5_Init 2
|
../Core/Src/main.c:459:13:MX_UART5_Init 2
|
||||||
../Core/Src/main.c:463:13:MX_USART1_UART_Init 2
|
../Core/Src/main.c:492:13:MX_USART1_UART_Init 2
|
||||||
../Core/Src/main.c:496:13:MX_USART2_UART_Init 2
|
../Core/Src/main.c:525:13:MX_USART2_UART_Init 2
|
||||||
../Core/Src/main.c:529:13:MX_USART3_UART_Init 2
|
../Core/Src/main.c:558:13:MX_USART3_UART_Init 2
|
||||||
../Core/Src/main.c:562:13:MX_GPIO_Init 1
|
../Core/Src/main.c:591:13:MX_GPIO_Init 1
|
||||||
../Core/Src/main.c:619:9:Q_IsEmpty 1
|
../Core/Src/main.c:644:6:HAL_UART_RxCpltCallback 2
|
||||||
../Core/Src/main.c:622:9:Q_IsMax 1
|
../Core/Src/main.c:651:6:handleUARTMessages 5
|
||||||
../Core/Src/main.c:625:9:Q_Enqueue 1
|
../Core/Src/main.c:678:6:addUSBReport 3
|
||||||
../Core/Src/main.c:628:9:Q_Dequeue 1
|
../Core/Src/main.c:686:6:matrixScan 4
|
||||||
../Core/Src/main.c:631:9:Q_Peek 1
|
../Core/Src/main.c:699:6:resetReport 1
|
||||||
../Core/Src/main.c:635:6:addUSBReport 3
|
../Core/Src/main.c:710:6:Error_Handler 1
|
||||||
../Core/Src/main.c:643:6:matrixScan 4
|
|
||||||
../Core/Src/main.c:656:6:resetReport 1
|
|
||||||
../Core/Src/main.c:667:6:Error_Handler 1
|
|
||||||
|
|||||||
Binary file not shown.
@@ -1,20 +1,17 @@
|
|||||||
../Core/Src/main.c:143:5:main 8 static
|
../Core/Src/main.c:149:5:main 24 static
|
||||||
../Core/Src/main.c:218:6:SystemClock_Config 88 static
|
../Core/Src/main.c:247:6:SystemClock_Config 88 static
|
||||||
../Core/Src/main.c:265:13:MX_I2C1_Init 8 static
|
../Core/Src/main.c:294:13:MX_I2C1_Init 8 static
|
||||||
../Core/Src/main.c:299:13:MX_TIM2_Init 48 static
|
../Core/Src/main.c:328:13:MX_TIM2_Init 48 static
|
||||||
../Core/Src/main.c:348:13:MX_TIM3_Init 56 static
|
../Core/Src/main.c:377:13:MX_TIM3_Init 56 static
|
||||||
../Core/Src/main.c:397:13:MX_UART4_Init 8 static
|
../Core/Src/main.c:426:13:MX_UART4_Init 8 static
|
||||||
../Core/Src/main.c:430:13:MX_UART5_Init 8 static
|
../Core/Src/main.c:459:13:MX_UART5_Init 8 static
|
||||||
../Core/Src/main.c:463:13:MX_USART1_UART_Init 8 static
|
../Core/Src/main.c:492:13:MX_USART1_UART_Init 8 static
|
||||||
../Core/Src/main.c:496:13:MX_USART2_UART_Init 8 static
|
../Core/Src/main.c:525:13:MX_USART2_UART_Init 8 static
|
||||||
../Core/Src/main.c:529:13:MX_USART3_UART_Init 8 static
|
../Core/Src/main.c:558:13:MX_USART3_UART_Init 8 static
|
||||||
../Core/Src/main.c:562:13:MX_GPIO_Init 48 static
|
../Core/Src/main.c:591:13:MX_GPIO_Init 48 static
|
||||||
../Core/Src/main.c:619:9:Q_IsEmpty 16 static
|
../Core/Src/main.c:644:6:HAL_UART_RxCpltCallback 16 static
|
||||||
../Core/Src/main.c:622:9:Q_IsMax 16 static
|
../Core/Src/main.c:651:6:handleUARTMessages 56 static
|
||||||
../Core/Src/main.c:625:9:Q_Enqueue 16 static
|
../Core/Src/main.c:678:6:addUSBReport 24 static
|
||||||
../Core/Src/main.c:628:9:Q_Dequeue 16 static
|
../Core/Src/main.c:686:6:matrixScan 16 static
|
||||||
../Core/Src/main.c:631:9:Q_Peek 16 static
|
../Core/Src/main.c:699:6:resetReport 8 static
|
||||||
../Core/Src/main.c:635:6:addUSBReport 24 static
|
../Core/Src/main.c:710:6:Error_Handler 4 static,ignoring_inline_asm
|
||||||
../Core/Src/main.c:643:6:matrixScan 16 static
|
|
||||||
../Core/Src/main.c:656:6:resetReport 8 static
|
|
||||||
../Core/Src/main.c:667: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
1415
hardware/numpad/numpad/sierra_quote.log
Normal file
1415
hardware/numpad/numpad/sierra_quote.log
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user