Skip to content

Instantly share code, notes, and snippets.

@kuro68k
kuro68k / gist:f207221265553e8789d235bf55a1af74
Created July 22, 2022 13:58
Windows/Linux portable touch shell script
:<<BATCH
@echo off
@cd ..\src
@copy /b version.c +,, >NUL
exit /b
BATCH
touch src/version.c
@kuro68k
kuro68k / gist:8b0e38efe15603ed630e66a77dbe70b4
Last active August 3, 2022 11:47
Date and time (timestamp) strings with the C preprocessor
// build.c
//
// Build timestamp and time derived build number strings
#define MONTH_CH0 (\
__DATE__ [2] == 't' ? '1' \
: __DATE__ [2] == 'v' ? '1' \
: __DATE__ [2] == 'c' ? '1' \
: '0')
// DST dates
// EU, from year 2000, start day in March, end day in October, at 01:00.
uint8_t eu_dst_dates[] = {
26, 29, // 2000
25, 28,
31, 27,
30, 26,
28, 31,
27, 30,
@kuro68k
kuro68k / iso_8601.c
Created March 28, 2018 10:22
Format __DATE__ and __TIME__ to ISO 8601
#include <stdio.h>
#define MONTH0 ( __DATE__ [2] == 'n' ? (__DATE__ [1] == 'a' ? '0' : '0') \
: __DATE__ [2] == 'b' ? 2 \
: __DATE__ [2] == 'r' ? (__DATE__ [0] == 'M' ? '0' : '0') \
: __DATE__ [2] == 'y' ? '0' \
: __DATE__ [2] == 'l' ? '0' \
: __DATE__ [2] == 'g' ? '0' \
: __DATE__ [2] == 'p' ? '0' \
: __DATE__ [2] == 't' ? '1' \
HID descriptor locations:
src\ASF\common\services\usb\class\hid\device\generic\udi_hid_generic.c - contains 'udi_hid_generic_report_desc'
src\ASF\common\services\usb\class\hid\device\generic\udi_hid_generic.h - contains 'udi_hid_generic_report_desc_t'
To handle feature requests, add this to conf_usb.h:
#define UDI_HID_GENERIC_GET_FEATURE(payload, size) HID_get_feature_report_out(payload, size)
@kuro68k
kuro68k / MS USB extended descriptors in ASF
Last active November 5, 2021 01:30
Add Microsoft WCID descriptors to Atmel's ASF USB stack
To add MS USB extended descriptors to an ASF project:
0. Optionally disable disabling peripheral clocks in common/services/clock/xmega/sysclk.c -> sysclk_init()
1. Configure clocks and oscillators in config/conf_board.h:
// required for the ASF clock module
#define BOARD_XOSC_HZ F_CPU
#define BOARD_XOSC_STARTUP_US 1024
@kuro68k
kuro68k / xmega_crc.c
Created October 19, 2015 10:35
XMEGA NVM flash memory CRC compatible implementation in C
/**************************************************************************************************
* XMEGA NVM compatible CRC32
*/
#define XMEGA_CRC32_POLY 0x0080001B // Polynomial for use with Xmega devices
uint32_t xmega_nvm_crc32(uint8_t *buffer, uint32_t buffer_length)
{
uint32_t address;
uint32_t data_reg, help_a, help_b;
uint32_t crc_reg = 0;
@kuro68k
kuro68k / crc32.c
Created October 19, 2015 10:34
CRC32 in C
// crc.cpp
#include <stdint.h>
#include <stdlib.h>
#include "crc.h"
/**************************************************************************************************
* Reverse bits in a uint32
*/