Skip to content

Commit 79cffa0

Browse files
committed
cc2531: USB CDC-ACM code style fixes
Closes #18
1 parent be93f1a commit 79cffa0

File tree

2 files changed

+43
-48
lines changed

2 files changed

+43
-48
lines changed

Diff for: cpu/cc253x/usb/common/cdc-acm/cdc-acm.c

+38-38
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313

1414
static uint8_t usb_ctrl_data_buffer[32];
1515

16-
static struct usb_cdc_line_coding usb_line_coding = {9600, 0x00, 0x00, 0x08}; // 9600 baud, 8N1
16+
static struct usb_cdc_line_coding usb_line_coding = { 9600, 0x00, 0x00, 0x08 }; // 9600 baud, 8N1
1717
static uint8_t line_state;
1818
static uint8_t events;
19-
static struct process * cdc_event_process = NULL;
19+
static struct process *cdc_event_process = NULL;
2020

2121
static void
2222
notify_user(uint8_t e)
@@ -36,18 +36,20 @@ encapsulated_command(uint8_t *data, unsigned int length)
3636
static void
3737
set_line_encoding(uint8_t *data, unsigned int length)
3838
{
39-
if (length == 7) {
39+
if(length == 7) {
4040
#ifdef DEBUG
41-
static const char parity_char[] = {'N', 'O', 'E', 'M', 'S'};
42-
static const char *stop_bits_str[] = {"1","1.5","2"};
41+
static const char parity_char[] = { 'N', 'O', 'E', 'M', 'S' };
42+
static const char *stop_bits_str[] = { "1", "1.5", "2" };
4343
const struct usb_cdc_line_coding *coding =
4444
(const struct usb_cdc_line_coding *)usb_ctrl_data_buffer;
4545
char parity = ((coding->bParityType > 4)
46-
? '?' : parity_char[coding->bParityType]);
46+
? '?' : parity_char[coding->bParityType]);
47+
4748
const char *stop_bits = ((coding->bCharFormat > 2)
48-
? "?" : stop_bits_str[coding->bCharFormat]);
49+
? "?" : stop_bits_str[coding->bCharFormat]);
50+
4951
PRINTF("Got CDC line coding: %ld/%d/%c/%s\n",
50-
coding->dwDTERate, coding->bDataBits, parity, stop_bits);
52+
coding->dwDTERate, coding->bDataBits, parity, stop_bits);
5153
#endif
5254
memcpy(&usb_line_coding, data, sizeof(usb_line_coding));
5355
notify_user(USB_CDC_ACM_LINE_CODING);
@@ -60,12 +62,14 @@ set_line_encoding(uint8_t *data, unsigned int length)
6062
static unsigned int
6163
handle_cdc_acm_requests()
6264
{
63-
PRINTF("CDC request %02x %02x\n", usb_setup_buffer.bmRequestType, usb_setup_buffer.bRequest);
64-
switch(usb_setup_buffer.bmRequestType) {
65+
PRINTF("CDC request %02x %02x\n", usb_setup_buffer.bmRequestType,
66+
usb_setup_buffer.bRequest);
67+
switch (usb_setup_buffer.bmRequestType) {
6568
case 0x21: /* CDC interface OUT requests */
6669
/* Check if it's the right interface */
67-
if (usb_setup_buffer.wIndex != 0) return 0;
68-
switch(usb_setup_buffer.bRequest) {
70+
if(usb_setup_buffer.wIndex != 0)
71+
return 0;
72+
switch (usb_setup_buffer.bRequest) {
6973
case SET_CONTROL_LINE_STATE:
7074
line_state = usb_setup_buffer.wValue;
7175
notify_user(USB_CDC_ACM_LINE_STATE);
@@ -74,54 +78,51 @@ handle_cdc_acm_requests()
7478

7579
case SEND_ENCAPSULATED_COMMAND:
7680
{
77-
unsigned int len = usb_setup_buffer.wLength;
78-
if (len > sizeof(usb_ctrl_data_buffer))
79-
len = sizeof(usb_ctrl_data_buffer);
80-
usb_get_ctrl_data(usb_ctrl_data_buffer, len,
81-
encapsulated_command);
81+
unsigned int len = usb_setup_buffer.wLength;
82+
if(len > sizeof(usb_ctrl_data_buffer))
83+
len = sizeof(usb_ctrl_data_buffer);
84+
usb_get_ctrl_data(usb_ctrl_data_buffer, len, encapsulated_command);
8285
}
8386

8487
return 1;
8588

8689

8790
case SET_LINE_CODING:
8891
{
89-
unsigned int len = usb_setup_buffer.wLength;
90-
if (len > sizeof(usb_ctrl_data_buffer))
91-
len = sizeof(usb_ctrl_data_buffer);
92-
usb_get_ctrl_data(usb_ctrl_data_buffer, len,
93-
set_line_encoding);
92+
unsigned int len = usb_setup_buffer.wLength;
93+
if(len > sizeof(usb_ctrl_data_buffer))
94+
len = sizeof(usb_ctrl_data_buffer);
95+
usb_get_ctrl_data(usb_ctrl_data_buffer, len, set_line_encoding);
9496
}
9597
return 1;
9698
}
9799
break;
98-
case 0xa1: /* CDC interface IN requests */
99-
if (usb_setup_buffer.wIndex != 0) return 0;
100-
switch(usb_setup_buffer.bRequest) {
100+
case 0xa1: /* CDC interface IN requests */
101+
if(usb_setup_buffer.wIndex != 0)
102+
return 0;
103+
switch (usb_setup_buffer.bRequest) {
101104
case GET_ENCAPSULATED_RESPONSE:
102105
PRINTF("CDC response");
103106
usb_send_ctrl_status();
104107
return 1;
105108
case GET_LINE_CODING:
106-
usb_send_ctrl_response((uint8_t *) &usb_line_coding, 7);
109+
usb_send_ctrl_response((uint8_t *) & usb_line_coding, 7);
107110
return 1;
108111
}
109112
}
110113
return 0;
111114
}
112115

113-
static const struct USBRequestHandler cdc_acm_request_handler =
114-
{
115-
0x21, 0x7f,
116-
0x00, 0x00,
117-
handle_cdc_acm_requests
118-
};
116+
static const struct USBRequestHandler cdc_acm_request_handler = {
117+
0x21, 0x7f,
118+
0x00, 0x00,
119+
handle_cdc_acm_requests
120+
};
119121

120-
static struct USBRequestHandlerHook cdc_acm_request_hook =
121-
{
122-
NULL,
123-
&cdc_acm_request_handler
124-
};
122+
static struct USBRequestHandlerHook cdc_acm_request_hook = {
123+
NULL,
124+
&cdc_acm_request_handler
125+
};
125126

126127
void
127128
usb_cdc_acm_setup()
@@ -154,4 +155,3 @@ usb_cdc_acm_set_event_process(struct process *p)
154155
{
155156
cdc_event_process = p;
156157
}
157-

Diff for: cpu/cc253x/usb/common/cdc-acm/cdc-acm.h

+5-10
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,21 @@
44
#include "cdc.h"
55
#include "contiki.h"
66

7-
void
8-
usb_cdc_acm_setup();
7+
void usb_cdc_acm_setup();
98

109

1110
#define USB_CDC_ACM_LINE_CODING 0x1
1211
#define USB_CDC_ACM_LINE_STATE 0x2
13-
uint8_t
14-
usb_cdc_acm_get_events(void);
12+
uint8_t usb_cdc_acm_get_events(void);
1513

1614

1715
#define USB_CDC_ACM_DTE 0x1
1816
#define USB_CDC_ACM_RTS 0x2
19-
uint8_t
20-
usb_cdc_acm_get_line_state(void);
17+
uint8_t usb_cdc_acm_get_line_state(void);
2118

2219

23-
const struct usb_cdc_line_coding *
24-
usb_cdc_acm_get_line_coding(void);
20+
const struct usb_cdc_line_coding *usb_cdc_acm_get_line_coding(void);
2521

26-
void
27-
usb_cdc_acm_set_event_process(struct process *p);
22+
void usb_cdc_acm_set_event_process(struct process *p);
2823

2924
#endif /* __CDC_ACM_H__UFV6K50827__ */

0 commit comments

Comments
 (0)