-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBlUsbDev.h
118 lines (94 loc) · 3.85 KB
/
BlUsbDev.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*****************************************************************************/
/* BlUsbDev.h : declaration of the USB device communication classes */
/*****************************************************************************/
/*
Copyright (C) 2019 Hermann Seib
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, version 3.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef _BlusbDev_h__included_
#define _BlusbDev_h__included_
#include "usb_ll.h"
/*****************************************************************************/
/* Definitions */
/*****************************************************************************/
#ifdef LIBUSB_H
enum blusb_error {
BLUSB_SUCCESS = LIBUSB_SUCCESS,
BLUSB_ERROR_IO = LIBUSB_ERROR_IO,
BLUSB_ERROR_INVALID_PARAM = LIBUSB_ERROR_INVALID_PARAM,
BLUSB_ERROR_ACCESS = LIBUSB_ERROR_ACCESS,
BLUSB_ERROR_NO_DEVICE = LIBUSB_ERROR_NO_DEVICE,
BLUSB_ERROR_NOT_FOUND = LIBUSB_ERROR_NOT_FOUND,
BLUSB_ERROR_BUSY = LIBUSB_ERROR_BUSY,
BLUSB_ERROR_TIMEOUT = LIBUSB_ERROR_TIMEOUT,
BLUSB_ERROR_OVERFLOW = LIBUSB_ERROR_OVERFLOW,
BLUSB_ERROR_PIPE = LIBUSB_ERROR_PIPE,
BLUSB_ERROR_INTERRUPTED = LIBUSB_ERROR_INTERRUPTED,
BLUSB_ERROR_NO_MEM = LIBUSB_ERROR_NO_MEM,
BLUSB_ERROR_NOT_SUPPORTED = LIBUSB_ERROR_NOT_SUPPORTED,
BLUSB_ERROR_OTHER = LIBUSB_ERROR_OTHER,
};
#else
enum blusb_error {
BLUSB_SUCCESS = 0,
BLUSB_ERROR_IO = -1,
BLUSB_ERROR_INVALID_PARAM = -2,
BLUSB_ERROR_ACCESS = -3,
BLUSB_ERROR_NO_DEVICE = -4,
BLUSB_ERROR_NOT_FOUND = -5,
BLUSB_ERROR_BUSY = -6,
BLUSB_ERROR_TIMEOUT = -7,
BLUSB_ERROR_OVERFLOW = -8,
BLUSB_ERROR_PIPE = -9,
BLUSB_ERROR_INTERRUPTED = -10,
BLUSB_ERROR_NO_MEM = -11,
BLUSB_ERROR_NOT_SUPPORTED = -12,
BLUSB_ERROR_OTHER = -99,
// our private codes
BLUSB_ERROR_NO_LAYOUT = -1000,
};
#endif
/*****************************************************************************/
/* BlUsbDev : BlUSB device communication class declaration */
/*****************************************************************************/
class BlUsbDev : public UsbLL
{
public:
BlUsbDev(void);
~BlUsbDev(void);
int Open(wxUint16 vendor = 0x04b3, wxUint16 product = 0x301c,
wxUint16 Usage = -1, wxUint16 UsagePage = -1);
bool IsOpen() { return !!handle; }
void Close() { if (IsOpen()) UsbLL::Close(handle); handle = NULL; }
int EnableServiceMode();
int DisableServiceMode();
int ReadVersion(wxUint8 *buffer, int buflen);
int ReadPWM(wxUint8 &pwmUSB, wxUint8 &pwmBT);
int WritePWM(wxUint8 pwmUSB, wxUint8 pwmBT);
int ReadMatrix(wxUint8 *buffer, int buflen);
int ReadLayout(wxUint8 *buffer, int buflen);
int WriteLayout(wxUint8 *buffer, int buflen);
int ReadDebounce();
int WriteDebounce(int nDebounce);
int ReadMacros(wxUint8 *buffer, int buflen);
int WriteMacros(wxUint8 *buffer, int buflen);
int EnterBootloader();
int ExitBootloader();
int UpdateFirmware(wxUint16 startAddr, wxUint16 endAddr, wxUint8 *buffer);
int GetFwMajorVersion() { return blVer[0]; }
int GetFwMinorVersion() { return blVer[1]; }
int GetFwVersion() { return (((int)blVer[0]) << 8) | blVer[1]; }
void SetFWVersion(int newver) { blVer[0] = (newver >> 8) & 0xff; blVer[1] = newver & 0xff; }
protected:
void *handle;
wxUint8 blVer[2]; // version major/minor
};
#endif // defined(_BlusbDev_h__included_)