Skip to content

Commit d32759c

Browse files
committed
usbd(cdc): add support for line break
and add a callback to it
1 parent 62f20b8 commit d32759c

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

micropython/usbd/cdc.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ def __init__(self, _):
8686
self.stop_bits = 0
8787
self.parity = 0
8888
self.data_bits = None
89+
self.break_cb = None # callback for break condition
90+
8991
self.line_coding_state = bytearray(7)
9092

9193
def get_itf_descriptor(self, num_eps, itf_idx, str_idx):
@@ -157,6 +159,10 @@ def handle_interface_control_xfer(self, stage, request):
157159
self.dtr = bool(wValue & 0x1)
158160
self.rts = bool(wValue & 0x2)
159161
return b""
162+
elif bRequest == _SEND_BREAK_REQ:
163+
if self.break_cb:
164+
self.break_cb(wValue)
165+
return b""
160166

161167
if stage == STAGE_DATA:
162168
if req_type == REQ_TYPE_CLASS:
@@ -167,6 +173,11 @@ def handle_interface_control_xfer(self, stage, request):
167173
'<LBBB', self.line_coding_state)
168174
return True
169175

176+
def set_break_cb(self, cb):
177+
# sets a callback for the break condition
178+
# callback must have one parameter (duration in msec)
179+
self.break_cb = cb
180+
170181
def get_control_line(self):
171182
return self.dtr, self.rts
172183

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy