Python LT8900 via SPI

Check-in [831f49e143]
Login

Check-in [831f49e143]

Overview
Comment:Allow user to configure SPI parameters
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 831f49e1437ab4568fc783b473681d72f0987223baff01fc1766d1e8416011d4
User & Date: rkeene on 2020-04-27 13:44:49
Other Links: manifest | tags
Context
2020-04-28
17:39
Fixed some bugs and made a few changes check-in: 88cba7a2f5 user: rkeene tags: trunk
2020-04-27
13:44
Allow user to configure SPI parameters check-in: 831f49e143 user: rkeene tags: trunk
13:38
Allow user to configure multi-transmit delay check-in: a1662e7ae5 user: rkeene tags: trunk
Changes

Modified __init__.py from [db9b618ade] to [8b552dec0f].

218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
	]

	def __init__(self, spi_bus, spi_dev, config = None):
		spi = spidev.SpiDev()
		spi.open(spi_bus, spi_dev)
		self.__spi = spi

		self.__set_spi_mode(1)

		self.configure(config)

		if len(self.__register_map) != 53:
			raise ValueError('Inconsistent register map!')

		return None








<
<







218
219
220
221
222
223
224


225
226
227
228
229
230
231
	]

	def __init__(self, spi_bus, spi_dev, config = None):
		spi = spidev.SpiDev()
		spi.open(spi_bus, spi_dev)
		self.__spi = spi



		self.configure(config)

		if len(self.__register_map) != 53:
			raise ValueError('Inconsistent register map!')

		return None

255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
		if reg_string.isnumeric():
			return int(reg_string)
		for reg_number, reg_info in enumerate(self.__register_map):
			if reg_info['name'] == reg_string:
				return reg_number
		raise NameError("Invalid register value {}".format(reg_string_orig))

	def __set_spi_mode(self, mode):
		if mode != self.__spi.mode:
			self.__spi.mode = mode
		return True

	def __get_spi_mode(self):
		return self.__spi.mode

	def __check_radio(self):
		old_mode = self.__get_spi_mode()

		value1 = self.get_register(0);
		value2 = self.get_register(1);

		if value1 == 0x6fe0 and value2 == 0x5681:
			return True
		return False








<
<
<
<
<
<
<
<

<
<







253
254
255
256
257
258
259








260


261
262
263
264
265
266
267
		if reg_string.isnumeric():
			return int(reg_string)
		for reg_number, reg_info in enumerate(self.__register_map):
			if reg_info['name'] == reg_string:
				return reg_number
		raise NameError("Invalid register value {}".format(reg_string_orig))









	def __check_radio(self):


		value1 = self.get_register(0);
		value2 = self.get_register(1);

		if value1 == 0x6fe0 and value2 == 0x5681:
			return True
		return False

402
403
404
405
406
407
408






409
410
411
412
413
414
415
	def configure(self, config):
		self.__config = config

		if config is None:
			return None

		self.__spi.max_speed_hz = self.__config.get('frequency', 4000000)







		return None

	def initialize(self):
		self.__reset_device()

		self.__set_defaults()







>
>
>
>
>
>







390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
	def configure(self, config):
		self.__config = config

		if config is None:
			return None

		self.__spi.max_speed_hz = self.__config.get('frequency', 4000000)
		self.__spi.bits_per_word = self.__config.get('bits_per_word', 8)
		self.__spi.cshigh = self.__config.get('csigh', False)
		self.__spi.no_cs  = self.__config.get('no_cs', False)
		self.__spi.lsbfirst = self.__config.get('lsbfirst', False)
		self.__spi.threewire = self.__config.get('threewire', False)
		self.__spi.mode = self.__config.get('mode', 1)

		return None

	def initialize(self):
		self.__reset_device()

		self.__set_defaults()