Skip to content

Instantly share code, notes, and snippets.

@savent404
savent404 / Euclidean.c
Last active January 29, 2019 02:59
get Maximun common divisor
int Euclidean(int num_1, int num_2) {
int a = num_1 > num_2 ? num_1 : num_2;
int b = num_1 > num_2 ? num_2 : num_1;
int tmp;
while (a % b = tmp) {
a = b;
b = tmp;
}
return b;
}
#include "ADS1115.h"
uint8_t ADS1115_Init(ADS1115_t *ptr)
{
uint16_t buf = 0x8083;
// Pins
buf &= ~(0x03 << 12); //[14:12]
buf |= ptr->Pin << 12;
@savent404
savent404 / INA226.c
Last active October 12, 2020 01:37
STM32 Driver for INA226
#include "INA226.h"
int16_t combi_int16(uint8_t *ptr)
{
return *ptr++ << 8 | *ptr;
}
uint8_t INA226_Reset(INA226_t *ptr)
{
@savent404
savent404 / TCA6424A.c
Last active October 12, 2020 01:37
IIC接口的IO扩展芯片驱动
#include "TCA6424A.h"
/* 7Bit - 0x23 (a0 = 1)
7Bit - 0x22 (a0 = 0)
*/
const uint8_t SlaveAddress = 0x46;
static uint32_t OUTPUT_Reg = 0x00;
/** 底层调用定义 */
@savent404
savent404 / CMakeLists.txt
Created January 9, 2019 16:14 — forked from eugene-babichenko/CMakeLists.txt
CMakeLists.txt and toolchain file for building STM32 HAL-based projects generated with STM32CubeMX with arm-none-eabi-gcc. STM32CubeMX settings. Toolchain: SW4STM32. ☑ Generate under root.
set(PRJ_NAME CLion_STM_LED)
set(MCU_FAMILY STM32F1xx)
set(MCU_LINE STM32F103xB)
set(MCU_LINKER_SCRIPT STM32F103RBTx_FLASH.ld)
cmake_minimum_required(VERSION 3.6)
project(${PRJ_NAME} C ASM)
add_definitions(-D${MCU_LINE})
#!/bin/bash
function use_proxy() {
git config --global http.proxy $1
git config --global https.proxy $1
export http_proxy=$1
export https_proxy=$1
export ftp_proxy=$1
export rsync_proxy=$1
export all_proxy=$1
@savent404
savent404 / circle_buffer.hpp
Last active October 12, 2020 01:32
ring buffer static implement
#pragma once
template <typename T, int N>
struct _CircleBuffer_iterator {
private:
T *_base;
T *_ptr;
static inline size_t _modN_(size_t pos) { return pos % N; }
static inline size_t _iter_pos_(T *ptr, T *base) { return (ptr - base); }
@savent404
savent404 / hwo-to-package-qt-to-appimage.md
Last active June 10, 2021 04:53
hwo-to-package-qt-to-appimage

Install linuxdeployqt

1.method:: just download Appimage file from github

download page.

2.method:: build based qmake

git clone https://github.com/probonopd/linuxdeployqt.git
cd linuxdeployqt
mkdir build &amp;&amp; cd build
@savent404
savent404 / install_zsh.sh
Created October 21, 2023 02:36
Custom zsh and omz install steps
#/bin/sh
# install zsh and oh-my-zsh
sudo apt install -y curl zsh fonts-powerline
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# install powerlevel10k theme
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
# set ZSH_THEME="powerlevel10k/powerlevel10k" in ~/.zshrc.
sed -i 's/^ZSH_THEME=.*/ZSH_THEME="powerlevel10k\/powerlevel10k"/g' ~/.zshrc
@savent404
savent404 / mp_pool_test.cxx
Last active January 24, 2024 07:09
Estimate compiler opt for the mp template pool allocator
#include <cstddef>
#include <cstdint>
#include <type_traits>
template <typename T, T _base, size_t _size>
struct StaticBlock {
static_assert(std::is_pointer<T>::value);
static constexpr void* base = _base;
static constexpr const size_t size = _size;