zephyr: Cleanup I2C initialization
Move the I2C initialization to compile time, saving a modest amount of
RAM space
BRANCH=none
TEST=zmake testall
TEST=boot Zephyr on Herobrine.
* This macro should be called from within DT_FOREACH_CHILD.
*/
#define INIT_DEV_BINDING(id) \
- i2c_devices[I2C_PORT(id)] = DEVICE_DT_GET(DT_PHANDLE(id, i2c_port));
+ [I2C_PORT(id)] = DEVICE_DT_GET(DT_PHANDLE(id, i2c_port)),
#define INIT_REMOTE_PORTS(id) \
- i2c_remote_ports[I2C_PORT(id)] = DT_PROP_OR(id, remote_port, -1);
+ [I2C_PORT(id)] = DT_PROP_OR(id, remote_port, -1),
#define INIT_PHYSICAL_PORTS(id) \
i2c_physical_ports[I2C_PORT(id)] = DT_PROP_OR(id, physical_port, -1);
@@ -45,16 +45,18 @@ const struct i2c_port_t i2c_ports[] = {
DT_FOREACH_CHILD(DT_PATH(named_i2c_ports), I2C_PORT_INIT)
};
const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
-static int i2c_remote_ports[I2C_PORT_COUNT];
+static const int i2c_remote_ports[I2C_PORT_COUNT] = {
+ DT_FOREACH_CHILD(DT_PATH(named_i2c_ports), INIT_REMOTE_PORTS)
+};
static int i2c_physical_ports[I2C_PORT_COUNT];
-static const struct device *i2c_devices[I2C_PORT_COUNT];
+static const struct device *i2c_devices[I2C_PORT_COUNT] = {
+ DT_FOREACH_CHILD(DT_PATH(named_i2c_ports), INIT_DEV_BINDING)
+};
static int init_device_bindings(const struct device *device)
{
ARG_UNUSED(device);
- DT_FOREACH_CHILD(DT_PATH(named_i2c_ports), INIT_DEV_BINDING)
- DT_FOREACH_CHILD(DT_PATH(named_i2c_ports), INIT_REMOTE_PORTS)
DT_FOREACH_CHILD(DT_PATH(named_i2c_ports), INIT_PHYSICAL_PORTS)
return 0;
}
