U20_bsp_差异文件

/******************************************************************************
版权所有:  深圳市**科技有限公司 
文件名:    bsp_beep_control.c 
作者:      wangdy
创建日期:  2020/06/27
描述:      蜂鸣器控制  
其它:      
修改历史:  //修改历史记录列表,每条修改记录应包含修改日期、修改者及修改内容简述
            序号    修改时间    修改人  修改内容
			????    ????/??/??  ??????  参考样式       
******************************************************************************/

/************************************头文件************************************/

#include "driver_timer.h"
#include "bsp_beep_control.h"

/*************************************变量*************************************/



/*************************************函数*************************************/

//设置占空比 
static void timer_setcompare(TIM_NumTypeDef TIMx,uint32_t duty)
{
	static uint32_t  timer_all_count_value = 9600*38;
	
	uint32_t duty_temp = 0;
	
	//查看电机转速是否ok 
	if(duty == 0)
	{
		duty_temp = 0;
	}
	else 
	{
		duty_temp = ((duty*timer_all_count_value)/100);
	}
	
	TIM_SetPWMPeriod(TIMx,timer_all_count_value-duty_temp,duty_temp);
}

/*******************************************************************************
* 名称:		Buzzer_Init       
* 描述:		蜂鸣器初始化 
* 输入参数:	无  
* 输出参数:	无   
* 其它:		无   
*******************************************************************************/
void Buzzer_Init(void)
{
	//有源 
	#if ACTIVE_BUZZER
		GPIO_InitTypeDef GPIO_InitStruct;
		
		GPIO_InitStruct.GPIO_Pin = PIN_BEEP_CONTROL;
		GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
		GPIO_Init(PORT_BEEP_CONTROL, &GPIO_InitStruct);
		GPIO_Config(PORT_BEEP_CONTROL, PIN_BEEP_CONTROL, OUTPUT_LOW); 	
	#else 
		PWM_InitTypeDef PWM_init_struct;

		PWM_init_struct.TIMx = TIM0;
		PWM_init_struct.LowLevelPeriod = 9600*38;
		PWM_init_struct.HighLevelPeriod = 0;
		PWM_init_struct.SatrtLevel = OutputLow;
		GPIO_Config(PORT_BEEP_CONTROL, PIN_BEEP_CONTROL, GPCFG_PWM_OUT0);
		TIM_PWMInit(&PWM_init_struct);

		/* Configure PWM for counting mode */
		TIM_ModeConfig(TIM0, TIM_Mode_PWM);

		/* The last step must be enabled */
		TIM_Cmd(TIM0, ENABLE);
		
	#endif 
}

/*******************************************************************************
* 名称:		Buzzer_OnOff       
* 描述:		蜂鸣器开/关     
* 输入参数:	无  
* 输出参数:	无   
* 其它:		无   
*******************************************************************************/
void Buzzer_OnOff(bool state)
{	
	#if ACTIVE_BUZZER
		if(state)
		{
			Buzzer_On();
		}
		else 
		{
			Buzzer_Off();
		}
	#else 
		if(state)
		{
			timer_setcompare(TIM0,50);
		}
		else 
		{
			timer_setcompare(TIM0,0);
		}
	#endif 
}




























/******************************************************************************
版权所有:  深圳市普实科技有限公司 
文件名:    bsp_charge_control
作者:      wangdy
创建日期:  2018/08/16
描述:      打印芯片控制 
其它:      
修改历史:  //修改历史记录列表,每条修改记录应包含修改日期、修改者及修改内容简述
            序号    修改时间    修改人  修改内容
			????    ????/??/??  ??????  参考样式       
******************************************************************************/

/************************************头文件************************************/

#include "driver_timer.h"
#include "bsp_charge_control.h"
#include "yc_gpio.h"
#include "yc_chrg.h"

/*************************************变量*************************************/



/*************************************函数*************************************/

/*******************************************************************************
* 名称:		Charge_Control_Init       
* 描述:		充电初始化      
* 输入参数:	无  
* 输出参数:	无   
* 其它:		无   
*******************************************************************************/
void Charge_Control_Init(void)
{	
	//充电完成  IO
	GPIO_InitTypeDef GPIO_InitStruct;
	
	GPIO_InitStruct.GPIO_Pin = PIN_BAT_CHARGE_FINISH;
  //_  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPU;   
	GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_Init(PORT_BAT_CHARGE_FINISH, &GPIO_InitStruct);	
	
	//充电控制 IO	
	GPIO_InitStruct.GPIO_Pin = PIN_BAT_CHARGE_CONTROL;
    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(PORT_BAT_CHARGE_CONTROL, &GPIO_InitStruct);
	
	//初始化后   打开充电  
	Matchine_Bat_Charge_On();
}

bool  ChargingState_Get(void)
{
	bool charge_state = false;
	//充电状态  
	charge_state = CHARGE_InsertDet();
	
	//充电状态  
	if(CHARGE_IN == charge_state)
	{
		return true;
	}

	return false;
}

//获取充电完成状态 
bool  ChargeFinish_State_Get(void){
	//低电平表示在充电中 
	if(RESET == READ_CHARGE_FINISH_STATE){
		return false;
	}
	
	return true;
}

























/******************************************************************************
版权所有:  
文件名:  bsp_led_control.c  
作者:      wangdy
创建日期:  2018/08/16
描述:      stm32单片机的串口驱动整合,将接收与发送合并至一起,并且不使用DMA发送 
其它:      
修改历史:  //修改历史记录列表,每条修改记录应包含修改日期、修改者及修改内容简述
            序号    修改时间    修改人  修改内容      
******************************************************************************/

/************************************头文件************************************/

#include "bsp_led_control.h"


/*************************************变量*************************************/



/*************************************函数*************************************/

/*******************************************************************************
* 名称:		bsp_led_control       
* 描述:		led_control   
* 输入参数:	
* 输出参数:	无   
* 其它:		
*******************************************************************************/
void 	LED_Control_Init(void)
{
	//LED_RED 
	GPIO_InitTypeDef GPIO_InitStruct;
	
	GPIO_InitStruct.GPIO_Pin = PIN_LED_RED_STATUS;
    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(PORT_LED_RED_STATUS, &GPIO_InitStruct);
	GPIO_Config(PORT_LED_RED_STATUS, PIN_LED_RED_STATUS, OUTPUT_LOW); 	
	LED_Red_Status_Off();
	
	//LED_BLUE 
	GPIO_InitStruct.GPIO_Pin = PIN_LED_BLUE_BT;
    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(PORT_LED_BLUE_BT, &GPIO_InitStruct);
	GPIO_Config(PORT_LED_BLUE_BT, PIN_LED_BLUE_BT, OUTPUT_LOW); 	
	LED_Blue_Bt_Off();
}






























/******************************************************************************
版权所有:  
文件名:    
作者:      
创建日期:  2017/12/14
描述:      定时器控制   
其它:      
修改历史:  //修改历史记录列表,每条修改记录应包含修改日期、修改者及修改内容简述
            序号    修改时间    修改人  修改内容
			????    ????/??/??  ??????  参考样式       
******************************************************************************/

/*********************************防止多次编译*********************************/
#ifndef _BSP_LED_CONTROL_H
#define _BSP_LED_CONTROL_H

/************************************头文件************************************/
#include <stdint.h>
#include <stdbool.h>
#include "yc_gpio.h"

/************************************宏定义************************************/

//状态指示灯 
#define   PIN_LED_RED_STATUS				GPIO_Pin_4
#define   PORT_LED_RED_STATUS				GPIOA

//蓝牙状态指示灯 
#define   PIN_LED_BLUE_BT					GPIO_Pin_5
#define   PORT_LED_BLUE_BT					GPIOA


//状态指示灯(红色)  开/关 
#define   LED_Red_Status_Off()				GPIO_ResetBits(PORT_LED_RED_STATUS,PIN_LED_RED_STATUS)
#define   LED_Red_Status_On()				GPIO_SetBits(PORT_LED_RED_STATUS,PIN_LED_RED_STATUS)
//蓝牙状态指示灯(蓝色)  开/关 
#define   LED_Blue_Bt_Off()					GPIO_ResetBits(PORT_LED_BLUE_BT,PIN_LED_BLUE_BT)
#define   LED_Blue_Bt_On()					GPIO_SetBits(PORT_LED_BLUE_BT,PIN_LED_BLUE_BT)

/************************************结构体************************************/

/**********************************可导出变量**********************************/

/***********************************函数实现***********************************/
void 	LED_Control_Init(void);



#endif





























/******************************************************************************
版权所有:  
文件名:    
作者:      wangdy
创建日期:  2018/08/16
描述:      电机控制 
其它:      
修改历史:  //修改历史记录列表,每条修改记录应包含修改日期、修改者及修改内容简述
            序号    修改时间    修改人  修改内容
			????    ????/??/??  ??????  参考样式       
******************************************************************************/

/************************************头文件************************************/

#include "driver_timer.h"
#include "bsp_motor_control.h"
#include "yc_gpio.h"

/*************************************变量*************************************/

MotorRunDirectTypeDef		MotorRunDirect = MOTOR_RUN_POSITIVE;	//电机转向 

/*************************************函数*************************************/

/*******************************************************************************
* 名称:		Motor_Control_Init       
* 描述:		电机控制初始化     
* 输入参数:	无  
* 输出参数:	无   
* 其它:		无   
*******************************************************************************/
void Motor_Control_Init(void)
{
	GPIO_InitTypeDef GPIO_InitStruct;
	
	//使能脚 
	GPIO_InitStruct.GPIO_Pin = PIN_MOTOR_CONTROL_EN;
    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(PORT_MOTOR_CONTROL_EN, &GPIO_InitStruct);
	GPIO_Config(PORT_MOTOR_CONTROL_EN, PIN_MOTOR_CONTROL_EN, OUTPUT_LOW); 
	
	GPIO_InitStruct.GPIO_Pin = PIN_MOTOR_CONTROL_A1;
    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(PORT_MOTOR_CONTROL_A1, &GPIO_InitStruct);
	GPIO_Config(PORT_MOTOR_CONTROL_A1, PIN_MOTOR_CONTROL_A1, OUTPUT_LOW); 
	
	GPIO_InitStruct.GPIO_Pin = PIN_MOTOR_CONTROL_A2;
    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(PORT_MOTOR_CONTROL_A2, &GPIO_InitStruct);
	GPIO_Config(PORT_MOTOR_CONTROL_A2, PIN_MOTOR_CONTROL_A2, OUTPUT_LOW); 
	
	GPIO_InitStruct.GPIO_Pin = PIN_MOTOR_CONTROL_B1;
    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(PORT_MOTOR_CONTROL_B1, &GPIO_InitStruct);
	GPIO_Config(PORT_MOTOR_CONTROL_B1, PIN_MOTOR_CONTROL_B1, OUTPUT_LOW); 
	
	GPIO_InitStruct.GPIO_Pin = PIN_MOTOR_CONTROL_B2;
    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(PORT_MOTOR_CONTROL_B2, &GPIO_InitStruct);
	GPIO_Config(PORT_MOTOR_CONTROL_B2, PIN_MOTOR_CONTROL_B2, OUTPUT_LOW); 

	Motor_Control_Dis();				//电机默认失能 
	Motor_A1_Off();
	Motor_A2_Off();
	Motor_B1_Off();
	Motor_B2_Off();
}


