ZNKT-ST-M/BSP/Inc/Usart.h
2025-01-15 16:02:53 +08:00

143 lines
4.9 KiB
C
Raw Permalink 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 _USART_H_
#define _USART_H_
#include "stdint.h"
#include "Include.h"
#include "user_queue.h"
#define MAX_SLAVE_NUMBER ( 8 )
#define MAC_ADDRESS_LENGTH ( 12 )
#define BLE_USART ( USART1 )
#define BLE_USART_GPIO_CLK ( RCC_AHB1Periph_GPIOB )
#define BLE_USART_CLK ( RCC_APB2Periph_USART1 )
#define BLE_USART_GPIO_PORT ( GPIOB )
#define BLE_USART_TX_GPIO_PIN ( GPIO_Pin_6 )
#define BLE_USART_RX_GPIO_PIN ( GPIO_Pin_7 )
#define BLE_USART_BAUDRATE ( 115200 )
#define BLE_NVIC_IRQChannel ( USART1_IRQn )
/**********************¸´ÓÃ**************************/
#define BLE_USART_TX_PinSource ( GPIO_PinSource6 )
#define BLE_USART_RX_PinSource ( GPIO_PinSource7 )
#define BLE_GPIO_AF_USART ( GPIO_AF_USART1 )
#define USART1_RX_BUFFER_SIZE ( 50 )
#define FrameHead ( 0xAA )
#define FrameTail ( 0x55 )
/*********¹¦ÄÜÂë**********/
#define WaveformSet ( 0x71 )
#define AcquisitionCtrl ( 0x72 )
#define CurrentSet ( 0x73 )
#define EMG_DataReport ( 0x74 )
#define EMG_FormatSwitching ( 0x75 )
#define CurrentPreinstallCtrl ( 0x76 )
#define TriggerModeCtrl ( 0x77 )
#define Poll ( 0x78 )
#define SliceFalLSwitch ( 0x79 )
#define ShutDown ( 0x7A )
/***********Æ«ÒÆ***********/
#define HeadOffset ( 0x00 )
#define LengthOffset ( 0x01 )
#define FunctionCodeOffset ( 0x02 )
#define DeviceNumberOffset ( 0x03 )
#define ChannelOffset ( 0x04 )
/**********Êý¾Ý************/
#define ChannelModeAcquisition ( 0x01 )
#define ChannelModeStimulation ( 0x02 )
#define ChannelModeTrigger ( 0x03 )
#define AcquisitionRate4K ( 0x01 )
#define AcquisitionRate8K ( 0x02 )
#define TurnOff ( 0x00 )
#define TurnOn ( 0x01 )
#define Pause ( 0x02 )
#define Continue ( 0x03 )
#define RMS_Data ( 0x00 )
#define OriginalData ( 0x01 )
#define Acquisition ( 0x00 )
#define Stimulation ( 0x01 )
#define SliceFall ( 0x00 )
#define SliceConnect ( 0x01 )
#define SliceUnmonitored ( 0x02 )
#define IdleState ( 0x00 )
#define ClimbState ( 0x01 )
#define DownState ( 0x02 )
#define KeepState ( 0x03 )
#define RestState ( 0x04 )
#define Charging ( 0x00 )
#define BatterySupply ( 0x01 )
#define SlaveConnect ( 0x01 )
#define SlaveDisconnect ( 0x02 )
#define BLE_Disconnect ( 0x01 )
#define BLE_Connect ( 0x02 )
#define Reset ( 0x00 )
#define NotReset ( 0x01 )
typedef struct
{
uint8_t mode; //ģʽ
uint8_t rate; //²ÉÑùÂÊ
uint8_t EMG_data_mode; //¼¡µçÊý¾Ýģʽ
uint8_t state; //¿ª¹Ø״̬
}channel_data_t;
typedef struct
{
channel_data_t channel1;
channel_data_t channel2;
uint8_t output_current_mA; //Êä³öµçÁ÷Ç¿¶È
uint8_t preinstall_state; //Ô¤É迪¹Ø
uint8_t stimulate_state; //´Ì¼¤¿ª¹Ø
uint8_t slice_state; //¼«Æ¬×´Ì¬
uint8_t slice_detect_state; //ÍÑÂä¼ì²â¿ª¹Ø
uint8_t formwave_state; //²¨ÐÎ״̬
uint8_t mac_address[MAC_ADDRESS_LENGTH]; //mac
uint8_t connection_state; //À¶ÑÀÁ¬½Ó״̬
uint8_t adapter_state; //ÊÊÅäÆ÷״̬
uint8_t electric_quantity; //µçÁ¿
uint8_t reset_flag; //¸´Î»±ê־λ
uint16_t frequency_Hz; //ƵÂÊ
uint16_t width_us; //Âö¿í
uint16_t climb_time_ms; //ÉÏÉýʱ¼ä
uint16_t keep_time_ms; //±£³Öʱ¼ä
uint16_t down_time_ms; //ϽµÊ±¼ä
uint16_t rest_time_ms; //ÐÝϢʱ¼ä
}device_state_t;
void ble_usart_init(uint32_t baudrate);
//void ble_usart_send(uint8_t *ucpTx_Data,uint8_t ucTx_length);
uint8_t ble_usart_send(uint8_t ucTx_length);
uint8_t Analysis_data(void);
extern uint8_t usart1_tx_done ;//´®¿Ú1·¢ËÍÍê³É±êÖ¾
void net_received_data_analysis(void);
void parameters_init(void);
#endif