Skip to content

Commit 9a96f71

Browse files
committed
implement USB_SUPPORT_ENABLED guard to allow compilation without USB support
1 parent 0ee8305 commit 9a96f71

File tree

2 files changed

+60
-9
lines changed

2 files changed

+60
-9
lines changed

include/mdt/drivers/usb_input.h

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,71 @@
22
#define MDT_USB_INPUT_H
33

44
#include <stdbool.h>
5+
#if __has_include( "usbh_hid.h")
56
#include "usbh_hid.h"
7+
#define USB_SUPPORT_ENABLED
8+
#endif
9+
10+
typedef struct {
11+
uint8_t state;
12+
uint8_t lctrl;
13+
uint8_t lshift;
14+
uint8_t lalt;
15+
uint8_t lgui;
16+
uint8_t rctrl;
17+
uint8_t rshift;
18+
uint8_t ralt;
19+
uint8_t rgui;
20+
uint8_t keys[6];
21+
} MDT_USB_INPUT_KeybdInfo;
22+
23+
typedef struct {
24+
uint8_t x;
25+
uint8_t y;
26+
uint8_t buttons[3];
27+
} MDT_USB_INPUT_MouseInfo;
28+
29+
30+
#ifdef USB_SUPPORT_ENABLED
631

732

833
void MDT_USB_INPUT_Init();
934

1035
bool MDT_USB_INPUT_IsKbdKeyPressed(uint8_t key);
1136

12-
HID_KEYBD_Info_TypeDef* MDT_USB_INPUT_GetKbdInfo();
13-
14-
HID_MOUSE_Info_TypeDef* MDT_USB_INPUT_GetMouseInfo();
37+
MDT_USB_INPUT_KeybdInfo* MDT_USB_INPUT_GetKeybdInfo();
1538

16-
USBH_HandleTypeDef* MDT_USB_INPUT_GetHandle();
39+
MDT_USB_INPUT_MouseInfo* MDT_USB_INPUT_GetMouseInfo();
1740

1841
uint16_t MDT_USB_INPUT_GetEventCount();
1942

43+
USBH_HandleTypeDef* MDT_USB_INPUT_GetHandle();
44+
2045
USBH_StatusTypeDef MDT_USB_INPUT_GetLastCode();
2146

2247
const char* MDT_USB_INPUT_GetState();
2348

49+
50+
#else
51+
52+
53+
#define MDT_USB_INPUT_Init()
54+
55+
#define MDT_USB_INPUT_GetState() "USB_DISABLED"
56+
57+
#define MDT_USB_INPUT_GetKeybdInfo() (NULL)
58+
59+
#define MDT_USB_INPUT_GetMouseInfo() (NULL)
60+
61+
#define MDT_USB_INPUT_GetEventCount() (0)
62+
63+
#define MDT_USB_INPUT_GetHandle() (NULL)
64+
65+
#define MDT_USB_INPUT_GetLastCode() (0)
66+
67+
#define MDT_USB_INPUT_IsKbdKeyPressed(k) (false)
68+
69+
70+
#endif
71+
2472
#endif

src/drivers/usb_input.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
#include <stm32f4xx_ll_bus.h>
44
#include <stm32f4xx_ll_tim.h>
55

6-
#include "usbh_core.h"
76
#include "mdt/clkinfo.h"
87
#include "mdt/drivers/usb_input.h"
98

9+
#ifdef USB_SUPPORT_ENABLED
10+
11+
#include "usbh_core.h"
1012

1113
static USBH_HandleTypeDef hUsbHost;
1214

@@ -92,16 +94,16 @@ const char* MDT_USB_INPUT_GetState() {
9294
}
9395

9496

95-
HID_KEYBD_Info_TypeDef* MDT_USB_INPUT_GetKbdInfo() {
97+
MDT_USB_INPUT_KeybdInfo* MDT_USB_INPUT_GetKeybdInfo() {
9698

97-
return kbdInfo;
99+
return (MDT_USB_INPUT_KeybdInfo*) kbdInfo;
98100

99101
}
100102

101103

102-
HID_MOUSE_Info_TypeDef* MDT_USB_INPUT_GetMouseInfo() {
104+
MDT_USB_INPUT_MouseInfo* MDT_USB_INPUT_GetMouseInfo() {
103105

104-
return mouseInfo;
106+
return (MDT_USB_INPUT_MouseInfo*) mouseInfo;
105107

106108
}
107109

@@ -202,3 +204,4 @@ static void USBH_UserProcess(USBH_HandleTypeDef *phost, uint8_t id) {
202204

203205
}
204206

207+
#endif

0 commit comments

Comments
 (0)