Browse Source

fix some bug

master
zhaohe 2 years ago
parent
commit
a260a81955
  1. 20
      chip/zgpio.cpp
  2. 9
      components/step_motor_45/step_motor_45.cpp

20
chip/zgpio.cpp

@ -119,9 +119,6 @@ bool ZGPIO::enableClock() {
return false; return false;
} }
void regIRQGPIO(ZGPIO *gpio) { void regIRQGPIO(ZGPIO *gpio) {
for (int i = 0; i < s_irqGPIO_num; i++) { for (int i = 0; i < s_irqGPIO_num; i++) {
if (s_irqGPIO[i] == gpio) { 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_gpio = chip_get_gpio(pin);
m_pinoff = chip_get_pinoff(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(); enableClock();
GPIO_InitTypeDef m_GPIO_InitStruct = {0}; GPIO_InitTypeDef m_GPIO_InitStruct = {0};
if (m_irqtype == kIRQ_noIrq) { if (m_irqtype == kIRQ_noIrq) {
m_GPIO_InitStruct.Pin = m_pinoff; m_GPIO_InitStruct.Pin = m_pinoff;
m_GPIO_InitStruct.Mode = GPIO_MODE_INPUT; 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; m_GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
} else if (m_irqtype == kIRQ_risingIrq) { } else if (m_irqtype == kIRQ_risingIrq) {
m_GPIO_InitStruct.Pin = m_pinoff; m_GPIO_InitStruct.Pin = m_pinoff;
m_GPIO_InitStruct.Mode = m_mirror ? GPIO_MODE_IT_FALLING : GPIO_MODE_IT_RISING; 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; m_GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
} else if (m_irqtype == kIRQ_fallingIrq) { } else if (m_irqtype == kIRQ_fallingIrq) {
m_GPIO_InitStruct.Pin = m_pinoff; m_GPIO_InitStruct.Pin = m_pinoff;
m_GPIO_InitStruct.Mode = !m_mirror ? GPIO_MODE_IT_FALLING : GPIO_MODE_IT_RISING; 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; m_GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
} else if (m_irqtype == kIRQ_risingAndFallingIrq) { } else if (m_irqtype == kIRQ_risingAndFallingIrq) {
m_GPIO_InitStruct.Pin = m_pinoff; m_GPIO_InitStruct.Pin = m_pinoff;
m_GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING; 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; m_GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
} }

9
components/step_motor_45/step_motor_45.cpp

@ -83,11 +83,14 @@ int32_t StepMotor45::stop() {
} }
int32_t StepMotor45::zero_calibration() { int32_t StepMotor45::zero_calibration() {
CriticalContext cc; CriticalContext cc;
ZLOGI(TAG, "zero_calibration1 %d", getzeropinstate());
if (getzeropinstate()) { if (getzeropinstate()) {
ZLOGI(TAG, "zero_calibration2");
m_calibration = true; m_calibration = true;
m_pos = 0; m_pos = 0;
return (int32_t)0; return (int32_t)0;
} }
ZLOGI(TAG, "zero_calibration");
m_exec_zero_calibration_task = true; m_exec_zero_calibration_task = true;
m_state = krollback; m_state = krollback;
return (int32_t)0; return (int32_t)0;
@ -96,14 +99,18 @@ int32_t StepMotor45::zero_calibration() {
void StepMotor45::onTimIRQ1ms() { void StepMotor45::onTimIRQ1ms() {
CriticalContext cc; CriticalContext cc;
if (m_state == kstop) { if (m_state == kstop) {
m_lastzeropinstate = getzeropinstate();
return; return;
} else {
schedule();
} }
schedule();
} }
int32_t StepMotor45::get_zero_pin_state(int32_t& state) { int32_t StepMotor45::get_zero_pin_state(int32_t& state) {
CriticalContext cc; CriticalContext cc;
state = getzeropinstate(); state = getzeropinstate();
// ZLOGI(TAG, "zero_calibration1 %d", getzeropinstate());
return (int32_t)0; return (int32_t)0;
} }

Loading…
Cancel
Save