This repository was archived by the owner on Sep 3, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathState.cs
More file actions
49 lines (47 loc) · 2.36 KB
/
State.cs
File metadata and controls
49 lines (47 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
namespace DeviceProgramming.Dfu
{
public enum State : byte
{
AppIdle = 0, /// Device is running its normal application.
AppDetach = 1, /// Device is running its normal application, has received the DFU_DETACH request,
/// and is waiting for a USB reset.
Idle = 2, /// Device is waiting for requests in DFU mode.
DnloadSync = 3, /// Device has received a block and is waiting for the host to solicit the status via DFU_GETSTATUS.
DnloadBusy = 4, /// Device is programming a control-write block into its non-volatile memories.
DnloadIdle = 5, /// Device is processing a download operation.
ManifestSync = 6, /// Device has received the final block of firmware from the host
/// and is waiting for receipt of DFU_GETSTATUS to begin the Manifestation phase;
/// or device has completed the Manifestation phase and is waiting for receipt of DFU_GETSTATUS.
Manifest = 7, /// Device is in the Manifestation phase.
ManifestWaitReset = 8, /// Device has programmed its memories and is waiting for a USB reset or a power on reset.
UploadIdle = 9, /// The device is processing an upload operation.
Error = 10, /// An error has occurred.
}
public static class StateMethods
{
/// <summary>
/// Determines if the state permits executing an Abort command.
/// </summary>
/// <param name="state"></param>
/// <returns></returns>
public static bool Abortable(this State state)
{
// nothing is aborted when already in idle
return //(state == State.Idle) ||
(state == State.DnloadSync) ||
(state == State.DnloadIdle) ||
(state == State.ManifestSync) ||
(state == State.UploadIdle);
}
/// <summary>
/// Determines if the state is an Application state, i.e. the device needs reconfiguration
/// before any other DFU operation can be performed.
/// </summary>
/// <param name="state"></param>
/// <returns></returns>
public static bool IsAppState(this State state)
{
return (state < State.Idle);
}
}
}