From: Erik Andresen Date: Tue, 20 Dec 2016 20:45:24 +0000 (+0100) Subject: bus pirate/i2c: support different speeds X-Git-Url: https://defiant.homedns.org/gitweb/?a=commitdiff_plain;h=b72bb34f3d40f0e0b6178f261403f93cbda82d95;p=pyshared.git bus pirate/i2c: support different speeds --- diff --git a/bus_pirate.py b/bus_pirate.py index 08305f5..f64c8e3 100644 --- a/bus_pirate.py +++ b/bus_pirate.py @@ -107,12 +107,19 @@ class BP: state = self.update_io() return state & (1 << dPinToBit[pin]) - def mode_i2c(self, bEnablePower=False, bEnablePullup=False): + def mode_i2c(self, bEnablePower=False, bEnablePullup=False, iSpeedkHz=100): if self.command(chr(0x2), 4) != "I2C1": raise Exception() - # 100kHz - ret = self.command(chr(0b01100010), 1) + dSpeeds = { + 5: 0x0, + 50: 0x1, + 100: 0x2, + 400: 0x3, + } + if iSpeedkHz not in dSpeeds.keys(): + raise Exception("Invalid I2C speed") + ret = self.command(chr(0b01100000 | dSpeeds[iSpeedkHz]), 1) if ord(ret) != 0x1: raise Exception()