Digipots refactor / cleanup (#19690)
This commit is contained in:
@@ -24,6 +24,8 @@
|
||||
|
||||
#if ENABLED(DIGIPOT_MCP4018)
|
||||
|
||||
#include "digipot.h"
|
||||
|
||||
#include <Stream.h>
|
||||
#include <SlowSoftI2CMaster.h> // https://github.com/stawel/SlowSoftI2CMaster
|
||||
|
||||
@@ -68,7 +70,7 @@ static SlowSoftI2CMaster pots[DIGIPOT_I2C_NUM_CHANNELS] = {
|
||||
#endif
|
||||
};
|
||||
|
||||
static void i2c_send(const uint8_t channel, const byte v) {
|
||||
static void digipot_i2c_send(const uint8_t channel, const byte v) {
|
||||
if (WITHIN(channel, 0, DIGIPOT_I2C_NUM_CHANNELS - 1)) {
|
||||
pots[channel].i2c_start(((DIGIPOT_I2C_ADDRESS_A) << 1) | I2C_WRITE);
|
||||
pots[channel].i2c_write(v);
|
||||
@@ -77,12 +79,12 @@ static void i2c_send(const uint8_t channel, const byte v) {
|
||||
}
|
||||
|
||||
// This is for the MCP4018 I2C based digipot
|
||||
void digipot_i2c_set_current(const uint8_t channel, const float current) {
|
||||
void DigipotI2C::set_current(const uint8_t channel, const float current) {
|
||||
const float ival = _MIN(_MAX(current, 0), float(DIGIPOT_MCP4018_MAX_VALUE));
|
||||
i2c_send(channel, current_to_wiper(ival));
|
||||
digipot_i2c_send(channel, current_to_wiper(ival));
|
||||
}
|
||||
|
||||
void digipot_i2c_init() {
|
||||
void DigipotI2C::init() {
|
||||
LOOP_L_N(i, DIGIPOT_I2C_NUM_CHANNELS) pots[i].i2c_init();
|
||||
|
||||
// Init currents according to Configuration_adv.h
|
||||
@@ -94,7 +96,7 @@ void digipot_i2c_init() {
|
||||
#endif
|
||||
;
|
||||
LOOP_L_N(i, COUNT(digipot_motor_current))
|
||||
digipot_i2c_set_current(i, pgm_read_float(&digipot_motor_current[i]));
|
||||
set_current(i, pgm_read_float(&digipot_motor_current[i]));
|
||||
}
|
||||
|
||||
#endif // DIGIPOT_MCP4018
|
||||
|
Reference in New Issue
Block a user