]> defiant.homedns.org Git - pyshared.git/commitdiff
Added jump to bootloader
authorErik Andresen <erik@vontaene.de>
Fri, 21 Jul 2017 18:29:03 +0000 (20:29 +0200)
committerErik Andresen <erik@vontaene.de>
Fri, 21 Jul 2017 18:29:03 +0000 (20:29 +0200)
Added pwm to bus_pirate

bootloader.py
bus_pirate.py

index 04370cd8b30a6eafc5d3c345a6fbcd2e9ea5730e..1f5707a884e8745275d9be6166d3cfc35dc1f83f 100755 (executable)
@@ -179,9 +179,12 @@ if __name__ == "__main__":
        usage = "usage: %prog [options] addr [ihex]"
        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")
 
        (options, args) = parser.parse_args()
-       if len(args) > 0:
+       if not args:
+               print "Missing Address"
+       else:
                addr = int(args[0], 16)
                if options.bToBoot:
                        to_bootloader(addr)
index 4ef9c61d4eacf79612be535156477e553b4d770b..52a1c5c1b759fc2f8f20fd633b0fbbbc9ec4f3f9 100644 (file)
@@ -64,6 +64,29 @@ class BP:
                v = struct.unpack(">h", s)
                return v[0]/1024.0*6.6
 
+       # http://codepad.org/qtYpZmIF
+       def pwm(self, freq, duty_cycle):
+               lPrescaler = {0:1, 1:8 , 2:64, 3:256}
+               Fosc = 32e6
+               Tcy = 2.0 / Fosc
+               period = 1.0 / freq
+               prescaler = 1
+
+               # find needed prescaler
+               for i in range(4):
+                       prescaler = lPrescaler[i]
+                       PRy = period * 1.0 / (Tcy * prescaler)
+                       PRy = int(PRy - 1)
+                       OCR = int(PRy * duty_cycle)
+
+                       if PRy < (2 ** 16 - 1):
+                               break # valid value for PRy, keep values
+
+               cmd = struct.pack(">BBHH", 0b00010010, prescaler, duty_cycle, period)
+               ret = self.command(cmd, 1)
+               if ord(ret) != 0x1:
+                       raise Exception()
+
        def spi_command(self, cmd):
                ret = self.command(cmd, 1)
                if ord(ret) != 0x1: