ESPHome 2025.9.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 {
5namespace a4988 {
6
7static const char *const TAG = "a4988.stepper";
8
10 if (this->sleep_pin_ != nullptr) {
11 this->sleep_pin_->setup();
12 this->sleep_pin_->digital_write(false);
13 this->sleep_pin_state_ = false;
14 }
15 this->step_pin_->setup();
16 this->step_pin_->digital_write(false);
17 this->dir_pin_->setup();
18 this->dir_pin_->digital_write(false);
19}
21 ESP_LOGCONFIG(TAG, "A4988:");
22 LOG_PIN(" Step Pin: ", this->step_pin_);
23 LOG_PIN(" Dir Pin: ", this->dir_pin_);
24 LOG_PIN(" Sleep Pin: ", this->sleep_pin_);
25 LOG_STEPPER(this);
26}
28 bool at_target = this->has_reached_target();
29 if (this->sleep_pin_ != nullptr) {
30 bool sleep_rising_edge = !sleep_pin_state_ & !at_target;
31 this->sleep_pin_->digital_write(!at_target);
32 this->sleep_pin_state_ = !at_target;
33 if (sleep_rising_edge) {
35 }
36 }
37 if (at_target) {
38 this->high_freq_.stop();
39 } else {
40 this->high_freq_.start();
41 }
42
43 int32_t dir = this->should_step_();
44 if (dir == 0)
45 return;
46
47 this->dir_pin_->digital_write(dir == 1);
49 this->step_pin_->digital_write(true);
51 this->step_pin_->digital_write(false);
52}
53
54} // namespace a4988
55} // namespace esphome
virtual void setup()=0
virtual void digital_write(bool value)=0
void stop()
Stop running the loop continuously.
Definition helpers.cpp:570
void start()
Start running the loop continuously.
Definition helpers.cpp:564
void dump_config() override
Definition a4988.cpp:20
GPIOPin * sleep_pin_
Definition a4988.h:23
GPIOPin * dir_pin_
Definition a4988.h:22
void setup() override
Definition a4988.cpp:9
GPIOPin * step_pin_
Definition a4988.h:21
void loop() override
Definition a4988.cpp:27
HighFrequencyLoopRequester high_freq_
Definition a4988.h:25
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
Definition core.cpp:31