#include "DFUMode.h" #include #include "stdafx.h" #include #include #include #include "lmdfu.h" #include "lmdfuwrap.h" #include "ProgressMode.h" #include "TwineDFUExtras.h" #pragma once using namespace System; namespace Tango { namespace FirmwareUpdateLib { /// /// Represents the upload operation progress callback delegate. /// /// The progress mode. /// The current. /// The total. public delegate void ProgressCallbackDelegate(ProgressMode progressMode, int current, int total); public ref class DFUDevice { private: unsigned char *lastDownloadBytes; tLMDFUDeviceInfo *devInfo; tLMDFUHandle devHandle; bool _isDisposed; public: /// /// Vendor ID published in the device descriptor. /// property String^ VID; /// /// Product ID published in the device descriptor. /// property String^ PID; /// /// BCD device release number published in the device descriptor. /// property String^ DeviceName; /// /// The manufacturer name string published in the device. /// property String^ Manufacturer; /// /// The interface string published in the DFU interface descriptor. /// property String^ DFUInterface; /// /// The serial number string published in the device descriptor. /// property String^ SerialNumber; /// /// Maximum number of bytes that the device can accept per control-write transaction as published in the DFU functional descriptor. /// property int MaxTransfer; /// /// Determines the current DFU driver mode. (An update can only be applied while in DFU mode). /// property DFUMode Mode; /// /// Indicates that the device will detach and reattach automatically on receipt of the DFU_DETACH request whereas 'false' indicates that the host must issue a USB reset after the DFU_DETACH request. /// property bool WillDetach; /// /// Indicates that the device supports firmware download operations and: 'false' indicates that download is not supported. /// property bool ManifestTolerant; property bool UploadCable; property bool DownloadCable; /// ///Determines whether the DFU device supports the Tiva DFU binary protocol or false otherwise. (If not than AppStartAddress should be provided!). /// property bool SupportsTivaExtensions; /// /// The size of a flash block in bytes. /// property short FlashBlockSize; /// /// The number of blocks of flash in the device. Total flash size is NumFlashBlocks * FlashBlockSize. /// property short NumFlashBlocks; /// /// Address 1 byte above the highest location the boot loader can access. /// property long FlashTopAddress; /// /// Total flash size in bytes. /// property int FlashSize; /// /// Lowest address the boot loader can write or erase. /// property long AppStartAddress; /// /// Image Size. /// property long ImageLength; /// /// Optional Twine information which will be flashed to the top of the memory. /// property TwineDFUExtras^ TwineExtras; /// /// Initializes a new instance of the class. /// DFUDevice(); /// /// Finalizes an instance of the class. /// ~DFUDevice(); /// /// Switch the device to DFU upgrade mode. /// void SwitchToDFUMode(); /// /// Clears the flash. /// void ClearFlash(); /// /// Resets the device. /// void Reset(); /// /// Uploads the specified image bytes to the firmware via the DFU class. /// /// The bytes. /// The progress callback. void Upload(array^ bytes, ProgressCallbackDelegate^ callback); /// /// Uploads the specified twine extras to the top of the flash memory. /// /// The extras. /// The progress callback. void UploadTwineExtras(TwineDFUExtras^ extras, ProgressCallbackDelegate^ callback); /// /// Downloads the existing image bytes from the firmware via the DFU class. /// /// The progress callback. /// void Download(ProgressCallbackDelegate^ callback); /// /// Gets the last download operation bytes. /// /// array^ GetDownloadBytes(); internal: const int EXTENSION_LENGTH = 1024; const int EXTENSION_CODE = 1357; const int EXTENSION_COMMENTS_LENGTH = 992; /// /// Fetches the twine extras. /// void FetchTwineExtras(); /// /// Initializes a new instance of the class. /// /// The device information. /// The device handle. DFUDevice(tLMDFUDeviceInfo *deviceInfo, tLMDFUHandle deviceHandle); }; } }