On Fri, Feb 5, 2021 at 9:51 AM Xiaofan Chen <xiaof...@gmail.com> wrote: > > On Thu, Dec 10, 2020 at 3:46 AM Shawn Hoffman <godisgovernm...@gmail.com> > wrote: > > > > I've made some minor changes to libftdi to allow building with msvc > > (cmake/ninja/msvc and the ms crt for example). During this, I noticed > > that the cmake files of libftdi seem to be quite outdated. Would a > > patch updating cmake files to use more modern features (and therefore > > require a higher cmake version) be acceptable? Is there a specific > > cmake version libftdi is trying to maintain compatibility with? > > > > fwiw, the minimum code change required for msvc support is just > > implementing gettimeofday() as a wrapper around the C-standard > > timespec_get(). Unfortunately libftdi exposes `struct timeval` in it's > > API as part of `FTDIProgressInfo`, so it probably doesn't make sense > > to just migrate all uses of gettimeofday to timespec_get. > > > > Additionally, the "deprecated #define" can be implemented as e.g. > > #pragma deprecated("SIO_RESET_PURGE_RX") > > for msvc. > > This would be a nice addition. > > One possibility is to create a github repo fork and then send the patch info > to the mailing list. > http://developer.intra2net.com/mailarchive/html/libftdi/2021/msg00000.html > https://github.com/planetmarshall/libftdi/tree/modernize_cmake > > Or you can just send the patch series to the mailing list.
Just wondering if there are any updates on this topic. So far I can see that the most promising msvc patches are here: https://github.com/planetmarshall/libftdi/tree/msvc_support But if it is to build ftdi1.dll, then indeed the following patch is enough. >From here: https://github.com/svitalij/libftdi/blob/MSVC/src/ftdi_stream.c diff --git a/src/ftdi_stream.c b/src/ftdi_stream.c index f5f1287..4fa87d1 100644 --- a/src/ftdi_stream.c +++ b/src/ftdi_stream.c @@ -49,6 +49,62 @@ #include "ftdi.h" +#ifndef HAVE_GETTIMEOFDAY +#ifdef _WIN32 + +#include < time.h > +#include <windows.h> + +#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) +#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64 +#else +#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL +#endif + +struct timezone +{ + int tz_minuteswest; /* minutes W of Greenwich */ + int tz_dsttime; /* type of dst correction */ +}; + +int gettimeofday(struct timeval* tv, struct timezone* tz) +{ + FILETIME ft; + unsigned __int64 tmpres = 0; + static int tzflag; + + if (NULL != tv) + { + GetSystemTimeAsFileTime(&ft); + + tmpres |= ft.dwHighDateTime; + tmpres <<= 32; + tmpres |= ft.dwLowDateTime; + + /*converting file time to unix epoch*/ + tmpres -= DELTA_EPOCH_IN_MICROSECS; + tmpres /= 10; /*convert into microseconds*/ + tv->tv_sec = (long)(tmpres / 1000000UL); + tv->tv_usec = (long)(tmpres % 1000000UL); + } + + if (NULL != tz) + { + if (!tzflag) + { + _tzset(); + tzflag++; + } + tz->tz_minuteswest = _timezone / 60; + tz->tz_dsttime = _daylight; + } + + return 0; +} +#endif // _WIN32 +#endif // HAVE_GETTIMEOFDAY + + typedef struct { FTDIStreamCallback *callback; -- Xiaofan -- libftdi - see http://www.intra2net.com/en/developer/libftdi for details. To unsubscribe send a mail to libftdi+unsubscr...@developer.intra2net.com