#ifndef __LTC2640_H__
#define __LTC2640_H__

#ifdef __cplusplus
 extern "C" {
#endif

#include "stm32f4xx.h"

#define LTC2640_PIN_CLR (GPIO_Pin_7)
#define LTC2640_PIN_CS  (GPIO_Pin_15)
#define LTC2640_PIN_SCK (GPIO_Pin_3)
#define LTC2640_PIN_SDI (GPIO_Pin_5)

#define LTC2640_OUTPUT_LEN (3)

#define VOLTAGE_200MV  (328)
#define VOLTAGE_300MV  (492)
#define VOLTAGE_400MV  (655)
#define VOLTAGE_2000MV (3277)
#define VOLTAGE_2400MV (3932)
#define VOLTAGE_2500MV (4095)

struct data_ltc2640_s {
    uint32_t sig_low;
    uint32_t sig_high;
    uint32_t ref_low;
    uint32_t ref_high;
    uint16_t temperature_low;
    uint16_t temperature_high;
    int32_t reading_neg_threshold;
    int32_t reading_range;
    int32_t reading_range_high;
};

extern uint8_t data_ltc2640_output[LTC2640_OUTPUT_LEN];

extern uint32_t system_tick_cnt;

void ltc2640_calc_sig_ref(uint8_t ch, uint32_t temperature, uint32_t *sig, uint32_t *ref);
void ltc2640_data_init(void);
int32_t ltc2640_data_process(void);
void ltc2640_init(void);
void ltc2640_send_data(uint16_t data);
void ltc2640_loop(void);

#ifdef __cplusplus
}
#endif

#endif /* __LTC2640_H__ */
