온도 센서 TMP235 삭제(IMU 온도로 대체)
This commit is contained in:
@@ -1,109 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* @file tmp235.c
|
||||
* @brief TMP235-Q1 온도 센서 드라이버 (Zephyr SAADC, AIN3 = P0.05)
|
||||
*
|
||||
* 배터리 ADC와 동일한 방식 (ADC_DT_SPEC_GET_BY_NAME + adc_read_dt).
|
||||
* 채널 설정은 overlay channel@3에서 관리.
|
||||
*
|
||||
* 변환 공식:
|
||||
* V_mV = raw × 3600 / 4095 (1/6 gain, 0.6V ref, 12-bit)
|
||||
* T(°C × 100) = (V_mV - 500) × 10
|
||||
******************************************************************************/
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/drivers/adc.h>
|
||||
#include <zephyr/devicetree.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "tmp235.h"
|
||||
#include "debug_print.h"
|
||||
|
||||
/*==============================================================================
|
||||
* ADC 디바이스트리 설정
|
||||
*============================================================================*/
|
||||
#define ZEPHYR_USER_NODE DT_PATH(zephyr_user)
|
||||
|
||||
static const struct adc_dt_spec temp_adc =
|
||||
ADC_DT_SPEC_GET_BY_NAME(ZEPHYR_USER_NODE, temperature);
|
||||
|
||||
static int16_t adc_buffer;
|
||||
|
||||
/*==============================================================================
|
||||
* 내부 변환
|
||||
*============================================================================*/
|
||||
|
||||
/**
|
||||
* @brief ADC raw → 온도 (°C × 100)
|
||||
*
|
||||
* V_mV = raw × 3600 / 4095
|
||||
* T_cdeg = (V_mV - 500) × 10
|
||||
*
|
||||
* 정수 연산 (오버플로 없음):
|
||||
* raw 최대 4095 → V_mV 최대 3600 → T_cdeg 최대 31000 → int32 OK
|
||||
*/
|
||||
static int16_t raw_to_cdeg(int16_t raw)
|
||||
{
|
||||
if (raw < 0) {
|
||||
raw = 0;
|
||||
}
|
||||
int32_t v_mv = (int32_t)raw * 3600 / 4095;
|
||||
int32_t t_cdeg = (v_mv - 500) * 10;
|
||||
return (int16_t)t_cdeg;
|
||||
}
|
||||
|
||||
/*==============================================================================
|
||||
* 공개 API
|
||||
*============================================================================*/
|
||||
|
||||
int temp_init(void)
|
||||
{
|
||||
if (!adc_is_ready_dt(&temp_adc)) {
|
||||
DBG_ERR("[TEMP] FAIL — ADC device not ready\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int err = adc_channel_setup_dt(&temp_adc);
|
||||
if (err) {
|
||||
DBG_ERR("[TEMP] FAIL — channel setup (err=%d)\r\n", err);
|
||||
return -2;
|
||||
}
|
||||
|
||||
DBG_PRINTF("[TEMP] OK — TMP235 ch=%d, res=%d, os=%d\r\n",
|
||||
temp_adc.channel_id,
|
||||
temp_adc.resolution,
|
||||
temp_adc.oversampling);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int16_t temp_read_cdeg(void)
|
||||
{
|
||||
/* 매번 채널 재설정 (배터리 ADC와 SAADC 공유) */
|
||||
int err = adc_channel_setup_dt(&temp_adc);
|
||||
if (err) {
|
||||
DBG_ERR("[TEMP] FAIL — channel setup (err=%d)\r\n", err);
|
||||
return INT16_MIN;
|
||||
}
|
||||
|
||||
struct adc_sequence seq = {0};
|
||||
|
||||
err = adc_sequence_init_dt(&temp_adc, &seq);
|
||||
if (err) {
|
||||
DBG_ERR("[TEMP] FAIL — sequence init (err=%d)\r\n", err);
|
||||
return INT16_MIN;
|
||||
}
|
||||
|
||||
seq.buffer = &adc_buffer;
|
||||
seq.buffer_size = sizeof(adc_buffer);
|
||||
|
||||
err = adc_read_dt(&temp_adc, &seq);
|
||||
if (err) {
|
||||
DBG_ERR("[TEMP] FAIL — read (err=%d)\r\n", err);
|
||||
return INT16_MIN;
|
||||
}
|
||||
|
||||
int16_t t = raw_to_cdeg(adc_buffer);
|
||||
|
||||
DBG_PRINTF("[TEMP] raw=%d -> %d.%02d C\r\n",
|
||||
adc_buffer, t / 100, (t < 0 ? -t : t) % 100);
|
||||
|
||||
return t;
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* @file tmp235.h
|
||||
* @brief TMP235-Q1 온도 센서 드라이버 (Zephyr SAADC, AIN3 = P0.05)
|
||||
*
|
||||
* 출력 공식: V = 500mV + 10mV/°C × T
|
||||
* → T(°C) = (V_mV - 500) / 10
|
||||
* → T(°Cx100) = (V_mV - 500) × 10
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef TMP235_H__
|
||||
#define TMP235_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* @brief 온도 센서 초기화 — ADC 채널 설정
|
||||
* @return 0 성공, 음수 에러
|
||||
*/
|
||||
int temp_init(void);
|
||||
|
||||
/**
|
||||
* @brief 온도 1회 측정
|
||||
* @return 온도 (°C × 100), 에러 시 INT16_MIN
|
||||
*/
|
||||
int16_t temp_read_cdeg(void);
|
||||
|
||||
#endif /* TMP235_H__ */
|
||||
@@ -26,7 +26,6 @@
|
||||
#include "battery_adc.h"
|
||||
#include "parser.h"
|
||||
#include "imu_i2c.h"
|
||||
#include "tmp235.h"
|
||||
|
||||
LOG_MODULE_REGISTER(vesiscan, LOG_LEVEL_INF);
|
||||
|
||||
@@ -606,7 +605,6 @@ int main(void)
|
||||
battery_adc_init();
|
||||
battery_timer_init();
|
||||
imu_init();
|
||||
temp_init();
|
||||
piezo_config_init();
|
||||
DBG_CORE(" gpio/timer/config/led/batt/imu/temp/piezo-cfg OK\r\n");
|
||||
|
||||
|
||||
+6
-29
@@ -22,7 +22,6 @@
|
||||
#include "echo_adc.h"
|
||||
#include "imu_i2c.h"
|
||||
#include "piezo.h"
|
||||
#include "tmp235.h"
|
||||
|
||||
/*==============================================================================
|
||||
* Piezo / echo measurement constants
|
||||
@@ -718,46 +717,24 @@ static int cmd_msp(const uint8_t *data, uint8_t data_len)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* mst? → 피에조 전원 ON → TMP235 온도 측정 → 전원 OFF → rso: + 온도(°C × 100, BE)
|
||||
*
|
||||
* TMP235가 피에조 레일을 공유하므로 ON/OFF 시퀀스를 한 커맨드에서 처리.
|
||||
* 안정화 대기 10ms: TMP235 start-up(~2ms) + 레일 RC 필터 여유분.
|
||||
* 에러 응답: 0xFFFF = ADC 읽기 실패 */
|
||||
/* mst? -> IMU internal temperature -> rso: + temperature (degC x 100, BE)
|
||||
* Error response: 0xFFFF = IMU temperature read failed. */
|
||||
static int cmd_mst(const uint8_t *data, uint8_t data_len)
|
||||
{
|
||||
ARG_UNUSED(data);
|
||||
ARG_UNUSED(data_len);
|
||||
|
||||
/*
|
||||
* mst?는 "온도만 읽는 명령"처럼 보이지만,
|
||||
* 실제로는 TMP235가 piezo 전원 레일을 같이 쓰기 때문에
|
||||
* 전원 ON/OFF 시퀀스까지 같이 처리해야 한다.
|
||||
*/
|
||||
power_button_suspend(true);
|
||||
|
||||
if (piezo_init() != 0)
|
||||
{
|
||||
power_button_suspend(false);
|
||||
send_response_u16("rso:", 0xFFFF);
|
||||
DBG_PRINTF("[CMD] mst: piezo init fail\r\n");
|
||||
return 1;
|
||||
}
|
||||
int16_t t_cdeg = INT16_MIN;
|
||||
int ret = imu_read_temperature_cdeg(&t_cdeg);
|
||||
|
||||
/* 전원 ON → 센서 안정화 대기 */
|
||||
piezo_power_on();
|
||||
k_msleep(10);
|
||||
|
||||
int16_t t_cdeg = temp_read_cdeg();
|
||||
|
||||
/* 전원 OFF (측정 완료, 레일 끄기) */
|
||||
piezo_power_off();
|
||||
power_button_suspend(false);
|
||||
|
||||
/* ADC 읽기 실패 → 에러 코드 0xFFFF */
|
||||
if (t_cdeg == INT16_MIN)
|
||||
if ((ret != 0) || (t_cdeg == INT16_MIN))
|
||||
{
|
||||
send_response_u16("rso:", 0xFFFF);
|
||||
DBG_PRINTF("[CMD] mst: temp read fail\r\n");
|
||||
DBG_PRINTF("[CMD] mst: imu temp read fail ret=%d\r\n", ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user