arduino-emulator
Loading...
Searching...
No Matches
SPIWrapper.h
1/*
2 SPIWrapper.h
3 Copyright (c) 2025 Phil Schatzmann. All right reserved.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18*/
19
20#pragma once
21#include "Sources.h"
22#include "api/HardwareSPI.h"
23
24namespace arduino {
25
53class SPIWrapper : public HardwareSPI {
54 public:
55 SPIWrapper() = default;
57 SPIWrapper(HardwareSPI& spi) { setSPI(&spi); }
58 ~SPIWrapper() = default;
59 void begin();
60 void end();
61 uint8_t transfer(uint8_t data);
62 uint16_t transfer16(uint16_t data);
63 void transfer(void* data, size_t count);
64 void usingInterrupt(int interruptNumber);
65 void notUsingInterrupt(int interruptNumber);
66 void beginTransaction(SPISettings settings);
67 void endTransaction(void);
68 void attachInterrupt();
69 void detachInterrupt();
70
72 void setSPI(HardwareSPI* spi) {
73 p_spi = spi;
74 p_source = nullptr;
75 }
78 p_source = source;
79 p_spi = nullptr;
80 }
81
82 protected:
83 HardwareSPI* p_spi = nullptr;
84 SPISource* p_source = nullptr;
85
86 HardwareSPI* getSPI() {
87 HardwareSPI* result = p_spi;
88 if (result == nullptr && p_source != nullptr) {
89 result = p_source->getSPI();
90 }
91 return result;
92 }
93};
94
96extern SPIWrapper SPI;
97
98} // namespace arduino
Definition DMAPool.h:103
Definition HardwareSPI.h:120
Definition HardwareSPI.h:46
Abstract interface for providing SPI hardware implementations.
Definition Sources.h:51
SPI wrapper class that provides flexible hardware abstraction.
Definition SPIWrapper.h:53
void setSource(SPISource *source)
alternatively defines a class that provides the SPI implementation
Definition SPIWrapper.h:77
void setSPI(HardwareSPI *spi)
defines the spi implementation: use nullptr to reset.
Definition SPIWrapper.h:72
We provide the WiFi class to simulate the Arduino WIFI. In in Linux we can expect that networking is ...
Definition CanMsg.cpp:31
SPIWrapper SPI
Global SPI instance used by Arduino API and direct access.
Definition SPIWrapper.cpp:27