//电机打印  启停 direct - 方向  start - 启停止 
void PrintMotor_Control_Set(MotorRunDirectTypeDef direct,bool start)
{
	if(start)
	{
		Motor_Control_En();
		MotorRunDirect = direct;

		TIMER_MOTOR_START;		//开启电机相关定时器 
	}
	else 
	{
		Motor_Control_Dis();
		MotorRunDirect = direct;
		
		Motor_A1_Off();
		Motor_A2_Off();
		Motor_B1_Off();
		Motor_B2_Off();
		
		TIMER_MOTOR_STOP;		//停止电机相关定时器 
	}
}


//电机在启动时  仅转动一下  启停 direct - 方向  start - 启停止 
void PrintMotor_CalibrationRunOnPhase(MotorRunDirectTypeDef direct,bool start)
{
	static uint8_t  motor_step = 0;
	
	if(start)
	{
		Motor_Control_En();
		
		#if MOTOR_EIGHT_PHASE
			switch(motor_step){
				case 0:{			
					Motor_A1_On();
					Motor_A2_Off();
					Motor_B1_Off();
					Motor_B2_Off();
					break;
				}
				case 1:{				
					Motor_A1_On();
					Motor_A2_Off();
					Motor_B1_On();
					Motor_B2_Off();
					break;
				}
				case 2:{
					Motor_A1_Off();
					Motor_A2_Off();
					Motor_B1_On();
					Motor_B2_Off();
					break;
				}
				case 3:{
					Motor_A1_Off();
					Motor_A2_On();
					Motor_B1_On();
					Motor_B2_Off();
					break;
				}
				case 4:{
					Motor_A1_Off();
					Motor_A2_On();
					Motor_B1_Off();
					Motor_B2_Off();
					break;
				}
				case 5:{
					Motor_A1_Off();
					Motor_A2_On();
					Motor_B1_Off();
					Motor_B2_On();
					break;
				}
				case 6:{
					Motor_A1_Off();
					Motor_A2_Off();
					Motor_B1_Off();
					Motor_B2_On();
					break;
				}
				case 7:{
					Motor_A1_On();
					Motor_A2_Off();
					Motor_B1_Off();
					Motor_B2_On();
					break;
				}
				default:{
					break;
				}
			}
			//电机正转 
			if(direct == MOTOR_RUN_POSITIVE ){
				if(0 == motor_step)
				{
					motor_step = 7;
				}
				else if(motor_step > 0)
				{
					motor_step--;
				}
			}
			else if(direct == MOTOR_RUN_INVERSE){

				motor_step++;
				if(motor_step >= 8)
				{
					motor_step = 0;
				}
			}
		#else 
			switch(motor_step){
				case 0:{			
					Motor_A1_On();
					Motor_A2_Off();
					Motor_B1_On();
					Motor_B2_Off();
					break;
				}
				case 1:{				
					Motor_A1_Off();
					Motor_A2_On();
					Motor_B1_On();
					Motor_B2_Off();
					break;
				}
				case 2:{
					Motor_A1_Off();
					Motor_A2_On();
					Motor_B1_Off();
					Motor_B2_On();
					break;
				}
				case 3:{
					Motor_A1_On();
					Motor_A2_Off();
					Motor_B1_Off();
					Motor_B2_On();
					break;
				}
				default:{
					break;
				}
			}
			
			//电机转速
			if(direct == MOTOR_RUN_POSITIVE){
				motor_step++;
				if(motor_step >= 4){
					motor_step = 0;
				}
			}
			else if(direct == MOTOR_RUN_INVERSE){
				if(0 == motor_step){
					motor_step = 3;
				}
				else if(motor_step > 0){
					motor_step--;
				}
			}
		#endif 
	}
	else 
	{
		Motor_Control_Dis();
		
		Motor_A1_Off();
		Motor_A2_Off();
		Motor_B1_Off();
		Motor_B2_Off();
	}
	TIMER_MOTOR_STOP;
}
//电机保持相位不变  启停 direct - 方向  start - 启停止 
void PrintMotor_CalibrationPhaseInvariant(MotorRunDirectTypeDef direct,bool start)
{
	static uint8_t  motor_step = 0;
	
	if(start)
	{
		Motor_Control_En();
		
		#if MOTOR_EIGHT_PHASE
			switch(motor_step){
				case 0:{			
					Motor_A1_On();
					Motor_A2_Off();
					Motor_B1_Off();
					Motor_B2_Off();
					break;
				}
				case 1:{				
					Motor_A1_On();
					Motor_A2_Off();
					Motor_B1_On();
					Motor_B2_Off();
					break;
				}
				case 2:{
					Motor_A1_Off();
					Motor_A2_Off();
					Motor_B1_On();
					Motor_B2_Off();
					break;
				}
				case 3:{
					Motor_A1_Off();
					Motor_A2_On();
					Motor_B1_On();
					Motor_B2_Off();
					break;
				}
				case 4:{
					Motor_A1_Off();
					Motor_A2_On();
					Motor_B1_Off();
					Motor_B2_Off();
					break;
				}
				case 5:{
					Motor_A1_Off();
					Motor_A2_On();
					Motor_B1_Off();
					Motor_B2_On();
					break;
				}
				case 6:{
					Motor_A1_Off();
					Motor_A2_Off();
					Motor_B1_Off();
					Motor_B2_On();
					break;
				}
				case 7:{
					Motor_A1_On();
					Motor_A2_Off();
					Motor_B1_Off();
					Motor_B2_On();
					break;
				}
				default:{
					break;
				}
			}
			//电机正转 
			if(direct == MOTOR_RUN_POSITIVE ){
				if(0 == motor_step)
				{
					motor_step = 7;
				}
				else if(motor_step > 0)
				{
				//	motor_step--;
				}
			}
			else if(direct == MOTOR_RUN_INVERSE){

			//	motor_step++;
				if(motor_step >= 8)
				{
					motor_step = 0;
				}
			}
		#else 
			switch(motor_step){
				case 0:{			
					Motor_A1_On();
					Motor_A2_Off();
					Motor_B1_On();
					Motor_B2_Off();
					break;
				}
				case 1:{				
					Motor_A1_Off();
					Motor_A2_On();
					Motor_B1_On();
					Motor_B2_Off();
					break;
				}
				case 2:{
					Motor_A1_Off();
					Motor_A2_On();
					Motor_B1_Off();
					Motor_B2_On();
					break;
				}
				case 3:{
					Motor_A1_On();
					Motor_A2_Off();
					Motor_B1_Off();
					Motor_B2_On();
					break;
				}
				default:{
					break;
				}
			}
			
			//电机转速
			if(direct == MOTOR_RUN_POSITIVE){
				motor_step++;
				if(motor_step >= 4){
					motor_step = 0;
				}
			}
			else if(direct == MOTOR_RUN_INVERSE){
				if(0 == motor_step){
					motor_step = 3;
				}
				else if(motor_step > 0){
					motor_step--;
				}
			}
		#endif 
	}
	else 
	{
		Motor_Control_Dis();
		
		Motor_A1_Off();
		Motor_A2_Off();
		Motor_B1_Off();
		Motor_B2_Off();
	}
	TIMER_MOTOR_STOP;
}

