Expose variables via USB

This commit is contained in:
Eric Tang
2018-07-19 21:11:02 -07:00
parent 1bced1be13
commit 63d82d92db
6 changed files with 75 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
#include "usb_protocol_handler.h"
#include "usb_commands/usb_command_get_variable.h"
#include "key_matrix.h"
void UsbCommand_GetVariable(void)
{
usb_variable_id_t variableId = GetUsbRxBufferUint8(1);
switch (variableId) {
case UsbVariable_TestMode:
break;
case UsbVariable_TestUsbStack:
break;
case UsbVariable_DebounceTimePress:
SetUsbTxBufferUint8(1, DebounceTimePress);
break;
case UsbVariable_DebounceTimeRelease:
SetUsbTxBufferUint8(1, DebounceTimeRelease);
break;
}
}

View File

@@ -0,0 +1,8 @@
#ifndef __USB_COMMAND_GET_VARIABLE_H__
#define __USB_COMMAND_GET_VARIABLE_H__
// Functions:
void UsbCommand_GetVariable(void);
#endif

View File

@@ -0,0 +1,21 @@
#include "usb_protocol_handler.h"
#include "usb_commands/usb_command_set_variable.h"
#include "key_matrix.h"
void UsbCommand_SetVariable(void)
{
usb_variable_id_t variableId = GetUsbRxBufferUint8(1);
switch (variableId) {
case UsbVariable_TestMode:
break;
case UsbVariable_TestUsbStack:
break;
case UsbVariable_DebounceTimePress:
DebounceTimePress = GetUsbRxBufferUint8(2);
break;
case UsbVariable_DebounceTimeRelease:
DebounceTimeRelease = GetUsbRxBufferUint8(2);
break;
}
}

View File

@@ -0,0 +1,8 @@
#ifndef __USB_COMMAND_SET_VARIABLE_H__
#define __USB_COMMAND_SET_VARIABLE_H__
// Functions:
void UsbCommand_SetVariable(void);
#endif

View File

@@ -17,6 +17,8 @@
#include "usb_commands/usb_command_get_slave_i2c_errors.h" #include "usb_commands/usb_command_get_slave_i2c_errors.h"
#include "usb_commands/usb_command_set_i2c_baud_rate.h" #include "usb_commands/usb_command_set_i2c_baud_rate.h"
#include "usb_commands/usb_command_switch_keymap.h" #include "usb_commands/usb_command_switch_keymap.h"
#include "usb_commands/usb_command_get_variable.h"
#include "usb_commands/usb_command_set_variable.h"
void UsbProtocolHandler(void) void UsbProtocolHandler(void)
{ {
@@ -77,6 +79,12 @@ void UsbProtocolHandler(void)
case UsbCommandId_SwitchKeymap: case UsbCommandId_SwitchKeymap:
UsbCommand_SwitchKeymap(); UsbCommand_SwitchKeymap();
break; break;
case UsbCommandId_GetVariable:
UsbCommand_GetVariable();
break;
case UsbCommandId_SetVariable:
UsbCommand_SetVariable();
break;
default: default:
SetUsbTxBufferUint8(0, UsbStatusCode_InvalidCommand); SetUsbTxBufferUint8(0, UsbStatusCode_InvalidCommand);
break; break;

View File

@@ -34,8 +34,17 @@
UsbCommandId_GetSlaveI2cErrors = 0x0f, UsbCommandId_GetSlaveI2cErrors = 0x0f,
UsbCommandId_SetI2cBaudRate = 0x10, UsbCommandId_SetI2cBaudRate = 0x10,
UsbCommandId_SwitchKeymap = 0x11, UsbCommandId_SwitchKeymap = 0x11,
UsbCommandId_GetVariable = 0x12,
UsbCommandId_SetVariable = 0x13,
} usb_command_id_t; } usb_command_id_t;
typedef enum {
UsbVariable_TestMode,
UsbVariable_TestUsbStack,
UsbVariable_DebounceTimePress,
UsbVariable_DebounceTimeRelease
} usb_variable_id_t;
typedef enum { typedef enum {
UsbStatusCode_Success = 0, UsbStatusCode_Success = 0,
UsbStatusCode_InvalidCommand = 1, UsbStatusCode_InvalidCommand = 1,