mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-17 05:32:55 +08:00
update clear status and get state
This commit is contained in:
parent
6a68fc6997
commit
b4fde90b55
@ -61,6 +61,13 @@ static void dfu_req_getstatus_reply(uint8_t rhport, tusb_control_request_t c
|
|||||||
static void dfu_req_dnload_reply(uint8_t rhport, tusb_control_request_t const * request);
|
static void dfu_req_dnload_reply(uint8_t rhport, tusb_control_request_t const * request);
|
||||||
static bool dfu_state_machine(uint8_t rhport, tusb_control_request_t const * request);
|
static bool dfu_state_machine(uint8_t rhport, tusb_control_request_t const * request);
|
||||||
|
|
||||||
|
static void reset_state(void)
|
||||||
|
{
|
||||||
|
_dfu_ctx.state = DFU_IDLE;
|
||||||
|
_dfu_ctx.status = DFU_STATUS_OK;
|
||||||
|
_dfu_ctx.blk_transfer_in_proc = false;
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// Debug
|
// Debug
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
@ -224,10 +231,7 @@ bool dfu_moded_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_reque
|
|||||||
{
|
{
|
||||||
// Switch Alt interface and Re-initalize state machine
|
// Switch Alt interface and Re-initalize state machine
|
||||||
_dfu_ctx.alt_num = (uint8_t) request->wValue;
|
_dfu_ctx.alt_num = (uint8_t) request->wValue;
|
||||||
_dfu_ctx.state = DFU_IDLE;
|
reset_state();
|
||||||
_dfu_ctx.status = DFU_STATUS_OK;
|
|
||||||
_dfu_ctx.blk_transfer_in_proc = false;
|
|
||||||
|
|
||||||
return tud_control_status(rhport, request);
|
return tud_control_status(rhport, request);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -264,14 +268,26 @@ bool dfu_moded_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_reque
|
|||||||
{
|
{
|
||||||
if (tud_dfu_abort_cb) tud_dfu_abort_cb(_dfu_ctx.alt_num);
|
if (tud_dfu_abort_cb) tud_dfu_abort_cb(_dfu_ctx.alt_num);
|
||||||
|
|
||||||
_dfu_ctx.state = DFU_IDLE;
|
reset_state();
|
||||||
_dfu_ctx.status = DFU_STATUS_OK;
|
|
||||||
_dfu_ctx.blk_transfer_in_proc = false;
|
|
||||||
|
|
||||||
tud_control_status(rhport, request);
|
tud_control_status(rhport, request);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case DFU_REQUEST_CLRSTATUS:
|
||||||
|
if ( stage == CONTROL_STAGE_SETUP )
|
||||||
|
{
|
||||||
|
reset_state();
|
||||||
|
tud_control_status(rhport, request);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DFU_REQUEST_GETSTATE:
|
||||||
|
if ( stage == CONTROL_STAGE_SETUP )
|
||||||
|
{
|
||||||
|
tud_control_xfer(rhport, request, &_dfu_ctx.state, 1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case DFU_REQUEST_UPLOAD:
|
case DFU_REQUEST_UPLOAD:
|
||||||
if ( stage == CONTROL_STAGE_SETUP )
|
if ( stage == CONTROL_STAGE_SETUP )
|
||||||
{
|
{
|
||||||
@ -298,8 +314,7 @@ bool dfu_moded_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_reque
|
|||||||
}
|
}
|
||||||
// fallthrough
|
// fallthrough
|
||||||
case DFU_REQUEST_GETSTATUS:
|
case DFU_REQUEST_GETSTATUS:
|
||||||
case DFU_REQUEST_CLRSTATUS:
|
|
||||||
case DFU_REQUEST_GETSTATE:
|
|
||||||
{
|
{
|
||||||
if(stage == CONTROL_STAGE_SETUP)
|
if(stage == CONTROL_STAGE_SETUP)
|
||||||
{
|
{
|
||||||
@ -339,11 +354,6 @@ static void dfu_req_getstatus_reply(uint8_t rhport, tusb_control_request_t const
|
|||||||
tud_control_xfer(rhport, request, &resp, sizeof(dfu_status_req_payload_t));
|
tud_control_xfer(rhport, request, &resp, sizeof(dfu_status_req_payload_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dfu_req_getstate_reply(uint8_t rhport, tusb_control_request_t const * request)
|
|
||||||
{
|
|
||||||
tud_control_xfer(rhport, request, &_dfu_ctx.state, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void dfu_req_dnload_setup(uint8_t rhport, tusb_control_request_t const * request)
|
static void dfu_req_dnload_setup(uint8_t rhport, tusb_control_request_t const * request)
|
||||||
{
|
{
|
||||||
// TODO: add "zero" copy mode so the buffer we read into can be provided by the user
|
// TODO: add "zero" copy mode so the buffer we read into can be provided by the user
|
||||||
@ -404,10 +414,6 @@ static bool dfu_state_machine(uint8_t rhport, tusb_control_request_t const * req
|
|||||||
dfu_req_getstatus_reply(rhport, request);
|
dfu_req_getstatus_reply(rhport, request);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DFU_REQUEST_GETSTATE:
|
|
||||||
dfu_req_getstate_reply(rhport, request);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
_dfu_ctx.state = DFU_ERROR;
|
_dfu_ctx.state = DFU_ERROR;
|
||||||
return false; // stall on all other requests
|
return false; // stall on all other requests
|
||||||
@ -434,10 +440,6 @@ static bool dfu_state_machine(uint8_t rhport, tusb_control_request_t const * req
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DFU_REQUEST_GETSTATE:
|
|
||||||
dfu_req_getstate_reply(rhport, request);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
_dfu_ctx.state = DFU_ERROR;
|
_dfu_ctx.state = DFU_ERROR;
|
||||||
return false; // stall on all other requests
|
return false; // stall on all other requests
|
||||||
@ -487,10 +489,6 @@ static bool dfu_state_machine(uint8_t rhport, tusb_control_request_t const * req
|
|||||||
dfu_req_getstatus_reply(rhport, request);
|
dfu_req_getstatus_reply(rhport, request);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DFU_REQUEST_GETSTATE:
|
|
||||||
dfu_req_getstate_reply(rhport, request);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
_dfu_ctx.state = DFU_ERROR;
|
_dfu_ctx.state = DFU_ERROR;
|
||||||
return false; // stall on all other requests
|
return false; // stall on all other requests
|
||||||
@ -520,10 +518,6 @@ static bool dfu_state_machine(uint8_t rhport, tusb_control_request_t const * req
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DFU_REQUEST_GETSTATE:
|
|
||||||
dfu_req_getstate_reply(rhport, request);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
_dfu_ctx.state = DFU_ERROR;
|
_dfu_ctx.state = DFU_ERROR;
|
||||||
return false; // stall on all other requests
|
return false; // stall on all other requests
|
||||||
@ -565,10 +559,6 @@ static bool dfu_state_machine(uint8_t rhport, tusb_control_request_t const * req
|
|||||||
dfu_req_getstatus_reply(rhport, request);
|
dfu_req_getstatus_reply(rhport, request);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DFU_REQUEST_GETSTATE:
|
|
||||||
dfu_req_getstate_reply(rhport, request);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return false; // stall on all other requests
|
return false; // stall on all other requests
|
||||||
break;
|
break;
|
||||||
@ -584,14 +574,6 @@ static bool dfu_state_machine(uint8_t rhport, tusb_control_request_t const * req
|
|||||||
dfu_req_getstatus_reply(rhport, request);
|
dfu_req_getstatus_reply(rhport, request);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DFU_REQUEST_CLRSTATUS:
|
|
||||||
_dfu_ctx.state = DFU_IDLE;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DFU_REQUEST_GETSTATE:
|
|
||||||
dfu_req_getstate_reply(rhport, request);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return false; // stall on all other requests
|
return false; // stall on all other requests
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user