#include "board_stm32.h" #include "bsplib.h" #include Board_STM32 Board_STM32::board; #define CONFIG_EEPROM_BASE ((uint32_t)0x800F400) #ifndef MOTOR_DRIVER #define MOTOR_DRIVER MOTOR_DRIVER_TB6612 #endif Board* Board::get() { return &Board_STM32::board; } Board_STM32::Board_STM32() { } Board_STM32::~Board_STM32() { } void Board_STM32::init() { PB_System_Timer_Init(); DOInit(); DIInit(); } void Board_STM32::enable_irq() { } void Board_STM32::disable_irq() { } void Board_STM32::usart_debug_init() { PB_USART_Init(1, 115200, 0); } #ifdef __cplusplus extern "C" { #endif int fputc(int ch, FILE *f) { PB_USART_Put_Char(1, ch); return (ch); } #ifdef __cplusplus } #endif void Board_STM32::usart_init(unsigned char num, unsigned long buad) { if (num == (unsigned char)USART_1) { PB_USART_Init(1, 115200, 0); } else if (num == (unsigned char)USART_3) { PB_USART_Init(3, 115200, 0); } } Queue* Board_STM32::usart_getDataQueue(unsigned char num) { if (num == (unsigned char)USART_1) { } else if (num == (unsigned char)USART_3) { return &usart3_queue; } return 0; } void Board_STM32::usart_write(unsigned char num, unsigned char ch) { if (num == (unsigned char)USART_1) { PB_USART_Put_Char(1, ch); } else if (num == (unsigned char)USART_3) { PB_USART_Put_Char(3, ch); } } void Board_STM32::usart_write(unsigned char num, unsigned char* data, unsigned char len) { if (num == (unsigned char)USART_1) { while(len--) PB_USART_Put_Char(1, *data++); } else if (num == (unsigned char)USART_3) { while(len--) PB_USART_Put_Char(3, *data++); } } void Board_STM32::set_config(unsigned char* data, unsigned short len) { if (len%2==0) { PB_Flash_EnableWrite(); for(int i=0;i 5) { #if MOTOR_DRIVER == MOTOR_DRIVER_TB6612 GPIO_SetBits(GPIOB, GPIO_Pin_13); PB_Set_PWM(TIM2, 4, (uint16_t)pwm_value); #else PB_Set_PWM(TIM2, 4, (uint16_t)pwm_value); PB_Set_PWM(TIM1, 1, 0); #endif } else if (pwm_value < -5) { #if MOTOR_DRIVER == MOTOR_DRIVER_TB6612 GPIO_ResetBits(GPIOB, GPIO_Pin_13); PB_Set_PWM(TIM2, 4, (uint16_t)-pwm_value); #else PB_Set_PWM(TIM1, 1, (uint16_t)-pwm_value); PB_Set_PWM(TIM2, 4, 0); #endif } else { #if MOTOR_DRIVER == MOTOR_DRIVER_TB6612 GPIO_ResetBits(GPIOB, GPIO_Pin_13); PB_Set_PWM(TIM2, 4, 0); #else PB_Set_PWM(TIM1, 1, 0); PB_Set_PWM(TIM2, 4, 0); #endif } } else if (num == MOTOR_2) { if (pwm_value > 5) { #if MOTOR_DRIVER == MOTOR_DRIVER_TB6612 GPIO_ResetBits(GPIOB, GPIO_Pin_14); PB_Set_PWM(TIM2, 3, (uint16_t)pwm_value); #else PB_Set_PWM(TIM1, 4, (uint16_t)pwm_value); PB_Set_PWM(TIM2, 3, 0); #endif } else if (pwm_value < -5) { #if MOTOR_DRIVER == MOTOR_DRIVER_TB6612 GPIO_SetBits(GPIOB, GPIO_Pin_14); PB_Set_PWM(TIM2, 3, (uint16_t)-pwm_value); #else PB_Set_PWM(TIM1, 4, 0); PB_Set_PWM(TIM2, 3, (uint16_t)-pwm_value); #endif } else { #if MOTOR_DRIVER == MOTOR_DRIVER_TB6612 GPIO_ResetBits(GPIOB, GPIO_Pin_14); PB_Set_PWM(TIM2, 3, 0); #else PB_Set_PWM(TIM1, 4, 0); PB_Set_PWM(TIM2, 3, 0); #endif } } else if (num == MOTOR_3) { } else if (num == MOTOR_4) { } } unsigned long Board_STM32::getTickCount() { return GetSystemTime() / 1000; } void Board_STM32::encoder_init(unsigned char motor_id) { if (motor_id == MOTOR_1) { Encoder_Init(TIM3, 0); } else if (motor_id == MOTOR_2) { Encoder_Init(TIM4, 0); } } long Board_STM32::getEncoderCount(unsigned char motorId) { if (motorId == MOTOR_1) { return GetEncoderTIM3(); } else if (motorId == MOTOR_2) { return GetEncoderTIM4(); } return 0; } void Board_STM32::i2c_init() { PB_I2C_Init(); } unsigned char Board_STM32::i2c_write_byte(unsigned char equipment_address, unsigned char reg_address, unsigned char pt_char) { return PB_I2C_Write_Byte(equipment_address, reg_address, pt_char); } unsigned char Board_STM32::i2c_write_buf(unsigned char equipment_address, unsigned char reg_address, unsigned char* pt_char, unsigned char size) { return PB_I2C_Write_Buf(equipment_address, reg_address, pt_char, size); } unsigned char Board_STM32::i2c_read_byte(unsigned char equipment_address, unsigned char reg_address, unsigned char* pt_char) { return PB_I2C_Read_Byte(equipment_address, reg_address, pt_char); } unsigned char Board_STM32::i2c_read_buf(unsigned char equipment_address, unsigned char reg_address, unsigned char* pt_char, unsigned char size) { return PB_I2C_Read_Buf(equipment_address, reg_address, pt_char, size); }