Skip to content

Commit 6941abc

Browse files
authored
fix(drivers): Proper static/const for data/config (#2769)
Save a tiny bit of RAM by properly marking our device config struct instances const consistently, and also add missing static modifiers to properly isolate config/data for drivers.
1 parent 700e9b2 commit 6941abc

File tree

9 files changed

+14
-17
lines changed

9 files changed

+14
-17
lines changed

app/module/drivers/display/il0323.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,14 +371,14 @@ static int il0323_init(const struct device *dev) {
371371
return il0323_controller_init(dev);
372372
}
373373

374-
static struct il0323_cfg il0323_config = {
374+
static const struct il0323_cfg il0323_config = {
375375
.spi = SPI_DT_SPEC_INST_GET(0, SPI_OP_MODE_MASTER | SPI_WORD_SET(8), 0),
376376
.reset = GPIO_DT_SPEC_INST_GET(0, reset_gpios),
377377
.busy = GPIO_DT_SPEC_INST_GET(0, busy_gpios),
378378
.dc = GPIO_DT_SPEC_INST_GET(0, dc_gpios),
379379
};
380380

381-
static struct display_driver_api il0323_driver_api = {
381+
static const struct display_driver_api il0323_driver_api = {
382382
.blanking_on = il0323_blanking_on,
383383
.blanking_off = il0323_blanking_off,
384384
.write = il0323_write,

app/module/drivers/gpio/gpio_595.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ static int reg_595_init(const struct device *dev) {
202202
GPIO_PORT_PIN_MASK_FROM_NGPIOS(DT_INST_PROP(inst, ngpios))
203203

204204
#define REG_595_INIT(n) \
205-
static struct reg_595_config reg_595_##n##_config = { \
205+
static const struct reg_595_config reg_595_##n##_config = { \
206206
.common = \
207207
{ \
208208
.port_pin_mask = GPIO_PORT_PIN_MASK_FROM_DT_INST(n), \

app/module/drivers/gpio/gpio_max7318.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ static int max7318_init(const struct device *dev) {
322322
GPIO_PORT_PIN_MASK_FROM_NGPIOS(DT_INST_PROP(inst, ngpios))
323323

324324
#define MAX7318_INIT(inst) \
325-
static struct max7318_config max7318_##inst##_config = { \
325+
static const struct max7318_config max7318_##inst##_config = { \
326326
.common = {.port_pin_mask = GPIO_PORT_PIN_MASK_FROM_DT_INST(inst)}, \
327327
.i2c_bus = I2C_DT_SPEC_INST_GET(inst)}; \
328328
\

app/module/drivers/input/input_mock.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,10 @@ int input_mock_init(const struct device *dev) {
6868
return 0;
6969
}
7070

71-
#define GET_EVENT(n, inst) \
72-
{}
73-
7471
#define INPUT_MOCK_INST(n) \
75-
struct input_mock_data input_mock_data_##n = {}; \
76-
const uint32_t mock_data_##n[] = DT_INST_PROP(n, events); \
77-
const struct input_mock_config input_mock_cfg_##n = { \
72+
static struct input_mock_data input_mock_data_##n = {}; \
73+
static const uint32_t mock_data_##n[] = DT_INST_PROP(n, events); \
74+
static const struct input_mock_config input_mock_cfg_##n = { \
7875
.events = mock_data_##n, \
7976
.events_len = DT_INST_PROP_LEN(n, events), \
8077
.startup_delay = DT_INST_PROP(n, event_startup_delay), \

app/module/drivers/kscan/kscan_gpio_charlieplex.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ static const struct kscan_driver_api kscan_charlieplex_api = {
445445
.charlieplex_state = kscan_charlieplex_state_##n, \
446446
}; \
447447
\
448-
static struct kscan_charlieplex_config kscan_charlieplex_config_##n = { \
448+
static const struct kscan_charlieplex_config kscan_charlieplex_config_##n = { \
449449
.cells = KSCAN_GPIO_LIST(kscan_charlieplex_cells_##n), \
450450
.debounce_config = \
451451
{ \

app/module/drivers/kscan/kscan_gpio_direct.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ static const struct kscan_driver_api kscan_direct_api = {
397397
.pin_state = kscan_direct_state_##n, \
398398
COND_INTERRUPTS((.irqs = kscan_direct_irqs_##n, ))}; \
399399
\
400-
static struct kscan_direct_config kscan_direct_config_##n = { \
400+
static const struct kscan_direct_config kscan_direct_config_##n = { \
401401
.debounce_config = \
402402
{ \
403403
.debounce_press_ms = INST_DEBOUNCE_PRESS_MS(n), \

app/module/drivers/kscan/kscan_gpio_matrix.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ static const struct kscan_driver_api kscan_matrix_api = {
515515
.matrix_state = kscan_matrix_state_##n, \
516516
COND_INTERRUPTS((.irqs = kscan_matrix_irqs_##n, ))}; \
517517
\
518-
static struct kscan_matrix_config kscan_matrix_config_##n = { \
518+
static const struct kscan_matrix_config kscan_matrix_config_##n = { \
519519
.rows = ARRAY_SIZE(kscan_matrix_rows_##n), \
520520
.cols = ARRAY_SIZE(kscan_matrix_cols_##n), \
521521
.outputs = \

app/module/drivers/sensor/ec11/ec11.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ int ec11_init(const struct device *dev) {
148148
}
149149

150150
#define EC11_INST(n) \
151-
struct ec11_data ec11_data_##n; \
152-
const struct ec11_config ec11_cfg_##n = { \
151+
static struct ec11_data ec11_data_##n; \
152+
static const struct ec11_config ec11_cfg_##n = { \
153153
.a = GPIO_DT_SPEC_INST_GET(n, a_gpios), \
154154
.b = GPIO_DT_SPEC_INST_GET(n, b_gpios), \
155155
.resolution = DT_INST_PROP_OR(n, resolution, 1), \

app/module/drivers/sensor/max17048/max17048.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ static const struct sensor_driver_api max17048_api_table = {.sample_fetch = max1
205205
.channel_get = max17048_channel_get};
206206

207207
#define MAX17048_INIT(inst) \
208-
static struct max17048_config max17048_##inst##_config = {.i2c_bus = \
209-
I2C_DT_SPEC_INST_GET(inst)}; \
208+
static const struct max17048_config max17048_##inst##_config = { \
209+
.i2c_bus = I2C_DT_SPEC_INST_GET(inst)}; \
210210
\
211211
static struct max17048_drv_data max17048_##inst##_drvdata = { \
212212
.raw_state_of_charge = 0, \

0 commit comments

Comments
 (0)