generated from hulk/gd32e23x_template_cmake_vscode
122 lines
4.1 KiB
C
122 lines
4.1 KiB
C
//
|
|
// Created by dell on 24-12-3.
|
|
//
|
|
|
|
#ifndef LDC1612_H
|
|
#define LDC1612_H
|
|
|
|
#include "gd32e23x_it.h"
|
|
#include "gd32e23x.h"
|
|
#include "systick.h"
|
|
#include <stdbool.h>
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <math.h>
|
|
#include "board_config.h"
|
|
#include "soft_i2c.h"
|
|
#include "i2c.h"
|
|
|
|
/***************************************************************************/
|
|
|
|
/* IIC Interface Selection */
|
|
#ifdef SOFTWARE_IIC
|
|
#define LDC1612_IIC_WRITE_16BITS(addr, reg, data) soft_i2c_write_16bits(addr, reg, data)
|
|
#define LDC1612_IIC_READ_16BITS(addr, reg, data) soft_i2c_read_16bits(addr, reg, data)
|
|
#define LDC1612_IIC_TYPE_STR "Software IIC"
|
|
#else
|
|
#define LDC1612_IIC_WRITE_16BITS(addr, reg, data) i2c_write_16bits(addr, reg, data)
|
|
#define LDC1612_IIC_READ_16BITS(addr, reg, data) i2c_read_16bits(addr, reg, data)
|
|
#define LDC1612_IIC_TYPE_STR "Hardware IIC"
|
|
#endif
|
|
|
|
/***************************************************************************/
|
|
|
|
#define LDC1612_ADDR 0x2B
|
|
|
|
/*Register Rddr*/
|
|
/***************************************************************************/
|
|
|
|
#define CONVERTION_RESULT_REG_START 0X00
|
|
#define SET_CONVERSION_TIME_REG_START 0X08
|
|
#define SET_CONVERSION_OFFSET_REG_START 0X0C
|
|
#define SET_LC_STABILIZE_REG_START 0X10
|
|
#define SET_FREQ_REG_START 0X14
|
|
|
|
#define SENSOR_STATUS_REG 0X18
|
|
#define ERROR_CONFIG_REG 0X19
|
|
#define SENSOR_CONFIG_REG 0X1A
|
|
#define MUL_CONFIG_REG 0X1B
|
|
#define SENSOR_RESET_REG 0X1C
|
|
#define SET_DRIVER_CURRENT_REG 0X1E
|
|
|
|
#define READ_MANUFACTURER_ID 0X7E
|
|
#define READ_DEVICE_ID 0X7F
|
|
|
|
/******************************************************************************/
|
|
|
|
#define CHANNEL_0 0
|
|
#define CHANNEL_1 1
|
|
|
|
/*************************MUX_CONFIG********************************************/
|
|
#define LDC1612_MUX_CONFIG 0x0200
|
|
|
|
/***********************SENSOR_CONFIG********************************************/
|
|
|
|
#define LDC1612_SENSOR_CONFIG_CH0 0x1601 //
|
|
|
|
/****************************CONVERSION_TIME************************************/
|
|
#define LDC1612_CONVERSION_TIME_CH0 0x1000 // 0x1000=4096个时钟周期
|
|
#define LC_STABILIZE_TIME_CH0 0x0020 // 0x0020=32个时钟周期
|
|
|
|
/**************************DRIVE_CURRENT****************************************/
|
|
#define LDC1612_DRIVE_CURRENT 0x9000 //A000
|
|
|
|
/**************************SENSOR_CONFIG***************************************/
|
|
#define LDC1612_SLEEP_MODE 0x2801
|
|
/**************************OTHER_CONFIG*****************************************/
|
|
#define LDC1612_ERROR_CONFIG 0x0000
|
|
#define SET_CONVERSION_OFFSET_CH0 0x0000
|
|
#define LDC1612_RESET_DEV 0x8000 //[15:0] 0b1000 0000 0000 0000
|
|
|
|
/******************************************************************************/
|
|
|
|
#define COIL_RP_KOM 7.2
|
|
#define COIL_L_UH 33
|
|
#define COIL_C_PF 150
|
|
#define COIL_Q_FACTOR 35.97
|
|
#define COIL_FREQ_HZ 2262000
|
|
|
|
/******************************************************************************/
|
|
|
|
typedef enum {
|
|
LDC1612_STATUS_SUCCESS = 0,
|
|
LDC1612_STATUS_ERROR,
|
|
LDC1612_STATUS_TIMEOUT,
|
|
LDC1612_STATUS_INVALID_PARAM,
|
|
LDC1612_STATUS_NO_COIL,
|
|
LDC1612_STATUS_UNDER_RANGE,
|
|
LDC1612_STATUS_OVER_RANGE
|
|
} ldc1612_status_t;
|
|
|
|
/******************************************************************************/
|
|
ldc1612_status_t ldc1612_init(void);
|
|
|
|
ldc1612_status_t ldc1612_reset_sensor(void);
|
|
|
|
ldc1612_status_t ldc1612_config_single_channel(uint8_t channel);
|
|
|
|
uint16_t ldc1612_get_manufacturer_id(void);
|
|
|
|
uint16_t ldc1612_get_deveice_id(void);
|
|
|
|
uint32_t ldc1612_get_raw_channel_result(uint8_t channel);
|
|
|
|
uint32_t ldc1612_parse_raw_result(uint32_t raw_result);
|
|
|
|
uint16_t ldc1612_get_sensor_status(void);
|
|
|
|
bool ldc1612_is_data_ready(uint8_t channel);
|
|
|
|
#endif //LDC1612_H
|