Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
BusOut.h
00001 #ifndef CPP_TO_PIGPIO_BUSOUT_HEADER 00002 #define CPP_TO_PIGPIO_BUSOUT_HEADER 00003 00004 #include <vector> 00005 namespace CPPToPigpio{ 00006 /** 00007 * A BusOut interface is used to create several DigitalOut pins that can be written to using only one value. 00008 */ 00009 00010 class BusOut : public CPPToPigpio{ 00011 private: 00012 std::vector<DigitalOut *> _digitalOuts; 00013 long long _lastWrittenValue; //Track what we last wrote to outputs for read() 00014 public: 00015 00016 /** Create an BusOut, connected to the specified pins 00017 * 00018 * @param p0 DigitalOut pin to connect to bus bit 00019 * @param p1 DigitalOut pin to connect to bus bit 00020 * @param p2 DigitalOut pin to connect to bus bit 00021 * @param p3 DigitalOut pin to connect to bus bit 00022 * @param p4 DigitalOut pin to connect to bus bit 00023 * @param p5 DigitalOut pin to connect to bus bit 00024 * @param p6 DigitalOut pin to connect to bus bit 00025 * @param p7 DigitalOut pin to connect to bus bit 00026 * @param p8 DigitalOut pin to connect to bus bit 00027 * @param p9 DigitalOut pin to connect to bus bit 00028 * @param p10 DigitalOut pin to connect to bus bit 00029 * @param p11 DigitalOut pin to connect to bus bit 00030 * @param p12 DigitalOut pin to connect to bus bit 00031 * @param p13 DigitalOut pin to connect to bus bit 00032 * @param p14 DigitalOut pin to connect to bus bit 00033 * @param p15 DigitalOut pin to connect to bus bit 00034 */ 00035 BusOut (PinName p0, PinName p1=NC, PinName p2=NC, PinName p3=NC, PinName p4=NC, PinName p5=NC, PinName p6=NC, PinName p7=NC, PinName p8=NC, PinName p9=NC, PinName p10=NC, PinName p11=NC, PinName p12=NC, PinName p13=NC, PinName p14=NC, PinName p15=NC); 00036 00037 /** Create an BusOut, connected to the specified pins 00038 * 00039 * @param p0 DigitalOut pin to connect to bus bit 00040 * @param p1 DigitalOut pin to connect to bus bit 00041 * @param p2 DigitalOut pin to connect to bus bit 00042 * @param p3 DigitalOut pin to connect to bus bit 00043 * @param p4 DigitalOut pin to connect to bus bit 00044 * @param p5 DigitalOut pin to connect to bus bit 00045 * @param p6 DigitalOut pin to connect to bus bit 00046 * @param p7 DigitalOut pin to connect to bus bit 00047 * @param p8 DigitalOut pin to connect to bus bit 00048 * @param p9 DigitalOut pin to connect to bus bit 00049 * @param p10 DigitalOut pin to connect to bus bit 00050 * @param p11 DigitalOut pin to connect to bus bit 00051 * @param p12 DigitalOut pin to connect to bus bit 00052 * @param p13 DigitalOut pin to connect to bus bit 00053 * @param p14 DigitalOut pin to connect to bus bit 00054 * @param p15 DigitalOut pin to connect to bus bit 00055 */ 00056 BusOut (int p0, int p1=-1, int p2=-1, int p3=-1, int p4=-1, int p5=-1, int p6=-1, int p7=-1, int p8=-1, int p9=-1, int p10=-1, int p11=-1, int p12=-1, int p13=-1, int p14=-1, int p15=-1); 00057 00058 /** Creates a BusOut, connected to the specific pins. 00059 * 00060 * @param number of pins specified 00061 * @param array of pins to connect to bus 00062 */ 00063 00064 //This is different from standard MBED API. Since the literal 0 is a valid pinName, need busSize to be passed in to tell which pins matter. 00065 BusOut (int busSize, PinName pinNames[16]); 00066 00067 /** Creates a BusOut, connected to the specific pins. 00068 * 00069 * @param number of pins specified 00070 * @param array of pins to connect to bus 00071 */ 00072 00073 //This is different from standard MBED API. Since the literal 0 is a valid pinName, need busSize to be passed in to tell which pins matter. 00074 BusOut (int busSize, int pinNames[16]); 00075 00076 /** Write the value to the output bus 00077 * 00078 * @param value An integer specifying a bit to write for every corresponding DigitalOut pin 00079 */ 00080 void write(int value); 00081 00082 /** Read the value currently output on the bus 00083 * 00084 * @returns An integer with each bit corresponding to associated DigitalOut pin setting 00085 */ 00086 int read(); 00087 00088 /** A shorthand for read() 00089 * \sa BusOut::read() 00090 */ 00091 operator int(); 00092 00093 /** Access to particular bit in random-iterator fashion 00094 * @param index Bit Position 00095 */ 00096 DigitalOut & operator[](int index); 00097 00098 /** A shorthand for write() 00099 * \sa BusOut::write() 00100 */ 00101 BusOut & operator=(int v); //Short for write 00102 00103 /** Binary mask of bus pins connected to actual pins (not NC pins) 00104 * If bus pin is in NC state make corresponding bit will be cleared (set to 0), else bit will be set to 1 00105 * 00106 * @returns Binary mask of connected pins 00107 */ 00108 //Returns mask of connected pins, double check that this matches what it should do. Note that since 0 is valid, mask of BusIn(0) will return 0b000..1 and mask(BusIn(1)) returns 0b000..10 00109 long long mask(); 00110 00111 /** Desconstructor for object 00112 */ 00113 ~BusOut(); 00114 00115 }; 00116 00117 00118 } 00119 00120 #endif
Generated on Tue Jul 12 2022 14:39:23 by
1.7.2