/*******************************************************************************
* 名称:		Motor_Run_One_Phase      
* 描述:		电机转动一个相位
* 输入参数:	start - 启停止 
* 输出参数:	无   
* 其它:		无   
*******************************************************************************/
void Motor_Run_One_Phase(void)
{
	static uint8_t motor_step = 0;		//电机拍数 
	
	#if MOTOR_EIGHT_PHASE
		switch(motor_step){
			case 0:{			
				Motor_A1_On();
				Motor_A2_Off();
				Motor_B1_Off();
				Motor_B2_Off();
				break;
			}
			case 1:{				
				Motor_A1_On();
				Motor_A2_Off();
				Motor_B1_On();
				Motor_B2_Off();
				break;
			}
			case 2:{
				Motor_A1_Off();
				Motor_A2_Off();
				Motor_B1_On();
				Motor_B2_Off();
				break;
			}
			case 3:{
				Motor_A1_Off();
				Motor_A2_On();
				Motor_B1_On();
				Motor_B2_Off();
				break;
			}
			case 4:{
				Motor_A1_Off();
				Motor_A2_On();
				Motor_B1_Off();
				Motor_B2_Off();
				break;
			}
			case 5:{
				Motor_A1_Off();
				Motor_A2_On();
				Motor_B1_Off();
				Motor_B2_On();
				break;
			}
			case 6:{
				Motor_A1_Off();
				Motor_A2_Off();
				Motor_B1_Off();
				Motor_B2_On();
				break;
			}
			case 7:{
				Motor_A1_On();
				Motor_A2_Off();
				Motor_B1_Off();
				Motor_B2_On();
				break;
			}
			default:{
				break;
			}
		}
		//电机正转 
		if(MotorRunDirect == MOTOR_RUN_POSITIVE ){
//			motor_step++;
//			if(motor_step >= 8)
//			{
//				motor_step = 0;
//			}
			if(0 == motor_step)
			{
				motor_step = 7;
			}
			else if(motor_step > 0)
			{
				motor_step--;
			}
		}
		else if(MotorRunDirect == MOTOR_RUN_INVERSE){
			motor_step++;
			if(motor_step >= 8)
			{
				motor_step = 0;
			}
		}
	#else 
		switch(motor_step){
			case 0:{			
				Motor_A1_On();
				Motor_A2_Off();
				Motor_B1_On();
				Motor_B2_Off();
				break;
			}
			case 1:{				
				Motor_A1_Off();
				Motor_A2_On();
				Motor_B1_On();
				Motor_B2_Off();
				break;
			}
			case 2:{
				Motor_A1_Off();
				Motor_A2_On();
				Motor_B1_Off();
				Motor_B2_On();
				break;
			}
			case 3:{
				Motor_A1_On();
				Motor_A2_Off();
				Motor_B1_Off();
				Motor_B2_On();
				break;
			}
			default:{
				break;
			}
		}
		
		//电机转速
		if(MotorRunDirect == MOTOR_RUN_POSITIVE){
			motor_step++;
			if(motor_step >= 4){
				motor_step = 0;
			}
		}
		else if(MotorRunDirect == MOTOR_RUN_INVERSE){
			if(0 == motor_step){
				motor_step = 3;
			}
			else if(motor_step > 0){
				motor_step--;
			}
		}
	#endif 
}





























/******************************************************************************
版权所有:  深圳**科技有限公司  
文件名:     
作者:      wangdy  
创建日期:  2023/1/15
描述:      电机控制  
其它:      
修改历史:  //修改历史记录列表,每条修改记录应包含修改日期、修改者及修改内容简述
            序号    修改时间    修改人  修改内容
			????    ????/??/??  ??????  参考样式       

*********************************防止多次编译*********************************/

#ifndef _BSP_MOTOR_CONTROL_H
#define _BSP_MOTOR_CONTROL_H

/************************************头文件************************************/
#include <stdint.h>
#include <stdbool.h>


/************************************宏定义************************************/


#define   MOTOR_EIGHT_PHASE     1 			//1-8拍   0-4拍 

//#define   PIX_MOTOR_N_STEP		27			//多少步  对应一个像素 
#define   PIX_MOTOR_N_STEP		    4			//多少步  对应1个像素


//电机正反转控制  
typedef enum
{
	MOTOR_RUN_POSITIVE = 1,
	MOTOR_RUN_INVERSE,
}MotorRunDirectTypeDef;


//电机控制  使能 
#define   PIN_MOTOR_CONTROL_EN				GPIO_Pin_0
#define   PORT_MOTOR_CONTROL_EN				GPIOC

//电机控制  A1
#define   PIN_MOTOR_CONTROL_A1				GPIO_Pin_1
#define   PORT_MOTOR_CONTROL_A1				GPIOC

