arduino-emulator
Loading...
Searching...
No Matches
HardwareSetupRPI.h
1#pragma once
2/*
3 HardwareSetupRPI.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#if defined(USE_RPI) && !defined(SKIP_HARDWARE_SETUP)
21#include "FileStream.h"
22#include "HardwareGPIO_RPI.h"
23#include "HardwareI2C_RPI.h"
24#include "HardwareSPI_RPI.h"
25
26namespace arduino {
27
32class HardwareSetupRPI : public I2CSource, public SPISource, public GPIOSource {
33 public:
37 HardwareSetupRPI() = default;
38
43
47 bool begin(bool asDefault = true) {
48 Logger.info("Using Raspberry Pi hardware interfaces");
49 is_default_objects_active = asDefault;
50 gpio.begin();
51
52 // define the global hardware interfaces
53 if (asDefault) {
54 Logger.warning("GPIO, I2C, SPI set up for Raspberry Pi");
55 GPIO.setGPIO(&gpio);
56 SPI.setSPI(&spi);
57 Wire.setI2C(&i2c);
58 }
59
60 return gpio && i2c && spi;
61 }
62
66 void end() {
67 if (is_default_objects_active) {
68 GPIO.setGPIO(nullptr);
69 SPI.setSPI(nullptr);
70 Wire.setI2C(nullptr);
71 }
72 }
73
74 HardwareGPIO_RPI* getGPIO() { return &gpio; }
75 HardwareI2C_RPI* getI2C() { return &i2c; }
76 HardwareSPI_RPI* getSPI() { return &spi; }
77
78 protected:
79 HardwareGPIO_RPI gpio;
80 HardwareI2C_RPI i2c;
81 HardwareSPI_RPI spi;
82 bool is_default_objects_active = false;
83};
84
92
102static FileStream Serial2("/dev/serial0");
103
104} // namespace arduino
105
106#endif
Definition DMAPool.h:103
We use the FileStream class to be able to provide Serail, Serial1 and Serial2 outside of the Arduino ...
Definition FileStream.h:30
Abstract interface for providing GPIO hardware implementations.
Definition Sources.h:66
void setGPIO(HardwareGPIO *gpio)
Set the GPIO implementation directly.
Definition GPIOWrapper.h:153
GPIO hardware abstraction for Raspberry Pi in the Arduino emulator.
Definition HardwareGPIO_RPI.h:41
void begin()
Initialize the GPIO hardware interface for Raspberry Pi.
Definition HardwareGPIO_RPI.cpp:36
Sets up hardware interfaces for Raspberry Pi (GPIO, I2C, SPI).
Definition HardwareSetupRPI.h:32
~HardwareSetupRPI()
Destructor. Cleans up hardware interfaces.
Definition HardwareSetupRPI.h:42
bool begin(bool asDefault=true)
Initializes hardware pointers to Raspberry Pi interfaces.
Definition HardwareSetupRPI.h:47
HardwareSetupRPI()=default
Constructor. Initializes hardware interfaces.
void end()
Resets hardware pointers to nullptr.
Definition HardwareSetupRPI.h:66
Abstract interface for providing I2C hardware implementations.
Definition Sources.h:36
void setI2C(HardwareI2C *i2c)
defines the i2c implementation: use nullptr to reset.
Definition I2CWrapper.h:74
Abstract interface for providing SPI hardware implementations.
Definition Sources.h:51
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
I2CWrapper Wire
Global Wire instance used by Arduino API functions and direct access.
Definition I2CWrapper.cpp:24
SPIWrapper SPI
Global SPI instance used by Arduino API and direct access.
Definition SPIWrapper.cpp:27
GPIOWrapper GPIO
Global GPIO instance used by Arduino API functions and direct access.
Definition GPIOWrapper.cpp:35
static FileStream Serial2("/dev/serial0")
Second hardware serial port for Raspberry Pi.
static HardwareSetupRPI RPI
Global instance for Raspberry Pi hardware setup.
Definition HardwareSetupRPI.h:91