Skip to content

Commit

Permalink
i2c: drop i2c_modify_bits
Browse files Browse the repository at this point in the history
No longer used and niche

Signed-off-by: Timofey Titovets <[email protected]>
  • Loading branch information
nefelim4ag authored and KevinOConnor committed Sep 22, 2024
1 parent 71433b8 commit 8a5801a
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 50 deletions.
18 changes: 1 addition & 17 deletions klippy/extras/bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def __init__(self, mcu, bus, addr, speed, sw_pins=None):
% (self.oid, speed, addr))
self.cmd_queue = self.mcu.alloc_command_queue()
self.mcu.register_config_callback(self.build_config)
self.i2c_write_cmd = self.i2c_read_cmd = self.i2c_modify_bits_cmd = None
self.i2c_write_cmd = self.i2c_read_cmd = None
def get_oid(self):
return self.oid
def get_mcu(self):
Expand All @@ -180,9 +180,6 @@ def build_config(self):
"i2c_read oid=%c reg=%*s read_len=%u",
"i2c_read_response oid=%c response=%*s", oid=self.oid,
cq=self.cmd_queue)
self.i2c_modify_bits_cmd = self.mcu.lookup_command(
"i2c_modify_bits oid=%c reg=%*s clear_set_bits=%*s",
cq=self.cmd_queue)
def i2c_write(self, data, minclock=0, reqclock=0):
if self.i2c_write_cmd is None:
# Send setup message via mcu initialization
Expand All @@ -197,19 +194,6 @@ def i2c_write_wait_ack(self, data, minclock=0, reqclock=0):
minclock=minclock, reqclock=reqclock)
def i2c_read(self, write, read_len):
return self.i2c_read_cmd.send([self.oid, write, read_len])
def i2c_modify_bits(self, reg, clear_bits, set_bits,
minclock=0, reqclock=0):
clearset = clear_bits + set_bits
if self.i2c_modify_bits_cmd is None:
# Send setup message via mcu initialization
reg_msg = "".join(["%02x" % (x,) for x in reg])
clearset_msg = "".join(["%02x" % (x,) for x in clearset])
self.mcu.add_config_cmd(
"i2c_modify_bits oid=%d reg=%s clear_set_bits=%s" % (
self.oid, reg_msg, clearset_msg), is_init=True)
return
self.i2c_modify_bits_cmd.send([self.oid, reg, clearset],
minclock=minclock, reqclock=reqclock)

def MCU_I2C_from_config(config, default_addr=None, default_speed=100000):
# Load bus parameters
Expand Down
33 changes: 0 additions & 33 deletions src/i2ccmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,36 +81,3 @@ command_i2c_read(uint32_t * args)
sendf("i2c_read_response oid=%c response=%*s", oid, data_len, data);
}
DECL_COMMAND(command_i2c_read, "i2c_read oid=%c reg=%*s read_len=%u");

void
command_i2c_modify_bits(uint32_t *args)
{
uint8_t oid = args[0];
struct i2cdev_s *i2c = oid_lookup(oid, command_config_i2c);
uint8_t reg_len = args[1];
uint8_t *reg = command_decode_ptr(args[2]);
uint32_t clear_set_len = args[3];
if (clear_set_len % 2 != 0)
shutdown("i2c_modify_bits: Odd number of bits!");
uint8_t data_len = clear_set_len/2;
uint8_t *clear_set = command_decode_ptr(args[4]);
uint8_t receive_data[reg_len + data_len];
uint_fast8_t flags = i2c->flags;
memcpy(receive_data, reg, reg_len);
if (CONFIG_WANT_SOFTWARE_I2C && flags & IF_SOFTWARE)
i2c_software_read(
i2c->i2c_software, reg_len, reg, data_len, receive_data + reg_len);
else
i2c_read(
i2c->i2c_config, reg_len, reg, data_len, receive_data + reg_len);
for (int i = 0; i < data_len; i++) {
receive_data[reg_len + i] &= ~clear_set[i];
receive_data[reg_len + i] |= clear_set[data_len + i];
}
if (CONFIG_WANT_SOFTWARE_I2C && flags & IF_SOFTWARE)
i2c_software_write(i2c->i2c_software, reg_len + data_len, receive_data);
else
i2c_write(i2c->i2c_config, reg_len + data_len, receive_data);
}
DECL_COMMAND(command_i2c_modify_bits,
"i2c_modify_bits oid=%c reg=%*s clear_set_bits=%*s");

0 comments on commit 8a5801a

Please sign in to comment.