ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
a4988.cpp
Go to the documentation of this file.
1#include "a4988.h"
2#include "esphome/core/log.h"
3
4namespace esphome::a4988 {
5
6static const char *const TAG = "a4988.stepper";
7
9 if (this->sleep_pin_ != nullptr) {
10 this->sleep_pin_->setup();
11 this->sleep_pin_->digital_write(false);
12 this->sleep_pin_state_ = false;
13 }
14 this->step_pin_->setup();
15 this->step_pin_->digital_write(false);
16 this->dir_pin_->setup();
17 this->dir_pin_->digital_write(false);
18}
20 ESP_LOGCONFIG(TAG, "A4988:");
21 LOG_PIN(" Step Pin: ", this->step_pin_);
22 LOG_PIN(" Dir Pin: ", this->dir_pin_);
23 LOG_PIN(" Sleep Pin: ", this->sleep_pin_);
24 LOG_STEPPER(this);
25}
27 bool at_target = this->has_reached_target();
28 if (this->sleep_pin_ != nullptr) {
29 bool sleep_rising_edge = !sleep_pin_state_ & !at_target;
30 this->sleep_pin_->digital_write(!at_target);
31 this->sleep_pin_state_ = !at_target;
32 if (sleep_rising_edge) {
34 }
35 }
36 if (at_target) {
37 this->high_freq_.stop();
38 } else {
39 this->high_freq_.start();
40 }
41
42 int32_t dir = this->should_step_();
43 if (dir == 0)
44 return;
45
46 this->dir_pin_->digital_write(dir == 1);
48 this->step_pin_->digital_write(true);
50 this->step_pin_->digital_write(false);
51}
52
53} // namespace esphome::a4988
virtual void setup()=0
virtual void digital_write(bool value)=0
void stop()
Stop running the loop continuously.
Definition helpers.cpp:735
void start()
Start running the loop continuously.
Definition helpers.cpp:729
void dump_config() override
Definition a4988.cpp:19
GPIOPin * sleep_pin_
Definition a4988.h:22
GPIOPin * dir_pin_
Definition a4988.h:21
void setup() override
Definition a4988.cpp:8
GPIOPin * step_pin_
Definition a4988.h:20
void loop() override
Definition a4988.cpp:26
HighFrequencyLoopRequester high_freq_
Definition a4988.h:24
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
Definition hal.cpp:48