44 lines
839 B
C
44 lines
839 B
C
#pragma once
|
|
|
|
#ifndef LIDAR_H
|
|
#define LIDAR_H
|
|
|
|
#include "stm32g431xx.h"
|
|
|
|
#define USART3_START_BYTE 0x59
|
|
#define USART3_FRAME_SIZE 9
|
|
#define LIDAR_MIN_DIST 0.01f
|
|
#define LIDAR_MAX_DIST 40.0f
|
|
#define TF02_I2C_ADDR 0x10
|
|
|
|
typedef struct
|
|
{
|
|
uint8_t header1; // 0x59
|
|
uint8_t header2; // 0x59
|
|
uint8_t distance_l; // cm
|
|
uint8_t distance_h; // cm
|
|
uint8_t strength_l;
|
|
uint8_t strength_h;
|
|
uint8_t temp_l;
|
|
uint8_t temp_h;
|
|
uint8_t checksum;
|
|
} lidar_data_buf;
|
|
|
|
typedef struct
|
|
{
|
|
uint16_t distance; // meters
|
|
uint16_t strength;
|
|
uint16_t temperature;
|
|
} lidar_data;
|
|
|
|
void lidar_init();
|
|
void USART3_IRQHandler();
|
|
void lidar_update(lidar_data* lidar);
|
|
|
|
void lidar_i2c2_init();
|
|
static void i2c2_wait_txis();
|
|
static void i2c2_wait_stop();
|
|
static int i2c2_write(uint8_t addr, uint8_t *data, uint8_t size);
|
|
void tf02_force_uart();
|
|
|
|
#endif |