arduino-emulator
Loading...
Searching...
No Matches
HardwareSetupFTDI.h
1#pragma once
2/*
3 HardwareSetupFTDI.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_FTDI) && !defined(SKIP_HARDWARE_SETUP)
21#include "FileStream.h"
22#include "HardwareGPIO_FTDI.h"
23#include "HardwareI2C_FTDI.h"
24#include "HardwareSPI_FTDI.h"
25
26namespace arduino {
27
39class HardwareSetupFTDI : public I2CSource, public SPISource, public GPIOSource {
40 public:
44 HardwareSetupFTDI() = default;
45
54 const char* description = nullptr,
55 const char* serial = nullptr)
56 : vid(vendor_id), pid(product_id), desc(description), ser(serial) {}
57
62
68 bool begin(bool asDefault = true) {
69 Logger.info("Using FTDI FT2232HL hardware interfaces");
70 is_default_objects_active = asDefault;
71
72 // Initialize GPIO first as it opens the FTDI context
73 bool gpio_ok = gpio.begin(vid, pid, desc, ser);
74 bool i2c_ok = i2c.begin(vid, pid, desc, ser);
75 bool spi_ok = spi.begin(vid, pid, desc, ser);
76
77 // Define the global hardware interfaces
78 if (asDefault) {
79 GPIO.setGPIO(&gpio);
80 SPI.setSPI(&spi);
81 Wire.setI2C(&i2c);
82 }
83
84 return gpio_ok && i2c_ok && spi_ok;
85 }
86
90 void end() {
91 if (is_default_objects_active) {
92 GPIO.setGPIO(nullptr);
93 SPI.setSPI(nullptr);
94 Wire.setI2C(nullptr);
95 }
96 gpio.end();
97 i2c.end();
98 spi.end();
99 }
100
101 HardwareGPIO_FTDI* getGPIO() { return &gpio; }
102 HardwareI2C_FTDI* getI2C() { return &i2c; }
103 HardwareSPI_FTDI* getSPI() { return &spi; }
104
113 const char* description = nullptr,
114 const char* serial = nullptr) {
115 vid = vendor_id;
116 pid = product_id;
117 desc = description;
118 ser = serial;
119 }
120
121 protected:
125 bool is_default_objects_active = false;
126
127 // Device identification parameters
128 int vid = 0x0403; // FTDI vendor ID
129 int pid = 0x6010; // FT2232HL product ID
130 const char* desc = nullptr; // Device description
131 const char* ser = nullptr; // Device serial number
132};
133
141
142} // namespace arduino
143
144#endif
Definition DMAPool.h:103
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 FTDI FT2232HL in the Arduino emulator.
Definition HardwareGPIO_FTDI.h:53
bool begin(int vendor_id=0x0403, int product_id=0x6010, const char *description=nullptr, const char *serial=nullptr)
Initialize the GPIO hardware interface for FTDI FT2232HL.
Definition HardwareGPIO_FTDI.cpp:29
void end()
Close the FTDI connection and cleanup resources.
Definition HardwareGPIO_FTDI.cpp:97
Implementation of I2C communication for FTDI FT2232HL using MPSSE mode.
Definition HardwareI2C_FTDI.h:55
void end() override
Close the I2C interface and cleanup resources.
Definition HardwareI2C_FTDI.cpp:97
bool begin(int vendor_id=0x0403, int product_id=0x6010, const char *description=nullptr, const char *serial=nullptr)
Initialize the I2C interface.
Definition HardwareI2C_FTDI.cpp:37
Implementation of SPI communication for FTDI FT2232HL using MPSSE mode.
Definition HardwareSPI_FTDI.h:54
void end() override
Close the SPI interface and cleanup resources.
Definition HardwareSPI_FTDI.cpp:88
Sets up hardware interfaces for FTDI FT2232HL (GPIO, I2C, SPI).
Definition HardwareSetupFTDI.h:39
void setDeviceParams(int vendor_id, int product_id, const char *description=nullptr, const char *serial=nullptr)
Set custom device parameters for targeting specific FTDI device.
Definition HardwareSetupFTDI.h:112
HardwareSetupFTDI(int vendor_id, int product_id, const char *description=nullptr, const char *serial=nullptr)
Constructor with custom device parameters.
Definition HardwareSetupFTDI.h:53
void end()
Resets hardware pointers to nullptr.
Definition HardwareSetupFTDI.h:90
HardwareSetupFTDI()=default
Constructor. Initializes FTDI hardware interfaces.
~HardwareSetupFTDI()
Destructor. Cleans up FTDI hardware interfaces.
Definition HardwareSetupFTDI.h:61
bool begin(bool asDefault=true)
Initializes hardware pointers to FTDI interfaces.
Definition HardwareSetupFTDI.h:68
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 HardwareSetupFTDI FTDI
Global instance for FTDI FT2232HL hardware setup.
Definition HardwareSetupFTDI.h:140