6 namespace grove_tb6612fng {
8 static const char *
const TAG =
"GroveMotorDriveTB6612FNG";
10 static const uint8_t GROVE_MOTOR_DRIVER_I2C_CMD_BRAKE = 0x00;
11 static const uint8_t GROVE_MOTOR_DRIVER_I2C_CMD_STOP = 0x01;
12 static const uint8_t GROVE_MOTOR_DRIVER_I2C_CMD_CW = 0x02;
13 static const uint8_t GROVE_MOTOR_DRIVER_I2C_CMD_CCW = 0x03;
14 static const uint8_t GROVE_MOTOR_DRIVER_I2C_CMD_STANDBY = 0x04;
15 static const uint8_t GROVE_MOTOR_DRIVER_I2C_CMD_NOT_STANDBY = 0x05;
16 static const uint8_t GROVE_MOTOR_DRIVER_I2C_CMD_STEPPER_RUN = 0x06;
17 static const uint8_t GROVE_MOTOR_DRIVER_I2C_CMD_STEPPER_STOP = 0x07;
18 static const uint8_t GROVE_MOTOR_DRIVER_I2C_CMD_STEPPER_KEEP_RUN = 0x08;
19 static 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!");
67 speed = clamp<int16_t>(
speed, -255, 255);
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) {
125 rpm = clamp<uint16_t>(rpm, 1, 300);
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;
156 rpm = clamp<uint16_t>(rpm, 1, 300);
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");
void dc_motor_brake(uint8_t channel)
void status_set_warning(const char *message="unspecified")
No error found during execution of method.
BedjetMode mode
BedJet operating mode.
void dump_config() override
void dc_motor_run(uint8_t channel, int16_t speed)
void set_i2c_addr(uint8_t addr)
void stepper_run(StepperModeTypeT mode, int16_t steps, uint16_t rpm)
virtual void mark_failed()
Mark this component as failed.
void dc_motor_stop(uint8_t channel)
Implementation of SPI Controller mode.
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 stepper_keep_run(StepperModeTypeT mode, uint16_t rpm, bool is_cw)
void set_i2c_address(uint8_t address)
We store the address of the device on the bus.