Skip to content

Instantly share code, notes, and snippets.

@andelf
andelf / font.py
Created January 16, 2021 05:32
CJK Font for Rust embedded-graphics
from PIL import Image, ImageDraw, ImageFont
import PIL.features
# ! brew install libraqm
print('libraqm:', PIL.features.check('raqm'))
size = (320, 16)
"""
FORMAT = "RGB"
@andelf
andelf / STM32_HID_Bootloader.diff
Created January 12, 2021 13:12
STM32_HID_Bootloader path for a STM32F407VGT board
diff --git a/bootloader/F4/Inc/main.h b/bootloader/F4/Inc/main.h
index a095644..e57185f 100644
--- a/bootloader/F4/Inc/main.h
+++ b/bootloader/F4/Inc/main.h
@@ -95,11 +95,11 @@
-#define BOOT_1_PIN GPIO_PIN_15 //DIYMROE STM32F407VGT board (Button PD15, LED PE0)
-#define BOOT_1_PORT GPIOD
@andelf
andelf / crop-blue30.py
Last active April 12, 2024 12:56
Generate Chinese font for waveshare-epd
from PIL import Image, ImageDraw, ImageFont, ImageFilter
im = Image.open("./blue30.png")
POS = (1, 4)
X = POS[0] * 80
Y = POS[1] * 80
im1 = im.crop((X, Y, X + 30, Y + 30))
@andelf
andelf / bmp085.rs
Created November 27, 2020 18:07
BMP085 Rust embedded-hal-driver
use embedded_hal::blocking::delay::DelayMs;
use embedded_hal::blocking::i2c::{Write, WriteRead};
// BMP085 default address.
const BMP085_I2CADDR: u8 = 0x77;
// Operating Modes
pub const BMP085_ULTRALOWPOWER: u8 = 0;
pub const BMP085_STANDARD: u8 = 1;
pub const BMP085_HIGHRES: u8 = 2;
@andelf
andelf / calculate_pll_register_value.rs
Created November 11, 2020 09:14
calculate_pll_register_value for k210
// nrx, nfx, no, nb
// clkr, clkf, clkod, bwad
#[allow(warnings)]
fn calculate_pll_register_value(freq_in: u32, freq_out: u32) -> Option<(u8, u8, u8, u8)> {
/* constants */
const vco_min: f64 = 3.5e+08;
const vco_max: f64 = 1.75e+09;
const ref_min: f64 = 1.36719e+07;
const ref_max: f64 = 1.75e+09;
const nr_min: i32 = 1;
@andelf
andelf / main.rs
Created November 7, 2020 10:40
Non-alloc string formatter for embedded Rust
use core::fmt::{self, Write};
use core::str;
fn main() {
// For LCD 160 / 8 = 20 chars
let mut buf = [0u8; 20];
let mut buf = ByteMutWriter::new(&mut buf[..]);
buf.clear();
write!(&mut buf, "Hello {}!", "Rust").unwrap();
@andelf
andelf / test.html
Created October 23, 2020 10:18
trezor-connect test
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Trezor Test</title>
<meta name="description" content="The HTML5 Herald">
<meta name="author" content="SitePoint">
@andelf
andelf / java-tron.conf
Created September 20, 2020 16:27
java-tron config
# The Java-Tron Configuration File
log.level = {
root = "INFO" # TRACE;DEBUG;INFO;WARN;ERROR
}
## The Chain
net {
# option: [ mainnet | testnet ]
@andelf
andelf / poc.sol
Created August 28, 2020 23:31
Bug
// Store.sol
pragma solidity >0.5.9;
contract Store {
uint256 internal value;
// 5247 energy
function reset() external {
value = 0;
@andelf
andelf / Microsoft.PowerShell_profile.ps1
Last active July 21, 2020 13:57
Powershell with vcvars64.bat
Import-Module 'C:\Users\mono\Repos\vcpkg\scripts\posh-vcpkg'
Set-PSReadLineOption -EditMode Emacs
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete
# Environment variables
$Env:Path = "C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem"
# $Env:Path += ";C:\Windows\System32\WindowsPowerShell\v1.0\"