1 /***************************************************************************
2  *   Copyright (C) 2003 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 #include "micropackage.h"
12 
13 #include <QDebug>
14 
PicPin()15 PicPin::PicPin()
16 {
17 	pinID = QString::fromLatin1("INVALID");
18 	type = PicPin::type_bidir;
19 	portName = QString::fromLatin1("INVALID");
20 	portPosition = -1;
21 }
22 
23 
PicPin(const QString & _pinID,PicPin::pin_type _type,const QString & _portName,int _portPosition)24 PicPin::PicPin( const QString &_pinID, PicPin::pin_type _type, const QString &_portName, int _portPosition )
25 {
26 	pinID = _pinID;
27 	type = _type;
28 	portName = _portName;
29 	portPosition = _portPosition;
30 }
31 
MicroPackage(const int pinCount)32 MicroPackage::MicroPackage( const int pinCount )
33 {
34 	m_numPins = pinCount;
35 }
36 
~MicroPackage()37 MicroPackage::~MicroPackage()
38 {
39 }
40 
assignPin(int pinPosition,PicPin::pin_type type,const QString & pinID,const QString & portName,int portPosition)41 void MicroPackage::assignPin( int pinPosition, PicPin::pin_type type, const QString& pinID, const QString& portName, int portPosition )
42 {
43 	if ( m_picPinMap.find(pinPosition) != m_picPinMap.end() )
44 	{
45 		qCritical() << "PicDevice::assignBidirPin: Attempting to reset pin "<<pinPosition<<endl;
46 		return;
47 	}
48 	if ( !m_portNames.contains(portName) && !portName.isEmpty() )
49 	{
50 		m_portNames.append(portName);
51 		m_portNames.sort();
52 	}
53 
54 	m_picPinMap[pinPosition] = PicPin( pinID, type, portName, portPosition );
55 
56 }
57 
pins(uint pinType,const QString & portName)58 PicPinMap MicroPackage::pins( uint pinType, const QString& portName )
59 {
60 	if ( pinType == 0 ) pinType = (1<<30)-1;
61 
62 	PicPinMap list;
63 
64 	const PicPinMap::iterator picPinListEnd = m_picPinMap.end();
65 	for ( PicPinMap::iterator it = m_picPinMap.begin(); it != picPinListEnd; ++it )
66 	{
67 		if ( (it.value().type & pinType) &&
68 					(portName.isEmpty() || it.value().portName == portName) )
69 		{
70 			list[it.key()] = it.value();
71 		}
72 	}
73 
74 	return list;
75 }
76 
pinIDs(uint pinType,const QString & portName)77 QStringList MicroPackage::pinIDs( uint pinType, const QString& portName )
78 {
79 	if ( pinType == 0 ) pinType = (1<<30)-1;
80 	QStringList list;
81 
82 	const PicPinMap::iterator picPinListEnd = m_picPinMap.end();
83 	for ( PicPinMap::iterator it = m_picPinMap.begin(); it != picPinListEnd; ++it )
84 	{
85 		if ( (it.value().type & pinType) &&
86 					(portName.isEmpty() || it.value().portName == portName) )
87 		{
88 			list.append( it.value().pinID );
89 		}
90 	}
91 
92 	return list;
93 }
94 
pinCount(uint pinType,const QString & portName)95 int MicroPackage::pinCount( uint pinType, const QString& portName )
96 {
97 	if ( pinType == 0 ) pinType = (1<<30)-1;
98 	int count = 0;
99 
100 	const PicPinMap::iterator picPinListEnd = m_picPinMap.end();
101 	for ( PicPinMap::iterator it = m_picPinMap.begin(); it != picPinListEnd; ++it )
102 	{
103 		if ( (it.value().type & pinType) &&
104 					(portName.isEmpty() || it.value().portName == portName) ) count++;
105 	}
106 
107 	return count;
108 }
109 
110