RF22
GenericSPI.h
1 // GenericSPI.h
2 // Author: Mike McCauley (mikem@airspayce.com)
3 // Copyright (C) 2011 Mike McCauley
4 // Contributed by Joanna Rutkowska
5 // $Id: GenericSPI.h,v 1.1 2014/04/01 05:06:44 mikem Exp mikem $
6 
7 #ifndef GENERICSPI_H
8 #define GENERICSPI_H
9 
10 #if ARDUINO >= 100
11 #include <Arduino.h>
12 #else
13 #include <wiring.h>
14 #include "pins_arduino.h"
15 #endif
16 
17 /////////////////////////////////////////////////////////////////////
18 /// \class GenericSPIClass GenericSPI.h <GenericSPI.h>
19 /// \brief Base class for SPI interfaces
20 ///
21 /// This generic abstract class is used to encapsulate hardware or software SPI interfaces.
22 /// The intention is so that the main RF22 class can be configured to use hardware or software SPI
23 /// without changing the main code.
24 ///
25 /// You must provide a subclass of this class to RF22 constructor.
26 /// A concrete subclass theat encapsualtes the standard Arcuino hardware SPI is provided
27 
29 {
30 public:
31 
32  /// Transfer a single octet to and from the SPI interface
33  /// \param[in] data The octet to send
34  /// \return The octet read from SPI while the data octet was sent
35  virtual uint8_t transfer(uint8_t data) = 0;
36 
37  // SPI Configuration methods
38  /// Enable SPI interrupts (if supported)
39  /// This can be used in an SPI slave to indicate when an SPI message has been received
40  virtual void attachInterrupt() {};
41 
42  /// Disable SPI interrupts (if supported)
43  /// This can be used to diable the SPI interrupt in slaves where that is supported.
44  virtual void detachInterrupt() {};
45 
46  /// Initialise the SPI library.
47  /// Call this before configuring or using the SPI library
48  virtual void begin() {};
49 
50  /// Disables the SPI bus (leaving pin modes unchanged).
51  /// Call this after you have finished using the SPI interface
52  virtual void end() {};
53 
54  /// Sets the bit order the SPI interface will use
55  /// Sets the order of the bits shifted out of and into the SPI bus, either
56  /// LSBFIRST (least-significant bit first) or MSBFIRST (most-significant bit first).
57  /// \param[in] bitOrder Bit order to be used: LSBFIRST or MSBFIRST
58  virtual void setBitOrder(uint8_t bitOrder) {};
59 
60  /// Sets the SPI data mode: that is, clock polarity and phase.
61  /// See the Wikipedia article on SPI for details.
62  /// \param[in] mode The mode to use: SPI_MODE0 SPI_MODE1 SPI_MODE2 SPI_MODE3
63  virtual void setDataMode(uint8_t mode) {};
64 
65  /// Sets the SPI clock divider relative to the system clock.
66  /// On AVR based boards, the dividers available are 2, 4, 8, 16, 32, 64 or 128.
67  /// The default setting is SPI_CLOCK_DIV4, which sets the SPI clock to one-quarter
68  /// the frequency of the system clock (4 Mhz for the boards at 16 MHz).
69  /// \param[in] rate The data rate to use: one of SPI_CLOCK_
70  virtual void setClockDivider(uint8_t rate) {};
71 };
72 #endif
virtual uint8_t transfer(uint8_t data)=0
virtual void setBitOrder(uint8_t bitOrder)
Definition: GenericSPI.h:58
virtual void setClockDivider(uint8_t rate)
Definition: GenericSPI.h:70
virtual void detachInterrupt()
Definition: GenericSPI.h:44
virtual void end()
Definition: GenericSPI.h:52
Base class for SPI interfaces.
Definition: GenericSPI.h:28
virtual void attachInterrupt()
Definition: GenericSPI.h:40
virtual void setDataMode(uint8_t mode)
Definition: GenericSPI.h:63
virtual void begin()
Definition: GenericSPI.h:48