diff options
author | Marti Bolivar <mbolivar@leaflabs.com> | 2012-08-04 01:47:22 -0400 |
---|---|---|
committer | Marti Bolivar <mbolivar@leaflabs.com> | 2012-08-04 01:47:22 -0400 |
commit | c7eeac87ba20fbb7ffd96706c8ff521fe54321c9 (patch) | |
tree | 4817b6bf2ee67382a90aed79071bef37ba46111d /libmaple | |
parent | 4e20db54c8134c5f967f5ca4d9efe0577b920041 (diff) | |
download | librambutan-c7eeac87ba20fbb7ffd96706c8ff521fe54321c9.tar.gz librambutan-c7eeac87ba20fbb7ffd96706c8ff521fe54321c9.zip |
usb_cdcacm: Expose line coding state.
This was already supported, so just move the line coding structure to
the header and add some functions for accessing the current values.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
Diffstat (limited to 'libmaple')
-rw-r--r-- | libmaple/include/libmaple/usb_cdcacm.h | 27 | ||||
-rw-r--r-- | libmaple/usb/stm32f1/usb_cdcacm.c | 50 |
2 files changed, 55 insertions, 22 deletions
diff --git a/libmaple/include/libmaple/usb_cdcacm.h b/libmaple/include/libmaple/usb_cdcacm.h index 5ceecc3..6649854 100644 --- a/libmaple/include/libmaple/usb_cdcacm.h +++ b/libmaple/include/libmaple/usb_cdcacm.h @@ -70,6 +70,33 @@ uint16 usb_cdcacm_get_pending(void); uint8 usb_cdcacm_get_dtr(void); uint8 usb_cdcacm_get_rts(void); +typedef struct usb_cdcacm_line_coding { + uint32 dwDTERate; /* Baud rate */ + +#define USB_CDCACM_STOP_BITS_1 0 +#define USB_CDCACM_STOP_BITS_1_5 1 +#define USB_CDCACM_STOP_BITS_2 2 + uint8 bCharFormat; /* Stop bits */ + +#define USB_CDCACM_PARITY_NONE 0 +#define USB_CDCACM_PARITY_ODD 1 +#define USB_CDCACM_PARITY_EVEN 2 +#define USB_CDCACM_PARITY_MARK 3 +#define USB_CDCACM_PARITY_SPACE 4 + uint8 bParityType; /* Parity type */ + + uint8 bDataBits; /* Data bits: 5, 6, 7, 8, or 16 */ +} __packed usb_cdcacm_line_coding; + +/* Retrieve a copy of the current line coding structure. */ +void usb_cdcacm_get_line_coding(usb_cdcacm_line_coding*); + +/* Line coding conveniences. */ +int usb_cdcacm_get_baud(void); /* dwDTERate */ +int usb_cdcacm_get_stop_bits(void); /* bCharFormat */ +int usb_cdcacm_get_parity(void); /* bParityType */ +int usb_cdcacm_get_n_data_bits(void); /* bDataBits */ + /* * Hack: hooks for bootloader reset signalling */ diff --git a/libmaple/usb/stm32f1/usb_cdcacm.c b/libmaple/usb/stm32f1/usb_cdcacm.c index 2a942e5..f425cb8 100644 --- a/libmaple/usb/stm32f1/usb_cdcacm.c +++ b/libmaple/usb/stm32f1/usb_cdcacm.c @@ -308,29 +308,11 @@ static volatile uint32 n_unread_bytes = 0; /* Other state (line coding, DTR/RTS) */ -typedef struct usb_line_coding { - uint32 dwDTERate; /* Baud rate */ - -#define STOP_BITS_1 0 -#define STOP_BITS_1_5 1 -#define STOP_BITS_2 2 - uint8 bCharFormat; /* Stop bits */ - -#define PARITY_NONE 0 -#define PARITY_ODD 1 -#define PARITY_EVEN 2 -#define PARITY_MARK 3 -#define PARITY_SPACE 4 - uint8 bParityType; /* Parity type */ - - uint8 bDataBits; /* Data bits: 5, 6, 7, 8, or 16 */ -} usb_line_coding; - -static volatile usb_line_coding line_coding = { +static volatile usb_cdcacm_line_coding line_coding = { /* This default is 115200 baud, 8N1. */ .dwDTERate = 115200, - .bCharFormat = STOP_BITS_1, - .bParityType = PARITY_NONE, + .bCharFormat = USB_CDCACM_STOP_BITS_1, + .bParityType = USB_CDCACM_PARITY_NONE, .bDataBits = 8, }; @@ -526,6 +508,30 @@ uint8 usb_cdcacm_get_rts() { return ((line_dtr_rts & USB_CDCACM_CONTROL_LINE_RTS) != 0); } +void usb_cdcacm_get_line_coding(usb_cdcacm_line_coding *ret) { + ret->dwDTERate = line_coding.dwDTERate; + ret->bCharFormat = line_coding.bCharFormat; + ret->bParityType = line_coding.bParityType; + ret->bDataBits = line_coding.bDataBits; +} + +int usb_cdcacm_get_baud(void) { + return line_coding.dwDTERate; +} + +int usb_cdcacm_get_stop_bits(void) { + return line_coding.bCharFormat; +} + +int usb_cdcacm_get_parity(void) { + return line_coding.bParityType; +} + +int usb_cdcacm_get_n_data_bits(void) { + return line_coding.bDataBits; +} + + /* * Callbacks */ @@ -555,7 +561,7 @@ static void vcomDataRxCb(void) { static uint8* vcomGetSetLineCoding(uint16 length) { if (length == 0) { - pInformation->Ctrl_Info.Usb_wLength = sizeof(struct usb_line_coding); + pInformation->Ctrl_Info.Usb_wLength = sizeof(struct usb_cdcacm_line_coding); } return (uint8*)&line_coding; } |