ESPHome 2025.5.0
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 ESP_LOGCONFIG(TAG, "Setting up A4988...");
11 if (this->sleep_pin_ != nullptr) {
12 this->sleep_pin_->setup();
13 this->sleep_pin_->digital_write(false);
14 this->sleep_pin_state_ = false;
15 }
16 this->step_pin_->setup();
17 this->step_pin_->digital_write(false);
18 this->dir_pin_->setup();
19 this->dir_pin_->digital_write(false);
20}
22 ESP_LOGCONFIG(TAG, "A4988:");
23 LOG_PIN(" Step Pin: ", this->step_pin_);
24 LOG_PIN(" Dir Pin: ", this->dir_pin_);
25 LOG_PIN(" Sleep Pin: ", this->sleep_pin_);
26 LOG_STEPPER(this);
27}
29 bool at_target = this->has_reached_target();
30 if (this->sleep_pin_ != nullptr) {
31 bool sleep_rising_edge = !sleep_pin_state_ & !at_target;
32 this->sleep_pin_->digital_write(!at_target);
33 this->sleep_pin_state_ = !at_target;
34 if (sleep_rising_edge) {
36 }
37 }
38 if (at_target) {
39 this->high_freq_.stop();
40 } else {
41 this->high_freq_.start();
42 }
43
44 int32_t dir = this->should_step_();
45 if (dir == 0)
46 return;
47
48 this->dir_pin_->digital_write(dir == 1);
50 this->step_pin_->digital_write(true);
52 this->step_pin_->digital_write(false);
53}
54
55} // namespace a4988
56} // namespace esphome
virtual void setup()=0
virtual void digital_write(bool value)=0
void stop()
Stop running the loop continuously.
Definition helpers.cpp:679
void start()
Start running the loop continuously.
Definition helpers.cpp:673
void dump_config() override
Definition a4988.cpp:21
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:28
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:30