]> defiant.homedns.org Git - pyshared.git/commitdiff
Bootloader: Allow to set i2c addr
authorErik Andresen <erik@vontaene.de>
Mon, 15 Feb 2021 21:10:45 +0000 (22:10 +0100)
committerErik Andresen <erik@vontaene.de>
Mon, 15 Feb 2021 21:10:45 +0000 (22:10 +0100)
bootloader.py

index a077d38db510f687759670608f86662d1b6f87b3..60e645a38de61a715e478b6c48cbf07b98f09711 100755 (executable)
@@ -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: