Skip to content

Commit c685ebb

Browse files
committed
usb_cdc: Change callback return values to allow error return
Require a return value from: CDC_SET_COMM_FEATURE_CALLBACK() CDC_CLEAR_COMM_FEATURE_CALLBACK() CDC_SET_LINE_CODING_CALLBACK() This allows the application to return -1 so a STALL can be sent to the host.
1 parent 8d40043 commit c685ebb

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed

apps/cdc_acm/main.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,18 +280,18 @@ int16_t app_get_encapsulated_response(uint8_t interface,
280280
return -1;
281281
}
282282

283-
void app_set_comm_feature_callback(uint8_t interface,
283+
int8_t app_set_comm_feature_callback(uint8_t interface,
284284
bool idle_setting,
285285
bool data_multiplexed_state)
286286
{
287-
287+
return -1;
288288
}
289289

290-
void app_clear_comm_feature_callback(uint8_t interface,
290+
int8_t app_clear_comm_feature_callback(uint8_t interface,
291291
bool idle_setting,
292292
bool data_multiplexed_state)
293293
{
294-
294+
return -1;
295295
}
296296

297297
int8_t app_get_comm_feature_callback(uint8_t interface,
@@ -301,10 +301,10 @@ int8_t app_get_comm_feature_callback(uint8_t interface,
301301
return -1;
302302
}
303303

304-
void app_set_line_coding_callback(uint8_t interface,
304+
int8_t app_set_line_coding_callback(uint8_t interface,
305305
const struct cdc_line_coding *coding)
306306
{
307-
307+
return -1;
308308
}
309309

310310
int8_t app_get_line_coding_callback(uint8_t interface,

usb/include/usb_cdc.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,12 @@ extern int16_t CDC_GET_ENCAPSULATED_RESPONSE_CALLBACK(uint8_t interface,
356356
* the idle setting.
357357
* @param data_multiplexed_state Whether to set the data multiplexed
358358
* state. True = clear the multiplexed state.
359+
*
360+
* @returns
361+
* Return 0 if the request can be handled or -1 if it cannot. Returning -1
362+
* will cause STALL to be returned to the host.
359363
*/
360-
extern void CDC_SET_COMM_FEATURE_CALLBACK(uint8_t interface,
364+
extern int8_t CDC_SET_COMM_FEATURE_CALLBACK(uint8_t interface,
361365
bool idle_setting,
362366
bool data_multiplexed_state);
363367
#endif
@@ -376,10 +380,14 @@ extern void CDC_SET_COMM_FEATURE_CALLBACK(uint8_t interface,
376380
* the idle setting.
377381
* @param data_multiplexed_state Whether to clear the data multiplexed
378382
* state. True = clear the multiplexed state.
383+
*
384+
* @returns
385+
* Return 0 if the request can be handled or -1 if it cannot. Returning -1
386+
* will cause STALL to be returned to the host.
379387
*/
380-
extern void CDC_CLEAR_COMM_FEATURE_CALLBACK(uint8_t interface,
381-
bool idle_setting,
382-
bool data_multiplexed_state);
388+
extern int8_t CDC_CLEAR_COMM_FEATURE_CALLBACK(uint8_t interface,
389+
bool idle_setting,
390+
bool data_multiplexed_state);
383391
#endif
384392

385393
#ifdef CDC_GET_COMM_FEATURE_CALLBACK
@@ -416,8 +424,11 @@ extern int8_t CDC_GET_COMM_FEATURE_CALLBACK(
416424
* @param interface The interface for which the command is intended
417425
* @param coding The new line coding set by the host
418426
*
427+
* @returns
428+
* Return 0 if the request can be handled or -1 if it cannot. Returning -1
429+
* will cause STALL to be returned to the host.
419430
*/
420-
extern void CDC_SET_LINE_CODING_CALLBACK(uint8_t interface,
431+
extern int8_t CDC_SET_LINE_CODING_CALLBACK(uint8_t interface,
421432
const struct cdc_line_coding *coding);
422433
#endif
423434

usb/src/usb_cdc.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ static int8_t set_or_clear_comm_feature_callback(bool transfer_ok, void *context
9292
bool data_multiplexed_state = (transfer_data.comm_feature & 2) != 0;
9393

9494
if (set_or_clear_request == CDC_SET_COMM_FEATURE) {
95-
CDC_SET_COMM_FEATURE_CALLBACK(transfer_interface,
96-
idle_setting,
97-
data_multiplexed_state);
95+
return CDC_SET_COMM_FEATURE_CALLBACK(transfer_interface,
96+
idle_setting,
97+
data_multiplexed_state);
9898
}
9999
else {
100100
/* request == CDC_CLEAR_COMM_FEATURE */
101-
CDC_CLEAR_COMM_FEATURE_CALLBACK(transfer_interface,
102-
idle_setting,
103-
data_multiplexed_state);
101+
return CDC_CLEAR_COMM_FEATURE_CALLBACK(transfer_interface,
102+
idle_setting,
103+
data_multiplexed_state);
104104
}
105105
return 0;
106106
}
@@ -111,9 +111,8 @@ static int8_t set_line_coding(bool transfer_ok, void *context) {
111111
if (!transfer_ok)
112112
return -1;
113113

114-
CDC_SET_LINE_CODING_CALLBACK(transfer_interface,
115-
&transfer_data.line_coding);
116-
return 0;
114+
return CDC_SET_LINE_CODING_CALLBACK(transfer_interface,
115+
&transfer_data.line_coding);
117116
}
118117
#endif
119118

0 commit comments

Comments
 (0)