arduino-emulator
Loading...
Searching...
No Matches
HardwareSPI_FIR.h
1#pragma once
2/*
3 HardwareSPI_FIR.h
4 Copyright (c) 2025 Phil Schatzmann. All right reserved.
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19*/
20#ifdef USE_FIRMATA
21#include "api/HardwareSPI.h"
22#include "FirmataTransport.h"
23#include <condition_variable>
24#include <memory>
25#include <mutex>
26#include <vector>
27
28namespace arduino {
29
46 public:
55
57 bool begin(Stream &stream);
60 bool begin(FirmataTransport &transport);
61
62 void begin() override;
63 void end() override;
64
65 uint8_t transfer(uint8_t data) override;
66 uint16_t transfer16(uint16_t data) override;
67 void transfer(void *buf, size_t count) override;
68
69 void usingInterrupt(int interruptNumber) override {}
70 void notUsingInterrupt(int interruptNumber) override {}
71 void beginTransaction(SPISettings settings) override;
72 void endTransaction(void) override {}
73
74 void attachInterrupt() override {}
75 void detachInterrupt() override {}
76
78 void setTimeout(unsigned long timeout_ms) { timeout_ms_ = timeout_ms; }
79
80 operator bool() { return is_open; }
81
82 protected:
83 FirmataTransport *transport_ = nullptr; // non-owning
84 std::unique_ptr<FirmataTransport> owned_transport_; // set by begin(Stream&)
85 bool is_open = false;
86 bool configured_ = false;
87 unsigned long timeout_ms_ = 1000;
88
89 uint8_t device_id_;
90 int8_t cs_pin_;
91 SPISettings settings_;
92
93 std::mutex reply_mutex_;
94 std::condition_variable reply_cv_;
95 std::vector<uint8_t> reply_buffer_;
96 bool reply_pending_ = false;
97
98 void sendDeviceConfig();
99 void doTransfer(uint8_t *buf, size_t count);
100 void handleSysex(const FirmataSysexMessage &msg);
101};
102
103} // namespace arduino
104
105#endif // USE_FIRMATA
Definition DMAPool.h:103
Single reader thread + byte-stream parser shared by every Firmata-based hardware backend (GPIO,...
Definition FirmataTransport.h:66
SPI master implementation that speaks the SysEx SPI protocol implemented by ConfigurableFirmata's Spi...
Definition HardwareSPI_FIR.h:45
bool begin(Stream &stream)
Start talking Firmata over the given stream (owns a private transport).
Definition HardwareSPI_FIR.cpp:41
void setTimeout(unsigned long timeout_ms)
Maximum time transfer() waits for the SPI_REPLY, in milliseconds.
Definition HardwareSPI_FIR.h:78
Definition HardwareSPI.h:120
Definition HardwareSPI.h:46
Definition Stream.h:51
We provide the WiFi class to simulate the Arduino WIFI. In in Linux we can expect that networking is ...
Definition CanMsg.cpp:31