/************************************************************************************** @project : XDrive_Step** @brief : Stepper motor with multi-function interface and closed loop function.** @brief : 具有多功能接口和闭环功能的步进电机** @author : unlir (知不知啊)** @contacts: QQ.1354077136******** @address : https://github.com/unlir/XDrive************************************************************************************** {Stepper motor with multi-function interface and closed loop function.}** Copyright (c) {2020} {unlir(知不知啊)}**** This program is free software: you can redistribute it and/or modify** it under the terms of the GNU General Public License as published by** the Free Software Foundation, either version 3 of the License, or** (at your option) any later version.**** This program is distributed in the hope that it will be useful,** but WITHOUT ANY WARRANTY; without even the implied warranty of** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the** GNU General Public License for more details.**** You should have received a copy of the GNU General Public License** along with this program. If not, see <http://www.gnu.org/licenses/>.******************************************************************************
******/#ifndefMT6816_H#defineMT6816_H#ifdef__cplusplusextern"C"{#endif#include<stdbool.h>//引用端口定义/********** MT6816 **********///MT6816模式控制(GPIO)#defineSENSOR_HVPP_CLK_ENABLE()__HAL_RCC_GPIOA_CLK_ENABLE()//PA7#defineSENSOR_HVPP_GPIO_Port(GPIOA)#defineSENSOR_HVPP_Pin(GPIO_PIN_7)//MT6816_PWM采集(AFIO & TIM)#defineMT6816_PWM_GPIO_CLK_ENABLE()__HAL_RCC_GPIOA_CLK_ENABLE()//PA6#defineMT6816_PWM_GPIO_Port(GPIOA)#defineMT6816_PWM_Pin(GPIO_PIN_6)#defineMT6816_PWM_TIM_CLK_ENABLE()__HAL_RCC_TIM3_CLK_ENABLE()//TIM3#defineMT6816_PWM_Get_TIM(TIM3)#defineMT6816_PWM_Get_HTIM(htim3)#defineMT6816_PWM_Get_IRQn(TIM3_IRQn)//TIM3中断//MT6816_ABZ采集(GPIO)#defineMT6816_ABZ_Z_GPIO_CLK_ENABLE()__HAL_RCC_GPIOA_CLK_ENABLE()//PA10#defineMT6816_ABZ_Z_GPIO_Port(GPIOA)#defineMT6816_ABZ_Z_Pin(GPIO_PIN_10)#defineMT6816_ABZ_Z_EXTI_IRQn(EXTI15_10_IRQn)//EXTI15_10中断//MT6816_ABZ采集(AFIO & TIM)#defineMT6816_ABZ_A_GPIO_CLK_ENABLE()__HAL_RCC_GPIOA_CLK_ENABLE()//PA8#defineMT6816_ABZ_A_GPIO_Port(GPIOA)#defineMT6816_ABZ_A_Pin(GPIO_PIN_8)#defineMT6816_ABZ_B_GPIO_CLK_ENABLE()__HAL_RCC_GPIOA_CLK_ENABLE()//PA9#defineMT6816_ABZ_B_GPIO_Port(GPIOA)#defineMT6816_ABZ_B_Pin(GPIO_PIN_9)#defineMT6816_ABZ_TIM_CLK_ENABLE()__HAL_RCC_TIM1_CLK_ENABLE()//TIM1#defineMT6816_ABZ_Get_TIM(TIM1)#defineMT6816_ABZ_Get_HTIM(htim1)//MT6816_SPI采集(GPIO)//#define MT6816_SPI_CS_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE() //PB12//#define MT6816_SPI_CS_GPIO_Port (GPIOB)//#define MT6816_SPI_CS_Pin (GPIO_PIN_12)//MT6816_SPI采集(AFIO & SPI)//#define MT6816_SPI_CLK_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE() //PB13//#define MT6816_SPI_CLK_GPIO_Port (GPIOB)//#define MT6816_SPI_CLK_Pin (GPIO_PIN_13)//#define MT6816_SPI_MISO_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE() //PB14//#define MT6816_SPI_MISO_GPIO_Port (GPIOB)//#define MT6816_SPI_MISO_Pin (GPIO_PIN_14)//#define MT6816_SPI_MOSI_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE() //PB15//#define MT6816_SPI_MOSI_GPIO_Port (GPIOB)//#define MT6816_SPI_MOSI_Pin (GPIO_PIN_15)//#define MT6816_SPI_SPI_CLK_ENABLE() __HAL_RCC_SPI2_CLK_ENABLE(); //SPI2//#define MT6816_SPI_Get_SPI (SPI2)//#define MT6816_SPI_Get_HSPI (hspi2)//#define MT6816_SPI_AFIO_REMAP __HAL_AFIO_REMAP_SPI2_ENABLE(); //SPI2_AFIO端口重新映射/********** MT6816 **********///MT6816_SPI采集(GPIO)#defineMT6816_SPI_CS_GPIO_CLK_ENABLE()__HAL_RCC_GPIOA_CLK_ENABLE()//PA15#defineMT6816_SPI_CS_GPIO_Port(GPIOA)#defineMT6816_SPI_CS_Pin(GPIO_PIN_15)//MT6816_SPI采集(AFIO & SPI)#defineMT6816_SPI_CLK_GPIO_CLK_ENABLE()__HAL_RCC_GPIOB_CLK_ENABLE()//PB3#defineMT6816_SPI_CLK_GPIO_Port(GPIOB)#defineMT6816_SPI_CLK_Pin(GPIO_PIN_3)#defineMT6816_SPI_MISO_GPIO_CLK_ENABLE()__HAL_RCC_GPIOB_CLK_ENABLE()//PB4#defineMT6816_SPI_MISO_GPIO_Port(GPIOB)#defineMT6816_SPI_MISO_Pin(GPIO_PIN_4)#defineMT6816_SPI_MOSI_GPIO_CLK_ENABLE()__HAL_RCC_GPIOB_CLK_ENABLE()//PB5#defineMT6816_SPI_MOSI_GPIO_Port(GPIOB)#defineMT6816_SPI_MOSI_Pin(GPIO_PIN_5)#defineMT6816_SPI_SPI_CLK_ENABLE()__HAL_RCC_SPI1_CLK_ENABLE();//SPI1#defineMT6816_SPI_Get_SPI(SPI1)#defineMT6816_SPI_Get_HSPI(hspi1)#defineMT6816_SPI_AFIO_REMAP__HAL_AFIO_REMAP_SPI1_ENABLE();//SPI1_AFIO端口重新映射#defineMT6816_SPI_Prescaler(SPI_BAUDRATEPRESCALER_8)//MT6816工作模式定义#defineMT6816_Mode_PWM(0x01)//MT6816工作在PWM模式 (支持该模式的硬件版本:XDrive_REIN_Basic_H1_0)#defineMT6816_Mode_ABZ(0x02)//MT6816工作在ABZ模式 (支持该模式的硬件版本:XDrive_REIN_Basic_H1_0)#defineMT6816_Mode_SPI(0x03)//MT6816工作在SPI模式 (支持该模式的硬件版本:XDrive_REIN_Basic_H1_0 / XDrive_REIN_Basic_H1_1)//MT6816工作模式配置#defineMT6816_ModeMT6816_Mode_PWM#if(MT6816_Mode == MT6816_Mode_PWM)#include"tim.h"/********** MT6816_PWM **********//********** MT6816_PWM **********//********** MT6816_PWM **********/typedefstruct{//采集数据(PWM)uint16_t h_width;//PWM高宽度uint16_t period;//PWM周期uint8_t count_rising;//PWM上升沿计数器镜像uint8_t count_falling;//PWM下降沿计数器镜像uint8_t count_update;//PWM更新计数器bool whole_h_flag;//PWM全高标志bool whole_l_flag;//PWM全低标志bool ready_once;//PWM就绪标志(完成一次PWM采集后置位)bool ready_again;//PWM就绪标志(完成二次PWM采集后置位)uint16_t valid_width;//PWM有效宽度//输出数据(PWM)uint16_t angle;} MT6816_PWM_Signal_Typedef;//MT6816_PWMvoidREIN_MT6816_PWM_Signal_Init(void);//MT6816_PWM采集初始化voidREIN_MT6816_PWM_TIM_Callback(void);//MT6816_PWM采集中断回调voidREIN_MT6816_PWM_Get_AngleData(void);//MT6816_PWM获取角度数据#elif(MT6816_Mode == MT6816_Mode_ABZ)/********** MT6816_ABZ **********//********** MT6816_ABZ **********//********** MT6816_ABZ **********/typedefstruct{//采集数据(ABZ)uint16_t sample_data;//ABZ读取到的数据//输出数据(ABZ)uint16_t angle;//ABZ输出的角度} MT6816_ABZ_Signal_Typedef;//MT6816_ABZvoidREIN_MT6816_ABZ_Signal_Init(void);//MT6816_ABZ采集初始化voidREIN_MT6816_ABZ_ZPulse_Callback(void);//MT6816_ABZ采集Z脉冲中断回调voidREIN_MT6816_ABZ_Get_AngleData(void);//MT6816_ABZ获取角度数据#elif(MT6816_Mode == MT6816_Mode_SPI)#include"spi.h"/********** MT6816_SPI **********//********** MT6816_SPI **********//********** MT6816_SPI **********/typedefstruct{//采集数据uint16_t sample_data;//SPI读取到的数据//输出数据uint16_t angle;//SPI输出的角度bool no_mag_flag;//磁铁数据有效标志bool pc_flag;//奇偶校验位} MT6816_SPI_Signal_Typedef;//MT6816_SPIvoidREIN_MT6816_SPI_Signal_Init(void);//MT6816_SPI采集初始化voidRINE_MT6816_SPI_Get_AngleData(void);//MT6816_SPI采集获取角度数据#endif/********** MT6816 **********//********** MT6816 **********//********** MT6816 **********/typedefstruct{uint16_t angle_data;//角度数据float angle;//角度数据// bool rectify_valid; //校准数据有效标志} MT6816_Typedef;extern MT6816_Typedef mt6816;//MT6816voidREIN_MT6816_Init(void);//MT6816初始化voidREIN_MT6816_Get_AngleData(void);//MT6816获取角度数据#ifdef__cplusplus}#endif#endif