From: Erik Andresen Date: Mon, 15 Feb 2021 21:10:45 +0000 (+0100) Subject: Bootloader: Allow to set i2c addr X-Git-Url: https://defiant.homedns.org/gitweb/?a=commitdiff_plain;h=1c4ce051633cb05741796f49e178f4b3bde28c4a;p=pyshared.git Bootloader: Allow to set i2c addr --- diff --git a/bootloader.py b/bootloader.py index a077d38..60e645a 100755 --- a/bootloader.py +++ b/bootloader.py @@ -14,6 +14,7 @@ CMD_WRITE = 0x3 CMD_ERASE_ALL = 0x5 CMD_JUMP = 0x6 CMD_PAGESIZE = 0x7 +CMD_I2C_ADDR = 0x80 CMD_INFO = 0x99 class bootloader: @@ -166,6 +167,9 @@ class bootloader: raise Exception("Unsupported pagesize") return i + def set_i2c_addr(self, addr): + self.run_cmd(CMD_I2C_ADDR, addr) + def to_bootloader(addr): dev = i2c(addr) @@ -179,6 +183,7 @@ if __name__ == "__main__": parser = OptionParser(usage=usage) parser.add_option("-b", "--start-bootloader", action="store_true", dest="bToBoot", default=False, help="Start Bootloader") parser.add_option("-j", "--jump", action="store_true", dest="bJump", default=False, help="Jump to Program") + parser.add_option("-s", "--set-i2c-addr", dest="i2c_addr", type="int", help="Set I2C address") (options, args) = parser.parse_args() if not args: @@ -189,6 +194,9 @@ if __name__ == "__main__": to_bootloader(addr) sleep(1) loader = bootloader(addr) + if options.i2c_addr is not None: + print "Setting i2c address to 0x%X" % (options.i2c_addr) + loader.set_i2c_addr(options.i2c_addr) if len(args) > 1: loader.load(args[1]) if options.bJump: