This repository has been archived by the owner on May 24, 2020. It is now read-only.
forked from PaulStoffregen/RadioHead
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RHHardwareSPI1.h
76 lines (66 loc) · 2.95 KB
/
RHHardwareSPI1.h
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
// RHHardwareSPI.h
// Author: Mike McCauley ([email protected])
// Copyright (C) 2011 Mike McCauley
// Contributed by Joanna Rutkowska
// $Id: RHHardwareSPI.h,v 1.9 2014/08/12 00:54:52 mikem Exp $
#ifndef RHHardwareSPI1_h
#define RHHardwareSPI1_h
#if defined(__arm__) && defined(TEENSYDUINO) && (defined(KINETISL) || defined(__MK64FX512__) || defined(__MK66FX1M0__) )
#include <RHGenericSPI.h>
/////////////////////////////////////////////////////////////////////
/// \class RHHardwareSPI RHHardwareSPI.h <RHHardwareSPI.h>
/// \brief Encapsulate a hardware SPI bus interface
///
/// This concrete subclass of GenericSPIClass encapsulates the standard Arduino hardware and other
/// hardware SPI interfaces.
class RHHardwareSPI1 : public RHGenericSPI
{
#ifdef RH_HAVE_HARDWARE_SPI
public:
/// Constructor
/// Creates an instance of a hardware SPI interface, using whatever SPI hardware is available on
/// your processor platform. On Arduino and Uno32, uses SPI. On Maple, uses HardwareSPI.
/// \param[in] frequency One of RHGenericSPI::Frequency to select the SPI bus frequency. The frequency
/// is mapped to the closest available bus frequency on the platform.
/// \param[in] bitOrder Select the SPI bus bit order, one of RHGenericSPI::BitOrderMSBFirst or
/// RHGenericSPI::BitOrderLSBFirst.
/// \param[in] dataMode Selects the SPI bus data mode. One of RHGenericSPI::DataMode
RHHardwareSPI1(Frequency frequency = Frequency1MHz, BitOrder bitOrder = BitOrderMSBFirst, DataMode dataMode = DataMode0);
/// Transfer a single octet to and from the SPI interface
/// \param[in] data The octet to send
/// \return The octet read from SPI while the data octet was sent
uint8_t transfer(uint8_t data);
// SPI Configuration methods
/// Enable SPI interrupts
/// This can be used in an SPI slave to indicate when an SPI message has been received
/// It will cause the SPI_STC_vect interrupt vectr to be executed
void attachInterrupt();
/// Disable SPI interrupts
/// This can be used to diable the SPI interrupt in slaves where that is supported.
void detachInterrupt();
/// Initialise the SPI library
/// Call this after configuring the SPI interface and before using it to transfer data.
/// Initializes the SPI bus by setting SCK, MOSI, and SS to outputs, pulling SCK and MOSI low, and SS high.
void begin();
/// Disables the SPI bus (leaving pin modes unchanged).
/// Call this after you have finished using the SPI interface.
void end();
#if (RH_PLATFORM == RH_PLATFORM_ARDUINO) && defined(SPI_HAS_TRANSACTION)
public:
void beginTransaction();
void endTransaction();
SPISettings _settings;
#endif
#else
// not supported on ATTiny etc
uint8_t transfer(uint8_t data) {return 0;}
void begin(){}
void end(){}
#endif
};
// Built in default instance
extern RHHardwareSPI1 hardware_spi1;
#else
#error ("RadioHead SPI1 only supported on Teensy 3.5, 3.6 and LC")
#endif
#endif