V148

Fork of RadioHead-148 by David Rimer

Committer:
davidr99
Date:
Thu Oct 15 01:27:00 2015 +0000
Revision:
0:ab4e012489ef
Messy start, but a port for RadioHead.; Currently the SPI modulus are the only ones that work.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
davidr99 0:ab4e012489ef 1 // RHHardwareSPI.h
davidr99 0:ab4e012489ef 2 // Author: Mike McCauley (mikem@airspayce.com)
davidr99 0:ab4e012489ef 3 // Copyright (C) 2011 Mike McCauley
davidr99 0:ab4e012489ef 4 // Contributed by Joanna Rutkowska
davidr99 0:ab4e012489ef 5 // $Id: RHHardwareSPI.h,v 1.9 2014/08/12 00:54:52 mikem Exp $
davidr99 0:ab4e012489ef 6
davidr99 0:ab4e012489ef 7 #ifndef RHHardwareSPI_h
davidr99 0:ab4e012489ef 8 #define RHHardwareSPI_h
davidr99 0:ab4e012489ef 9
davidr99 0:ab4e012489ef 10 #include <RHGenericSPI.h>
davidr99 0:ab4e012489ef 11
davidr99 0:ab4e012489ef 12 /////////////////////////////////////////////////////////////////////
davidr99 0:ab4e012489ef 13 /// \class RHHardwareSPI RHHardwareSPI.h <RHHardwareSPI.h>
davidr99 0:ab4e012489ef 14 /// \brief Encapsulate a hardware SPI bus interface
davidr99 0:ab4e012489ef 15 ///
davidr99 0:ab4e012489ef 16 /// This concrete subclass of GenericSPIClass encapsulates the standard Arduino hardware and other
davidr99 0:ab4e012489ef 17 /// hardware SPI interfaces.
davidr99 0:ab4e012489ef 18 class RHHardwareSPI : public RHGenericSPI
davidr99 0:ab4e012489ef 19 {
davidr99 0:ab4e012489ef 20 #ifdef RH_HAVE_HARDWARE_SPI
davidr99 0:ab4e012489ef 21 public:
davidr99 0:ab4e012489ef 22 /// Constructor
davidr99 0:ab4e012489ef 23 /// Creates an instance of a hardware SPI interface, using whatever SPI hardware is available on
davidr99 0:ab4e012489ef 24 /// your processor platform. On Arduino and Uno32, uses SPI. On Maple, uses HardwareSPI.
davidr99 0:ab4e012489ef 25 /// \param[in] frequency One of RHGenericSPI::Frequency to select the SPI bus frequency. The frequency
davidr99 0:ab4e012489ef 26 /// is mapped to the closest available bus frequency on the platform.
davidr99 0:ab4e012489ef 27 /// \param[in] bitOrder Select the SPI bus bit order, one of RHGenericSPI::BitOrderMSBFirst or
davidr99 0:ab4e012489ef 28 /// RHGenericSPI::BitOrderLSBFirst.
davidr99 0:ab4e012489ef 29 /// \param[in] dataMode Selects the SPI bus data mode. One of RHGenericSPI::DataMode
davidr99 0:ab4e012489ef 30 RHHardwareSPI(Frequency frequency = Frequency1MHz, BitOrder bitOrder = BitOrderMSBFirst, DataMode dataMode = DataMode0);
davidr99 0:ab4e012489ef 31
davidr99 0:ab4e012489ef 32 /// Transfer a single octet to and from the SPI interface
davidr99 0:ab4e012489ef 33 /// \param[in] data The octet to send
davidr99 0:ab4e012489ef 34 /// \return The octet read from SPI while the data octet was sent
davidr99 0:ab4e012489ef 35 uint8_t transfer(uint8_t data);
davidr99 0:ab4e012489ef 36
davidr99 0:ab4e012489ef 37 // SPI Configuration methods
davidr99 0:ab4e012489ef 38 /// Enable SPI interrupts
davidr99 0:ab4e012489ef 39 /// This can be used in an SPI slave to indicate when an SPI message has been received
davidr99 0:ab4e012489ef 40 /// It will cause the SPI_STC_vect interrupt vectr to be executed
davidr99 0:ab4e012489ef 41 void attachInterrupt();
davidr99 0:ab4e012489ef 42
davidr99 0:ab4e012489ef 43 /// Disable SPI interrupts
davidr99 0:ab4e012489ef 44 /// This can be used to diable the SPI interrupt in slaves where that is supported.
davidr99 0:ab4e012489ef 45 void detachInterrupt();
davidr99 0:ab4e012489ef 46
davidr99 0:ab4e012489ef 47 /// Initialise the SPI library
davidr99 0:ab4e012489ef 48 /// Call this after configuring the SPI interface and before using it to transfer data.
davidr99 0:ab4e012489ef 49 /// Initializes the SPI bus by setting SCK, MOSI, and SS to outputs, pulling SCK and MOSI low, and SS high.
davidr99 0:ab4e012489ef 50 void begin();
davidr99 0:ab4e012489ef 51
davidr99 0:ab4e012489ef 52 /// Disables the SPI bus (leaving pin modes unchanged).
davidr99 0:ab4e012489ef 53 /// Call this after you have finished using the SPI interface.
davidr99 0:ab4e012489ef 54 void end();
davidr99 0:ab4e012489ef 55 #else
davidr99 0:ab4e012489ef 56 // not supported on ATTiny etc
davidr99 0:ab4e012489ef 57 uint8_t transfer(uint8_t data) {return 0;}
davidr99 0:ab4e012489ef 58 void begin(){}
davidr99 0:ab4e012489ef 59 void end(){}
davidr99 0:ab4e012489ef 60
davidr99 0:ab4e012489ef 61 #endif
davidr99 0:ab4e012489ef 62 };
davidr99 0:ab4e012489ef 63
davidr99 0:ab4e012489ef 64 // Built in default instance
davidr99 0:ab4e012489ef 65 extern RHHardwareSPI hardware_spi;
davidr99 0:ab4e012489ef 66
davidr99 0:ab4e012489ef 67 #endif