aboutsummaryrefslogtreecommitdiffstats
path: root/ice40
diff options
context:
space:
mode:
Diffstat (limited to 'ice40')
-rw-r--r--ice40/chip.cc26
-rw-r--r--ice40/chip.h1
2 files changed, 13 insertions, 14 deletions
diff --git a/ice40/chip.cc b/ice40/chip.cc
index 88fcc512..918a7fb4 100644
--- a/ice40/chip.cc
+++ b/ice40/chip.cc
@@ -52,27 +52,25 @@ BelType belTypeFromId(IdString id)
// -----------------------------------------------------------------------
-IdString portPinToId(PortPin type)
+void IdString::initialize_chip()
{
-#define X(t) \
- if (type == PIN_##t) \
- return #t;
-
+#define X(t) initialize_add(#t, PIN_##t);
#include "portpins.inc"
-
#undef X
- return IdString();
}
-PortPin portPinFromId(IdString id)
+IdString portPinToId(PortPin type)
{
-#define X(t) \
- if (id == #t) \
- return PIN_##t;
-
-#include "portpins.inc"
+ IdString ret;
+ if (type > 0 && type < PIN_MAXIDX)
+ ret.index = type;
+ return ret;
+}
-#undef X
+PortPin portPinFromId(IdString id)
+{
+ if (id.index > 0 && id.index < PIN_MAXIDX)
+ return PortPin(id.index);
return PIN_NONE;
}
diff --git a/ice40/chip.h b/ice40/chip.h
index 73e8d33b..f8946610 100644
--- a/ice40/chip.h
+++ b/ice40/chip.h
@@ -62,6 +62,7 @@ enum PortPin
#define X(t) PIN_##t,
#include "portpins.inc"
#undef X
+ PIN_MAXIDX
};
IdString portPinToId(PortPin type);