Example #1
0
 def set_watchdog_prescale(self, val):
     val = Utils.to_int(val)
     wd_vals = {2: 0, 4: 1, 8: 2, 16: 3, 32: 4, 64: 5, 128: 6, 256: 7}
     if val not in wd_vals.keys():
         raise ValueError("must be one of %s" % list(wd_vals.keys()))
     self.msr[0] &= 0xf8
     self.msr[0] |= wd_vals[val]
Example #2
0
 def set_flash_split(self, val):
     num_val = Utils.to_int(val)
     if num_val < 512 or num_val > 65024 or (num_val % 512) != 0:
         raise ValueError(
             "must be between 512 and 65024 bytes and a multiple of 512 bytes"
         )
     self.msr[4] = num_val // 256
Example #3
0
 def set_osc_stable_delay(self, val):
     val = Utils.to_int(val)
     osc_vals = {4096: 0, 8192: 1, 16384: 2, 32768: 3}
     if val not in osc_vals.keys():
         raise ValueError("must be one of %s" % list(osc_vals.keys()))
     self.msr[0] &= 0xcf
     self.msr[0] |= osc_vals[val] << 4
Example #4
0
 def set_watchdog_prescale(self, val):
     val = Utils.to_int(val)
     wd_vals = {2: 0, 4: 1, 8: 2, 16: 3, 32: 4, 64: 5, 128: 6, 256: 7}
     if val not in wd_vals.keys():
         raise ValueError("must be one of %s" % list(wd_vals.keys()))
     self.msr[3] &= 0xf8
     self.msr[3] |= wd_vals[val]
Example #5
0
 def set_osc_stable_delay(self, val):
     val = Utils.to_int(val)
     osc_vals = {4096: 0, 8192: 1, 16384: 2, 32768: 3}
     if val not in osc_vals.keys():
         raise ValueError("must be one of %s" % list(osc_vals.keys()))
     self.msr[0] &= 0xcf
     self.msr[0] |= osc_vals[val] << 4
Example #6
0
 def test_to_int(self):
     """Test wrapped integer conversion"""
     self.assertEqual(Utils.to_int("2"), 2)
     self.assertEqual(Utils.to_int("0x10"), 16)
     with self.assertRaises(ValueError):
         Utils.to_int("a")
     with self.assertRaises(ValueError):
         Utils.to_int("")
     with self.assertRaises(ValueError):
         Utils.to_int(None)
Example #7
0
 def test_to_int(self):
     """Test wrapped integer conversion"""
     self.assertEqual(Utils.to_int("2"), 2)
     self.assertEqual(Utils.to_int("0x10"), 16)
     with self.assertRaises(ValueError):
         Utils.to_int("a")
     with self.assertRaises(ValueError):
         Utils.to_int("")
     with self.assertRaises(ValueError):
         Utils.to_int(None)
Example #8
0
 def set_low_voltage(self, val):
     val = Utils.to_int(val)
     if val not in range(0, 8):
         raise ValueError("must be one of %s" % list(range(0, 8)))
     self.msr[1] &= 0xf8
     self.msr[1] |= val
Example #9
0
 def set_flash_split(self, val):
     num_val = Utils.to_int(val)
     if num_val < 512 or num_val > 65024 or (num_val % 512) != 0:
         raise ValueError("must be between 512 and 65024 bytes and a multiple of 512 bytes")
     self.msr[4] = num_val // 256
Example #10
0
 def set_low_voltage(self, val):
     val = Utils.to_int(val)
     if val not in range(0, 4):
         raise ValueError("must be one of %s" % list(range(0, 4)))
     self.msr[2] &= 0xfc
     self.msr[2] |= 3 - val