use of net.sourceforge.usbdm.deviceEditor.information.Signal 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.Signal in project usbdm-eclipse-plugins by podonoghue.
the class FamilyXmlWriter method writePin.
/**
* Writes XML describing how peripheral signals are mapped to a pin
* e.g.<pre>
* <pin name=="PTD7">
* <mux sel="mux1" signal="GPIOD_7" />
* <mux sel="mux2" signal="CMT_IRO" />
* <reset sel="Disabled" />
* <default sel="mux1" />
* </pin>
* </pre>
*
* @param documentUtilities Where to write
* @param pin Pin to write definitions for
*
* @throws IOException
*/
private void writePin(XmlDocumentUtilities documentUtilities, Pin pin) throws IOException {
documentUtilities.openTag("pin");
Map<MuxSelection, MappingInfo> mappingInfo = pin.getMappableSignals();
Set<MuxSelection> sortedSelectionIndexes = mappingInfo.keySet();
boolean isFixed = false;
// Construct list of alternatives
StringBuffer alternativeHint = new StringBuffer();
for (MuxSelection selection : mappingInfo.keySet()) {
if (selection == MuxSelection.fixed) {
isFixed = true;
}
MappingInfo mInfo = mappingInfo.get(selection);
StringBuffer name = new StringBuffer();
name.append(mInfo.getSignalList());
if (alternativeHint.length() != 0) {
alternativeHint.append(", ");
}
alternativeHint.append(name);
}
documentUtilities.writeAttribute("name", pin.getName());
if (isFixed) {
documentUtilities.writeAttribute("isFixed", "true");
}
for (MuxSelection selection : sortedSelectionIndexes) {
MappingInfo mInfo = mappingInfo.get(selection);
StringBuffer name = new StringBuffer();
name.append(mInfo.getSignalList());
for (Signal fn : mInfo.getSignals()) {
documentUtilities.openTag("mux");
documentUtilities.writeAttribute("sel", selection.name());
documentUtilities.writeAttribute("signal", fn.getName());
documentUtilities.closeTag();
}
}
documentUtilities.openTag("reset");
documentUtilities.writeAttribute("sel", pin.getResetValue().name());
documentUtilities.closeTag();
// documentUtilities.openTag("default");
// documentUtilities.writeAttribute("sel", pin.getDefaultValue().name());
// documentUtilities.closeTag();
documentUtilities.closeTag();
}
use of net.sourceforge.usbdm.deviceEditor.information.Signal in project usbdm-eclipse-plugins by podonoghue.
the class ParseFamilyCSV method createSignalsFromString.
/**
* Create a list of signals described by a string
*
* @param pinText Text of signal names e.g. <b><i>PTA4/LLWU_P3</b></i>
*
* @return List of signals created
*
* @throws Exception
*/
private ArrayList<Signal> createSignalsFromString(String pinText, Boolean convert) {
ArrayList<Signal> signalList = new ArrayList<Signal>();
pinText = pinText.trim();
if (pinText.isEmpty()) {
return signalList;
}
String[] signalNames = pinText.split("\\s*/\\s*");
for (String signalName : signalNames) {
signalName = signalName.trim();
signalName = fixSignalName(signalName);
if (signalName.isEmpty()) {
continue;
}
if (convert) {
signalName = convertName(signalName);
}
Signal signal = fDeviceInfo.findOrCreateSignal(signalName);
if (signal != null) {
// XXX Log creating signals
// System.err.println("Added "+signalName+" to "+signal.getPeripheral());
signalList.add(signal);
if (signal != Signal.DISABLED_SIGNAL) {
Peripheral x = signal.getPeripheral();
if ((x == null) || x.getClass().equals(WriterForNull.class)) {
System.err.println("Signal \'" + signalName + "\' added to WriterForNull");
}
}
} else {
System.err.println("Signal not found for " + signalName);
}
}
return signalList;
}
use of net.sourceforge.usbdm.deviceEditor.information.Signal 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.Signal in project usbdm-eclipse-plugins by podonoghue.
the class PinListDialogue method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
Composite container = (Composite) super.createDialogArea(parent);
GridLayout gl = new GridLayout(5, true);
gl.marginLeft = 10;
gl.marginRight = 10;
gl.marginTop = 10;
container.setLayout(gl);
container.layout();
String[] initialSelections = fInitialSelections.split("[, ]+");
Vector<Signal> pinTable = fPeripheral.getSignalTables().get(0).table;
for (int i = 0; i < fCombos.length; i++) {
try {
fCombos[i] = new Combo(container, SWT.CHECK);
fCombos[i].setItems(fPinList);
if (i < initialSelections.length) {
int signalIndex = Integer.parseInt(initialSelections[i]);
Signal entry = pinTable.elementAt(signalIndex);
String item = String.format(PIN_TEMPLATE, entry.getName(), entry.getMappedPin().getPin().getName());
int sel = fCombos[i].indexOf(item);
if (sel > 0) {
fCombos[i].select(sel);
} else {
fCombos[i].select(0);
}
}
} catch (NumberFormatException e) {
}
}
parent.layout(true);
return container;
}
Aggregations