aboutsummaryrefslogtreecommitdiffstats
path: root/libs/abstract_spidev/__init__.py
blob: 4d9e3e115c391c9b8360b416b279f4da46ff4e9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# -*- coding: utf-8 -*-
#
# Abstract spidev module interface implementation
#
# Copyright 2018 Michael Buesch <m@bues.ch>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


class Abstract_SpiDev(object):

	__slots__ = (
		"mode",
		"bits_per_word",
		"max_speed_hz",
		"_bus",
		"_device",
		"_opened",
	)

	def __init__(self, bus=-1, client=-1):
		self.mode = 0
		self.bits_per_word = 0
		self.max_speed_hz = 0
		self._opened = -1
		if bus >= 0:
			self.open(bus, client)

	@property
	def cshigh(self):
		raise NotImplementedError

	@cshigh.setter
	def cshigh(self, cshigh):
		raise NotImplementedError

	@property
	def threewire(self):
		raise NotImplementedError

	@threewire.setter
	def threewire(self, threewire):
		raise NotImplementedError

	@property
	def lsbfirst(self):
		raise NotImplementedError

	@lsbfirst.setter
	def lsbfirst(self, lsbfirst):
		raise NotImplementedError

	@property
	def loop(self):
		raise NotImplementedError

	@loop.setter
	def loop(self, loop):
		raise NotImplementedError

	@property
	def no_cs(self):
		raise NotImplementedError

	@no_cs.setter
	def no_cs(self, no_cs):
		raise NotImplementedError

	def open(self, bus, device):
		assert(bus >= 0)
		assert(device >= 0)
		self._bus = bus
		self._device = device
		self._opened = 42

	def close(self):
		if self._opened >= 0:
			self._opened = -1

	def fileno(self):
		raise NotImplementedError

	def readbytes(self, length):
		raise NotImplementedError

	def writebytes(self, data):
		raise NotImplementedError

	def xfer(self, data, speed_hz=0, delay_usecs=0, bits_per_word=0):
		raise NotImplementedError

	def xfer2(self, data, speed_hz=0, delay_usecs=0, bits_per_word=0):
		raise NotImplementedError

	def __enter__(self):
		pass

	def __exit__(self, exc_type, exc_value, traceback):
		self.close()
		return False


bues.ch cgit interface