File indexing completed on 2024-04-21 05:43:48

0001 /***************************************************************************
0002  *   Copyright (C) 2003 by David Saxton                                    *
0003  *   david@bluehaze.org                                                    *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  ***************************************************************************/
0010 
0011 #include "micropackage.h"
0012 
0013 #include <ktechlab_debug.h>
0014 
0015 PicPin::PicPin()
0016 {
0017     pinID = QString::fromLatin1("INVALID");
0018     type = PicPin::type_bidir;
0019     portName = QString::fromLatin1("INVALID");
0020     portPosition = -1;
0021 }
0022 
0023 PicPin::PicPin(const QString &_pinID, PicPin::pin_type _type, const QString &_portName, int _portPosition)
0024 {
0025     pinID = _pinID;
0026     type = _type;
0027     portName = _portName;
0028     portPosition = _portPosition;
0029 }
0030 
0031 MicroPackage::MicroPackage(const int pinCount)
0032 {
0033     m_numPins = pinCount;
0034 }
0035 
0036 MicroPackage::~MicroPackage()
0037 {
0038 }
0039 
0040 void MicroPackage::assignPin(int pinPosition, PicPin::pin_type type, const QString &pinID, const QString &portName, int portPosition)
0041 {
0042     if (m_picPinMap.find(pinPosition) != m_picPinMap.end()) {
0043         qCCritical(KTL_LOG) << "PicDevice::assignBidirPin: Attempting to reset pin " << pinPosition;
0044         return;
0045     }
0046     if (!m_portNames.contains(portName) && !portName.isEmpty()) {
0047         m_portNames.append(portName);
0048         m_portNames.sort();
0049     }
0050 
0051     m_picPinMap[pinPosition] = PicPin(pinID, type, portName, portPosition);
0052 }
0053 
0054 PicPinMap MicroPackage::pins(uint pinType, const QString &portName)
0055 {
0056     if (pinType == 0)
0057         pinType = (1 << 30) - 1;
0058 
0059     PicPinMap list;
0060 
0061     const PicPinMap::iterator picPinListEnd = m_picPinMap.end();
0062     for (PicPinMap::iterator it = m_picPinMap.begin(); it != picPinListEnd; ++it) {
0063         if ((it.value().type & pinType) && (portName.isEmpty() || it.value().portName == portName)) {
0064             list[it.key()] = it.value();
0065         }
0066     }
0067 
0068     return list;
0069 }
0070 
0071 QStringList MicroPackage::pinIDs(uint pinType, const QString &portName)
0072 {
0073     if (pinType == 0)
0074         pinType = (1 << 30) - 1;
0075     QStringList list;
0076 
0077     const PicPinMap::iterator picPinListEnd = m_picPinMap.end();
0078     for (PicPinMap::iterator it = m_picPinMap.begin(); it != picPinListEnd; ++it) {
0079         if ((it.value().type & pinType) && (portName.isEmpty() || it.value().portName == portName)) {
0080             list.append(it.value().pinID);
0081         }
0082     }
0083 
0084     return list;
0085 }
0086 
0087 int MicroPackage::pinCount(uint pinType, const QString &portName)
0088 {
0089     if (pinType == 0)
0090         pinType = (1 << 30) - 1;
0091     int count = 0;
0092 
0093     const PicPinMap::iterator picPinListEnd = m_picPinMap.end();
0094     for (PicPinMap::iterator it = m_picPinMap.begin(); it != picPinListEnd; ++it) {
0095         if ((it.value().type & pinType) && (portName.isEmpty() || it.value().portName == portName))
0096             count++;
0097     }
0098 
0099     return count;
0100 }