Coverage for /usr/lib/python3/dist-packages/gpiozero/pins/__init__.py: 77%
100 statements
« prev ^ index » next coverage.py v7.2.7, created at 2024-04-05 16:40 +0100
« prev ^ index » next coverage.py v7.2.7, created at 2024-04-05 16:40 +0100
1# vim: set fileencoding=utf-8:
2#
3# GPIO Zero: a library for controlling the Raspberry Pi's GPIO pins
4#
5# Copyright (c) 2015-2021 Dave Jones <dave@waveform.org.uk>
6# Copyright (c) 2018 Rick Ansell <rick@nbinvincible.org.uk>
7# Copyright (c) 2018 Mike Kazantsev <mk.fraggod@gmail.com>
8# Copyright (c) 2016 Andrew Scheller <github@loowis.durge.org>
9#
10# SPDX-License-Identifier: BSD-3-Clause
12from __future__ import (
13 unicode_literals,
14 absolute_import,
15 print_function,
16 division,
17 )
18str = type('')
20from weakref import ref
21from collections import defaultdict
22from threading import Lock
24from ..devices import Device
25from ..exc import (
26 PinInvalidFunction,
27 PinSetInput,
28 PinFixedPull,
29 PinUnsupported,
30 PinSPIUnsupported,
31 PinPWMUnsupported,
32 PinEdgeDetectUnsupported,
33 SPIFixedClockMode,
34 SPIFixedBitOrder,
35 SPIFixedSelect,
36 SPIFixedWordSize,
37 SPIFixedRate,
38 GPIOPinInUse,
39 )
42class Factory(object):
43 """
44 Generates pins and SPI interfaces for devices. This is an abstract
45 base class for pin factories. Descendents *must* override the following
46 methods:
48 * :meth:`ticks`
49 * :meth:`ticks_diff`
51 Descendents *may* override the following methods, if applicable:
53 * :meth:`close`
54 * :meth:`reserve_pins`
55 * :meth:`release_pins`
56 * :meth:`release_all`
57 * :meth:`pin`
58 * :meth:`spi`
59 * :meth:`_get_pi_info`
60 """
61 def __init__(self):
62 self._reservations = defaultdict(list)
63 self._res_lock = Lock()
65 def reserve_pins(self, requester, *pins):
66 """
67 Called to indicate that the device reserves the right to use the
68 specified *pins*. This should be done during device construction. If
69 pins are reserved, you must ensure that the reservation is released by
70 eventually called :meth:`release_pins`.
71 """
72 with self._res_lock:
73 for pin in pins:
74 for reserver_ref in self._reservations[pin]: 74 ↛ 75line 74 didn't jump to line 75, because the loop on line 74 never started
75 reserver = reserver_ref()
76 if reserver is not None and requester._conflicts_with(reserver):
77 raise GPIOPinInUse('pin %s is already in use by %r' %
78 (pin, reserver))
79 self._reservations[pin].append(ref(requester))
81 def release_pins(self, reserver, *pins):
82 """
83 Releases the reservation of *reserver* against *pins*. This is
84 typically called during :meth:`~gpiozero.Device.close` to clean up
85 reservations taken during construction. Releasing a reservation that is
86 not currently held will be silently ignored (to permit clean-up after
87 failed / partial construction).
88 """
89 with self._res_lock:
90 for pin in pins:
91 self._reservations[pin] = [
92 ref for ref in self._reservations[pin]
93 if ref() not in (reserver, None) # may as well clean up dead refs
94 ]
96 def release_all(self, reserver):
97 """
98 Releases all pin reservations taken out by *reserver*. See
99 :meth:`release_pins` for further information).
100 """
101 # Yes, this would be more efficient if it simply regenerated the
102 # reservations list without any references to reserver instead of
103 # (in release_pins) looping over each pin individually. However, this
104 # then causes a subtle bug in LocalPiFactory which does something
105 # horribly naughty (with good reason) and makes its _reservations
106 # dictionary equivalent to a class-level one.
107 self.release_pins(reserver, *self._reservations)
109 def close(self):
110 """
111 Closes the pin factory. This is expected to clean up all resources
112 manipulated by the factory. It it typically called at script
113 termination.
114 """
115 pass
117 def pin(self, spec):
118 """
119 Creates an instance of a :class:`Pin` descendent representing the
120 specified pin.
122 .. warning::
124 Descendents must ensure that pin instances representing the same
125 hardware are identical; i.e. two separate invocations of
126 :meth:`pin` for the same pin specification must return the same
127 object.
128 """
129 raise PinUnsupported( # pragma: no cover
130 "Individual pins are not supported by this pin factory")
132 def spi(self, **spi_args):
133 """
134 Returns an instance of an :class:`SPI` interface, for the specified SPI
135 *port* and *device*, or for the specified pins (*clock_pin*,
136 *mosi_pin*, *miso_pin*, and *select_pin*). Only one of the schemes can
137 be used; attempting to mix *port* and *device* with pin numbers will
138 raise :exc:`SPIBadArgs`.
139 """
140 raise PinSPIUnsupported( # pragma: no cover
141 'SPI not supported by this pin factory')
143 def ticks(self):
144 """
145 Return the current ticks, according to the factory. The reference point
146 is undefined and thus the result of this method is only meaningful when
147 compared to another value returned by this method.
149 The format of the time is also arbitrary, as is whether the time wraps
150 after a certain duration. Ticks should only be compared using the
151 :meth:`ticks_diff` method.
152 """
153 raise NotImplementedError
155 def ticks_diff(self, later, earlier):
156 """
157 Return the time in seconds between two :meth:`ticks` results. The
158 arguments are specified in the same order as they would be in the
159 formula *later* - *earlier* but the result is guaranteed to be in
160 seconds, and to be positive even if the ticks "wrapped" between calls
161 to :meth:`ticks`.
162 """
163 raise NotImplementedError
165 def _get_pi_info(self):
166 return None # pragma: no cover
168 pi_info = property(
169 lambda self: self._get_pi_info(),
170 doc="""\
171 Returns a :class:`PiBoardInfo` instance representing the Pi that
172 instances generated by this factory will be attached to.
174 If the pins represented by this class are not *directly* attached to a
175 Pi (e.g. the pin is attached to a board attached to the Pi, or the pins
176 are not on a Pi at all), this may return :data:`None`.
177 """)
180class Pin(object):
181 """
182 Abstract base class representing a pin attached to some form of controller,
183 be it GPIO, SPI, ADC, etc.
185 Descendents should override property getters and setters to accurately
186 represent the capabilities of pins. Descendents *must* override the
187 following methods:
189 * :meth:`_get_function`
190 * :meth:`_set_function`
191 * :meth:`_get_state`
193 Descendents *may* additionally override the following methods, if
194 applicable:
196 * :meth:`close`
197 * :meth:`output_with_state`
198 * :meth:`input_with_pull`
199 * :meth:`_set_state`
200 * :meth:`_get_frequency`
201 * :meth:`_set_frequency`
202 * :meth:`_get_pull`
203 * :meth:`_set_pull`
204 * :meth:`_get_bounce`
205 * :meth:`_set_bounce`
206 * :meth:`_get_edges`
207 * :meth:`_set_edges`
208 * :meth:`_get_when_changed`
209 * :meth:`_set_when_changed`
210 """
212 def __repr__(self):
213 return "<Pin>" # pragma: no cover
215 def close(self):
216 """
217 Cleans up the resources allocated to the pin. After this method is
218 called, this :class:`Pin` instance may no longer be used to query or
219 control the pin's state.
220 """
221 pass
223 def output_with_state(self, state):
224 """
225 Sets the pin's function to "output" and specifies an initial state
226 for the pin. By default this is equivalent to performing::
228 pin.function = 'output'
229 pin.state = state
231 However, descendents may override this in order to provide the smallest
232 possible delay between configuring the pin for output and specifying an
233 initial value (which can be important for avoiding "blips" in
234 active-low configurations).
235 """
236 self.function = 'output'
237 self.state = state
239 def input_with_pull(self, pull):
240 """
241 Sets the pin's function to "input" and specifies an initial pull-up
242 for the pin. By default this is equivalent to performing::
244 pin.function = 'input'
245 pin.pull = pull
247 However, descendents may override this order to provide the smallest
248 possible delay between configuring the pin for input and pulling the
249 pin up/down (which can be important for avoiding "blips" in some
250 configurations).
251 """
252 self.function = 'input'
253 self.pull = pull
255 def _get_function(self):
256 raise NotImplementedError
258 def _set_function(self, value):
259 raise NotImplementedError
261 function = property(
262 lambda self: self._get_function(),
263 lambda self, value: self._set_function(value),
264 doc="""\
265 The function of the pin. This property is a string indicating the
266 current function or purpose of the pin. Typically this is the string
267 "input" or "output". However, in some circumstances it can be other
268 strings indicating non-GPIO related functionality.
270 With certain pin types (e.g. GPIO pins), this attribute can be changed
271 to configure the function of a pin. If an invalid function is
272 specified, for this attribute, :exc:`PinInvalidFunction` will be
273 raised.
274 """)
276 def _get_state(self):
277 raise NotImplementedError
279 def _set_state(self, value):
280 raise PinSetInput( # pragma: no cover
281 "Cannot set the state of pin %r" % self)
283 state = property(
284 lambda self: self._get_state(),
285 lambda self, value: self._set_state(value),
286 doc="""\
287 The state of the pin. This is 0 for low, and 1 for high. As a low level
288 view of the pin, no swapping is performed in the case of pull ups (see
289 :attr:`pull` for more information):
291 .. code-block:: text
293 HIGH - - - - > ,----------------------
294 |
295 |
296 LOW ----------------'
298 Descendents which implement analog, or analog-like capabilities can
299 return values between 0 and 1. For example, pins implementing PWM
300 (where :attr:`frequency` is not :data:`None`) return a value between
301 0.0 and 1.0 representing the current PWM duty cycle.
303 If a pin is currently configured for input, and an attempt is made to
304 set this attribute, :exc:`PinSetInput` will be raised. If an invalid
305 value is specified for this attribute, :exc:`PinInvalidState` will be
306 raised.
307 """)
309 def _get_pull(self):
310 return 'floating' # pragma: no cover
312 def _set_pull(self, value):
313 raise PinFixedPull( # pragma: no cover
314 "Cannot change pull-up on pin %r" % self)
316 pull = property(
317 lambda self: self._get_pull(),
318 lambda self, value: self._set_pull(value),
319 doc="""\
320 The pull-up state of the pin represented as a string. This is typically
321 one of the strings "up", "down", or "floating" but additional values
322 may be supported by the underlying hardware.
324 If the pin does not support changing pull-up state (for example because
325 of a fixed pull-up resistor), attempts to set this property will raise
326 :exc:`PinFixedPull`. If the specified value is not supported by the
327 underlying hardware, :exc:`PinInvalidPull` is raised.
328 """)
330 def _get_frequency(self):
331 return None # pragma: no cover
333 def _set_frequency(self, value):
334 if value is not None:
335 raise PinPWMUnsupported( # pragma: no cover
336 "PWM is not supported on pin %r" % self)
338 frequency = property(
339 lambda self: self._get_frequency(),
340 lambda self, value: self._set_frequency(value),
341 doc="""\
342 The frequency (in Hz) for the pin's PWM implementation, or :data:`None`
343 if PWM is not currently in use. This value always defaults to
344 :data:`None` and may be changed with certain pin types to activate or
345 deactivate PWM.
347 If the pin does not support PWM, :exc:`PinPWMUnsupported` will be
348 raised when attempting to set this to a value other than :data:`None`.
349 """)
351 def _get_bounce(self):
352 return None # pragma: no cover
354 def _set_bounce(self, value):
355 if value is not None: # pragma: no cover
356 raise PinEdgeDetectUnsupported(
357 "Edge detection is not supported on pin %r" % self)
359 bounce = property(
360 lambda self: self._get_bounce(),
361 lambda self, value: self._set_bounce(value),
362 doc="""\
363 The amount of bounce detection (elimination) currently in use by edge
364 detection, measured in seconds. If bounce detection is not currently in
365 use, this is :data:`None`.
367 For example, if :attr:`edges` is currently "rising", :attr:`bounce` is
368 currently 5/1000 (5ms), then the waveform below will only fire
369 :attr:`when_changed` on two occasions despite there being three rising
370 edges:
372 .. code-block:: text
374 TIME 0...1...2...3...4...5...6...7...8...9...10..11..12 ms
376 bounce elimination |===================| |==============
378 HIGH - - - - > ,--. ,--------------. ,--.
379 | | | | | |
380 | | | | | |
381 LOW ----------------' `-' `-' `-----------
382 : :
383 : :
384 when_changed when_changed
385 fires fires
387 If the pin does not support edge detection, attempts to set this
388 property will raise :exc:`PinEdgeDetectUnsupported`. If the pin
389 supports edge detection, the class must implement bounce detection,
390 even if only in software.
391 """)
393 def _get_edges(self):
394 return 'none' # pragma: no cover
396 def _set_edges(self, value):
397 raise PinEdgeDetectUnsupported( # pragma: no cover
398 "Edge detection is not supported on pin %r" % self)
400 edges = property(
401 lambda self: self._get_edges(),
402 lambda self, value: self._set_edges(value),
403 doc="""\
404 The edge that will trigger execution of the function or bound method
405 assigned to :attr:`when_changed`. This can be one of the strings
406 "both" (the default), "rising", "falling", or "none":
408 .. code-block:: text
410 HIGH - - - - > ,--------------.
411 | |
412 | |
413 LOW --------------------' `--------------
414 : :
415 : :
416 Fires when_changed "both" "both"
417 when edges is ... "rising" "falling"
419 If the pin does not support edge detection, attempts to set this
420 property will raise :exc:`PinEdgeDetectUnsupported`.
421 """)
423 def _get_when_changed(self):
424 return None # pragma: no cover
426 def _set_when_changed(self, value):
427 raise PinEdgeDetectUnsupported( # pragma: no cover
428 "Edge detection is not supported on pin %r" % self)
430 when_changed = property(
431 lambda self: self._get_when_changed(),
432 lambda self, value: self._set_when_changed(value),
433 doc="""\
434 A function or bound method to be called when the pin's state changes
435 (more specifically when the edge specified by :attr:`edges` is detected
436 on the pin). The function or bound method must accept two parameters:
437 the first will report the ticks (from :meth:`Factory.ticks`) when
438 the pin's state changed, and the second will report the pin's current
439 state.
441 .. warning::
443 Depending on hardware support, the state is *not guaranteed to be
444 accurate*. For instance, many GPIO implementations will provide
445 an interrupt indicating when a pin's state changed but not what it
446 changed to. In this case the pin driver simply reads the pin's
447 current state to supply this parameter, but the pin's state may
448 have changed *since* the interrupt. Exercise appropriate caution
449 when relying upon this parameter.
451 If the pin does not support edge detection, attempts to set this
452 property will raise :exc:`PinEdgeDetectUnsupported`.
453 """)
456class SPI(Device):
457 """
458 Abstract interface for `Serial Peripheral Interface`_ (SPI)
459 implementations. Descendents *must* override the following methods:
461 * :meth:`transfer`
462 * :meth:`_get_clock_mode`
464 Descendents *may* override the following methods, if applicable:
466 * :meth:`read`
467 * :meth:`write`
468 * :meth:`_set_clock_mode`
469 * :meth:`_get_lsb_first`
470 * :meth:`_set_lsb_first`
471 * :meth:`_get_select_high`
472 * :meth:`_set_select_high`
473 * :meth:`_get_bits_per_word`
474 * :meth:`_set_bits_per_word`
476 .. _Serial Peripheral Interface: https://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus
477 """
479 def read(self, n):
480 """
481 Read *n* words of data from the SPI interface, returning them as a
482 sequence of unsigned ints, each no larger than the configured
483 :attr:`bits_per_word` of the interface.
485 This method is typically used with read-only devices that feature
486 half-duplex communication. See :meth:`transfer` for full duplex
487 communication.
488 """
489 return self.transfer([0] * n)
491 def write(self, data):
492 """
493 Write *data* to the SPI interface. *data* must be a sequence of
494 unsigned integer words each of which will fit within the configured
495 :attr:`bits_per_word` of the interface. The method returns the number
496 of words written to the interface (which may be less than or equal to
497 the length of *data*).
499 This method is typically used with write-only devices that feature
500 half-duplex communication. See :meth:`transfer` for full duplex
501 communication.
502 """
503 return len(self.transfer(data))
505 def transfer(self, data):
506 """
507 Write *data* to the SPI interface. *data* must be a sequence of
508 unsigned integer words each of which will fit within the configured
509 :attr:`bits_per_word` of the interface. The method returns the sequence
510 of words read from the interface while writing occurred (full duplex
511 communication).
513 The length of the sequence returned dictates the number of words of
514 *data* written to the interface. Each word in the returned sequence
515 will be an unsigned integer no larger than the configured
516 :attr:`bits_per_word` of the interface.
517 """
518 raise NotImplementedError
520 @property
521 def clock_polarity(self):
522 """
523 The polarity of the SPI clock pin. If this is :data:`False` (the
524 default), the clock pin will idle low, and pulse high. Setting this to
525 :data:`True` will cause the clock pin to idle high, and pulse low. On
526 many data sheets this is documented as the CPOL value.
528 The following diagram illustrates the waveform when
529 :attr:`clock_polarity` is :data:`False` (the default), equivalent to
530 CPOL 0:
532 .. code-block:: text
534 on on on on on on on
535 ,---. ,---. ,---. ,---. ,---. ,---. ,---.
536 CLK | | | | | | | | | | | | | |
537 | | | | | | | | | | | | | |
538 ------' `---' `---' `---' `---' `---' `---' `------
539 idle off off off off off off idle
541 The following diagram illustrates the waveform when
542 :attr:`clock_polarity` is :data:`True`, equivalent to CPOL 1:
544 .. code-block:: text
546 idle off off off off off off idle
547 ------. ,---. ,---. ,---. ,---. ,---. ,---. ,------
548 | | | | | | | | | | | | | |
549 CLK | | | | | | | | | | | | | |
550 `---' `---' `---' `---' `---' `---' `---'
551 on on on on on on on
552 """
553 return bool(self.clock_mode & 2)
555 @clock_polarity.setter
556 def clock_polarity(self, value):
557 self.clock_mode = self.clock_mode & (~2) | (bool(value) << 1)
559 @property
560 def clock_phase(self):
561 """
562 The phase of the SPI clock pin. If this is :data:`False` (the default),
563 data will be read from the MISO pin when the clock pin activates.
564 Setting this to :data:`True` will cause data to be read from the MISO
565 pin when the clock pin deactivates. On many data sheets this is
566 documented as the CPHA value. Whether the clock edge is rising or
567 falling when the clock is considered activated is controlled by the
568 :attr:`clock_polarity` attribute (corresponding to CPOL).
570 The following diagram indicates when data is read when
571 :attr:`clock_polarity` is :data:`False`, and :attr:`clock_phase` is
572 :data:`False` (the default), equivalent to CPHA 0:
574 .. code-block:: text
576 ,---. ,---. ,---. ,---. ,---. ,---. ,---.
577 CLK | | | | | | | | | | | | | |
578 | | | | | | | | | | | | | |
579 ----' `---' `---' `---' `---' `---' `---' `-------
580 : : : : : : :
581 MISO---. ,---. ,---. ,---. ,---. ,---. ,---.
582 / \\ / \\ / \\ / \\ / \\ / \\ / \\
583 -{ Bit X Bit X Bit X Bit X Bit X Bit X Bit }------
584 \\ / \\ / \\ / \\ / \\ / \\ / \\ /
585 `---' `---' `---' `---' `---' `---' `---'
587 The following diagram indicates when data is read when
588 :attr:`clock_polarity` is :data:`False`, but :attr:`clock_phase` is
589 :data:`True`, equivalent to CPHA 1:
591 .. code-block:: text
593 ,---. ,---. ,---. ,---. ,---. ,---. ,---.
594 CLK | | | | | | | | | | | | | |
595 | | | | | | | | | | | | | |
596 ----' `---' `---' `---' `---' `---' `---' `-------
597 : : : : : : :
598 MISO ,---. ,---. ,---. ,---. ,---. ,---. ,---.
599 / \\ / \\ / \\ / \\ / \\ / \\ / \\
600 -----{ Bit X Bit X Bit X Bit X Bit X Bit X Bit }--
601 \\ / \\ / \\ / \\ / \\ / \\ / \\ /
602 `---' `---' `---' `---' `---' `---' `---'
603 """
604 return bool(self.clock_mode & 1)
606 @clock_phase.setter
607 def clock_phase(self, value):
608 self.clock_mode = self.clock_mode & (~1) | bool(value)
610 def _get_clock_mode(self):
611 raise NotImplementedError # pragma: no cover
613 def _set_clock_mode(self, value):
614 raise SPIFixedClockMode( # pragma: no cover
615 "clock_mode cannot be changed on %r" % self)
617 clock_mode = property( 617 ↛ exitline 617 didn't jump to the function exit
618 lambda self: self._get_clock_mode(),
619 lambda self, value: self._set_clock_mode(value),
620 doc="""\
621 Presents a value representing the :attr:`clock_polarity` and
622 :attr:`clock_phase` attributes combined according to the following
623 table:
625 +------+-----------------+--------------+
626 | mode | polarity (CPOL) | phase (CPHA) |
627 +======+=================+==============+
628 | 0 | False | False |
629 +------+-----------------+--------------+
630 | 1 | False | True |
631 +------+-----------------+--------------+
632 | 2 | True | False |
633 +------+-----------------+--------------+
634 | 3 | True | True |
635 +------+-----------------+--------------+
637 Adjusting this value adjusts both the :attr:`clock_polarity` and
638 :attr:`clock_phase` attributes simultaneously.
639 """)
641 def _get_lsb_first(self):
642 return False # pragma: no cover
644 def _set_lsb_first(self, value):
645 raise SPIFixedBitOrder( # pragma: no cover
646 "lsb_first cannot be changed on %r" % self)
648 lsb_first = property( 648 ↛ exitline 648 didn't jump to the function exit
649 lambda self: self._get_lsb_first(),
650 lambda self, value: self._set_lsb_first(value),
651 doc="""\
652 Controls whether words are read and written LSB in (Least Significant
653 Bit first) order. The default is :data:`False` indicating that words
654 are read and written in MSB (Most Significant Bit first) order.
655 Effectively, this controls the `Bit endianness`_ of the connection.
657 The following diagram shows the a word containing the number 5 (binary
658 0101) transmitted on MISO with :attr:`bits_per_word` set to 4, and
659 :attr:`clock_mode` set to 0, when :attr:`lsb_first` is :data:`False`
660 (the default):
662 .. code-block:: text
664 ,---. ,---. ,---. ,---.
665 CLK | | | | | | | |
666 | | | | | | | |
667 ----' `---' `---' `---' `-----
668 : ,-------. : ,-------.
669 MISO: | : | : | : |
670 : | : | : | : |
671 ----------' : `-------' : `----
672 : : : :
673 MSB LSB
675 And now with :attr:`lsb_first` set to :data:`True` (and all other
676 parameters the same):
678 .. code-block:: text
680 ,---. ,---. ,---. ,---.
681 CLK | | | | | | | |
682 | | | | | | | |
683 ----' `---' `---' `---' `-----
684 ,-------. : ,-------. :
685 MISO: | : | : | :
686 | : | : | : | :
687 --' : `-------' : `-----------
688 : : : :
689 LSB MSB
691 .. _Bit endianness: https://en.wikipedia.org/wiki/Endianness#Bit_endianness
692 """)
694 def _get_select_high(self):
695 return False # pragma: no cover
697 def _set_select_high(self, value):
698 raise SPIFixedSelect( # pragma: no cover
699 "select_high cannot be changed on %r" % self)
701 select_high = property( 701 ↛ exitline 701 didn't jump to the function exit
702 lambda self: self._get_select_high(),
703 lambda self, value: self._set_select_high(value),
704 doc="""\
705 If :data:`False` (the default), the chip select line is considered
706 active when it is pulled low. When set to :data:`True`, the chip select
707 line is considered active when it is driven high.
709 The following diagram shows the waveform of the chip select line, and
710 the clock when :attr:`clock_polarity` is :data:`False`, and
711 :attr:`select_high` is :data:`False` (the default):
713 .. code-block:: text
715 ---. ,------
716 __ | |
717 CS | chip is selected, and will react to clock | idle
718 `-----------------------------------------------------'
720 ,---. ,---. ,---. ,---. ,---. ,---. ,---.
721 CLK | | | | | | | | | | | | | |
722 | | | | | | | | | | | | | |
723 ----' `---' `---' `---' `---' `---' `---' `-------
725 And when :attr:`select_high` is :data:`True`:
727 .. code-block:: text
729 ,-----------------------------------------------------.
730 CS | chip is selected, and will react to clock | idle
731 | |
732 ---' `------
734 ,---. ,---. ,---. ,---. ,---. ,---. ,---.
735 CLK | | | | | | | | | | | | | |
736 | | | | | | | | | | | | | |
737 ----' `---' `---' `---' `---' `---' `---' `-------
738 """)
740 def _get_bits_per_word(self):
741 return 8 # pragma: no cover
743 def _set_bits_per_word(self, value):
744 raise SPIFixedWordSize( # pragma: no cover
745 "bits_per_word cannot be changed on %r" % self)
747 bits_per_word = property( 747 ↛ exitline 747 didn't jump to the function exit
748 lambda self: self._get_bits_per_word(),
749 lambda self, value: self._set_bits_per_word(value),
750 doc="""\
751 Controls the number of bits that make up a word, and thus where the
752 word boundaries appear in the data stream, and the maximum value of a
753 word. Defaults to 8 meaning that words are effectively bytes.
755 Several implementations do not support non-byte-sized words.
756 """)
758 def _get_rate(self):
759 return 100000 # pragma: no cover
761 def _set_rate(self, value):
762 raise SPIFixedRate( # pragma: no cover
763 "rate cannot be changed on %r" % self)
765 rate = property( 765 ↛ exitline 765 didn't jump to the function exit
766 lambda self: self._get_rate(),
767 lambda self, value: self._set_rate(value),
768 doc="""\
769 Controls the speed of the SPI interface in Hz (or baud).
771 Note that most software SPI implementations ignore this property, and
772 will raise :exc:`SPIFixedRate` if an attempt is made to set it, as they
773 have no rate control (they simply bit-bang as fast as possible because
774 typically this isn't very fast anyway, and introducing measures to
775 limit the rate would simply slow them down to the point of being
776 useless).
777 """)