//电机控制  A2
#define   PIN_MOTOR_CONTROL_A2				GPIO_Pin_10
#define   PORT_MOTOR_CONTROL_A2				GPIOC

//电机控制  B1
#define   PIN_MOTOR_CONTROL_B1				GPIO_Pin_12
#define   PORT_MOTOR_CONTROL_B1				GPIOC

//电机控制  B2
#define   PIN_MOTOR_CONTROL_B2				GPIO_Pin_11
#define   PORT_MOTOR_CONTROL_B2				GPIOC


#define   Motor_Control_En()				GPIO_SetBits(PORT_MOTOR_CONTROL_EN,PIN_MOTOR_CONTROL_EN)
#define   Motor_Control_Dis()				GPIO_ResetBits(PORT_MOTOR_CONTROL_EN,PIN_MOTOR_CONTROL_EN)

#define   Motor_A1_On()						GPIO_SetBits(PORT_MOTOR_CONTROL_A1,PIN_MOTOR_CONTROL_A1)
#define   Motor_A1_Off()					GPIO_ResetBits(PORT_MOTOR_CONTROL_A1,PIN_MOTOR_CONTROL_A1)

#define   Motor_A2_On()						GPIO_SetBits(PORT_MOTOR_CONTROL_A2,PIN_MOTOR_CONTROL_A2)
#define   Motor_A2_Off()					GPIO_ResetBits(PORT_MOTOR_CONTROL_A2,PIN_MOTOR_CONTROL_A2)

#define   Motor_B1_On()						GPIO_SetBits(PORT_MOTOR_CONTROL_B1,PIN_MOTOR_CONTROL_B1)
#define   Motor_B1_Off()					GPIO_ResetBits(PORT_MOTOR_CONTROL_B1,PIN_MOTOR_CONTROL_B1)

#define   Motor_B2_On()						GPIO_SetBits(PORT_MOTOR_CONTROL_B2,PIN_MOTOR_CONTROL_B2)
#define   Motor_B2_Off()					GPIO_ResetBits(PORT_MOTOR_CONTROL_B2,PIN_MOTOR_CONTROL_B2)


/************************************结构体************************************/

/**********************************可导出变量**********************************/


/***********************************函数实现***********************************/
void Motor_Control_Init(void);
void PrintMotor_Control_Set(MotorRunDirectTypeDef direct,bool start);				//正常打印模式下  电机走一步  由定时器控制  
void PrintMotor_CalibrationRunOnPhase(MotorRunDirectTypeDef direct,bool start);		//校准模式下  步进电机走一步(调用此函数走一步,不由定时器控制)
void Motor_Run_One_Phase(void);

#endif



























/******************************************************************************
版权所有:  
文件名:    
作者:      wangdy
创建日期:  2018/08/16
描述:      stm32单片机的串口驱动整合,将接收与发送合并至一起,并且不使用DMA发送 
其它:      
修改历史:  //修改历史记录列表,每条修改记录应包含修改日期、修改者及修改内容简述
            序号    修改时间    修改人  修改内容      
******************************************************************************/

/************************************头文件************************************/

#include "bsp_power_control.h"
#include "yc_gpio.h"

/*************************************变量*************************************/

/*************************************函数*************************************/

/*******************************************************************************
* 名称:		Power_Control_Init       
* 描述:		电源控制 IO初始化    
* 输入参数:	
* 输出参数:	无   
* 其它:		
*******************************************************************************/
void Power_Control_Init(void)
{
	//IO默认配置  

	
	GPIO_InitTypeDef GPIO_InitStruct;
	
	//电源-3V3引脚控制
	GPIO_InitStruct.GPIO_Pin = PIN_3V3_POWER_ON_OFF;
    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(PORT_3V3_POWER_ON_OFF, &GPIO_InitStruct);
	GPIO_Config(PORT_3V3_POWER_ON_OFF, PIN_3V3_POWER_ON_OFF, OUTPUT_LOW); 
	
	//电源-5V打印头和电机电源控制  
	GPIO_InitStruct.GPIO_Pin = PIN_5V_PRINTHEAD_MOTOR_ON_OFF;
    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(PORT_5V_PRINTHEAD_MOTOR_ON_OFF, &GPIO_InitStruct);
	GPIO_Config(PORT_5V_PRINTHEAD_MOTOR_ON_OFF, PIN_5V_PRINTHEAD_MOTOR_ON_OFF, OUTPUT_LOW); 
	
	Matchine_3V3_Power_Off();								//3V3电源默认关掉 	
	Matchine_5V_PrintHead_Motor_Power_Off();				//5V打印头和电机电源默认关掉 
}




























/******************************************************************************
版权所有:  
文件名:    bsp_power_control.h  
作者:      wangdy  
创建日期:  2017/12/14
描述:      定时器控制   
其它:      
修改历史:  //修改历史记录列表,每条修改记录应包含修改日期、修改者及修改内容简述
            序号    修改时间    修改人  修改内容
			????    ????/??/??  ??????  参考样式       
******************************************************************************/

/*********************************防止多次编译*********************************/
#ifndef _BSP_POWER_CONTROL_H
#define _BSP_POWER_CONTROL_H

/************************************头文件************************************/
#include <stdint.h>
#include <stdbool.h>


/************************************宏定义************************************/

#define   POWER_OFF_DELAY_TIME_COUNT	20000		//持续保持一段时间低电平则关机  


//3V3 电源控制
#define   	PIN_3V3_POWER_ON_OFF							GPIO_Pin_9
#define  	PORT_3V3_POWER_ON_OFF							GPIOA
//电源开/关
#define 	Matchine_3V3_Power_On()        					(GPIO_SetBits(PORT_3V3_POWER_ON_OFF, PIN_3V3_POWER_ON_OFF))
#define 	Matchine_3V3_Power_Off()       					(GPIO_ResetBits(PORT_3V3_POWER_ON_OFF, PIN_3V3_POWER_ON_OFF))


//5V电源输入 
#define    	PIN_5V_PRINTHEAD_MOTOR_ON_OFF					GPIO_Pin_12    //GPIO_Pin_6
#define  	PORT_5V_PRINTHEAD_MOTOR_ON_OFF					GPIOB
//电源开/关
#define 	Matchine_5V_PrintHead_Motor_Power_Off()        	(GPIO_ResetBits(PORT_5V_PRINTHEAD_MOTOR_ON_OFF, PIN_5V_PRINTHEAD_MOTOR_ON_OFF))
#define 	Matchine_5V_PrintHead_Motor_Power_On()       	(GPIO_SetBits(PORT_5V_PRINTHEAD_MOTOR_ON_OFF, PIN_5V_PRINTHEAD_MOTOR_ON_OFF))




/************************************结构体************************************/

/**********************************可导出变量**********************************/

/***********************************函数实现***********************************/
void 	Power_Control_Init(void);           //电源IO控制初始化  

#endif



























/******************************************************************************
版权所有:  深圳市普实科技有限公司 
文件名:    bsp_print_control  
作者:      wangdy
创建日期:  2018/08/16
描述:      打印芯片控制 
其它:      
修改历史:  //修改历史记录列表,每条修改记录应包含修改日期、修改者及修改内容简述
            序号    修改时间    修改人  修改内容
			????    ????/??/??  ??????  参考样式       
******************************************************************************/

/************************************头文件************************************/

#include "tools_function.h"
#include "bsp_print_control.h"
#include <stdbool.h>
#include "yc_gpio.h"
#include "printerConfig.h"
#include "driver_spi.h"

/*************************************变量*************************************/
volatile PrintHeadDataInfoTypeDef  PrintHeadDataInfo = {
	.current_offset = 0,
	.print_finish_flag = false,
	.print_all_buf = {0},
	.print_current_buf = {0},
	.print_heat_time = 0,
	.print_reversal_flsg = false,
};
/*************************************函数*************************************/

/*******************************************************************************
* 名称:		Print_Control_Init       
* 描述:		打印机控制初始化     
* 输入参数:	无  
* 输出参数:	无   
* 其它:		无   
*******************************************************************************/
void Print_Control_Init(void)
{
	GPIO_InitTypeDef GPIO_InitStruct;	
	
#if (!PRINTER_WITH_SPI)//
    //DI
	GPIO_InitStruct.GPIO_Pin = PIN_PRINTER_DATAIN;
    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(PORT_PRINTER_DATAIN, &GPIO_InitStruct);
	GPIO_Config(PORT_PRINTER_DATAIN, PIN_PRINTER_DATAIN, OUTPUT_LOW); 	
	
	//CLK
	GPIO_InitStruct.GPIO_Pin = PIN_PRINTER_CLK;
    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(PORT_PRINTER_CLK, &GPIO_InitStruct);
	GPIO_Config(PORT_PRINTER_CLK, PIN_PRINTER_CLK, OUTPUT_LOW); 
#else 
//	SPI_PrintHead_Configure();		//打印头初始化 
#endif 	
	SPI_PrintHead_GPIO_Disability();  

	//LAT
	GPIO_InitStruct.GPIO_Pin = PIN_PRINTER_LAT;
    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(PORT_PRINTER_LAT, &GPIO_InitStruct);
	GPIO_Config(PORT_PRINTER_LAT, PIN_PRINTER_LAT, OUTPUT_HIGH); 

	//STB
	GPIO_InitStruct.GPIO_Pin = PIN_PRINTER_STB;
    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(PORT_PRINTER_STB, &GPIO_InitStruct);
	GPIO_Config(PORT_PRINTER_STB, PIN_PRINTER_STB, OUTPUT_LOW); 
	
//	GPIO_InitStruct.GPIO_Pin = PIN_PRINTER_STB;
//    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
//    GPIO_Init(PORT_PRINTER_STB, &GPIO_InitStruct);
//	GPIO_Config(PORT_PRINTER_STB, PIN_PRINTER_STB, OUTPUT_HIGH); 
	//设置电平状态  
//	Printer_Power_Off();		//色带电源默认关掉 
	Printer_Lat_High();
	Printer_Stb_High();
#if (!PRINTER_WITH_SPI)//
	Printer_Clk_Low();
	Printer_DataIn_High();
#endif 
	

}


/*******************************************************************************
* 名称:		Print_Write_Line_Pixel       
* 描述:		打印机写一行像素点数据  
* 输入参数:	input_bytes - 输入的字符子串   isMirror-是否做镜像(黑底白字->白底黑字)  
* 输出参数:	无   
* 其它:		该打印头为一行96像素点,由于1字节为8bit,需要12字节凑够一行 
*******************************************************************************/
void Print_Write_Line_Pixel(uint8_t *input_bytes,bool isMirror)
{
	#if PRINTER_WITH_SPI
		uint8_t i = 0;
		uint8_t j = 0;
		static uint8_t  print_bytes[PRINTER_LINE_BYTES] = {0};
		
		memset(print_bytes,0x00,PRINTER_LINE_BYTES);
		
		if(isMirror){
			for(i = 0; i<PRINTER_LINE_BYTES; i++){
				for(j = 0; j<8; j++){
					print_bytes[i] = (((input_bytes[PRINTER_LINE_BYTES-1-i] >> (7-j)) & 0x01) << j) | print_bytes[i];
				}
			}
			SPI_PrintHead_SendData(print_bytes,PRINTER_LINE_BYTES);
		}
		else {
			memcpy(print_bytes,input_bytes,PRINTER_LINE_BYTES);
			SPI_PrintHead_SendData(print_bytes,PRINTER_LINE_BYTES);
		}	
	#else 
		uint8_t i = 0;
		uint8_t j = 0;
	
		for(i = 0; i< PRINTER_LINE_BYTES; i++)	//96/8字节数 
		{	
			for(j = 0; j < 8; j++)				//每个字节分别按位操作 
			{
				uint8_t curr_bit = 0;		//当前字节  
				
				if(! isMirror)		//非镜像  
				{
					curr_bit = ((input_bytes[PRINTER_LINE_BYTES-1-i]) >> (j)) & 0x01;
				}
				else				//镜像  
				{
					curr_bit = ((input_bytes[i]) >> (7-j)) & 0x01;
				}
			
				//如果有效字节  数据位置高电平  该位加热 
				if(curr_bit)
				{
					Printer_DataIn_High();
				}
				else 
				{
					Printer_DataIn_Low();
				}
				
				// CLK  上升沿 保存数据。打印头将高位脉冲数据位复制到最左边的位移寄存器中。
				// 其他位移寄存器中的数据位依次向右移位,为它留出空间 
				Printer_Clk_High();
				Printer_Clk_Low();
			}
		}
	#endif 
	//LAT 下降沿锁存  打印头将所有的数据位复制到锁存器中 
	Printer_Lat_Low();
	Printer_Lat_High();
}

