1 /*************************************************************************** 2 * Copyright (C) 2003-2005 by David Saxton * 3 * david@bluehaze.org * 4 * * 5 * This program is free software; you can redistribute it and/or modify * 6 * it under the terms of the GNU General Public License as published by * 7 * the Free Software Foundation; either version 2 of the License, or * 8 * (at your option) any later version. * 9 ***************************************************************************/ 10 11 #ifndef PICPACKAGES_H 12 #define PICPACKAGES_H 13 14 #include <QString> 15 #include <QStringList> 16 17 #include <QMap> 18 19 /** 20 @author David Saxton 21 */ 22 class PicPin 23 { 24 public: 25 enum pin_type 26 { 27 type_input = 0x1, // Input only pin 28 type_bidir = 0x2, // Bi-directional (input/output) 29 type_open = 0x4, // Open collector 30 type_vss = 0x8, // Voltage source 31 type_vdd = 0x10, // Voltage drain 32 type_mclr = 0x20, // Memory clear 33 type_osc = 0x40 // Oscillator 34 }; 35 36 PicPin(); 37 PicPin( const QString &_pinID, PicPin::pin_type _type, const QString &_portName = "", int _portPosition = -1 ); 38 39 PicPin::pin_type type; 40 41 QString pinID; // Id of pin, eg 'MCLR' 42 43 // For bidir (io) pins 44 QString portName; // Name of port, eg 'PORTA' 45 int portPosition; // Position in port 46 }; 47 48 typedef QMap<int, PicPin> PicPinMap; 49 50 /** 51 @short Describes the PIC package (i.e. pins) 52 @author David Saxton 53 */ 54 class MicroPackage 55 { 56 public: 57 MicroPackage( const int pinCount ); 58 virtual ~MicroPackage(); 59 60 /** 61 * Assigns a pin to a position in the package. 62 */ 63 void assignPin( int pinPosition, PicPin::pin_type type, const QString& pinID, const QString& portName = "", int portPosition = -1); 64 void assignPin( int pinPosition, PicPin::pin_type type, const char* pinID, const char* portName = "", int portPosition = -1) { 65 assignPin(pinPosition, type, QString::fromLatin1(pinID), QString::fromLatin1(portName), portPosition); 66 } 67 68 /** 69 * Returns the pins of the given type(s). If portName is not specified, all pins will be returned; 70 * not just those belonging to a given port. pin_type's can be OR'ed together 71 * e.g. pins( PicPin::type_input | PicPin::type_bidir, "PORTA" ) will return all bidirectional or 72 * input pins belonging to PORTA. If pinType is 0, then this will return all pins 73 */ 74 PicPinMap pins( uint pinType = 0, const QString& portName = "" ); 75 /** 76 * Returns just a QStringList of the pin ids. 77 * @see pins( uint pinType, const QString& portName ) 78 */ 79 QStringList pinIDs( uint pinType = 0, const QString& portName = "" ); 80 /** 81 * Returns the number of pins of the given type(s) (which can be OR'ed together), with the given 82 * port name if specified, while avoiding the construction of a new PicPinMap. if pinType is 0, 83 * then all pin types are considered 84 * @see pins 85 */ 86 int pinCount( uint pinType = 0, const QString& portName = "" ); 87 /** 88 * Returns a list of port names, eg 'PORTA', 'PORTB' for the package 89 */ portNames()90 QStringList portNames() const { return m_portNames; } 91 /** 92 * Returns the number of ports 93 */ portCount()94 uint portCount() const { return m_portNames.size(); } 95 96 private: 97 PicPinMap m_picPinMap; 98 QStringList m_portNames; 99 int m_numPins; 100 }; 101 102 #endif 103 104 105