6namespace grove_tb6612fng {
8static const char *
const TAG =
"GroveMotorDriveTB6612FNG";
10static const uint8_t GROVE_MOTOR_DRIVER_I2C_CMD_BRAKE = 0x00;
11static const uint8_t GROVE_MOTOR_DRIVER_I2C_CMD_STOP = 0x01;
12static const uint8_t GROVE_MOTOR_DRIVER_I2C_CMD_CW = 0x02;
13static const uint8_t GROVE_MOTOR_DRIVER_I2C_CMD_CCW = 0x03;
14static const uint8_t GROVE_MOTOR_DRIVER_I2C_CMD_STANDBY = 0x04;
15static const uint8_t GROVE_MOTOR_DRIVER_I2C_CMD_NOT_STANDBY = 0x05;
16static const uint8_t GROVE_MOTOR_DRIVER_I2C_CMD_STEPPER_RUN = 0x06;
17static const uint8_t GROVE_MOTOR_DRIVER_I2C_CMD_STEPPER_STOP = 0x07;
18static const uint8_t GROVE_MOTOR_DRIVER_I2C_CMD_STEPPER_KEEP_RUN = 0x08;
19static const uint8_t GROVE_MOTOR_DRIVER_I2C_CMD_SET_ADDR = 0x11;
22 ESP_LOGCONFIG(TAG,
"GroveMotorDriveTB6612FNG:");
27 ESP_LOGCONFIG(TAG,
"Setting up Grove Motor Drive TB6612FNG ...");
37 ESP_LOGW(TAG,
"Set standby failed!");
47 ESP_LOGW(TAG,
"Set not standby failed!");
55 if (addr == 0x00 || addr >= 0x80) {
59 ESP_LOGW(TAG,
"Set new i2c address failed!");
73 buffer_[1] = (uint8_t) (-
speed);
78 ESP_LOGW(TAG,
"Run motor failed!");
84 ESP_LOGW(TAG,
"Run motor failed!");
93 ESP_LOGW(TAG,
"Break motor failed!");
101 ESP_LOGW(TAG,
"Stop dc motor failed!");
110 uint16_t ms_per_step = 0;
116 else if (steps == 0) {
119 }
else if (steps == INT16_MIN) {
127 ms_per_step = (uint16_t) (3000.0 / (
float) rpm);
131 buffer_[3] = (steps >> 8);
132 buffer_[4] = ms_per_step;
133 buffer_[5] = (ms_per_step >> 8);
136 ESP_LOGW(TAG,
"Run stepper failed!");
144 ESP_LOGW(TAG,
"Send stop stepper failed!");
152 uint8_t cw = (is_cw) ? 5 : 4;
154 uint16_t ms_per_step = 0;
157 ms_per_step = (uint16_t) (3000.0 / (
float) rpm);
161 buffer_[2] = ms_per_step;
162 buffer_[3] = (ms_per_step >> 8);
165 ESP_LOGW(TAG,
"Write stepper keep run failed");
BedjetMode mode
BedJet operating mode.
virtual void mark_failed()
Mark this component as failed.
void status_set_warning(const char *message="unspecified")
void stepper_keep_run(StepperModeTypeT mode, uint16_t rpm, bool is_cw)
void dc_motor_brake(uint8_t channel)
void dc_motor_run(uint8_t channel, int16_t speed)
void stepper_run(StepperModeTypeT mode, int16_t steps, uint16_t rpm)
void dump_config() override
void set_i2c_addr(uint8_t addr)
void dc_motor_stop(uint8_t channel)
ErrorCode write_register(uint8_t a_register, const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a specific register in the I²C device
void set_i2c_address(uint8_t address)
We store the address of the device on the bus.
@ ERROR_OK
No error found during execution of method.
Providing packet encoding functions for exchanging data with a remote host.
constexpr const T & clamp(const T &v, const T &lo, const T &hi, Compare comp)