Skip to content

Commit f842e32

Browse files
MaureenHelmdpgeorge
authored andcommitted
zephyr: Const-ify struct device instance pointers.
Zephyr v2.4.0 added a const qualifier to usages of struct device to allow storing device driver instances exclusively in flash and thereby reduce ram footprint. Signed-off-by: Maureen Helm <[email protected]>
1 parent ce49be4 commit f842e32

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed

ports/zephyr/machine_i2c.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ STATIC const mp_obj_type_t machine_hard_i2c_type;
4242

4343
typedef struct _machine_hard_i2c_obj_t {
4444
mp_obj_base_t base;
45-
struct device *dev;
45+
const struct device *dev;
4646
bool restart;
4747
} machine_hard_i2c_obj_t;
4848

@@ -65,7 +65,7 @@ mp_obj_t machine_hard_i2c_make_new(const mp_obj_type_t *type, size_t n_args, siz
6565
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
6666

6767
const char *dev_name = mp_obj_str_get_str(args[ARG_id].u_obj);
68-
struct device *dev = device_get_binding(dev_name);
68+
const struct device *dev = device_get_binding(dev_name);
6969

7070
if (dev == NULL) {
7171
mp_raise_ValueError(MP_ERROR_TEXT("device not found"));

ports/zephyr/machine_pin.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void machine_pin_deinit(void) {
5858
MP_STATE_PORT(machine_pin_irq_list) = NULL;
5959
}
6060

61-
STATIC void gpio_callback_handler(struct device *port, struct gpio_callback *cb, gpio_port_pins_t pins) {
61+
STATIC void gpio_callback_handler(const struct device *port, struct gpio_callback *cb, gpio_port_pins_t pins) {
6262
machine_pin_irq_obj_t *irq = CONTAINER_OF(cb, machine_pin_irq_obj_t, callback);
6363

6464
#if MICROPY_STACK_CHECK
@@ -132,7 +132,7 @@ mp_obj_t mp_pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw,
132132
mp_obj_get_array_fixed_n(args[0], 2, &items);
133133
const char *drv_name = mp_obj_str_get_str(items[0]);
134134
int wanted_pin = mp_obj_get_int(items[1]);
135-
struct device *wanted_port = device_get_binding(drv_name);
135+
const struct device *wanted_port = device_get_binding(drv_name);
136136
if (!wanted_port) {
137137
mp_raise_ValueError(MP_ERROR_TEXT("invalid port"));
138138
}

ports/zephyr/modmachine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ MP_DECLARE_CONST_FUN_OBJ_0(machine_info_obj);
99

1010
typedef struct _machine_pin_obj_t {
1111
mp_obj_base_t base;
12-
struct device *port;
12+
const struct device *port;
1313
uint32_t pin;
1414
struct _machine_pin_irq_obj_t *irq;
1515
} machine_pin_obj_t;

ports/zephyr/modzsensor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
typedef struct _mp_obj_sensor_t {
3737
mp_obj_base_t base;
38-
struct device *dev;
38+
const struct device *dev;
3939
} mp_obj_sensor_t;
4040

4141
STATIC mp_obj_t sensor_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {

ports/zephyr/uart_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
5353
}
5454
}
5555
#else
56-
static struct device *uart_console_dev;
56+
static const struct device *uart_console_dev;
5757
if (uart_console_dev == NULL) {
5858
uart_console_dev = device_get_binding(CONFIG_UART_CONSOLE_ON_DEV_NAME);
5959
}

0 commit comments

Comments
 (0)