__init__.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. # -*- coding: utf-8 -*-
  2. #
  3. # Abstract spidev module interface implementation
  4. #
  5. # Copyright 2018 Michael Buesch <m@bues.ch>
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. class Abstract_SpiDev(object):
  20. __slots__ = (
  21. "mode",
  22. "bits_per_word",
  23. "max_speed_hz",
  24. "_bus",
  25. "_device",
  26. "_opened",
  27. )
  28. def __init__(self, bus=-1, client=-1):
  29. self.mode = 0
  30. self.bits_per_word = 0
  31. self.max_speed_hz = 0
  32. self._opened = -1
  33. if bus >= 0:
  34. self.open(bus, client)
  35. @property
  36. def cshigh(self):
  37. raise NotImplementedError
  38. @cshigh.setter
  39. def cshigh(self, cshigh):
  40. raise NotImplementedError
  41. @property
  42. def threewire(self):
  43. raise NotImplementedError
  44. @threewire.setter
  45. def threewire(self, threewire):
  46. raise NotImplementedError
  47. @property
  48. def lsbfirst(self):
  49. raise NotImplementedError
  50. @lsbfirst.setter
  51. def lsbfirst(self, lsbfirst):
  52. raise NotImplementedError
  53. @property
  54. def loop(self):
  55. raise NotImplementedError
  56. @loop.setter
  57. def loop(self, loop):
  58. raise NotImplementedError
  59. @property
  60. def no_cs(self):
  61. raise NotImplementedError
  62. @no_cs.setter
  63. def no_cs(self, no_cs):
  64. raise NotImplementedError
  65. def open(self, bus, device):
  66. assert(bus >= 0)
  67. assert(device >= 0)
  68. self._bus = bus
  69. self._device = device
  70. self._opened = 42
  71. def close(self):
  72. if self._opened >= 0:
  73. self._opened = -1
  74. def fileno(self):
  75. raise NotImplementedError
  76. def readbytes(self, length):
  77. raise NotImplementedError
  78. def writebytes(self, data):
  79. raise NotImplementedError
  80. def xfer(self, data, speed_hz=0, delay_usecs=0, bits_per_word=0):
  81. raise NotImplementedError
  82. def xfer2(self, data, speed_hz=0, delay_usecs=0, bits_per_word=0):
  83. raise NotImplementedError
  84. def __enter__(self):
  85. pass
  86. def __exit__(self, exc_type, exc_value, traceback):
  87. self.close()
  88. return False