88 lines
2.3 KiB
C
88 lines
2.3 KiB
C
#ifndef __TWAI_COMMUNICATION_H
|
|
#define __TWAI_COMMUNICATION_H
|
|
|
|
#include <stdint.h>
|
|
|
|
#define TX_GPIO_NUM 35
|
|
#define RX_GPIO_NUM 34
|
|
|
|
#define CMD_ERR 0xff
|
|
#define CMD_OK 0x00
|
|
|
|
// identifer
|
|
typedef enum
|
|
{
|
|
MEASUREMENT_ID = 0x0f000000,
|
|
ESP_RESTART_ID = 0x0f010000,
|
|
OTA_ID = 0x0f020000,
|
|
|
|
CMD_RESP_ID = 0x0A000000,
|
|
OTA_RESP_ID = 0x0A020000,
|
|
|
|
SEND_FFT_ARRAY_ID = 0x0B000000,
|
|
} twai_identifier_t;
|
|
|
|
// cmd
|
|
typedef enum
|
|
{
|
|
MC_READ_LISDSH_CONFIG = 0x10 | 0x01,
|
|
MC_READ_SHAKE_CONFIG,
|
|
MC_READ_MEASURE,
|
|
MC_WRITE_LISDSH_CONFIG = 0x20 | 0x01,
|
|
MC_WRITE_SHAKE_CONFIG,
|
|
MC_LISDSH_CONFIG_RESTORE_DEFAULT = 0x30 | 0x01,
|
|
MC_SHAKE_CONFIG_RESTORE_DEFAULT,
|
|
MC_LISDSH_CONFIG_SAVE = 0x40 | 0x01,
|
|
MC_SHAKE_CONFIG_SAVE,
|
|
MC_OPEN_DATA_SEND = 0x50 | 0x01,
|
|
} measurement_cmd_t;
|
|
|
|
typedef enum
|
|
{
|
|
OC_ENTER = 0x01,
|
|
OC_DOWNLOAD_DATA_IN = 0x02,
|
|
OC_DOWNLOAD_FINISH = 0x03,
|
|
READ_VERSIONS = 0x04,
|
|
} ota_cmd_t;
|
|
|
|
|
|
// subcmd
|
|
typedef enum
|
|
{
|
|
MLCS_FSCALE = 0x01, // 量程 000: 2g, 001: 4g, 010: 8g, 011: 16g
|
|
MLCS_ODR = 0x02, // 采样率:根据手册值
|
|
} measurement_lis3dsh_config_subcmd_t;
|
|
|
|
typedef enum
|
|
{
|
|
MSCS_FEQ_RANGE = 0x01,
|
|
MSCS_AMP_TH = 0x02,
|
|
MSCS_CHANNAL = 0x03
|
|
} measurement_shake_config_subcmd_t;
|
|
|
|
typedef enum
|
|
{
|
|
MDS_ACCELERATION_CX = 0x01, // bufr(cnt)、x
|
|
MDS_ACCELERATION_YZ = 0x02,
|
|
MDS_FFT = 0x03, // cnt、is_shake
|
|
MDS_ANGLE_CX = 0x04, // cnt、x
|
|
MDS_ANGLE_YZ = 0x05
|
|
} measurement_data_subcmd_t;
|
|
|
|
typedef enum
|
|
{
|
|
ORVS_PACKET1 = 0X01,
|
|
ORVS_PACKET2 = 0X02,
|
|
ORVS_PACKET3 = 0X03,
|
|
ORVS_PACKET4 = 0X04,
|
|
} ota_read_versions_subcmd_t;
|
|
|
|
#define TWAI_SEND_DATA_MAX (255 * 8)
|
|
extern bool twai_fft_array_data_send_enable;
|
|
#define twai_send_fft_array_data(data, len) twai_send_data(SEND_FFT_ARRAY_ID, data, len, twai_fft_array_data_send_enable)
|
|
|
|
|
|
void twai_init(void);
|
|
int twai_send_data(uint32_t identifier, const uint8_t *data, int len, bool enable);
|
|
|
|
#endif |