Skip to content

Commit 58fa8b6

Browse files
BennehBoyfpistm
authored andcommitted
Add DTR toggling sequence support
Enabled thanks: DTR_TOGGLING_SEQ User can redefine its own hook by redefining: dtr_togglingHook(uint8_t *buf, uint32_t *len) Signed-off-by: BennehBoy <bennyboy@benneh.net>
1 parent 3bdd8e3 commit 58fa8b6

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

cores/arduino/hooks.c

+20
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1717
*/
1818

19+
#include <stdint.h>
20+
1921
/**
2022
* Empty yield() hook.
2123
*
@@ -30,3 +32,21 @@ static void __empty()
3032
// Empty
3133
}
3234
void yield(void) __attribute__((weak, alias("__empty")));
35+
36+
#ifdef DTR_TOGGLING_SEQ
37+
/**
38+
* Empty dtr_toggling() hook.
39+
*
40+
* This function is intended to be used by library writers to build
41+
* libraries or sketches that require DTR toggling feature.
42+
*
43+
* Its defined as a weak symbol and it can be redefined to implement
44+
* task to achieve in this case.
45+
*/
46+
static void __empty_dtr_toggling(uint8_t *buf, uint32_t *len)
47+
{
48+
(void)buf;
49+
(void)len;
50+
}
51+
void dtr_togglingHook(uint8_t *buf, uint32_t *len) __attribute__((weak, alias("__empty_dtr_toggling")));
52+
#endif

cores/arduino/stm32/usb/cdc/usbd_cdc_if.c

+15
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ __IO uint32_t lineState = 0;
5454
__IO bool receivePended = true;
5555
static uint32_t transmitStart = 0;
5656

57+
#ifdef DTR_TOGGLING_SEQ
58+
/* DTR toggling sequence management */
59+
extern void dtr_togglingHook(uint8_t *buf, uint32_t *len);
60+
uint8_t dtr_toggling = 0;
61+
#endif
5762

5863
/** USBD_CDC Private Function Prototypes */
5964

@@ -182,6 +187,9 @@ static int8_t USBD_CDC_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length)
182187
if (lineState) { // Reset the transmit timeout when the port is connected
183188
transmitStart = 0;
184189
}
190+
#ifdef DTR_TOGGLING_SEQ
191+
dtr_toggling++; /* Count DTR toggling */
192+
#endif
185193
break;
186194

187195
case CDC_SEND_BREAK:
@@ -213,7 +221,14 @@ static int8_t USBD_CDC_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length)
213221
*/
214222
static int8_t USBD_CDC_Receive(uint8_t *Buf, uint32_t *Len)
215223
{
224+
#ifdef DTR_TOGGLING_SEQ
225+
if (dtr_toggling > 3) {
226+
dtr_togglingHook(Buf, Len);
227+
dtr_toggling = 0;
228+
}
229+
#else
216230
UNUSED(Buf);
231+
#endif
217232
/* It always contains required amount of free space for writing */
218233
CDC_ReceiveQueue_CommitBlock(&ReceiveQueue, (uint16_t)(*Len));
219234
receivePended = false;

0 commit comments

Comments
 (0)