-
-
Notifications
You must be signed in to change notification settings - Fork 212
/
Copy pathSPI.h
74 lines (58 loc) · 1.94 KB
/
SPI.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
/*
Copyright (c) 2016 Arduino LLC. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#pragma once
#include "Arduino.h"
#include "api/HardwareSPI.h"
#include <Mutex.h>
typedef struct _mbed_spi mbed_spi;
namespace arduino {
class MbedSPI : public SPIClass
{
public:
MbedSPI(int miso, int mosi, int sck);
MbedSPI(PinName miso, PinName mosi, PinName sck);
virtual uint8_t transfer(uint8_t data);
virtual uint16_t transfer16(uint16_t data);
virtual void transfer(void *buf, size_t count);
// Transaction Functions
virtual void usingInterrupt(int interruptNumber);
virtual void notUsingInterrupt(int interruptNumber);
virtual void beginTransaction(SPISettings settings);
virtual void endTransaction(void);
// SPI Configuration methods
virtual void attachInterrupt();
virtual void detachInterrupt();
virtual void begin();
virtual void end();
private:
SPISettings settings = SPISettings(0, MSBFIRST, SPI_MODE0);
_mbed_spi* dev = NULL;
rtos::Mutex spiLockMutex;
PinName _miso;
PinName _mosi;
PinName _sck;
};
}
#if !defined(ARDUINO_AS_MBED_LIBRARY)
#if SPI_HOWMANY > 0
extern arduino::MbedSPI SPI;
#endif
#if SPI_HOWMANY > 1
#ifdef SPI1
#undef SPI1
#endif
extern arduino::MbedSPI SPI1;
#endif
#endif