This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* simple doubly linked list imlementation */ | |
template<typename T> | |
class list { | |
public: | |
inline T* pfront() noexcept { return head ? &head->data : nullptr; } | |
inline T* pback() noexcept { return tail ? &tail->data : nullptr; } | |
template<typename ... Args> | |
inline T* construct(Args ... __args) noexcept { | |
return &append(new item(__args ...))->data; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** zero-dependency allocation-free mapping enum values to names */ | |
namespace enumnames { | |
typedef const char* (*name)(); | |
bool match(const char*, const char*) noexcept; /* to be provided by the user */ | |
template<typename T, T K, name V> | |
struct tuple { | |
typedef T key_t; | |
static constexpr T key = K; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** assign - assigns a value to all array elements | |
* usage: short arr[77]; assign(arr,88); | |
* License: MIT */ | |
template<typename T, size_t N, typename V> | |
static inline void assign(T (&a)[N], V v) noexcept { | |
for(size_t i=0; i<N; ++i) a[i] = v; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* container_of, inspired by AndrewTsao */ | |
template <class T, typename M> | |
constexpr T* container_of(M *m, const M T::*p) noexcept { | |
return reinterpret_cast<T*>(reinterpret_cast<char*>(m) | |
- reinterpret_cast<const ptrdiff_t>( | |
&(static_cast<const T *>(nullptr)->*p))); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//libusb+ch340 data transfer demo | |
//gcc usb.c `pkg-config libusb-1.0 --libs --cflags` -o usb | |
#include <errno.h> | |
#include <signal.h> | |
#include <string.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <stdint.h> | |
#include <unistd.h> | |
#include <sys/select.h> |
NewerOlder