Libraries/USB/src/USB/DFU/Device.h
Go to the documentation of this file.
1 /****
2  * DFU/Device.h
3  *
4  * Copyright 2023 mikee47 <mike@sillyhouse.net>
5  *
6  * This file is part of the Sming USB Library
7  *
8  * This library is free software: you can redistribute it and/or modify it under the terms of the
9  * GNU General Public License as published by the Free Software Foundation, version 3 or later.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along with this library.
16  * If not, see <https://www.gnu.org/licenses/>.
17  *
18  ****/
19 
20 #pragma once
21 
22 #include "../DeviceInterface.h"
23 
24 namespace USB::DFU
25 {
29 class Callbacks
30 {
31 public:
32  using Alternate = DfuAlternateId;
33 
40  virtual uint32_t getTimeout(Alternate alt, dfu_state_t state) = 0;
41 
48  virtual void download(Alternate alt, uint32_t offset, const void* data, uint16_t length) = 0;
49 
56  virtual void manifest(Alternate alt) = 0;
57 
62  virtual uint16_t upload(Alternate alt, uint32_t offset, void* data, uint16_t length) = 0;
63 
67  virtual void abort(Alternate alt) = 0;
68 
72  virtual void detach() = 0;
73 };
74 
75 class Device : public DeviceInterface
76 {
77 public:
78  Device(uint8_t inst, const char* name);
79 
80  static void begin(Callbacks& callbacks);
81 
87  static void complete(dfu_status_t status)
88  {
89  tud_dfu_finish_flashing(status);
90  }
91 };
92 
93 } // namespace USB::DFU
Applications must implement this class and pass an instance to Device::begin().
Definition: Libraries/USB/src/USB/DFU/Device.h:30
virtual void abort(Alternate alt)=0
Invoked when the Host has terminated a download or upload transfer.
virtual uint32_t getTimeout(Alternate alt, dfu_state_t state)=0
Invoked right before tud_dfu_download_cb() (state=DFU_DNBUSY) or tud_dfu_manifest_cb() (state=DFU_MAN...
virtual void detach()=0
Invoked when a DFU_DETACH request is received.
virtual void download(Alternate alt, uint32_t offset, const void *data, uint16_t length)=0
Invoked when received DFU_DNLOAD (wLength>0) following by DFU_GETSTATUS (state=DFU_DNBUSY) requests.
virtual void manifest(Alternate alt)=0
Invoked when download process is complete, received DFU_DNLOAD (wLength=0) following by DFU_GETSTATUS...
virtual uint16_t upload(Alternate alt, uint32_t offset, void *data, uint16_t length)=0
Invoked when received DFU_UPLOAD request Application must populate data with up to length bytes and r...
DfuAlternateId Alternate
Definition: Libraries/USB/src/USB/DFU/Device.h:32
Definition: Libraries/USB/src/USB/DFU/Device.h:76
static void begin(Callbacks &callbacks)
static void complete(dfu_status_t status)
Applications call this method from download and manifest callbacks.
Definition: Libraries/USB/src/USB/DFU/Device.h:87
Device(uint8_t inst, const char *name)
Base class to support a USB device interface implementation.
Definition: DeviceInterface.h:30
uint8_t inst
Definition: DeviceInterface.h:47
const char * name
Definition: DeviceInterface.h:48
Definition: Libraries/USB/src/USB/DFU/Device.h:25