Skip to content

Instantly share code, notes, and snippets.

View hidsh's full-sized avatar

yakshaver hidsh

View GitHub Profile
@hidsh
hidsh / variadic_macro.c
Created August 17, 2025 08:36 — forked from otaon/variadic_macro.c
C言語 - gccで可変長引数マクロを使用する方法
// gccでは...で表した可変長引数を__VA_ARGS__で指定できる
// 可変長引数を全て__VA_ARGS__とマップする
#define DEBUG_PRINT(...) printf(__VA_ARGS__); fflush(stdout)
// fmt以降の可変長引数を__VA_ARGS__とマップする
#define DEBUG_PRINT2(fmt, ...) printf(fmt, __VA_ARGS__); fflush(stdout)
// _1,_2,_3,の部分・・・引数の個数だけ用意する
// NAME・・・この部分に、目的の引数個数用の関数名が入る
#define GET_MACRO(_1,_2,_3,NAME,...) NAME
@hidsh
hidsh / CMakeLists.txt
Created August 16, 2025 06:57
zephyr button w/ "dynamic" pinctrl example for xiao_ble (seeed xiao nrf52840)
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(button)
target_sources(app PRIVATE src/main.c src/remap.c)
@hidsh
hidsh / read_bit_field.c
Created August 15, 2025 05:44
c example to use `FIELD_GET()` macro from zephyr
#include <stdint.h>
#include <stdio.h>
// zephyr-latest/zephyr-proj/zephyr/include/zephyr/sys/util_macro.h
/** @brief Extract the Least Significant Bit from @p value. */
#define LSB_GET(value) ((value) & -(value))
/**
* @brief Extract a bitfield element from @p value corresponding to
@hidsh
hidsh / custom.conf
Created August 13, 2025 15:43
zephyr button w/ "static" pinctrl example for xiao_ble (seeed xiao nrf52840)
# zephyr/samples/basic/button/boards/custom.conf
#
# "static" pinctrl to use external-uart breakout (AE-FT2232 / FTDI FT2232D) as /dev/ttyUSB0
# this file is to switch USB-CDC-ACM (/dev/ttyACM0) --> external uart (/dev/ttyUSB0)
# disable USB CDC ACM
CONFIG_USB_DEVICE_STACK=n
CONFIG_USB_DEVICE_STACK_NEXT=n
CONFIG_BOARD_SERIAL_BACKEND_CDC_ACM=n
@hidsh
hidsh / xiao_ble.overlay
Created August 12, 2025 15:29
zephyr button example for xiao_ble (seeed xiao nrf52840)
// zephyr/samples/basic/button/boards/xiao_ble.overlay
//
// adopt from zephyr/boards/nordic/nrf52dk/nrf52dk_nrf52810.dts
/{
buttons {
compatible = "gpio-keys";
button0: button_0 {
label = "Push button switch 0";
@hidsh
hidsh / main.c
Created August 7, 2025 10:49
An Arduino-style "Blinky" patching to ZMK firmware (zmk-firmware/zmk/app/src/main.c)
/*
* Copyright (c) 2020 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/
#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#include <zephyr/settings/settings.h>
@hidsh
hidsh / inline_func.c
Created July 30, 2025 11:12
c example for inline functions
#include <stdio.h>
int fun(int x) { return x * 10; }
// inline int fun_inline(int x) { return x * 100; } // --> causes undefined reference
extern inline int fun_inline(int x) { return x * 100; } // ok
// static inline int fun_inline(int x) { return x * 1000; } // ok, but this .c file local
int main(void) {
printf("%d, %d\n", fun(2), fun_inline(2));
@hidsh
hidsh / define-override-function-inline.c
Created July 30, 2025 10:49
c example to override functions using `#define` macros for inline functions
#include <stdio.h>
int fun0(void) { return 5; }
int fun1(int x) { return x * 10; }
// inline int fun1_inline(int x) { return x * 100; } // => undefined reference
extern inline int fun1_inline_extern(int x) { return x * 100; }
static inline int fun1_inline_static(int x) { return x * 1000; }
#define OVERRIDE 1
@hidsh
hidsh / define-override-function
Last active July 30, 2025 00:22
c example to override functions using `#define` macros
#include <stdio.h>
int fun0(void) { return 5; }
int fun1(int x) { return x * 2; }
#define OVERRIDE 1
#if OVERRIDE == 1
#define fun0() (9)
#define fun1(x) (99)
@hidsh
hidsh / myfilter.py
Last active July 20, 2025 03:41
A trivial python script to follow the `tail`ing logs such as `dmesg -w`
#!/usr/bin/env python3
#
# Example usage:
# dmesg -w | myfilter.py -x foo bar baz
#
import sys
import re
import argparse