Minor fixes + HIDBridge
* increased HW Serial1 RX buffer size from 16 to 32 (TX still 16) * removed fixed size in report buffers * used HID_KeyboardReport_Data_t now in Keyboard API HID Bridge works for transmitting
This commit is contained in:
parent
2f3e24f3b4
commit
4cfa0c6964
11 changed files with 118 additions and 63 deletions
|
|
@ -65,7 +65,10 @@ Version History
|
|||
```
|
||||
2.2 Release (xx.xx.2015)
|
||||
* added HID-Bridge
|
||||
* increased HW Serial1 RX buffer size from 16 to 32 (TX still 16)
|
||||
* added colour highlighting (through HID-Bridge library)
|
||||
* removed fixed size in report buffers
|
||||
* used HID_KeyboardReport_Data_t now in Keyboard API
|
||||
|
||||
2.1 Release (28.01.2015)
|
||||
* Reworked the whole USB-Core from scratch
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@
|
|||
#endif
|
||||
#if !defined(SERIAL_RX_BUFFER_SIZE)
|
||||
#if (RAMEND < 1000)
|
||||
#define SERIAL_RX_BUFFER_SIZE 16
|
||||
#define SERIAL_RX_BUFFER_SIZE 32
|
||||
#else
|
||||
#define SERIAL_RX_BUFFER_SIZE 64
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -55,9 +55,9 @@ THE SOFTWARE.
|
|||
|
||||
typedef union{
|
||||
// every usable Consumer key possible, up to 4 keys presses possible
|
||||
uint8_t whole8[8];
|
||||
uint16_t whole16[8 / 2];
|
||||
uint32_t whole32[8 / 4];
|
||||
uint8_t whole8[];
|
||||
uint16_t whole16[];
|
||||
uint32_t whole32[];
|
||||
struct{
|
||||
uint16_t key1;
|
||||
uint16_t key2;
|
||||
|
|
@ -104,7 +104,7 @@ public:
|
|||
HID_SendReport(HID_REPORTID_CONSUMERCONTROL, &_report, sizeof(_report));
|
||||
}
|
||||
inline void releaseAll(void){
|
||||
begin();
|
||||
end();
|
||||
}
|
||||
private:
|
||||
HID_ConsumerControlReport_Data_t _report;
|
||||
|
|
|
|||
|
|
@ -44,9 +44,9 @@ THE SOFTWARE.
|
|||
|
||||
typedef union {
|
||||
// 32 Buttons, 6 Axis, 2 D-Pads
|
||||
uint8_t whole8[15];
|
||||
uint16_t whole16[15 / 2];
|
||||
uint32_t whole32[15 / 4];
|
||||
uint8_t whole8[];
|
||||
uint16_t whole16[];
|
||||
uint32_t whole32[];
|
||||
uint32_t buttons;
|
||||
|
||||
struct{
|
||||
|
|
|
|||
|
|
@ -48,9 +48,9 @@ THE SOFTWARE.
|
|||
|
||||
Keyboard_ Keyboard;
|
||||
|
||||
void Keyboard_::sendReport(KeyReport* keys)
|
||||
void Keyboard_::sendReport(HID_KeyboardReport_Data_t* keys)
|
||||
{
|
||||
HID_SendReport(HID_REPORTID_KEYBOARD, keys, sizeof(KeyReport));
|
||||
HID_SendReport(HID_REPORTID_KEYBOARD, keys, sizeof(HID_KeyboardReport_Data_t));
|
||||
}
|
||||
|
||||
extern
|
||||
|
|
|
|||
|
|
@ -145,9 +145,9 @@ THE SOFTWARE.
|
|||
|
||||
typedef union{
|
||||
// Low level key report: up to 6 keys and shift, ctrl etc at once
|
||||
uint8_t whole8[8];
|
||||
uint16_t whole16[8 / 2];
|
||||
uint32_t whole32[8 / 4];
|
||||
uint8_t whole8[];
|
||||
uint16_t whole16[];
|
||||
uint32_t whole32[];
|
||||
struct{
|
||||
uint8_t modifiers;
|
||||
uint8_t reserved;
|
||||
|
|
@ -155,19 +155,11 @@ typedef union{
|
|||
};
|
||||
} HID_KeyboardReport_Data_t;
|
||||
|
||||
// Low level key report: up to 6 keys and shift, ctrl etc at once
|
||||
typedef struct
|
||||
{
|
||||
uint8_t modifiers;
|
||||
uint8_t reserved;
|
||||
uint8_t keys[6];
|
||||
} KeyReport; //TODO typedef union above
|
||||
|
||||
class Keyboard_ : public Print
|
||||
{
|
||||
protected:
|
||||
KeyReport _keyReport;
|
||||
void sendReport(KeyReport* keys);
|
||||
HID_KeyboardReport_Data_t _keyReport;
|
||||
void sendReport(HID_KeyboardReport_Data_t* keys);
|
||||
public:
|
||||
inline Keyboard_(void){
|
||||
// empty
|
||||
|
|
|
|||
|
|
@ -61,9 +61,9 @@ THE SOFTWARE.
|
|||
|
||||
typedef union{
|
||||
// mouse report: 8 buttons, position, wheel
|
||||
uint8_t whole8[4];
|
||||
uint16_t whole16[4 / 2];
|
||||
uint32_t whole32[4 / 4];
|
||||
uint8_t whole8[];
|
||||
uint16_t whole16[];
|
||||
uint32_t whole32[];
|
||||
struct{
|
||||
uint8_t buttons;
|
||||
int8_t xAxis;
|
||||
|
|
@ -74,9 +74,9 @@ typedef union{
|
|||
|
||||
typedef union{
|
||||
// mouse absolute report: 2 absolute axis
|
||||
uint8_t whole8[4];
|
||||
uint16_t whole16[4 / 2];
|
||||
uint32_t whole32[4 / 4];
|
||||
uint8_t whole8[];
|
||||
uint16_t whole16[];
|
||||
uint32_t whole32[];
|
||||
struct{
|
||||
int16_t xAxis;
|
||||
int16_t yAxis;
|
||||
|
|
|
|||
|
|
@ -33,9 +33,9 @@ THE SOFTWARE.
|
|||
|
||||
typedef union{
|
||||
// a RAWHID_TX_SIZE byte buffer for rx or tx
|
||||
uint8_t whole8[RAWHID_TX_SIZE];
|
||||
uint16_t whole16[RAWHID_TX_SIZE / 2];
|
||||
uint32_t whole32[RAWHID_TX_SIZE / 4];
|
||||
uint8_t whole8[];
|
||||
uint16_t whole16[];
|
||||
uint32_t whole32[];
|
||||
uint8_t buff[RAWHID_TX_SIZE];
|
||||
} HID_RawKeyboardReport_Data_t;
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ THE SOFTWARE.
|
|||
|
||||
typedef union{
|
||||
// every usable system control key possible
|
||||
uint8_t whole8[1];
|
||||
uint8_t whole8[];
|
||||
uint8_t key;
|
||||
} HID_SystemControlReport_Data_t;
|
||||
|
||||
|
|
|
|||
|
|
@ -43,64 +43,107 @@ void HIDBridge_::err(uint8_t error)
|
|||
|
||||
}
|
||||
|
||||
void HIDBridge_::task(void)
|
||||
void HIDBridge_::readSerial(void)
|
||||
{
|
||||
static NHP_Read_Data_t n = { 0 };
|
||||
uint8_t error = 0x00;
|
||||
|
||||
// read as long as the Serial is available
|
||||
// but do not block forever
|
||||
rx_buffer_index_t i = 0; //TODO availabel -> read -1
|
||||
while (Serial.available()) {
|
||||
if (NHPread(Serial.read(), &n)) {
|
||||
// read in new Serial byte and process with NHP protocol
|
||||
uint8_t b = Serial.read();
|
||||
bool newInput = NHPread(b, &n);
|
||||
|
||||
// proceed new valid NHP input
|
||||
if (newInput) {
|
||||
if (n.mode == NHP_ADDRESS) {
|
||||
switch (n.address) {
|
||||
case 0:
|
||||
// received a control address command
|
||||
if (n.data == 0) {
|
||||
case HIDBRIDGE_ADDRESS_CONTROL:
|
||||
// acknowledge/request
|
||||
if (n.data == HIDBRIDGE_CONTROL_ISREADY)
|
||||
isReady = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// pause
|
||||
else if (n.data == HIDBRIDGE_CONTROL_NOTREADY)
|
||||
isReady = false;
|
||||
|
||||
// not
|
||||
else
|
||||
error = 3;
|
||||
err(HID_BRIDGE_ERR_CONTROL);
|
||||
|
||||
break;
|
||||
// received HID out report TODO
|
||||
default:
|
||||
error = 1;
|
||||
err(HID_BRIDGE_ERR_ADDRESS);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
// received HID out report TODO
|
||||
else if (n.mode == NHP_COMMAND) {
|
||||
|
||||
error = 4;
|
||||
}
|
||||
else {
|
||||
}
|
||||
|
||||
// NHP reading error
|
||||
else if (n.errorLevel) {
|
||||
error = 2;
|
||||
}
|
||||
|
||||
}
|
||||
// do not block forever
|
||||
if (++i >= SERIAL_RX_BUFFER_SIZE)
|
||||
break;
|
||||
}
|
||||
|
||||
if (error)
|
||||
if (error){
|
||||
err(error);
|
||||
isReady = false; // revert
|
||||
}
|
||||
}
|
||||
|
||||
bool HIDBridge_::ready(void)
|
||||
|
||||
bool HIDBridge_::waitForReady(void)
|
||||
{
|
||||
//if (!hidReady) {
|
||||
|
||||
uint32_t currentMillis = millis();
|
||||
do{
|
||||
// check for new state information
|
||||
// maybe the host sended a pause signal
|
||||
readSerial();
|
||||
|
||||
// check for timeout //TODO move 1 up?
|
||||
if ((millis() - currentMillis) > HIDBRIDGE_TX_TIMEOUT) {
|
||||
err(1);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// try to wait for a new request/acknowledge
|
||||
while (!isReady)
|
||||
|
||||
return isReady;
|
||||
|
||||
//if (!isReady) { //TODO remove?
|
||||
// // try to wait for a new request/acknowledge
|
||||
// uint32_t currentMillis = millis();
|
||||
// while (!hidReady) {
|
||||
// readHIDReady();
|
||||
// if ((millis() - currentMillis) > 1000) {
|
||||
// errorHID(0);
|
||||
// return;
|
||||
// while (!isReady) {
|
||||
// readSerial();
|
||||
// // check for timeout //TODO move 1 up?
|
||||
// if ((millis() - currentMillis) > HIDBRIDGE_TX_TIMEOUT) {
|
||||
// err(1);
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//return true;
|
||||
}
|
||||
|
||||
// overwrites the HID_SendReport function which is empty/not used on a 328/2560
|
||||
void HID_SendReport(uint8_t reportID, const void* data, int len)
|
||||
{
|
||||
// check if we got a request/acknowledge
|
||||
if (!HIDBridge.ready()){
|
||||
// check the latest request/acknowledge, pause, error
|
||||
if (!HIDBridge.waitForReady()){
|
||||
HIDBridge.err(0);
|
||||
return;
|
||||
}
|
||||
|
|
@ -118,4 +161,7 @@ void HID_SendReport(uint8_t reportID, const void* data, int len)
|
|||
|
||||
// end transfer with zero command
|
||||
Serial.write(NHPwriteCommand(0));
|
||||
|
||||
// need a request/acknowledge next time again
|
||||
HIDBridge.isReady = false;
|
||||
}
|
||||
|
|
@ -36,6 +36,20 @@ THE SOFTWARE.
|
|||
// Definitions
|
||||
//================================================================================
|
||||
|
||||
#define HIDBRIDGE_TX_TIMEOUT 1000
|
||||
|
||||
#define HIDBRIDGE_ADDRESS_CONTROL 0
|
||||
|
||||
#define HIDBRIDGE_CONTROL_ISREADY 0
|
||||
#define HIDBRIDGE_CONTROL_NOTREADY 1
|
||||
|
||||
#define HID_BRIDGE_ERR_TIMEOUT 0
|
||||
#define HID_BRIDGE_ERR_NHP_ERR 1
|
||||
#define HID_BRIDGE_ERR_COMMAND 2
|
||||
#define HID_BRIDGE_ERR_ADDRESS 3
|
||||
#define HID_BRIDGE_ERR_CONTROL 4
|
||||
|
||||
|
||||
//================================================================================
|
||||
// HIDBridge
|
||||
//================================================================================
|
||||
|
|
@ -46,8 +60,8 @@ public:
|
|||
HIDBridge_(void);
|
||||
|
||||
bool begin(void);
|
||||
|
||||
bool ready(void);
|
||||
void readSerial(void);
|
||||
bool waitForReady(void);
|
||||
bool isReady;
|
||||
void task(void);
|
||||
void err(uint8_t error);
|
||||
|
|
|
|||
Loading…
Reference in a new issue