From b0f73aa8d989d6d44f695ab64612482b102889c1 Mon Sep 17 00:00:00 2001 From: Gwenhael Goavec-Merou Date: Fri, 30 Oct 2020 08:18:38 +0100 Subject: [PATCH] ftdipp_mpsse: add method to configure individually pins direction --- src/ftdipp_mpsse.cpp | 26 ++++++++++++++++++++++++++ src/ftdipp_mpsse.hpp | 3 +++ 2 files changed, 29 insertions(+) diff --git a/src/ftdipp_mpsse.cpp b/src/ftdipp_mpsse.cpp index c5a1c88..0cf2f38 100644 --- a/src/ftdipp_mpsse.cpp +++ b/src/ftdipp_mpsse.cpp @@ -479,6 +479,32 @@ void FTDIpp_MPSSE::gpio_set_dir(uint16_t dir) _cable.bit_high_dir = (dir >> 8) & 0xff; } +/** + * configure low or high pins as input + * @param[in] gpio: pins bitmask + * @param[int] low_pins: select between CBUS or DBUS + */ +void FTDIpp_MPSSE::gpio_set_input(uint16_t gpio, bool low_pins) +{ + if (low_pins) + _cable.bit_low_dir &= ~gpio; + else + _cable.bit_high_dir &= ~gpio; +} + +/** + * configure low or high pins as output + * @param[in] gpio: pins bitmask + * @param[int] low_pins: select between CBUS or DBUS + */ +void FTDIpp_MPSSE::gpio_set_output(uint16_t gpio, bool low_pins) +{ + if (low_pins) + _cable.bit_low_dir |= gpio; + else + _cable.bit_high_dir |= gpio; +} + /** * private method to write ftdi half bank GPIOs (pins state are in _cable) * @param[in] low or high half bank diff --git a/src/ftdipp_mpsse.hpp b/src/ftdipp_mpsse.hpp index 90cdad9..4dc8633 100644 --- a/src/ftdipp_mpsse.hpp +++ b/src/ftdipp_mpsse.hpp @@ -39,8 +39,11 @@ class FTDIpp_MPSSE { /* full access */ bool gpio_write(uint16_t gpio); bool gpio_write(uint8_t gpio, bool low_pins); + /* gpio direction */ void gpio_set_dir(uint8_t dir, bool low_pins); void gpio_set_dir(uint16_t dir); + void gpio_set_input(uint16_t gpio, bool low_pins); + void gpio_set_output(uint16_t gpio, bool low_pins); protected: void open_device(const std::string &serial, unsigned int baudrate);