Files
VesiScan-Basic_Zephyr/src/drivers/imu/imu_i2c.h
T
jh.chun 7cccee7cf2 IMU FIFO 샘플 대기 함수 추가
- 샘플 부족 방지 안전장치
2026-07-15 15:45:08 +09:00

103 lines
2.7 KiB
C

/*******************************************************************************
* @file imu_i2c.h
* @brief ICM42670P IMU 드라이버 (Zephyr I2C API)
*
* 핀 배치:
* SCL: P1.14
* SDA: P1.15
* I2C 주소: 0x68
******************************************************************************/
#ifndef IMU_I2C_H__
#define IMU_I2C_H__
#include <stdint.h>
#include <stdbool.h>
#define IMU_FIFO_SAMPLE_BYTES 12U
#define IMU_FIFO_RIM_TARGET_SAMPLES 15U
/**
* @brief IMU 초기화 — I2C 버스 준비 및 WHOAMI 확인
* @return 0 성공, 음수 에러
*/
int imu_init(void);
/**
* @brief IMU 1회 측정
*
* 센서 설정 → 전원 ON → 80ms 대기 → 12바이트 읽기 → 전원 OFF
*
* @param accel 가속도 XYZ (int16, ±4g, 100Hz)
* @param gyro 자이로 XYZ (int16, ±2000dps, 100Hz)
* @return 0 성공, 음수 에러
*/
int imu_read(int16_t accel[3], int16_t gyro[3]);
/**
* @brief IMU 6축 + 내부 온도 1회 측정
*
* 센서 설정 → 전원 ON → 80ms 대기 → temp/accel/gyro 14바이트 읽기 → 전원 OFF
*
* @param accel 가속도 XYZ
* @param gyro 자이로 XYZ
* @param temp_cdeg 섭씨 x100 출력
* @return 0 성공, 음수 에러
*/
int imu_read_with_temperature(int16_t accel[3], int16_t gyro[3], int16_t *temp_cdeg);
/**
* @brief IMU 내부 온도 1회 측정
*
* TEMP_DATA1/2를 읽어 섭씨 x100 정수로 변환한다.
*
* @param temp_cdeg 섭씨 x100 출력
* @return 0 성공, 음수 에러
*/
int imu_read_temperature_cdeg(int16_t *temp_cdeg);
/**
* @brief IMU FIFO 캡처 시작
*
* Accel/Gyro 50Hz, Low Noise, FIFO stream 모드로 설정하고 FIFO를 비운다.
*
* @return 0 성공, 음수 에러
*/
int imu_fifo_start(void);
/**
* @brief Wait until the running FIFO has at least target_samples records.
*
* @return 0 if the target is reached, -ETIMEDOUT on timeout, or a negative error.
*/
int imu_fifo_wait_samples(uint16_t target_samples, uint32_t timeout_ms);
/**
* @brief 실행 중인 FIFO에서 최신 샘플 읽기
*
* 각 샘플은 accel XYZ 6B + gyro XYZ 6B, 총 12B이다.
* 함수 종료 후에도 FIFO와 accel/gyro는 계속 동작한다.
*
* @param sample_bytes 12B 샘플이 연속 저장될 버퍼
* @param max_samples 버퍼에 담을 최대 샘플 수
* @param out_count 실제 저장한 샘플 수
* @return 0 성공, 음수 에러
*/
int imu_fifo_read_latest(uint8_t *sample_bytes, uint16_t max_samples, uint16_t *out_count);
/**
* @brief Return whether IMU FIFO streaming is active.
*/
bool imu_fifo_is_active(void);
/**
* @brief FIFO와 accel/gyro 전원 끄기
*
* 켜져 있지 않으면 아무 작업 없이 성공 처리한다.
*
* @return 0 성공, 음수 에러
*/
int imu_fifo_stop(void);
#endif /* IMU_I2C_H__ */