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

USB CDC line state#1382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fpistm merged 3 commits intostm32duino:masterfromfpistm:USB_linestate
May 5, 2021
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletionscores/arduino/USBSerial.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,7 +24,8 @@
#include "usbd_desc.h"
#include "wiring.h"

extern __IO uint32_t lineState;
extern __IO bool dtrState;
extern __IO bool rtsState;

USBSerial SerialUSB;
void serialEventUSB() __attribute__((weak));
Expand DownExpand Up@@ -175,24 +176,25 @@ uint8_t USBSerial::numbits()
return 8;
}

void USBSerial::dtr(bool enable)
{
CDC_enableDTR(enable);
}

bool USBSerial::dtr(void)
{
returnfalse;
returndtrState;
}

bool USBSerial::rts(void)
{
returnfalse;
returnrtsState;
}

USBSerial::operator bool()
{
bool result = false;
if (lineState == 1) {
result = true;
}
delay(10);
returnresult;
returndtrState;
}

#endif // USBCON && USBD_USE_CDC
2 changes: 2 additions & 0 deletionscores/arduino/USBSerial.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -51,6 +51,8 @@ class USBSerial : public Stream {
uint8_tstopbits();
uint8_tparitytype();
uint8_tnumbits();

voiddtr(bool enable);
booldtr();
boolrts();
enum {
Expand Down
2 changes: 1 addition & 1 deletioncores/arduino/stm32/usb/cdc/usbd_cdc.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -527,7 +527,7 @@ static uint8_t USBD_CDC_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
}

/**
* @briefUSBD_CDC_Init
* @briefUSBD_CDC_DeInit
* DeInitialize the CDC layer
* @param pdev: device instance
* @param cfgidx: Configuration index
Expand Down
4 changes: 4 additions & 0 deletionscores/arduino/stm32/usb/cdc/usbd_cdc.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -73,6 +73,10 @@ extern "C" {
#defineCDC_SET_CONTROL_LINE_STATE 0x22U
#defineCDC_SEND_BREAK 0x23U

// Control Line State bits
#defineCLS_DTR (1 << 0)
#defineCLS_RTS (1 << 1)

/**
* @}
*/
Expand Down
20 changes: 15 additions & 5 deletionscores/arduino/stm32/usb/cdc/usbd_cdc_if.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -47,11 +47,13 @@
USBD_HandleTypeDef hUSBD_Device_CDC;

static bool CDC_initialized = false;
static bool CDC_DTR_enabled = true;

/* Received Data over USB are stored in this buffer */
CDC_TransmitQueue_TypeDef TransmitQueue;
CDC_ReceiveQueue_TypeDef ReceiveQueue;
__IO uint32_t lineState = 0;
__IO bool dtrState = false; /* lineState */
__IO bool rtsState = false;
__IO bool receivePended = true;
static uint32_t transmitStart = 0;

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

case CDC_SET_CONTROL_LINE_STATE:
lineState =
(((USBD_SetupReqTypedef *)pbuf)->wValue & 0x01) != 0; // Check DTR state
if (lineState) { // Reset the transmit timeout when the port is connected
// Check DTR state
dtrState = (CDC_DTR_enabled) ? (((USBD_SetupReqTypedef *)pbuf)->wValue & CLS_DTR) : true;

if (dtrState) { // Reset the transmit timeout when the port is connected
transmitStart = 0;
}
rtsState = (((USBD_SetupReqTypedef *)pbuf)->wValue & CLS_RTS);
#ifdef DTR_TOGGLING_SEQ
dtr_toggling++; /* Count DTR toggling */
#endif
Expand DownExpand Up@@ -301,7 +305,7 @@ bool CDC_connected()
}
return ((hUSBD_Device_CDC.dev_state == USBD_STATE_CONFIGURED)
&& (transmitTime < USB_CDC_TRANSMIT_TIMEOUT)
&&lineState);
&&dtrState);
}

void CDC_continue_transmit(void)
Expand DownExpand Up@@ -350,6 +354,12 @@ bool CDC_resume_receive(void)
return false;
}

void CDC_enableDTR(bool enable)
{
CDC_DTR_enabled = enable;
dtrState = true;
}

#endif /* USBD_USE_CDC */
#endif /* USBCON */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Expand Down
1 change: 1 addition & 0 deletionscores/arduino/stm32/usb/cdc/usbd_cdc_if.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -51,6 +51,7 @@ bool CDC_resume_receive(void);
voidCDC_init(void);
voidCDC_deInit(void);
boolCDC_connected(void);
voidCDC_enableDTR(boolenable);

#ifdef__cplusplus
}
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp