全司美特-单片机程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

67 lines
4.0 KiB

#include "hardware.hpp"
#include "zsdk/zcanreceiver/zcanreceiver.hpp"
#define TAG "PROTO"
using namespace iflytop;
/***********************************************************************************************************************
* EXT *
***********************************************************************************************************************/
void Hardware::init() {
/***********************************************************************************************************************
* 水浸传感器初始化 *
***********************************************************************************************************************/
m_evaporation_bin_water_sensor.initAsInput(EVAPORATION_BIN_WATER_SENSOR_GPIO, kxs_gpio_nopull, kxs_gpio_no_irq, EVAPORATION_BIN_WATER_SENSOR_MIRROR /*mirror*/);
m_device_bottom_water_sensor.initAsInput(DEVICE_BOTTOM_WATER_SENSOR_GPIO, kxs_gpio_nopull, kxs_gpio_no_irq, DEVICE_BOTTOM_WATER_SENSOR_MIRROR /*mirror*/);
/***********************************************************************************************************************
* 驱动器初始化 *
***********************************************************************************************************************/
m_motor_spi.init(&MOTOR_SPI);
m_motor[0].initialize(&m_motor_spi, MOTOR1_ENN, MOTOR1_CSN);
m_motor[0].setIHOLD_IRUN(1, 15, 0);
m_motor[0].setMotorShaft(true);
m_motor[0].setAcceleration(300000);
m_motor[0].setDeceleration(300000);
m_motor[1].initialize(&m_motor_spi, MOTOR2_ENN, MOTOR2_CSN);
m_motor[1].setIHOLD_IRUN(1, 15, 0);
m_motor[1].setMotorShaft(true);
m_motor[1].setAcceleration(300000);
m_motor[1].setDeceleration(300000);
int32_t chipv0 = m_motor[0].readChipVERSION(); // 5130:0x11
int32_t chipv1 = m_motor[1].readChipVERSION(); // 5130:0x11
// m_motor[0].rotate(500000);
// m_motor[1].rotate(500000);
ZLOGI(TAG, "chipv0: %x, chipv1: %x", chipv0, chipv1);
auto gstate0 = m_motor[0].getGState();
auto gstate1 = m_motor[1].getGState();
ZLOGI(TAG, "motor0: reset:%d drv_err:%d uv_cp:%d", gstate0.reset, gstate0.drv_err, gstate0.uv_cp);
ZLOGI(TAG, "motor1: reset:%d drv_err:%d uv_cp:%d", gstate1.reset, gstate1.drv_err, gstate1.uv_cp);
gstate0 = m_motor[0].getGState();
gstate1 = m_motor[1].getGState();
ZLOGI(TAG, "motor0: reset:%d drv_err:%d uv_cp:%d", gstate0.reset, gstate0.drv_err, gstate0.uv_cp);
ZLOGI(TAG, "motor1: reset:%d drv_err:%d uv_cp:%d", gstate1.reset, gstate1.drv_err, gstate1.uv_cp);
/***********************************************************************************************************************
* 三色指示灯初始化 *
***********************************************************************************************************************/
triLight_R.initAsOutput(TRI_LIGHT_R, kxs_gpio_nopull, false, false);
triLight_G.initAsOutput(TRI_LIGHT_G, kxs_gpio_nopull, false, false);
triLight_B.initAsOutput(TRI_LIGHT_B, kxs_gpio_nopull, false, false);
triLight_BEEP.initAsOutput(TRI_LIGHT_BEEP, kxs_gpio_nopull, false, false);
/***********************************************************************************************************************
* 压力传感器初始化 *
***********************************************************************************************************************/
osDelay(1500); // 等待传感器上电
m_modbusBlockHost.initialize(&PRESSURE_SENSOR_UART);
m_pressureSensorBus.init(&m_modbusBlockHost);
}