summaryrefslogtreecommitdiffstats
path: root/src/micro/micropackage.h
blob: 0dc98fe5b057bb02a46f776f4d2bd4b2d5acfe5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/***************************************************************************
 *   Copyright (C) 2003-2005 by David Saxton                               *
 *   david@bluehaze.org                                                    *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/

#ifndef PICPACKAGES_H
#define PICPACKAGES_H

#include <qstring.h>
#include <qstringlist.h>

#include <qmap.h>

/**
@author David Saxton
*/
class PicPin
{
public:
	enum pin_type
	{
		type_input	= 0x1, // Input only pin
		type_bidir	= 0x2, // Bi-directional (input/output)
		type_open	= 0x4, // Open collector
		type_vss	= 0x8, // Voltage source
		type_vdd	= 0x10, // Voltage drain
		type_mclr	= 0x20, // Memory clear
		type_osc	= 0x40 // Oscillator
	};
	
	PicPin();
	PicPin( const QString &_pinID, PicPin::pin_type _type, const QString &_portName = "", int _portPosition = -1 );

	PicPin::pin_type type;
	
	QString pinID; // Id of pin, eg 'MCLR'
	
	// For bidir (io) pins
	QString portName; // Name of port, eg 'PORTA'
	int portPosition; // Position in port
};
typedef QMap<int, PicPin> PicPinMap;

/**
@short Describes the PIC package (i.e. pins)
@author David Saxton
*/
class MicroPackage
{
public:
	MicroPackage( const int pinCount );
	virtual ~MicroPackage();
	
	/**
	 * Assigns a pin to a position in the package.
	 */
	void assignPin( int pinPosition, PicPin::pin_type type, const QString& pinID, const QString& portName = "", int portPosition = -1);
	/**
	 * Returns the pins of the given type(s). If portName is not specified, all pins will be returned;
	 * not just those belonging to a given port. pin_type's can be OR'ed together
	 * e.g. pins( PicPin::type_input | PicPin::type_bidir, "PORTA" ) will return all bidirectional or
	 * input pins belonging to PORTA. If pinType is 0, then this will return all pins
	 */
	PicPinMap pins( uint pinType = 0, const QString& portName = "" );
	/**
	 * Returns just a QStringList of the pin ids.
	 * @see pins( uint pinType, const QString& portName )
	 */
	QStringList pinIDs( uint pinType = 0, const QString& portName = "" );
	/**
	 * Returns the number of pins of the given type(s) (which can be OR'ed together), with the given
	 * port name if specified, while avoiding the construction of a new PicPinMap. if pinType is 0,
	 * then all pin types are considered
	 * @see pins
	 */
	int pinCount( uint pinType = 0, const QString& portName = "" );
	/**
	 * Returns a list of port names, eg 'PORTA', 'PORTB' for the package
	 */
	QStringList portNames() const { return m_portNames; }
	/**
	 * Returns the number of ports
	 */
	uint portCount() const { return m_portNames.size(); }
	
private:
	PicPinMap m_picPinMap;
	QStringList m_portNames;
	int m_numPins;
};

#endif