Skip to content

Instantly share code, notes, and snippets.

@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})
@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 / 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)
{
#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 / 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;
}