49 lines
1.1 KiB
C
49 lines
1.1 KiB
C
/*
|
|
* @file utils.h
|
|
* @brief Utility functions and helpers
|
|
*
|
|
* Created: 21.09.2025
|
|
* Author: ThePetrovich
|
|
*
|
|
* Copyright YKSA - Sakha Aerospace Systems, LLC.
|
|
* See the LICENSE file for details.
|
|
*
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
*/
|
|
|
|
#ifndef UTILS_H
|
|
#define UTILS_H
|
|
|
|
#include <stdint.h>
|
|
|
|
/**
|
|
* @brief Calculate CRC16 using XMODEM polynomial
|
|
* @param data Pointer to data buffer
|
|
* @param len Length of data in bytes
|
|
* @return CRC16 checksum
|
|
*/
|
|
uint16_t calculate_crc16_xmodem(uint8_t *data, uint16_t len);
|
|
|
|
/**
|
|
* @brief Convert ADC reading to temperature in 0.1°C
|
|
* @param adc_value 12-bit ADC reading
|
|
* @return Temperature in 0.1°C
|
|
*/
|
|
int16_t adc_to_temperature_c(uint16_t adc_value);
|
|
|
|
/**
|
|
* @brief Convert ADC reading to voltage in mV
|
|
* @param adc_value ADC reading
|
|
* @return Voltage in mV
|
|
*/
|
|
uint16_t adc_to_voltage_mv(uint16_t adc_value);
|
|
|
|
/**
|
|
* @brief Read ADC with oversampling
|
|
* @param pin Analog pin to read
|
|
* @param samples Number of samples for oversampling
|
|
* @return Averaged ADC value
|
|
*/
|
|
uint16_t read_adc_oversampled(uint8_t pin, uint8_t samples);
|
|
|
|
#endif // UTILS_H
|