Files
car_stm32f103vet6/Core/Bsp/bsp_track_ir.h

50 lines
1.4 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#ifndef __BSP_TRACK_IR_H
#define __BSP_TRACK_IR_H
#include "main.h"
/*
* 红外循迹 4 路状态位定义bit=1 表示检测到黑线)
* bit0 -> H1, bit1 -> H2, bit2 -> H3, bit3 -> H4
*/
#define TRACK_IR_H1_BIT (1U << 0)
#define TRACK_IR_H2_BIT (1U << 1)
#define TRACK_IR_H3_BIT (1U << 2)
#define TRACK_IR_H4_BIT (1U << 3)
/*
* 红外模块有效电平:常见 TCRT5000 模块为低电平有效。
* 若你的模块是高电平有效,可在编译选项或此处改为 GPIO_PIN_SET。
*/
#ifndef TRACK_IR_ACTIVE_LEVEL
#define TRACK_IR_ACTIVE_LEVEL GPIO_PIN_RESET
#endif
/**
* @brief 基础循迹判定结果
*/
typedef enum {
TRACK_IR_STATE_LOST = 0, // 全灭,丢线
TRACK_IR_STATE_LEFT, // 线偏左
TRACK_IR_STATE_CENTER, // 居中
TRACK_IR_STATE_RIGHT, // 线偏右
TRACK_IR_STATE_CROSS // 十字/大面积黑线
} track_ir_state_t;
/* 初始化接口当前仅预留GPIO 配置由 CubeMX 负责) */
void track_ir_init(void);
/* 读取原始电平状态bit=1 表示 GPIO 为高电平) */
uint8_t track_ir_get_raw_mask(void);
/* 读取线状态掩码bit=1 表示对应通道检测到黑线) */
uint8_t track_ir_get_line_mask(void);
/* 最基础方向判定:丢线 / 左偏 / 居中 / 右偏 / 十字 */
track_ir_state_t track_ir_basic_judge(void);
/* 便于日志输出的状态字符串 */
const char *track_ir_state_to_string(track_ir_state_t state);
#endif /* __BSP_TRACK_IR_H */