|
arduino-emulator
|
GPIO hardware abstraction for FTDI FT2232HL in the Arduino emulator. More...
#include <HardwareGPIO_FTDI.h>
Classes | |
| struct | PWMPin |
Public Member Functions | |
| HardwareGPIO_FTDI ()=default | |
| Constructor for HardwareGPIO_FTDI. | |
| ~HardwareGPIO_FTDI () | |
| Destructor for HardwareGPIO_FTDI. | |
| int | analogRead (pin_size_t pinNumber) override |
| Read an analog value from a pin (not supported by FT2232HL). | |
| void | analogReference (uint8_t mode) override |
| Set the analog reference mode (not supported by FT2232HL). | |
| void | analogWrite (pin_size_t pinNumber, int value) override |
| Write an analog value (PWM) to a pin using software PWM. | |
| void | analogWriteFrequency (pin_size_t pinNumber, uint32_t frequency) |
| Set the PWM frequency for analogWrite() on a specific pin. | |
| void | analogWriteResolution (uint8_t bits) override |
| Set the resolution for analogWrite() operations. | |
| 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. | |
| PinStatus | digitalRead (pin_size_t pinNumber) override |
| Read a digital value from a GPIO pin. | |
| void | digitalWrite (pin_size_t pinNumber, PinStatus status) override |
| Write a digital value to a GPIO pin. | |
| void | end () |
| Close the FTDI connection and cleanup resources. | |
| void | getPWMStatistics (pin_size_t pin, uint64_t &cycles, uint64_t &max_jitter_us, uint64_t &avg_jitter_us) |
| Get PWM statistics for monitoring timing accuracy. | |
| void | noTone (uint8_t _pin) override |
| Stop tone generation on a pin (not supported by FT2232HL). | |
| operator bool () | |
| Boolean conversion operator. | |
| void | pinMode (pin_size_t pinNumber, PinMode pinMode) override |
| Set the mode of a GPIO pin (INPUT, OUTPUT, etc). | |
| unsigned long | pulseIn (uint8_t pin, uint8_t state, unsigned long timeout=1000000L) override |
| Measure pulse duration on a pin (not supported by FT2232HL). | |
| unsigned long | pulseInLong (uint8_t pin, uint8_t state, unsigned long timeout=1000000L) override |
| Measure long pulse duration on a pin (not supported by FT2232HL). | |
| void | tone (uint8_t _pin, unsigned int frequency, unsigned long duration=0) override |
| Generate a tone on a pin (not supported by FT2232HL). | |
Protected Member Functions | |
| int | getBitPosition (pin_size_t pin) |
| Get the bit position within a channel for a given pin. | |
| int | getChannel (pin_size_t pin) |
| Get the channel number for a given pin. | |
| void | pwmThreadFunction () |
| PWM thread function that handles software PWM generation. | |
| bool | readGPIOState (int channel, uint8_t &value) |
| Read current GPIO state from the FTDI device. | |
| void | startPWMThread () |
| Start the PWM background thread. | |
| void | stopPWMThread () |
| Stop the PWM background thread. | |
| bool | updateGPIOState (int channel) |
| Update the GPIO state on the FTDI device. | |
| void | updatePWMPin (pin_size_t pin, uint8_t duty_cycle, uint32_t frequency=1000) |
| Update PWM pin configuration. | |
Protected Attributes | |
| struct ftdi_context * | ftdi_context = nullptr |
| bool | is_open = false |
| uint8_t | pin_directions_a = 0x00 |
| uint8_t | pin_directions_b = 0x00 |
| std::map< pin_size_t, PinMode > | pin_modes |
| uint8_t | pin_values_a = 0x00 |
| uint8_t | pin_values_b = 0x00 |
| std::mutex | pwm_mutex |
| std::map< pin_size_t, PWMPin > | pwm_pins |
| std::thread | pwm_thread |
| std::atomic< bool > | pwm_thread_running {false} |
GPIO hardware abstraction for FTDI FT2232HL in the Arduino emulator.
This class implements the Arduino-style GPIO interface for FTDI FT2232HL devices, allowing digital I/O operations to be used in a manner compatible with Arduino code. The FT2232HL provides 16 GPIO pins (8 per channel) that can be configured for digital input/output.
Pin mapping for FT2232HL:
The class inherits from HardwareGPIO and is intended for use within the emulator when communicating with FTDI FT2232HL devices. It manages pin state and direction for supported pins.
|
overridevirtual |
Read an analog value from a pin (not supported by FT2232HL).
| pinNumber | Pin number |
Implements arduino::HardwareGPIO.
Set the analog reference mode (not supported by FT2232HL).
| mode | Reference mode (ignored) |
Implements arduino::HardwareGPIO.
Write an analog value (PWM) to a pin using software PWM.
| pinNumber | Pin number (0-15) |
| value | PWM duty cycle (0-255, where 0=0% and 255=100%) |
Implements arduino::HardwareGPIO.
|
virtual |
Set the PWM frequency for analogWrite() on a specific pin.
| pinNumber | Pin number (0-15) |
| frequency | PWM frequency in Hz (default: 1000Hz) |
Implements arduino::HardwareGPIO.
Set the resolution for analogWrite() operations.
| bits | The resolution in bits (8-bit by default for FTDI) |
Implements arduino::HardwareGPIO.
| bool arduino::HardwareGPIO_FTDI::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.
| vendor_id | USB vendor ID (default: 0x0403) |
| product_id | USB product ID (default: 0x6010 for FT2232HL) |
| description | Device description string (optional) |
| serial | Device serial number (optional) |
|
overridevirtual |
Read a digital value from a GPIO pin.
| pinNumber | Pin number (0-15) |
Implements arduino::HardwareGPIO.
|
overridevirtual |
Write a digital value to a GPIO pin.
| pinNumber | Pin number (0-15) |
| status | Pin status (HIGH or LOW) |
Implements arduino::HardwareGPIO.
|
inlineprotected |
Get the bit position within a channel for a given pin.
| pin | Pin number (0-15) |
|
inlineprotected |
Get the channel number for a given pin.
| pin | Pin number (0-15) |
| void arduino::HardwareGPIO_FTDI::getPWMStatistics | ( | pin_size_t | pin, |
| uint64_t & | cycles, | ||
| uint64_t & | max_jitter_us, | ||
| uint64_t & | avg_jitter_us | ||
| ) |
Get PWM statistics for monitoring timing accuracy.
| pin | Pin number |
| cycles | Total number of PWM cycles completed |
| max_jitter_us | Maximum jitter observed in microseconds |
| avg_jitter_us | Average jitter in microseconds |
Stop tone generation on a pin (not supported by FT2232HL).
| _pin | Pin number (ignored) |
Implements arduino::HardwareGPIO.
|
inline |
Boolean conversion operator.
|
overridevirtual |
Set the mode of a GPIO pin (INPUT, OUTPUT, etc).
| pinNumber | Pin number (0-15 for FT2232HL) |
| pinMode | Pin mode (INPUT, OUTPUT, INPUT_PULLUP) |
Implements arduino::HardwareGPIO.
|
overridevirtual |
Measure pulse duration on a pin (not supported by FT2232HL).
| pin | Pin number |
| state | Pin state to measure |
| timeout | Timeout in microseconds |
Implements arduino::HardwareGPIO.
|
overridevirtual |
Measure long pulse duration on a pin (not supported by FT2232HL).
| pin | Pin number |
| state | Pin state to measure |
| timeout | Timeout in microseconds |
Implements arduino::HardwareGPIO.
Read current GPIO state from the FTDI device.
| channel | Channel to read (0 for A, 1 for B) |
| value | Reference to store the read value |
|
overridevirtual |
Generate a tone on a pin (not supported by FT2232HL).
| _pin | Pin number |
| frequency | Frequency in Hz (ignored) |
| duration | Duration in ms (ignored) |
Implements arduino::HardwareGPIO.
Update the GPIO state on the FTDI device.
| channel | Channel to update (0 for A, 1 for B) |
|
protected |
Update PWM pin configuration.
| pin | Pin number |
| duty_cycle | Duty cycle (0-255) |
| frequency | Frequency in Hz |