diff --git a/chip/zgpio.cpp b/chip/zgpio.cpp index 2250b11..1d4ffb5 100644 --- a/chip/zgpio.cpp +++ b/chip/zgpio.cpp @@ -119,9 +119,6 @@ bool ZGPIO::enableClock() { return false; } - - - void regIRQGPIO(ZGPIO *gpio) { for (int i = 0; i < s_irqGPIO_num; i++) { if (s_irqGPIO[i] == gpio) { @@ -144,27 +141,36 @@ void ZGPIO::initAsInput(Pin_t pin, GPIOMode_t mode, GPIOIrqType_t irqtype, bool m_gpio = chip_get_gpio(pin); m_pinoff = chip_get_pinoff(pin); + uint32_t pulluptype = 0; + if (mode == kMode_nopull) { + pulluptype = GPIO_NOPULL; + } else if (mode == kMode_pullup) { + pulluptype = GPIO_PULLUP; + } else if (mode == kMode_pulldown) { + pulluptype = GPIO_PULLDOWN; + } + enableClock(); GPIO_InitTypeDef m_GPIO_InitStruct = {0}; if (m_irqtype == kIRQ_noIrq) { m_GPIO_InitStruct.Pin = m_pinoff; m_GPIO_InitStruct.Mode = GPIO_MODE_INPUT; - m_GPIO_InitStruct.Pull = 0; + m_GPIO_InitStruct.Pull = pulluptype; m_GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; } else if (m_irqtype == kIRQ_risingIrq) { m_GPIO_InitStruct.Pin = m_pinoff; m_GPIO_InitStruct.Mode = m_mirror ? GPIO_MODE_IT_FALLING : GPIO_MODE_IT_RISING; - m_GPIO_InitStruct.Pull = 0; + m_GPIO_InitStruct.Pull = pulluptype; m_GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; } else if (m_irqtype == kIRQ_fallingIrq) { m_GPIO_InitStruct.Pin = m_pinoff; m_GPIO_InitStruct.Mode = !m_mirror ? GPIO_MODE_IT_FALLING : GPIO_MODE_IT_RISING; - m_GPIO_InitStruct.Pull = 0; + m_GPIO_InitStruct.Pull = pulluptype; m_GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; } else if (m_irqtype == kIRQ_risingAndFallingIrq) { m_GPIO_InitStruct.Pin = m_pinoff; m_GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING; - m_GPIO_InitStruct.Pull = 0; + m_GPIO_InitStruct.Pull = pulluptype; m_GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; } diff --git a/components/step_motor_45/step_motor_45.cpp b/components/step_motor_45/step_motor_45.cpp index 538aa2e..b14b0ab 100644 --- a/components/step_motor_45/step_motor_45.cpp +++ b/components/step_motor_45/step_motor_45.cpp @@ -83,11 +83,14 @@ int32_t StepMotor45::stop() { } int32_t StepMotor45::zero_calibration() { CriticalContext cc; + ZLOGI(TAG, "zero_calibration1 %d", getzeropinstate()); if (getzeropinstate()) { + ZLOGI(TAG, "zero_calibration2"); m_calibration = true; m_pos = 0; return (int32_t)0; } + ZLOGI(TAG, "zero_calibration"); m_exec_zero_calibration_task = true; m_state = krollback; return (int32_t)0; @@ -96,14 +99,18 @@ int32_t StepMotor45::zero_calibration() { void StepMotor45::onTimIRQ1ms() { CriticalContext cc; if (m_state == kstop) { + m_lastzeropinstate = getzeropinstate(); return; + } else { + schedule(); } - schedule(); } int32_t StepMotor45::get_zero_pin_state(int32_t& state) { CriticalContext cc; state = getzeropinstate(); + // ZLOGI(TAG, "zero_calibration1 %d", getzeropinstate()); + return (int32_t)0; }