/*******************************************************************************
* 名称:		Print_Line_Start_Write_Heat       
* 描述:		准备打印加热 
* 输入参数:	pData - 指针  
* 输出参数:	无   
* 其它:		无 
*******************************************************************************/
void Print_Line_Start_Write_Heat(uint8_t *input_bytes,bool isMirror)
{ 
	Printer_Stb_High();		//拉高电平 
	Print_Write_Line_Pixel(input_bytes, isMirror);
	Printer_Stb_Low();		//拉低电平   用于加热  
}

/*******************************************************************************
* 名称:		Print_Line_Start_Write_Heat_WithOffset       
* 描述:		准备打印加热(加像素偏移)
* 输入参数:	pData - 指针  
* 输出参数:	无   
* 其它:		无 
*******************************************************************************/
void Print_Line_Start_Write_Heat_WithOffset(uint8_t *input_bytes,bool isMirror,int8_t offset)
{ 
	static uint8_t print_offset_buf[PRINTER_LINE_BYTES];
	//先全清0 
	memset(print_offset_buf,0x00,PRINTER_LINE_BYTES);
	
	Printer_Stb_High();		//拉高电平 
	#if 1
		//偏移  
		Tools_Bytes_Offset(input_bytes,offset,print_offset_buf);
	#else 
		//目前暂时取中间部分  
		memcpy((char *)print_offset_buf,input_bytes,PRINTER_LINE_BYTES);
	#endif 
	//加热 
	Print_Write_Line_Pixel(print_offset_buf, isMirror);
	Printer_Stb_Low();		//拉低电平   用于加热  
}


/*******************************************************************************
* 名称:		Print_Line_Stop_Write_Heat       
* 描述:		停止打印加热 
* 输入参数:	pData - 指针  
* 输出参数:	无   
* 其它:		无 
*******************************************************************************/
void Print_Line_Stop_Write_Heat(void){
	Printer_Stb_High();		//拉高电平   
}


/*******************************************************************************
* 名称:		Print_Write_Line     
* 描述:		打印机写一行像素点数据  
* 输入参数:	input_bytes - 输入的字符子串 
* 输出参数:	无   
* 其它:		该打印头为一行96像素点,由于1字节为8bit,需要12字节凑够一行 
*******************************************************************************/
static void Print_Write_Line_API(uint8_t *print_buf){
#if (!PRINTER_WITH_SPI)
	uint8_t i = 0;
	uint8_t j = 0;

	for(i = 0; i< PRINTER_LINE_BYTES; i++) {	//96/8字节数 	
		for(j = 0; j < 8; j++) {				//每个字节分别按位操作 
			uint8_t curr_bit = 0;		//当前字节  
			curr_bit = ((print_buf[PRINTER_LINE_BYTES-1-i]) >> (j)) & 0x01;
			
			//如果有效字节  数据位置高电平  该位加热 
			if(curr_bit){
				Printer_DataIn_High();
			}
			else{
				Printer_DataIn_Low();
			}
			
			// CLK  上升沿 保存数据。打印头将高位脉冲数据位复制到最左边的位移寄存器中。
			// 其他位移寄存器中的数据位依次向右移位,为它留出空间 
			Printer_Clk_High();
			Printer_Clk_Low();
		}
	}
#else 
	SPI_PrintHead_SendData(print_buf,PRINTER_LINE_BYTES);
#endif 
}
/*******************************************************************************
* 名称:		Print_Write_Line_Pixel_All       
* 描述:		打印机写一行像素点数据  
* 输入参数:	input_bytes - 输入的字符子串   isMirror-是否做镜像(黑底白字->白底黑字)  
* 输出参数:	无   
* 其它:		该打印头为一行96像素点,由于1字节为8bit,需要12字节凑够一行 
*******************************************************************************/
void Print_Write_Line_Pixel_All(PrintHeadParaTypeDef para,uint8_t *input_bytes)
{
	uint8_t i = 0;
	uint8_t j = 0;
	
	//数据进行分段处理 
	#if PRINTER_WITH_STEP
		PrintHeadDataInfo.current_offset = 0;				//打印字节偏移
		PrintHeadDataInfo.print_finish_flag = false;		//打印完成标记  
		memcpy((char *)PrintHeadDataInfo.print_all_buf,input_bytes,PRINTER_LINE_BYTES);		//复制所有数据  
		memset((char *)PrintHeadDataInfo.print_current_buf,0x00,PRINTER_LINE_BYTES);		//将当前行数据清0  
		memcpy((char *)PrintHeadDataInfo.print_current_buf  + PrintHeadDataInfo.current_offset,(char *)PrintHeadDataInfo.print_all_buf + PrintHeadDataInfo.current_offset, PRINTER_WITH_STEP_BYTES);  //像素信息 复制过来 
		PrintHeadDataInfo.current_offset += PRINTER_WITH_STEP_BYTES;
		//打印数据信息 
		Print_Write_Line_Pixel_With_Para(para,(uint8_t *)PrintHeadDataInfo.print_current_buf);
	#else 
		Print_Write_Line_Pixel_With_Para(para,input_bytes);
	#endif 
}


