Skip to content

Commit 0b95590

Browse files
committed
Add default value protection for line coding parameters in serial Host classes
Add preprocessor guards to allow customization of default line coding parameters. Summary of Changes: - Wrapped default line coding constants (RATE, STOP_BIT, PARITY, DATA_BIT) with #ifndef guards in CDC ACM, GSER, and Prolific host class headers - This allows users to define custom default values before including these headers in (ux_user.h) - Updated Prolific activation code to use DEFAULT constants instead of hardcoded values for consistency and better maintainability Files Modified: - common/usbx_host_classes/inc/ux_host_class_cdc_acm.h - common/usbx_host_classes/inc/ux_host_class_gser.h - common/usbx_host_classes/inc/ux_host_class_prolific.h - common/usbx_host_classes/src/ux_host_class_prolific_activate.c
1 parent 6dc0cf2 commit 0b95590

4 files changed

Lines changed: 39 additions & 2 deletions

File tree

common/usbx_host_classes/inc/ux_host_class_cdc_acm.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,21 @@ extern "C" {
135135

136136
/* Define CDC ACM default values. */
137137

138+
#ifndef UX_HOST_CLASS_CDC_ACM_LINE_CODING_DEFAULT_RATE
138139
#define UX_HOST_CLASS_CDC_ACM_LINE_CODING_DEFAULT_RATE 9600
140+
#endif
141+
142+
#ifndef UX_HOST_CLASS_CDC_ACM_LINE_CODING_DEFAULT_STOP_BIT
139143
#define UX_HOST_CLASS_CDC_ACM_LINE_CODING_DEFAULT_STOP_BIT 0
144+
#endif
145+
146+
#ifndef UX_HOST_CLASS_CDC_ACM_LINE_CODING_DEFAULT_PARITY
140147
#define UX_HOST_CLASS_CDC_ACM_LINE_CODING_DEFAULT_PARITY 0
148+
#endif
149+
150+
#ifndef UX_HOST_CLASS_CDC_ACM_LINE_CODING_DEFAULT_DATA_BIT
141151
#define UX_HOST_CLASS_CDC_ACM_LINE_CODING_DEFAULT_DATA_BIT 8
152+
#endif
142153

143154
/* Define CDC ACM line coding definitions. */
144155

common/usbx_host_classes/inc/ux_host_class_gser.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,21 @@ extern "C" {
115115

116116
/* Define CDC ACM default values. */
117117

118+
#ifndef UX_HOST_CLASS_GSER_LINE_CODING_DEFAULT_RATE
118119
#define UX_HOST_CLASS_GSER_LINE_CODING_DEFAULT_RATE 9600
120+
#endif
121+
122+
#ifndef UX_HOST_CLASS_GSER_LINE_CODING_DEFAULT_STOP_BIT
123+
#define UX_HOST_CLASS_GSER_LINE_CODING_DEFAULT_STOP_BIT 0
124+
#endif
125+
126+
#ifndef UX_HOST_CLASS_GSER_LINE_CODING_DEFAULT_PARITY
127+
#define UX_HOST_CLASS_GSER_LINE_CODING_DEFAULT_PARITY 0
128+
#endif
129+
130+
#ifndef UX_HOST_CLASS_GSER_LINE_CODING_DEFAULT_DATA_BIT
119131
#define UX_HOST_CLASS_GSER_LINE_CODING_DEFAULT_DATA_BIT 8
132+
#endif
120133

121134
/* Define CDC ACM line coding definitions. */
122135

common/usbx_host_classes/inc/ux_host_class_prolific.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,21 @@ extern "C" {
144144

145145
/* Define PROLIFIC default values. */
146146

147+
#ifndef UX_HOST_CLASS_PROLIFIC_LINE_CODING_DEFAULT_RATE
147148
#define UX_HOST_CLASS_PROLIFIC_LINE_CODING_DEFAULT_RATE 19200
149+
#endif
150+
151+
#ifndef UX_HOST_CLASS_PROLIFIC_LINE_CODING_DEFAULT_STOP_BIT
152+
#define UX_HOST_CLASS_PROLIFIC_LINE_CODING_DEFAULT_STOP_BIT 0
153+
#endif
154+
155+
#ifndef UX_HOST_CLASS_PROLIFIC_LINE_CODING_DEFAULT_PARITY
156+
#define UX_HOST_CLASS_PROLIFIC_LINE_CODING_DEFAULT_PARITY 0
157+
#endif
158+
159+
#ifndef UX_HOST_CLASS_PROLIFIC_LINE_CODING_DEFAULT_DATA_BIT
148160
#define UX_HOST_CLASS_PROLIFIC_LINE_CODING_DEFAULT_DATA_BIT 8
161+
#endif
149162

150163
/* Define PROLIFIC line coding definitions. */
151164

common/usbx_host_classes/src/ux_host_class_prolific_activate.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ UINT status;
125125
if (status == UX_SUCCESS)
126126
{
127127
line_coding.ux_host_class_prolific_line_coding_dter = UX_HOST_CLASS_PROLIFIC_LINE_CODING_DEFAULT_RATE;
128-
line_coding.ux_host_class_prolific_line_coding_stop_bit = UX_HOST_CLASS_PROLIFIC_LINE_CODING_STOP_BIT_0;
129-
line_coding.ux_host_class_prolific_line_coding_parity = UX_HOST_CLASS_PROLIFIC_LINE_CODING_PARITY_NONE;
128+
line_coding.ux_host_class_prolific_line_coding_stop_bit = UX_HOST_CLASS_PROLIFIC_LINE_CODING_DEFAULT_STOP_BIT;
129+
line_coding.ux_host_class_prolific_line_coding_parity = UX_HOST_CLASS_PROLIFIC_LINE_CODING_DEFAULT_PARITY;
130130
line_coding.ux_host_class_prolific_line_coding_data_bits = UX_HOST_CLASS_PROLIFIC_LINE_CODING_DEFAULT_DATA_BIT;
131131
status = _ux_host_class_prolific_ioctl(prolific, UX_HOST_CLASS_PROLIFIC_IOCTL_SET_LINE_CODING, (VOID *) &line_coding);
132132
}

0 commit comments

Comments
 (0)