use of net.sourceforge.usbdm.deviceEditor.information.Pin in project usbdm-eclipse-plugins by podonoghue.
the class WriteFamilyCpp method writeMappedSignals.
/**
* Write declarations for simple peripheral signals (e.g. GPIO,ADC,PWM) that
* are mapped to pins e.g.
*
* <pre>
* using adc_p53 = const USBDM::Adc1<4>;
* using adc_p54 = const USBDM::Adc1<5>;
* </pre>
*
* @param writer
* Where to write
*
* @throws Exception
*/
private void writeMappedSignals(DocumentUtilities writer) throws IOException {
writeIncludes(writer);
writer.writeOpenNamespace(DeviceInfo.NAME_SPACE, "Namespace enclosing USBDM classes");
writer.openUsbdmDocumentationGroup();
DocumentationGroups startGroup = new DocumentationGroups(writer);
for (String key : fDeviceInfo.getPeripherals().keySet()) {
Peripheral peripheral = fDeviceInfo.getPeripherals().get(key);
for (Entry<String, Pin> pinEntry : fDeviceInfo.getPins().entrySet()) {
Pin pin = pinEntry.getValue();
Map<MuxSelection, MappingInfo> mappedSignals = pin.getMappableSignals();
if (mappedSignals == null) {
continue;
}
for (Entry<MuxSelection, MappingInfo> muxEntry : mappedSignals.entrySet()) {
if (muxEntry.getKey() == MuxSelection.unassigned) {
continue;
}
MappingInfo mappedSignal = muxEntry.getValue();
for (int fnIndex = 0; fnIndex < mappedSignal.getSignals().size(); fnIndex++) {
Signal function = mappedSignal.getSignals().get(fnIndex);
if (function.getPeripheral() == peripheral) {
String template = getMappedSignals(peripheral, mappedSignal, fnIndex);
if (template != null) {
startGroup.openGroup(peripheral);
writer.write(template);
writer.flush();
}
}
}
}
}
}
startGroup.closeGroup();
writer.writeDocBanner("Used to configure pin-mapping before 1st use of peripherals");
writer.write("extern void " + DO_PIN_MAPPING_FUNCTION + "();\n");
writer.closeDocumentationGroup();
writer.writeCloseNamespace();
writer.flush();
}
use of net.sourceforge.usbdm.deviceEditor.information.Pin in project usbdm-eclipse-plugins by podonoghue.
the class WriteFamilyCpp method writeDocumentation.
/**
* Write pin mapping documentation
*
* @param writer
* Where to write
*
* @throws IOException
*/
private void writeDocumentation(DocumentUtilities writer) throws IOException {
Map<String, Pin> pinsByLocation = new TreeMap<String, Pin>(Signal.comparator);
Map<String, Pin> pinsByFunction = new TreeMap<String, Pin>(Signal.comparator);
writer.write(DOCUMENTATION_OPEN);
writer.write(String.format(TABLE_OPEN, "PinsByPinName", "Pins by Pin Name"));
for (String pinName : fDeviceInfo.getPins().keySet()) {
Pin pin = fDeviceInfo.getPins().get(pinName);
if (!pin.isAvailableInPackage()) {
// Discard pins without package location
continue;
}
String useDescription = pin.getPinUseDescription();
if (useDescription.isEmpty()) {
useDescription = "-";
}
Map<MuxSelection, MappingInfo> mappableSignals = pin.getMappableSignals();
MappingInfo mappedSignal = mappableSignals.get(pin.getMuxValue());
String signalList;
if (mappedSignal == null) {
signalList = "-";
} else {
signalList = mappedSignal.getSignalList();
}
writer.write(String.format(DOCUMENTATION_TEMPLATE, pin.getName(), signalList, pin.getLocation(), useDescription));
if ((pin.getLocation() != null) && !pin.getLocation().isEmpty()) {
pinsByLocation.put(pin.getLocation(), pin);
}
pinsByFunction.put(signalList, pin);
}
writer.write(TABLE_CLOSE);
writer.write(String.format(TABLE_OPEN, "PinsByLocation", "Pins by Location"));
for (String pinName : pinsByLocation.keySet()) {
Pin pin = pinsByLocation.get(pinName);
String useDescription = pin.getPinUseDescription();
if (useDescription.isEmpty()) {
useDescription = "-";
}
Map<MuxSelection, MappingInfo> mappableSignals = pin.getMappableSignals();
MappingInfo mappedSignal = mappableSignals.get(pin.getMuxValue());
String signalList;
if (mappedSignal == null) {
signalList = "-";
} else {
signalList = mappedSignal.getSignalList();
}
writer.write(String.format(DOCUMENTATION_TEMPLATE, pin.getName(), signalList, pin.getLocation(), useDescription));
}
writer.write(TABLE_CLOSE);
writer.write(String.format(TABLE_OPEN, "PinsByFunction", "Pins by Function"));
for (String pinName : pinsByFunction.keySet()) {
Pin pin = pinsByFunction.get(pinName);
String useDescription = pin.getPinUseDescription();
if (useDescription.isEmpty()) {
useDescription = "-";
}
Map<MuxSelection, MappingInfo> mappableSignals = pin.getMappableSignals();
MappingInfo mappedSignal = mappableSignals.get(pin.getMuxValue());
String signalList;
if (mappedSignal == null) {
signalList = "-";
} else {
signalList = mappedSignal.getSignalList();
}
writer.write(String.format(DOCUMENTATION_TEMPLATE, pin.getName(), signalList, pin.getLocation(), useDescription));
}
writer.write(TABLE_CLOSE);
writer.write(DOCUMENTATION_CLOSE);
writer.flush();
}
use of net.sourceforge.usbdm.deviceEditor.information.Pin in project usbdm-eclipse-plugins by podonoghue.
the class FamilyXmlWriter method writePins.
/**
* Writes XML describing how peripheral signals are mapped to all pins
* e.g.<pre>
* <pins>
* <pin name=="PTD7">
* <mux sel="mux1" signal="GPIOD_7" />
* ...
* </pin>
* ...
* </pins>
* </pre>
*
* @param documentUtilities Where to write
* @throws IOException
*/
private void writePins(XmlDocumentUtilities documentUtilities) throws IOException {
documentUtilities.openTag("pins");
HashMap<String, ArrayList<Pin>> categories = new HashMap<String, ArrayList<Pin>>();
class Pair {
public final String namePattern;
public final String titlePattern;
Pair(String n, String t) {
namePattern = n;
titlePattern = t;
}
}
;
final String UNMATCHED_NAME = "Miscellaneous Pins";
Pair[] pinPatterns = { new Pair("XXXX", UNMATCHED_NAME), new Pair("PT([A-Z]).*", "Port $1 Pins") };
ArrayList<String> categoryTitles = new ArrayList<String>();
for (String name : fDeviceInfo.getPins().keySet()) {
String categoryTitle = UNMATCHED_NAME;
for (Pair pair : pinPatterns) {
Pattern p = Pattern.compile(pair.namePattern);
Matcher m = p.matcher(name);
if (m.matches()) {
categoryTitle = m.replaceAll(pair.titlePattern);
break;
}
}
ArrayList<Pin> category = categories.get(categoryTitle);
if (category == null) {
category = new ArrayList<Pin>();
categories.put(categoryTitle, category);
categoryTitles.add(categoryTitle);
}
category.add(fDeviceInfo.findPin(name));
}
for (String p : categoryTitles) {
ArrayList<Pin> category = categories.get(p);
if (category != null) {
for (Pin pinInformation : category) {
writePin(documentUtilities, pinInformation);
}
}
}
documentUtilities.closeTag();
}
use of net.sourceforge.usbdm.deviceEditor.information.Pin in project usbdm-eclipse-plugins by podonoghue.
the class ParseFamilyCSV method parsePinLine.
/**
* Parse line containing Pin information
*
* @param line
* @throws Exception
*/
private void parsePinLine(String[] line) throws Exception {
StringBuffer sb = new StringBuffer();
if (!line[0].equals("Pin")) {
return;
}
String pinName = line[fPinIndex];
if ((pinName == null) || (pinName.isEmpty())) {
throw new Exception("No pin name");
}
pinName = fixSignalName(pinName);
// Use first name on pin as Pin name e.g. PTC4/LLWU_P8 => PTC4
Pattern p = Pattern.compile("(.+?)/.*");
Matcher m = p.matcher(pinName);
if (m.matches()) {
pinName = m.group(1);
}
final Pin pin = fDeviceInfo.createPin(pinName);
sb.append(String.format("%-10s => ", pin.getName()));
boolean pinIsMapped = false;
for (int col = fAltStartIndex; col <= fAltEndIndex; col++) {
if (col >= line.length) {
break;
}
ArrayList<Signal> signals = createSignalsFromString(line[col], true);
for (Signal signal : signals) {
sb.append(signal.getName() + ", ");
if ((signal != null)) {
MuxSelection muxValue = MuxSelection.valueOf(col - fAltStartIndex);
fDeviceInfo.createMapping(signal, pin, muxValue);
pinIsMapped = true;
}
}
}
if ((line.length > fResetIndex) && (line[fResetIndex] != null) && (!line[fResetIndex].isEmpty())) {
String resetName = line[fResetIndex];
ArrayList<Signal> resetSignals = createSignalsFromString(resetName, true);
if (!pinIsMapped) {
for (Signal resetSignal : resetSignals) {
sb.append("R:" + resetSignal.getName() + ", ");
// Pin is not mapped to this signal in the ALT columns - must be a non-mappable pin
MappingInfo mapping = fDeviceInfo.createMapping(resetSignal, pin, MuxSelection.fixed);
for (Signal signal : mapping.getSignals()) {
signal.setResetPin(mapping);
}
}
}
pin.setResetSignals(fDeviceInfo, resetName);
} else {
sb.append("R:" + Signal.DISABLED_SIGNAL.getName() + ", ");
fDeviceInfo.createMapping(Signal.DISABLED_SIGNAL, pin, MuxSelection.unassigned);
pin.setResetSignals(fDeviceInfo, Signal.DISABLED_SIGNAL.getName());
}
for (PackageColumnInfo pkgIndex : fPackageIndexes) {
String pinNum = line[pkgIndex.index];
if (pinNum.equals("*")) {
continue;
}
DevicePackage devicePackage = fDeviceInfo.findDevicePackage(pkgIndex.name);
if (devicePackage == null) {
throw new RuntimeException("Failed to find package " + pkgIndex.name + ", for " + pinName);
}
devicePackage.addPin(pin, pinNum);
sb.append("(" + pkgIndex.name + ":" + pinNum + ") ");
}
}
use of net.sourceforge.usbdm.deviceEditor.information.Pin in project usbdm-eclipse-plugins by podonoghue.
the class DeviceSignalsModel method createModels.
private void createModels(DeviceInfo fDeviceInfo) {
fMappingInfos = new ArrayList<MappingInfo>();
final ArrayList<PinCategory> categories = new ArrayList<PinCategory>();
// Construct categories
for (char c = 'A'; c <= 'I'; c++) {
categories.add(new PinCategory("Port " + c, "PT" + c + ".*"));
}
categories.add(new PinCategory("Power", "((VDD|VSS|VREGIN|VBAT|VOUT|(VREF(H|L)))).*"));
categories.add(new PinCategory("Miscellaneous", ".*"));
// Group pins into categories
for (String pName : fDeviceInfo.getPins().keySet()) {
Pin pinInformation = fDeviceInfo.getPins().get(pName);
if (pinInformation.isAvailableInPackage()) {
// Only add if available in package
for (PinCategory category : categories) {
if (category.tryAdd(pinInformation)) {
break;
}
}
}
}
for (PinCategory pinCategory : categories) {
if (pinCategory.getPins().isEmpty()) {
continue;
}
CategoryModel categoryModel = new CategoryModel(this, pinCategory.getName(), "");
for (Pin pinInformation : pinCategory.getPins()) {
new PinModel(categoryModel, pinInformation);
for (MappingInfo mappingInfo : pinInformation.getMappableSignals().values()) {
if (mappingInfo.getMux() == MuxSelection.fixed) {
continue;
}
if (mappingInfo.getMux() == MuxSelection.unassigned) {
continue;
}
if (mappingInfo.getSignals().get(0) == Signal.DISABLED_SIGNAL) {
continue;
}
fMappingInfos.add(mappingInfo);
}
}
}
}
Aggregations