Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcf6ba78

Browse files
authored
Merge pull request#1382 from fpistm/USB_linestate
USB CDC line state
2 parents7ce7ab8 +843fce7 commitcf6ba78

File tree

6 files changed

+33
-14
lines changed

6 files changed

+33
-14
lines changed

‎cores/arduino/USBSerial.cpp‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
#include"usbd_desc.h"
2525
#include"wiring.h"
2626

27-
extern __IOuint32_t lineState;
27+
extern __IObool dtrState;
28+
extern __IObool rtsState;
2829

2930
USBSerial SerialUSB;
3031
voidserialEventUSB() __attribute__((weak));
@@ -175,24 +176,25 @@ uint8_t USBSerial::numbits()
175176
return8;
176177
}
177178

179+
voidUSBSerial::dtr(bool enable)
180+
{
181+
CDC_enableDTR(enable);
182+
}
183+
178184
boolUSBSerial::dtr(void)
179185
{
180-
returnfalse;
186+
returndtrState;
181187
}
182188

183189
boolUSBSerial::rts(void)
184190
{
185-
returnfalse;
191+
returnrtsState;
186192
}
187193

188194
USBSerial::operatorbool()
189195
{
190-
bool result =false;
191-
if (lineState ==1) {
192-
result =true;
193-
}
194196
delay(10);
195-
returnresult;
197+
returndtrState;
196198
}
197199

198200
#endif// USBCON && USBD_USE_CDC

‎cores/arduino/USBSerial.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class USBSerial : public Stream {
5151
uint8_tstopbits();
5252
uint8_tparitytype();
5353
uint8_tnumbits();
54+
55+
voiddtr(bool enable);
5456
booldtr();
5557
boolrts();
5658
enum {

‎cores/arduino/stm32/usb/cdc/usbd_cdc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ static uint8_t USBD_CDC_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
527527
}
528528

529529
/**
530-
* @briefUSBD_CDC_Init
530+
* @briefUSBD_CDC_DeInit
531531
* DeInitialize the CDC layer
532532
* @param pdev: device instance
533533
* @param cfgidx: Configuration index

‎cores/arduino/stm32/usb/cdc/usbd_cdc.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ extern "C" {
7373
#defineCDC_SET_CONTROL_LINE_STATE 0x22U
7474
#defineCDC_SEND_BREAK 0x23U
7575

76+
// Control Line State bits
77+
#defineCLS_DTR (1 << 0)
78+
#defineCLS_RTS (1 << 1)
79+
7680
/**
7781
* @}
7882
*/

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,13 @@
4747
USBD_HandleTypeDefhUSBD_Device_CDC;
4848

4949
staticboolCDC_initialized= false;
50+
staticboolCDC_DTR_enabled= true;
5051

5152
/* Received Data over USB are stored in this buffer */
5253
CDC_TransmitQueue_TypeDefTransmitQueue;
5354
CDC_ReceiveQueue_TypeDefReceiveQueue;
54-
__IOuint32_tlineState=0;
55+
__IObooldtrState= false;/* lineState */
56+
__IOboolrtsState= false;
5557
__IOboolreceivePended= true;
5658
staticuint32_ttransmitStart=0;
5759

@@ -183,11 +185,13 @@ static int8_t USBD_CDC_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length)
183185
break;
184186

185187
caseCDC_SET_CONTROL_LINE_STATE:
186-
lineState=
187-
(((USBD_SetupReqTypedef*)pbuf)->wValue&0x01)!=0;// Check DTR state
188-
if (lineState) {// Reset the transmit timeout when the port is connected
188+
// Check DTR state
189+
dtrState= (CDC_DTR_enabled) ? (((USBD_SetupReqTypedef*)pbuf)->wValue&CLS_DTR) : true;
190+
191+
if (dtrState) {// Reset the transmit timeout when the port is connected
189192
transmitStart=0;
190193
}
194+
rtsState= (((USBD_SetupReqTypedef*)pbuf)->wValue&CLS_RTS);
191195
#ifdefDTR_TOGGLING_SEQ
192196
dtr_toggling++;/* Count DTR toggling */
193197
#endif
@@ -301,7 +305,7 @@ bool CDC_connected()
301305
}
302306
return ((hUSBD_Device_CDC.dev_state==USBD_STATE_CONFIGURED)
303307
&& (transmitTime<USB_CDC_TRANSMIT_TIMEOUT)
304-
&&lineState);
308+
&&dtrState);
305309
}
306310

307311
voidCDC_continue_transmit(void)
@@ -350,6 +354,12 @@ bool CDC_resume_receive(void)
350354
return false;
351355
}
352356

357+
voidCDC_enableDTR(boolenable)
358+
{
359+
CDC_DTR_enabled=enable;
360+
dtrState= true;
361+
}
362+
353363
#endif/* USBD_USE_CDC */
354364
#endif/* USBCON */
355365
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

‎cores/arduino/stm32/usb/cdc/usbd_cdc_if.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ bool CDC_resume_receive(void);
5151
voidCDC_init(void);
5252
voidCDC_deInit(void);
5353
boolCDC_connected(void);
54+
voidCDC_enableDTR(boolenable);
5455

5556
#ifdef__cplusplus
5657
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp