146 lines
3.9 KiB
C
146 lines
3.9 KiB
C
/*
|
|
* Copyright (c) 2024 PM
|
|
*
|
|
* using code from Melexis https://github.com/melexis/mlx90640-library,
|
|
* commit f6be7ca1d4a55146b705f3d347f84b773b29cc86 under Apache-2.0
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#ifndef ZEPHYR_DRIVERS_SENSOR_MLX90640_MLX90640_H_
|
|
#define ZEPHYR_DRIVERS_SENSOR_MLX90640_MLX90640_H_
|
|
|
|
#include <zephyr/device.h>
|
|
#include <zephyr/drivers/gpio.h>
|
|
#include <zephyr/drivers/i2c.h>
|
|
#include <zephyr/sys/util.h>
|
|
|
|
typedef struct
|
|
{
|
|
int16_t kVdd;
|
|
int16_t vdd25;
|
|
float KvPTAT;
|
|
float KtPTAT;
|
|
uint16_t vPTAT25;
|
|
float alphaPTAT;
|
|
int16_t gainEE;
|
|
float tgc;
|
|
float cpKv;
|
|
float cpKta;
|
|
uint8_t resolutionEE;
|
|
uint8_t calibrationModeEE;
|
|
float KsTa;
|
|
float ksTo[5];
|
|
int16_t ct[5];
|
|
uint16_t alpha[768];
|
|
uint8_t alphaScale;
|
|
int16_t offset[768];
|
|
int8_t kta[768];
|
|
uint8_t ktaScale;
|
|
int8_t kv[768];
|
|
uint8_t kvScale;
|
|
float cpAlpha[2];
|
|
int16_t cpOffset[2];
|
|
float ilChessC[3];
|
|
uint16_t brokenPixels[5];
|
|
uint16_t outlierPixels[5];
|
|
} mlx90640_params;
|
|
|
|
enum mlx90640_refresh_rate
|
|
{
|
|
MLX90640_REFRESH_0_5 = 0,
|
|
MLX90640_REFRESH_1 = 1,
|
|
MLX90640_REFRESH_2 = 2,
|
|
MLX90640_REFRESH_4 = 3,
|
|
MLX90640_REFRESH_8 = 4,
|
|
MLX90640_REFRESH_16 = 5,
|
|
MLX90640_REFRESH_32 = 6,
|
|
MLX90640_REFRESH_64 = 7,
|
|
};
|
|
|
|
enum mlx90640_adc_resolution
|
|
{
|
|
MLX90640_ADC_RES_16 = 0,
|
|
MLX90640_ADC_RES_17 = 1,
|
|
MLX90640_ADC_RES_18 = 2,
|
|
MLX90640_ADC_RES_19 = 3,
|
|
};
|
|
|
|
enum mlx90640_reading_pattern
|
|
{
|
|
MLX90640_PATTERN_INTERLEAVED = 0,
|
|
MLX90640_PATTERN_CHESS = 1,
|
|
};
|
|
|
|
struct mlx90640_config
|
|
{
|
|
const struct i2c_dt_spec i2c;
|
|
const enum mlx90640_refresh_rate refresh_rate;
|
|
const enum mlx90640_adc_resolution adc_resolution;
|
|
const enum mlx90640_reading_pattern reading_pattern;
|
|
};
|
|
|
|
struct mlx90640_data
|
|
{
|
|
float temps[768];
|
|
float vdd;
|
|
float ta;
|
|
uint16_t raw_data[833]; // 768 px + 64 metadata + 1 status
|
|
mlx90640_params params;
|
|
|
|
#ifdef CONFIG_MLX90640_TRIGGER
|
|
const struct device *dev;
|
|
struct gpio_callback gpio_cb;
|
|
|
|
sensor_trigger_handler_t drdy_handler;
|
|
const struct sensor_trigger *drdy_trigger;
|
|
|
|
sensor_trigger_handler_t th_handler;
|
|
const struct sensor_trigger *th_trigger;
|
|
|
|
#if defined(CONFIG_MLX90640_TRIGGER_OWN_THREAD)
|
|
K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_MLX90640_THREAD_STACK_SIZE);
|
|
struct k_sem gpio_sem;
|
|
struct k_thread thread;
|
|
#elif defined(CONFIG_MLX90640_TRIGGER_GLOBAL_THREAD)
|
|
struct k_work work;
|
|
#endif
|
|
|
|
#endif /* CONFIG_MLX90640_TRIGGER */
|
|
};
|
|
|
|
#ifdef CONFIG_MLX90640_TRIGGER
|
|
int mlx90640_attr_set(const struct device *dev, enum sensor_channel chan, enum sensor_attribute attr,
|
|
const struct sensor_value *val);
|
|
|
|
int mlx90640_trigger_set(const struct device *dev, const struct sensor_trigger *trig, sensor_trigger_handler_t handler);
|
|
|
|
int mlx90640_init_interrupt(const struct device *dev);
|
|
#endif /* CONFIG_MLX90640_TRIGGER */
|
|
|
|
// data
|
|
int mlx90640_synch_frame(const struct device *dev);
|
|
int mlx90640_trigger_measurement(const struct device *dev);
|
|
int mlx90640_get_frame_data(const struct device *dev);
|
|
|
|
// process
|
|
float mlx90640_get_vdd(const struct device *dev);
|
|
float mlx90640_get_ta(const struct device *dev);
|
|
|
|
// void mlx90640_get_image(const struct device *dev);
|
|
// or!
|
|
void mlx90640_calculate_to(const struct device *dev, float emissivity, float tr);
|
|
|
|
// optional /
|
|
void mlx90640_bad_pixels_correction(const struct device *dev, int mode);
|
|
|
|
int mlx90640_set_adc_resolution(const struct device *dev, enum mlx90640_adc_resolution res);
|
|
enum mlx90640_adc_resolution mlx90640_get_adc_resolution(const struct device *dev);
|
|
|
|
int mlx90640_set_refresh_rate(const struct device *dev, enum mlx90640_refresh_rate res);
|
|
enum mlx90640_refresh_rate mlx90640_get_refresh_rate(const struct device *dev);
|
|
|
|
int mlx90640_set_reading_pattern(const struct device *dev, enum mlx90640_reading_pattern res);
|
|
enum mlx90640_reading_pattern mlx90640_get_reading_pattern(const struct device *dev);
|
|
|
|
#endif
|