arduino-emulator
Loading...
Searching...
No Matches
HardwareGPIO_RPI.h
1#pragma once
2/*
3 HardwareGPIO_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 "HardwareGPIO.h"
22#include <map>
23
24
25namespace arduino {
26
42 public:
46 HardwareGPIO_RPI() = default;
47
52 HardwareGPIO_RPI(const char* devName) : device_name(devName) {}
53
58
65 void begin();
66
70 void pinMode(pin_size_t pinNumber, PinMode pinMode) override;
71
75 void digitalWrite(pin_size_t pinNumber, PinStatus status) override;
76
80 PinStatus digitalRead(pin_size_t pinNumber) override;
81
85 int analogRead(pin_size_t pinNumber) override;
86
90 void analogReference(uint8_t mode) override;
91
95 void analogWrite(pin_size_t pinNumber, int value) override;
96
103 void tone(uint8_t _pin, unsigned int frequency,
104 unsigned long duration = 0) override;
105
109 void noTone(uint8_t _pin) override;
110
117 unsigned long pulseIn(uint8_t pin, uint8_t state,
118 unsigned long timeout = 1000000L) override;
119
126 unsigned long pulseInLong(uint8_t pin, uint8_t state,
127 unsigned long timeout = 1000000L) override;
128
132 void analogWriteFrequency(pin_size_t pin, uint32_t freq);
133
139
144 operator bool() { return is_open; }
145
146 protected:
147 int m_analogReference = 0;
148 std::map<pin_size_t, uint32_t> gpio_frequencies;
149 int pwm_pins[4] = {12, 13, 18, 19};
150 bool is_open = false;
151 const char* device_name = "gpiochip0";
152 uint32_t max_value = 255; // Default for 8-bit resolution
153
154 uint32_t getFrequency(int pin);
155};
156
157} // namespace arduino
158
159#endif
Definition DMAPool.h:103
GPIO hardware abstraction for Raspberry Pi in the Arduino emulator.
Definition HardwareGPIO_RPI.h:41
unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout=1000000L) override
Measure long pulse duration on a pin.
Definition HardwareGPIO_RPI.cpp:221
void analogWriteFrequency(pin_size_t pin, uint32_t freq)
Set PWM frequency for a pin.
Definition HardwareGPIO_RPI.cpp:227
void analogWrite(pin_size_t pinNumber, int value) override
Write an analog value (PWM) to a pin.
Definition HardwareGPIO_RPI.cpp:127
void tone(uint8_t _pin, unsigned int frequency, unsigned long duration=0) override
Generate a tone on a pin.
Definition HardwareGPIO_RPI.cpp:203
void begin()
Initialize the GPIO hardware interface for Raspberry Pi.
Definition HardwareGPIO_RPI.cpp:36
void pinMode(pin_size_t pinNumber, PinMode pinMode) override
Set the mode of a GPIO pin (INPUT, OUTPUT, etc).
Definition HardwareGPIO_RPI.cpp:57
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout=1000000L) override
Measure pulse duration on a pin.
Definition HardwareGPIO_RPI.cpp:215
HardwareGPIO_RPI(const char *devName)
Constructor for HardwareGPIO_RPI with custom device name.
Definition HardwareGPIO_RPI.h:52
~HardwareGPIO_RPI()
Destructor for HardwareGPIO_RPI.
Definition HardwareGPIO_RPI.cpp:46
int analogRead(pin_size_t pinNumber) override
Read an analog value from a pin (if supported).
Definition HardwareGPIO_RPI.cpp:110
PinStatus digitalRead(pin_size_t pinNumber) override
Read a digital value from a GPIO pin.
Definition HardwareGPIO_RPI.cpp:93
HardwareGPIO_RPI()=default
Constructor for HardwareGPIO_RPI.
void analogWriteResolution(uint8_t bits)
Set the resolution (number of bits) for analogWrite (PWM output).
Definition HardwareGPIO_RPI.cpp:243
void noTone(uint8_t _pin) override
Stop tone generation on a pin.
Definition HardwareGPIO_RPI.cpp:213
void analogReference(uint8_t mode) override
Set the analog reference mode.
Definition HardwareGPIO_RPI.cpp:116
void digitalWrite(pin_size_t pinNumber, PinStatus status) override
Write a digital value to a GPIO pin.
Definition HardwareGPIO_RPI.cpp:79
Abstract base class for GPIO (General Purpose Input/Output) functions.
Definition HardwareGPIO.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