Skip to content

Commit b9960af

Browse files
committed
[USB HID] Clean HID composite interface
Signed-off-by: Frederic.Pillon <[email protected]>
1 parent 2c4a81c commit b9960af

File tree

8 files changed

+46
-43
lines changed

8 files changed

+46
-43
lines changed

cores/arduino/board.h

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ extern "C"{
2020
#include "timer.h"
2121
#include "twi.h"
2222
#include "uart.h"
23-
#include "usbd_interface.h"
2423

2524
void init( void ) ;
2625
#ifdef __cplusplus

cores/arduino/main.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ int main( void )
5454
{
5555
initVariant();
5656

57-
#if defined(USBCON)
58-
usbd_interface_init();
59-
#endif
60-
6157
setup();
6258

6359
for (;;)

cores/arduino/stm32/usbd_interface.c renamed to cores/arduino/stm32/usb/hid/usbd_hid_composite_if.c

+25-20
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
******************************************************************************
3-
* @file usbd_interface.c
4-
* @brief Provide the USB device interface
3+
* @file usbd_hid_composite_if.c
4+
* @brief Provide the USB HID composite interface
55
*
66
******************************************************************************
77
* @attention
@@ -33,33 +33,26 @@
3333
******************************************************************************
3434
*/
3535
#ifdef USBCON
36-
#include "usbd_desc.h"
37-
#include "usbd_interface.h"
3836
#ifdef USBD_USE_HID_COMPOSITE
37+
38+
#include "usbd_desc.h"
39+
#include "usbd_hid_composite_if.h"
3940
#include "usbd_hid_composite.h"
40-
#endif
41-
#ifdef USBD_USE_CDC
42-
#include "usbd_cdc_if.h"
43-
#endif
4441

4542
#ifdef __cplusplus
4643
extern "C" {
4744
#endif
4845

49-
/* USB Device Core handle declaration */
50-
#ifdef USBD_USE_HID_COMPOSITE
46+
/* USB Device Core HID composite handle declaration */
5147
USBD_HandleTypeDef hUSBD_Device_HID;
52-
#endif /* USBD_USE_HID_COMPOSITE*/
5348

5449
/**
55-
* @brief initialize USB devices
50+
* @brief Initialize USB devices
5651
* @param none
5752
* @retval none
5853
*/
59-
__attribute__((weak))
60-
void usbd_interface_init(void)
54+
void HID_Composite_Init(void)
6155
{
62-
#ifdef USBD_USE_HID_COMPOSITE
6356
/* Init Device Library */
6457
USBD_Init(&hUSBD_Device_HID, &HID_Desc, 0);
6558

@@ -68,17 +61,29 @@ void usbd_interface_init(void)
6861

6962
/* Start Device Process */
7063
USBD_Start(&hUSBD_Device_HID);
71-
#endif /* USBD_USE_HID_COMPOSITE */
7264
}
7365

74-
#ifdef USBD_USE_HID_COMPOSITE
66+
/**
67+
* @brief DeInitialize USB devices
68+
* @param none
69+
* @retval none
70+
*/
71+
void HID_Composite_DeInit(void)
72+
{
73+
/* Stop Device Process */
74+
USBD_Stop(&hUSBD_Device_HID);
75+
76+
/* DeInit Device Library */
77+
USBD_DeInit(&hUSBD_Device_HID);
78+
}
79+
7580
/**
7681
* @brief Send HID mouse Report
7782
* @param report pointer to report
7883
* @param len report lenght
7984
* @retval none
8085
*/
81-
void usbd_interface_mouse_sendReport(uint8_t *report, uint16_t len)
86+
void HID_Composite_mouse_sendReport(uint8_t *report, uint16_t len)
8287
{
8388
USBD_HID_MOUSE_SendReport(&hUSBD_Device_HID, report, len);
8489
}
@@ -89,14 +94,14 @@ void usbd_interface_mouse_sendReport(uint8_t *report, uint16_t len)
8994
* @param len report lenght
9095
* @retval none
9196
*/
92-
void usbd_interface_keyboard_sendReport(uint8_t *report, uint16_t len)
97+
void HID_Composite_keyboard_sendReport(uint8_t *report, uint16_t len)
9398
{
9499
USBD_HID_KEYBOARD_SendReport(&hUSBD_Device_HID, report, len);
95100
}
96-
#endif /* USBD_USE_HID_COMPOSITE */
97101

98102
#ifdef __cplusplus
99103
}
100104
#endif
105+
#endif /* USBD_USE_HID_COMPOSITE */
101106
#endif /* USBCON */
102107
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

cores/arduino/stm32/usbd_interface.h renamed to cores/arduino/stm32/usb/hid/usbd_hid_composite_if.h

+11-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
******************************************************************************
3-
* @file usbd_interface.h
4-
* @brief Header for USB device interface
3+
* @file usbd_hid_composite_if.h
4+
* @brief Header for USB HID composite interface
55
******************************************************************************
66
* @attention
77
*
@@ -33,32 +33,29 @@
3333
*/
3434

3535
/* Define to prevent recursive inclusion -------------------------------------*/
36-
#ifndef __USBD_INTERFACE_H
37-
#define __USBD_INTERFACE_H
36+
#ifndef __USBD_HID_COMPOSITE_IF_H
37+
#define __USBD_HID_COMPOSITE_IF_H
3838
#ifdef USBCON
39+
#ifdef USBD_USE_HID_COMPOSITE
3940

4041
/* Includes ------------------------------------------------------------------*/
4142
#ifdef __cplusplus
4243
extern "C" {
4344
#endif
4445

45-
/* Exported types ------------------------------------------------------------*/
46-
/* Exported constants --------------------------------------------------------*/
47-
/* Exported macro ------------------------------------------------------------*/
48-
/* Exported variables --------------------------------------------------------*/
4946
/* Exported functions ------------------------------------------------------- */
50-
void usbd_interface_init(void);
47+
void HID_Composite_Init(void);
48+
void HID_Composite_DeInit(void);
5149

52-
#ifdef USBD_USE_HID_COMPOSITE
53-
void usbd_interface_mouse_sendReport(uint8_t *report, uint16_t len);
54-
void usbd_interface_keyboard_sendReport(uint8_t *report, uint16_t len);
55-
#endif
50+
void HID_Composite_mouse_sendReport(uint8_t *report, uint16_t len);
51+
void HID_Composite_keyboard_sendReport(uint8_t *report, uint16_t len);
5652

5753
#ifdef __cplusplus
5854
}
5955
#endif
56+
#endif /* USBD_USE_HID_COMPOSITE */
6057
#endif /* USBCON */
6158

62-
#endif /* __USBD_INTERFACE_H */
59+
#endif /* __USBD_HID_COMPOSITE_IF_H */
6360

6461
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

libraries/Keyboard/library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Keyboard
2-
version=1.0.1
2+
version=1.1.0
33
author=Arduino
44
maintainer=Arduino <[email protected]>
55
sentence=Allows an Arduino/Genuino board with USB capabilites to act as a Keyboard.

libraries/Keyboard/src/Keyboard.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "Keyboard.h"
2323

2424
#if defined(USBCON)
25+
#include "usbd_hid_composite_if.h"
2526

2627
//================================================================================
2728
//================================================================================
@@ -33,18 +34,20 @@ Keyboard_::Keyboard_(void)
3334

3435
void Keyboard_::begin(void)
3536
{
37+
HID_Composite_Init();
3638
}
3739

3840
void Keyboard_::end(void)
3941
{
42+
HID_Composite_DeInit();
4043
}
4144

4245
void Keyboard_::sendReport(KeyReport* keys)
4346
{
4447
uint8_t buf[8] = {keys->modifiers, keys->reserved, keys->keys[0], keys->keys[1],
4548
keys->keys[2], keys->keys[3], keys->keys[4], keys->keys[5]};
4649

47-
usbd_interface_keyboard_sendReport(buf, 8);
50+
HID_Composite_keyboard_sendReport(buf, 8);
4851

4952
//delay required to prevent persistent key when call print
5053
delay(20);

libraries/Mouse/library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Mouse
2-
version=1.0.0
2+
version=1.1.0
33
author=Arduino
44
maintainer=Arduino <[email protected]>
55
sentence=Allows an Arduino board with USB capabilites to act as a Mouse. For Leonardo/Micro only

libraries/Mouse/src/Mouse.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "Mouse.h"
2323

2424
#if defined(USBCON)
25+
#include "usbd_hid_composite_if.h"
2526

2627
//================================================================================
2728
//================================================================================
@@ -33,10 +34,12 @@ Mouse_::Mouse_(void) : _buttons(0)
3334

3435
void Mouse_::begin(void)
3536
{
37+
HID_Composite_Init();
3638
}
3739

3840
void Mouse_::end(void)
3941
{
42+
HID_Composite_DeInit();
4043
}
4144

4245
void Mouse_::click(uint8_t b)
@@ -55,7 +58,7 @@ void Mouse_::move(signed char x, signed char y, signed char wheel)
5558
m[2] = y;
5659
m[3] = wheel;
5760

58-
usbd_interface_mouse_sendReport(m, 4);
61+
HID_Composite_mouse_sendReport(m, 4);
5962
}
6063

6164
void Mouse_::buttons(uint8_t b)

0 commit comments

Comments
 (0)