//打印像素 
void Print_Write_Line_Pixel_With_Para(PrintHeadParaTypeDef para,const uint8_t *input_bytes){
	uint32_t PrintBitCount = 0;
	uint32_t PrintHeatTime = 0;
	
	Print_Write_Line_API((uint8_t *)input_bytes);  //发送给打印头
	Printer_Lat_Low();
	Printer_Lat_High();
	//拉低电平   用于加热  
	Printer_Stb_Low();	
	//计算加热时间 	
//	PrintBitCount = CalcPrintDataBitCount(input_bytes,PRINTER_LINE_BYTES);
//	PrintHeatTime = Calc_Heattime(para.battery,PrintBitCount,para.density);
	//重新设置加热时间 
//	TIMER_HEATTIME_STOP;
//	TIMER_HEATTIME_SET_PERIOD(PrintHeatTime);	
}




























/******************************************************************************
版权所有:  
文件名:    bsp_print_control.h   
作者:      wangdy  
创建日期:  2017/12/14
描述:      电机控制   
其它:      
修改历史:  //修改历史记录列表,每条修改记录应包含修改日期、修改者及修改内容简述
            序号    修改时间    修改人  修改内容
			????    ????/??/??  ??????  参考样式       
******************************************************************************/

/*********************************防止多次编译*********************************/
#ifndef _BSP_PRINT_CONTROL_H
#define _BSP_PRINT_CONTROL_H

/************************************头文件************************************/
#include <stdint.h>
#include <stdbool.h>


/************************************宏定义************************************/

#define  PRINTER_OFFSET_EN				1		//是否允许偏位 
#define  PRINTER_WITH_SPI				1		//使用spi发送 
#define  PRINTER_WITH_STEP				1		//是否分布加热 

#if PRINTER_WITH_STEP
	#define PRINTER_WITH_STEP_BYTES		6		//一步加热多少字节  
	#define PRINTER_WITH_STEP_COUNT		2		//一步加热多少次数 
#endif 

#define PRINTER_LINE_BYTES     			12

//----------------------普通定义--------------------
#define  PRINTER_LINE_PIXEL				96 		//一行96像素点 

//----------------------IO定义----------------------


//PRINTER-DI
#define   PIN_PRINTER_DATAIN			GPIO_Pin_13
#define   PORT_PRINTER_DATAIN			GPIOB
//PRINTER-CLK
#define   PIN_PRINTER_CLK				GPIO_Pin_14
#define   PORT_PRINTER_CLK				GPIOB
//PRINTER-LAT
#define   PIN_PRINTER_LAT				GPIO_Pin_15
#define   PORT_PRINTER_LAT				GPIOB
//PRINTER-STB
#define   PIN_PRINTER_STB				GPIO_Pin_6    //GPIO_Pin_12
#define   PORT_PRINTER_STB				GPIOB



#define   Printer_DataIn_High()			GPIO_SetBits(PORT_PRINTER_DATAIN,PIN_PRINTER_DATAIN)
#define   Printer_DataIn_Low()			GPIO_ResetBits(PORT_PRINTER_DATAIN,PIN_PRINTER_DATAIN)

#define   Printer_Clk_High()			GPIO_SetBits(PORT_PRINTER_CLK,PIN_PRINTER_CLK)
#define   Printer_Clk_Low()				GPIO_ResetBits(PORT_PRINTER_CLK,PIN_PRINTER_CLK)

#define   Printer_Lat_High()			GPIO_SetBits(PORT_PRINTER_LAT,PIN_PRINTER_LAT)
#define   Printer_Lat_Low()				GPIO_ResetBits(PORT_PRINTER_LAT,PIN_PRINTER_LAT)

#define   Printer_Stb_High()			GPIO_ResetBits(PORT_PRINTER_STB,PIN_PRINTER_STB) //GPIO_SetBits(PORT_PRINTER_STB,PIN_PRINTER_STB)
#define   Printer_Stb_Low()				GPIO_SetBits(PORT_PRINTER_STB,PIN_PRINTER_STB)   //GPIO_ResetBits(PORT_PRINTER_STB,PIN_PRINTER_STB)   //开启加热


/************************************结构体************************************/
typedef struct{
	int  	 current_offset;								//当前偏移  
	bool     print_finish_flag;								//打印完成标记 
	uint8_t  print_all_buf[PRINTER_LINE_BYTES];		//打印数据  
	uint8_t  print_current_buf[PRINTER_LINE_BYTES];	//当前打印数据  
	uint16_t print_heat_time;                       //打印一点行加热时间
	bool     print_reversal_flsg;                    //
}PrintHeadDataInfoTypeDef;

//打印参数  
typedef struct{
	uint8_t  density;	//浓度 
	uint16_t battery;	//电池电量  
}PrintHeadParaTypeDef;

/**********************************可导出变量**********************************/
extern volatile PrintHeadDataInfoTypeDef  PrintHeadDataInfo;

/***********************************函数实现***********************************/
void Print_Control_Init(void);
static void Print_Write_Line_Pixel(uint8_t *input_bytes,bool isMirror);
uint8_t Print_Line_Heat(uint8_t *pData);
void Print_Line_Start_Write_Heat(uint8_t *input_bytes,bool isMirror);
void Print_Line_Stop_Write_Heat(void);

void Print_Line_Start_Write_Heat_WithOffset(uint8_t *input_bytes,bool isMirror,int8_t offset);		//偏移打印 
void Print_Write_Line_Pixel_With_Para(PrintHeadParaTypeDef para,const uint8_t *input_bytes);		//带参数打印 
void Print_Line_Heat_Test(void);

#endif



  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值