arduino-emulator
Loading...
Searching...
No Matches
HardwareSPI_RPI.h
1#pragma once
2/*
3 HardwareSPI_RPI.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_RPI
21#include <inttypes.h>
22
23#include "api/Common.h"
24#include "api/HardwareSPI.h"
25#include "api/Stream.h"
26
27namespace arduino {
28
40 public:
41 HardwareSPI_RPI(const char* device = "/dev/spidev0.0");
42 ~HardwareSPI_RPI() override;
43
44 uint8_t transfer(uint8_t data) override;
45 uint16_t transfer16(uint16_t data) override;
46 void transfer(void* buf, size_t count) override;
47
48 // Transaction Functions
49 void usingInterrupt(int interruptNumber) override;
50 void notUsingInterrupt(int interruptNumber) override;
51 void beginTransaction(SPISettings settings) override;
52 void endTransaction(void) override;
53
54 // SPI Configuration methods
55 void attachInterrupt() override;
56 void detachInterrupt() override;
57
58 void begin() override;
59 void end() override;
60
61 operator bool() { return is_open; }
62
63 protected:
64 int spi_fd = -1;
65 const char* device = "/dev/spidev0.0";
66 uint32_t spi_speed = 500000; // Default to 500kHz
67 uint8_t spi_mode = 0; // Default to SPI mode 0
68 uint8_t spi_bits = 8; // Default to 8 bits per word
69 bool is_open = false;
70};
71
72} // namespace arduino
73
74#endif // USE_RPI
Definition DMAPool.h:103
Implementation of SPI communication for Raspberry Pi using Linux SPI device interface.
Definition HardwareSPI_RPI.h:39
Definition HardwareSPI.h:120
Definition HardwareSPI.h:46
We provide the WiFi class to simulate the Arduino WIFI. In in Linux we can expect that networking is ...
Definition CanMsg.cpp:31