Skip to content

Commit ea7afdd

Browse files
masz-nordicgalak
authored andcommitted
usb: cdc_acm: SerialState notification full support
Added bBreak, bRingSignal, bFraming, bParity and bOverRun handling in cdc_acm_line_ctrl_set. Reference: Chapter 6.5.4 of Universal Serial Bus Communications Class Subclass Specification for PSTN Devices rev 1.2 Signed-off-by: Marcin Szymczyk <[email protected]>
1 parent 3c82d23 commit ea7afdd

File tree

2 files changed

+54
-6
lines changed

2 files changed

+54
-6
lines changed

include/usb/class/usb_cdc.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,21 @@
7272
#define SET_CONTROL_LINE_STATE_RTS 0x02
7373
#define SET_CONTROL_LINE_STATE_DTR 0x01
7474

75+
/** Enhance enum uart_line_ctrl with CDC specific values */
76+
#define USB_CDC_LINE_CTRL_BAUD_RATE LINE_CTRL_BAUD_RATE
77+
#define USB_CDC_LINE_CTRL_DCD LINE_CTRL_DCD
78+
#define USB_CDC_LINE_CTRL_DSR LINE_CTRL_DSR
79+
#define USB_CDC_LINE_CTRL_BREAK BIT(5)
80+
#define USB_CDC_LINE_CTRL_RING_SIGNAL BIT(6)
81+
#define USB_CDC_LINE_CTRL_FRAMING BIT(7)
82+
#define USB_CDC_LINE_CTRL_PARITY BIT(8)
83+
#define USB_CDC_LINE_CTRL_OVER_RUN BIT(9)
84+
7585
/** UART State Bitmap Values */
76-
#define SERIAL_STATE_OVERRUN 0x40
86+
#define SERIAL_STATE_OVER_RUN 0x40
7787
#define SERIAL_STATE_PARITY 0x20
7888
#define SERIAL_STATE_FRAMING 0x10
79-
#define SERIAL_STATE_RING 0x08
89+
#define SERIAL_STATE_RING_SIGNAL 0x08
8090
#define SERIAL_STATE_BREAK 0x04
8191
#define SERIAL_STATE_TX_CARRIER 0x02
8292
#define SERIAL_STATE_RX_CARRIER 0x01

subsys/usb/class/cdc_acm.c

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -812,25 +812,63 @@ static int cdc_acm_line_ctrl_set(struct device *dev,
812812
struct cdc_acm_dev_data_t * const dev_data = DEV_DATA(dev);
813813

814814
switch (ctrl) {
815-
case LINE_CTRL_BAUD_RATE:
815+
case USB_CDC_LINE_CTRL_BAUD_RATE:
816816
cdc_acm_baudrate_set(dev, val);
817817
return 0;
818-
case LINE_CTRL_DCD:
818+
case USB_CDC_LINE_CTRL_DCD:
819819
dev_data->serial_state &= ~SERIAL_STATE_RX_CARRIER;
820820

821821
if (val) {
822822
dev_data->serial_state |= SERIAL_STATE_RX_CARRIER;
823823
}
824-
825824
cdc_acm_send_notification(dev, SERIAL_STATE_RX_CARRIER);
826825
return 0;
827-
case LINE_CTRL_DSR:
826+
case USB_CDC_LINE_CTRL_DSR:
828827
dev_data->serial_state &= ~SERIAL_STATE_TX_CARRIER;
829828

830829
if (val) {
831830
dev_data->serial_state |= SERIAL_STATE_TX_CARRIER;
832831
}
832+
cdc_acm_send_notification(dev, dev_data->serial_state);
833+
return 0;
834+
case USB_CDC_LINE_CTRL_BREAK:
835+
dev_data->serial_state &= ~SERIAL_STATE_BREAK;
836+
837+
if (val) {
838+
dev_data->serial_state |= SERIAL_STATE_BREAK;
839+
}
840+
cdc_acm_send_notification(dev, dev_data->serial_state);
841+
return 0;
842+
case USB_CDC_LINE_CTRL_RING_SIGNAL:
843+
dev_data->serial_state &= ~SERIAL_STATE_RING_SIGNAL;
844+
845+
if (val) {
846+
dev_data->serial_state |= SERIAL_STATE_RING_SIGNAL;
847+
}
848+
cdc_acm_send_notification(dev, dev_data->serial_state);
849+
return 0;
850+
case USB_CDC_LINE_CTRL_FRAMING:
851+
dev_data->serial_state &= ~SERIAL_STATE_FRAMING;
852+
853+
if (val) {
854+
dev_data->serial_state |= SERIAL_STATE_FRAMING;
855+
}
856+
cdc_acm_send_notification(dev, dev_data->serial_state);
857+
return 0;
858+
case USB_CDC_LINE_CTRL_PARITY:
859+
dev_data->serial_state &= ~SERIAL_STATE_PARITY;
833860

861+
if (val) {
862+
dev_data->serial_state |= SERIAL_STATE_PARITY;
863+
}
864+
cdc_acm_send_notification(dev, dev_data->serial_state);
865+
return 0;
866+
case USB_CDC_LINE_CTRL_OVER_RUN:
867+
dev_data->serial_state &= ~SERIAL_STATE_OVER_RUN;
868+
869+
if (val) {
870+
dev_data->serial_state |= SERIAL_STATE_OVER_RUN;
871+
}
834872
cdc_acm_send_notification(dev, dev_data->serial_state);
835873
return 0;
836874
default:

0 commit comments

Comments
 (0)