/* * "PE4302.h" * * Added to the "TinySA" program in Version 1.1 by John Price (WA2FZW): * * This is the header file for the PE4302 class. */ #ifndef PE4302_H_ #define PE4302_H_ // Prevent double inclusion #include // General Arduino definitions #include // I2C library #include // Serial Peripheral Interface library #include "simpleSA.h" /* * In order to save GPIO pins on the ESP32, Glenn (VK3PE) and I decided to use a * PCF8574 GPIO expander chip between the processor and the parallel version of * of the PE4302 attenuator. We know some PE4302 modules are available with a * serial interface, but the ones we happen to have only support the parallel * interface. This lets us control it over the I2C bus. * * It's not clear to me that the native serial interface to the serial module * is an I2C interface, but we will also support that via a bit-banging techique. * We will also support the parallel interface module without the PCF8574. */ enum { PCF, P, S }; // Symbols for operational modes class PE4302 { public: /* * Function prototypes for the PE4302 available to the outside world: * * Constructors: */ explicit PE4302 ( SPIClass* spi, int le ); // For serial interface explicit PE4302 ( int address ); // For PCF8574 interface explicit PE4302 ( int c16, int c8, int c4, // For parallel interface int c2, int c1, int c0 ); void Init (); // Initialize the module bool SetAtten ( int8_t atten ); // Set the attenuation int GetAtten (); // Get the current attenuation private: uint8_t _pcf_I2C; // I2C address for the PCF8574 uint8_t _interface; // Interface type ( PCF, P or S ) uint8_t _le_Pin; // Enable (LE) pin for serial or parallel interdace uint8_t _parallel_Pins[6]; // Pin numbers ( c0 - c16 ) for parallel interface int16_t _atten; // Current attenuator setting ( 0 - 31 dB ) x 2 SPIClass* _spi; // Pointer to the SPI object used for serial mode }; /* * This is a stripped down version of the PCF8574 library. We only need the * constructor, the "begin" function (slightly modified from the original * library), the "write8" functions and a couple of the variables. */ class PCF8574 { public: explicit PCF8574 ( const uint8_t deviceAddress ); void begin ( const uint8_t deviceAddress, uint8_t val ); void write8 ( const uint8_t value ); private: uint8_t _address; // PCF8574 I2C address uint8_t _dataOut; // Data to be sent }; #endif