diff --git a/usrc/main.cpp b/usrc/main.cpp index cc59029..99c5851 100644 --- a/usrc/main.cpp +++ b/usrc/main.cpp @@ -21,31 +21,51 @@ IflytopCanProtocolStackProcesser m_protocolStack; TMC4361A m_motora; TMC4361A m_motorb; +ZGPIO arm_sensor1_gpio; +ZGPIO arm_sensor2_gpio; +ZGPIO arm_sensor3_gpio; +ZGPIO arm_sensor4_gpio; +ZGPIO arm_sensor5_gpio; +ZGPIO arm_sensor6_gpio; +ZGPIO arm_sensor7_gpio; +ZGPIO arm_sensor8_gpio; + +ZGPIO debuglight; + +ZGPIO tmc_motor1_spi_select1_io; +ZGPIO tmc_motor1_nfreeze_io; +ZGPIO tmc_motor1_nreset_io; +ZGPIO tmc_motor1_sub_ic_enn_io; +ZGPIO tmc_motor2_spi_select1_io; +ZGPIO tmc_motor2_nfreeze_io; +ZGPIO tmc_motor2_nreset_io; +ZGPIO tmc_motor2_sub_ic_enn_io; + void input_sensors_init() { - ARM_SENSOR1_GPIO.initAsInput(STM32_GPIO::kInput_risingAndFallingIrq, true); - ARM_SENSOR2_GPIO.initAsInput(STM32_GPIO::kInput_risingAndFallingIrq, true); - ARM_SENSOR3_GPIO.initAsInput(); - ARM_SENSOR4_GPIO.initAsInput(); - ARM_SENSOR5_GPIO.initAsInput(); - ARM_SENSOR6_GPIO.initAsInput(); - ARM_SENSOR7_GPIO.initAsInput(STM32_GPIO::kInput_risingAndFallingIrq, true); - ARM_SENSOR8_GPIO.initAsInput(STM32_GPIO::kInput_risingAndFallingIrq, true); + arm_sensor1_gpio.initAsInput(ARM_SENSOR1_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_risingAndFallingIrq, true); + arm_sensor2_gpio.initAsInput(ARM_SENSOR2_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_risingAndFallingIrq, true); + arm_sensor3_gpio.initAsInput(ARM_SENSOR3_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false); + arm_sensor4_gpio.initAsInput(ARM_SENSOR4_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false); + arm_sensor5_gpio.initAsInput(ARM_SENSOR5_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false); + arm_sensor6_gpio.initAsInput(ARM_SENSOR6_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false); + arm_sensor7_gpio.initAsInput(ARM_SENSOR7_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_risingAndFallingIrq, true); + arm_sensor8_gpio.initAsInput(ARM_SENSOR8_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_risingAndFallingIrq, true); } uint32_t intput_sensors_get_table0() { uint32_t val = 0; - val |= ARM_SENSOR1_GPIO.getStateUint32() << 1; - val |= ARM_SENSOR2_GPIO.getStateUint32() << 2; - val |= ARM_SENSOR3_GPIO.getStateUint32() << 3; - val |= ARM_SENSOR4_GPIO.getStateUint32() << 4; - val |= ARM_SENSOR5_GPIO.getStateUint32() << 5; - val |= ARM_SENSOR6_GPIO.getStateUint32() << 6; - val |= ARM_SENSOR7_GPIO.getStateUint32() << 7; - val |= ARM_SENSOR8_GPIO.getStateUint32() << 8; + val |= arm_sensor1_gpio.getStateUint32() << 1; + val |= arm_sensor2_gpio.getStateUint32() << 2; + val |= arm_sensor3_gpio.getStateUint32() << 3; + val |= arm_sensor4_gpio.getStateUint32() << 4; + val |= arm_sensor5_gpio.getStateUint32() << 5; + val |= arm_sensor6_gpio.getStateUint32() << 6; + val |= arm_sensor7_gpio.getStateUint32() << 7; + val |= arm_sensor8_gpio.getStateUint32() << 8; return val; } -STM32_GPIO *input_sensors_get_arm1_homegpio() { return &ARM_SENSOR8_GPIO; } -STM32_GPIO *input_sensors_get_arm2_homegpio() { return &ARM_SENSOR7_GPIO; } +ZGPIO *input_sensors_get_arm1_homegpio() { return &arm_sensor8_gpio; } +ZGPIO *input_sensors_get_arm2_homegpio() { return &arm_sensor7_gpio; } icps::error_t Main::onHostRegisterWriteEvent(IflytopCanProtocolStackProcesser *processer, icps::WriteEvent *event) {} icps::error_t Main::onHostRegisterReadEvent(IflytopCanProtocolStackProcesser *processer, icps::ReadEvent *event) {} @@ -60,8 +80,8 @@ void Main::run() { ZLOGI(TAG, "robotic_core_xy:%s", VERSION); - DEBUG_LIGHT_GPIO.initAsOutput(true); - ZHAL_CORE_REG(200, { DEBUG_LIGHT_GPIO.toggleState(); }); + debuglight.initAsOutput(DEBUG_LIGHT_GPIO, ZGPIO::kMode_nopull, false, false); + ZHAL_CORE_REG(200, { debuglight.toggleState(); }); /******************************************************************************* * GPIO输入初始化 * @@ -72,21 +92,22 @@ void Main::run() { /******************************************************************************* * 电机初始化 * *******************************************************************************/ - TMC_MOTOR1_SPI_SELECT1_IO.initAsOutput(true); - TMC_MOTOR1_nFREEZE_IO.initAsOutput(true); - TMC_MOTOR1_nRESET_IO.initAsOutput(true); - TMC_MOTOR1_SUB_IC_ENN_IO.initAsOutput(true); - TMC_MOTOR2_SPI_SELECT1_IO.initAsOutput(true); - TMC_MOTOR2_nFREEZE_IO.initAsOutput(true); - TMC_MOTOR2_nRESET_IO.initAsOutput(true); - TMC_MOTOR2_SUB_IC_ENN_IO.initAsOutput(true); + tmc_motor1_spi_select1_io.initAsOutput(TMC_MOTOR1_SPI_SELECT1_IO, ZGPIO::kMode_nopull, false, true); + tmc_motor1_nfreeze_io.initAsOutput(TMC_MOTOR1_nFREEZE_IO, ZGPIO::kMode_nopull, false, true); + tmc_motor1_nreset_io.initAsOutput(TMC_MOTOR1_nRESET_IO, ZGPIO::kMode_nopull, false, true); + tmc_motor1_sub_ic_enn_io.initAsOutput(TMC_MOTOR1_SUB_IC_ENN_IO, ZGPIO::kMode_nopull, false, true); + tmc_motor2_spi_select1_io.initAsOutput(TMC_MOTOR2_SPI_SELECT1_IO, ZGPIO::kMode_nopull, false, true); + tmc_motor2_nfreeze_io.initAsOutput(TMC_MOTOR2_nFREEZE_IO, ZGPIO::kMode_nopull, false, true); + tmc_motor2_nreset_io.initAsOutput(TMC_MOTOR2_nRESET_IO, ZGPIO::kMode_nopull, false, true); + tmc_motor2_sub_ic_enn_io.initAsOutput(TMC_MOTOR2_SUB_IC_ENN_IO, ZGPIO::kMode_nopull, false, true); + { TMC4361A::cfg_t motora_cfg = {.spi = &TMC_MOTOR_SPI, - .csgpio = &TMC_MOTOR1_SPI_SELECT1_IO, - .resetPin = &TMC_MOTOR1_nRESET_IO, - .fREEZEPin = &TMC_MOTOR1_nFREEZE_IO, + .csgpio = &tmc_motor1_spi_select1_io, + .resetPin = &tmc_motor1_nreset_io, + .fREEZEPin = &tmc_motor1_nfreeze_io, .ennPin = NULL, - .driverIC_ennPin = &TMC_MOTOR1_SUB_IC_ENN_IO, + .driverIC_ennPin = &tmc_motor1_sub_ic_enn_io, .driverIC_resetPin = NULL}; m_motora.initialize(&motora_cfg); @@ -97,11 +118,11 @@ void Main::run() { { TMC4361A::cfg_t motorb_cfg = {.spi = &TMC_MOTOR_SPI, - .csgpio = &TMC_MOTOR2_SPI_SELECT1_IO, - .resetPin = &TMC_MOTOR2_nRESET_IO, - .fREEZEPin = &TMC_MOTOR2_nFREEZE_IO, + .csgpio = &tmc_motor2_spi_select1_io, + .resetPin = &tmc_motor2_nreset_io, + .fREEZEPin = &tmc_motor2_nfreeze_io, .ennPin = NULL, - .driverIC_ennPin = &TMC_MOTOR2_SUB_IC_ENN_IO, + .driverIC_ennPin = &tmc_motor2_sub_ic_enn_io, .driverIC_resetPin = NULL}; m_motorb.initialize(&motorb_cfg); @@ -114,19 +135,19 @@ void Main::run() { * 扫码枪初始化 * *******************************************************************************/ { - // static ZUART uart; - // PB6.initAsOutput(STM32_GPIO::kOutput_nopull, true, false); - // ZUART::cfg_t cfg = { - // .name = "CODE_SCANER_UART", - // .huart = &CODE_SCANER_UART, - // .rxbuffersize = 300, - // .rxovertime_ms = 10, - // }; - // uart.initialize(&cfg,[](){}) - // uart.initialize_basic("CODE_SCANER_UART", &m_hardware, &CODE_SCANER_UART); - // uart.initialize_setRxBuffer(300); - // uart.initialize_setRxOvertime(33); - // uart.initialize_finished(); + // static ZUART uart; + // PB6.initAsOutput(STM32_GPIO::kOutput_nopull, true, false); + // ZUART::cfg_t cfg = { + // .name = "CODE_SCANER_UART", + // .huart = &CODE_SCANER_UART, + // .rxbuffersize = 300, + // .rxovertime_ms = 10, + // }; + // uart.initialize(&cfg,[](){}) + // uart.initialize_basic("CODE_SCANER_UART", &m_hardware, &CODE_SCANER_UART); + // uart.initialize_setRxBuffer(300); + // uart.initialize_setRxOvertime(33); + // uart.initialize_finished(); } /*******************************************************************************