refactor(app): replace struct device * with const struct device *

Replaced with RegExp: /(?<!const )(struct device \*)/g

See: https://docs.zephyrproject.org/latest/releases/release-notes-2.4.html
PR: #467
This commit is contained in:
innovaker
2020-12-10 19:31:51 +00:00
committed by Pete Johanson
parent 1411092a7b
commit 00ca0d2f1c
41 changed files with 172 additions and 163 deletions

View File

@@ -17,9 +17,9 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
#include <zmk/event-manager.h>
#include <zmk/events/battery-state-changed.h>
struct device *battery;
const struct device *battery;
static int zmk_battery_update(struct device *battery) {
static int zmk_battery_update(const struct device *battery) {
struct sensor_value state_of_charge;
int rc = sensor_sample_fetch_chan(battery, SENSOR_CHAN_GAUGE_STATE_OF_CHARGE);
@@ -64,7 +64,7 @@ static void zmk_battery_timer(struct k_timer *timer) { k_work_submit(&battery_wo
K_TIMER_DEFINE(battery_timer, zmk_battery_timer, NULL);
static int zmk_battery_init(struct device *_arg) {
static int zmk_battery_init(const struct device *_arg) {
battery = device_get_binding("BATTERY");
if (battery == NULL) {

View File

@@ -35,7 +35,7 @@ static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
return -ENOTSUP;
}
static int behavior_bt_init(struct device *dev) { return 0; };
static int behavior_bt_init(const struct device *dev) { return 0; };
static int on_keymap_binding_released(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {

View File

@@ -18,7 +18,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {
struct device *ext_power = device_get_binding("EXT_POWER");
const struct device *ext_power = device_get_binding("EXT_POWER");
if (ext_power == NULL) {
LOG_ERR("Unable to retrieve ext_power device: %d", binding->param1);
return -EIO;
@@ -46,7 +46,7 @@ static int on_keymap_binding_released(struct zmk_behavior_binding *binding,
return 0;
}
static int behavior_ext_power_init(struct device *dev) { return 0; };
static int behavior_ext_power_init(const struct device *dev) { return 0; };
static const struct behavior_driver_api behavior_ext_power_driver_api = {
.binding_pressed = on_keymap_binding_pressed,

View File

@@ -304,7 +304,7 @@ static void decide_hold_tap(struct active_hold_tap *hold_tap, enum decision_mome
static int on_hold_tap_binding_pressed(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {
struct device *dev = device_get_binding(binding->behavior_dev);
const struct device *dev = device_get_binding(binding->behavior_dev);
const struct behavior_hold_tap_config *cfg = dev->config;
if (undecided_hold_tap != NULL) {
@@ -479,7 +479,7 @@ void behavior_hold_tap_timer_work_handler(struct k_work *item) {
}
}
static int behavior_hold_tap_init(struct device *dev) {
static int behavior_hold_tap_init(const struct device *dev) {
static bool init_first_run = true;
if (init_first_run) {

View File

@@ -16,7 +16,7 @@
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
static int behavior_key_press_init(struct device *dev) { return 0; };
static int behavior_key_press_init(const struct device *dev) { return 0; };
static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {

View File

@@ -18,7 +18,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
struct behavior_mo_config {};
struct behavior_mo_data {};
static int behavior_mo_init(struct device *dev) { return 0; };
static int behavior_mo_init(const struct device *dev) { return 0; };
static int mo_keymap_binding_pressed(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {

View File

@@ -18,7 +18,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
struct behavior_none_config {};
struct behavior_none_data {};
static int behavior_none_init(struct device *dev) { return 0; };
static int behavior_none_init(const struct device *dev) { return 0; };
static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {

View File

@@ -34,7 +34,7 @@ static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
return -ENOTSUP;
}
static int behavior_out_init(struct device *dev) { return 0; }
static int behavior_out_init(const struct device *dev) { return 0; }
static const struct behavior_driver_api behavior_outputs_driver_api = {
.binding_pressed = on_keymap_binding_pressed,

View File

@@ -19,11 +19,11 @@ struct behavior_reset_config {
int type;
};
static int behavior_reset_init(struct device *dev) { return 0; };
static int behavior_reset_init(const struct device *dev) { return 0; };
static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {
struct device *dev = device_get_binding(binding->behavior_dev);
const struct device *dev = device_get_binding(binding->behavior_dev);
const struct behavior_reset_config *cfg = dev->config;
// TODO: Correct magic code for going into DFU?

View File

@@ -16,7 +16,7 @@
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
static int behavior_rgb_underglow_init(struct device *dev) { return 0; }
static int behavior_rgb_underglow_init(const struct device *dev) { return 0; }
static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {

View File

@@ -16,10 +16,10 @@
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
static int behavior_sensor_rotate_key_press_init(struct device *dev) { return 0; };
static int behavior_sensor_rotate_key_press_init(const struct device *dev) { return 0; };
static int on_sensor_binding_triggered(struct zmk_behavior_binding *binding, struct device *sensor,
int64_t timestamp) {
static int on_sensor_binding_triggered(struct zmk_behavior_binding *binding,
const struct device *sensor, int64_t timestamp) {
struct sensor_value value;
int err;
uint32_t keycode;

View File

@@ -127,7 +127,7 @@ static int stop_timer(struct active_sticky_key *sticky_key) {
static int on_sticky_key_binding_pressed(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {
struct device *dev = device_get_binding(binding->behavior_dev);
const struct device *dev = device_get_binding(binding->behavior_dev);
const struct behavior_sticky_key_config *cfg = dev->config;
struct active_sticky_key *sticky_key;
sticky_key = find_sticky_key(event.position);
@@ -242,7 +242,7 @@ void behavior_sticky_key_timer_handler(struct k_work *item) {
}
}
static int behavior_sticky_key_init(struct device *dev) {
static int behavior_sticky_key_init(const struct device *dev) {
static bool init_first_run = true;
if (init_first_run) {
for (int i = 0; i < ZMK_BHV_STICKY_KEY_MAX_HELD; i++) {

View File

@@ -18,7 +18,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
struct behavior_tog_config {};
struct behavior_tog_data {};
static int behavior_tog_init(struct device *dev) { return 0; };
static int behavior_tog_init(const struct device *dev) { return 0; };
static int tog_keymap_binding_pressed(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {

View File

@@ -18,7 +18,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
struct behavior_transparent_config {};
struct behavior_transparent_data {};
static int behavior_transparent_init(struct device *dev) { return 0; };
static int behavior_transparent_init(const struct device *dev) { return 0; };
static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {

View File

@@ -509,7 +509,7 @@ static void zmk_ble_ready(int err) {
update_advertising();
}
static int zmk_ble_init(struct device *_arg) {
static int zmk_ble_init(const struct device *_arg) {
int err = bt_enable(NULL);
if (err) {

View File

@@ -18,7 +18,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
#define ZMK_DISPLAY_NAME CONFIG_LVGL_DISPLAY_DEV_NAME
static struct device *display;
static const struct device *display;
static lv_obj_t *screen;

View File

@@ -156,7 +156,7 @@ static int endpoints_handle_set(const char *name, size_t len, settings_read_cb r
struct settings_handler endpoints_handler = {.name = "endpoints", .h_set = endpoints_handle_set};
#endif /* IS_ENABLED(CONFIG_SETTINGS) */
static int zmk_endpoints_init(struct device *_arg) {
static int zmk_endpoints_init(const struct device *_arg) {
#if IS_ENABLED(CONFIG_SETTINGS)
settings_subsys_init();

View File

@@ -26,7 +26,7 @@ struct ext_power_generic_config {
};
struct ext_power_generic_data {
struct device *gpio;
const struct device *gpio;
bool status;
#if IS_ENABLED(CONFIG_SETTINGS)
bool settings_init;
@@ -36,7 +36,7 @@ struct ext_power_generic_data {
#if IS_ENABLED(CONFIG_SETTINGS)
static void ext_power_save_state_work(struct k_work *work) {
char setting_path[40];
struct device *ext_power = device_get_binding(DT_INST_LABEL(0));
const struct device *ext_power = device_get_binding(DT_INST_LABEL(0));
struct ext_power_generic_data *data = ext_power->data;
snprintf(setting_path, 40, "ext_power/state/%s", DT_INST_LABEL(0));
@@ -55,7 +55,7 @@ int ext_power_save_state() {
#endif
}
static int ext_power_generic_enable(struct device *dev) {
static int ext_power_generic_enable(const struct device *dev) {
struct ext_power_generic_data *data = dev->data;
const struct ext_power_generic_config *config = dev->config;
@@ -67,7 +67,7 @@ static int ext_power_generic_enable(struct device *dev) {
return ext_power_save_state();
}
static int ext_power_generic_disable(struct device *dev) {
static int ext_power_generic_disable(const struct device *dev) {
struct ext_power_generic_data *data = dev->data;
const struct ext_power_generic_config *config = dev->config;
@@ -79,7 +79,7 @@ static int ext_power_generic_disable(struct device *dev) {
return ext_power_save_state();
}
static int ext_power_generic_get(struct device *dev) {
static int ext_power_generic_get(const struct device *dev) {
struct ext_power_generic_data *data = dev->data;
return data->status;
}
@@ -91,7 +91,7 @@ static int ext_power_settings_set(const char *name, size_t len, settings_read_cb
int rc;
if (settings_name_steq(name, DT_INST_LABEL(0), &next) && !next) {
struct device *ext_power = device_get_binding(DT_INST_LABEL(0));
const struct device *ext_power = device_get_binding(DT_INST_LABEL(0));
struct ext_power_generic_data *data = ext_power->data;
if (len != sizeof(data->status)) {
@@ -124,7 +124,7 @@ struct settings_handler ext_power_conf = {.name = "ext_power/state",
.h_set = ext_power_settings_set};
#endif
static int ext_power_generic_init(struct device *dev) {
static int ext_power_generic_init(const struct device *dev) {
struct ext_power_generic_data *data = dev->data;
const struct ext_power_generic_config *config = dev->config;

View File

@@ -121,7 +121,7 @@ bool is_active_layer(uint8_t layer, zmk_keymap_layers_state layer_state) {
int zmk_keymap_apply_position_state(int layer, uint32_t position, bool pressed, int64_t timestamp) {
struct zmk_behavior_binding *binding = &zmk_keymap[layer][position];
struct device *behavior;
const struct device *behavior;
struct zmk_behavior_binding_event event = {
.layer = layer,
.position = position,
@@ -168,13 +168,14 @@ int zmk_keymap_position_state_changed(uint32_t position, bool pressed, int64_t t
}
#if ZMK_KEYMAP_HAS_SENSORS
int zmk_keymap_sensor_triggered(uint8_t sensor_number, struct device *sensor, int64_t timestamp) {
int zmk_keymap_sensor_triggered(uint8_t sensor_number, const struct device *sensor,
int64_t timestamp) {
for (int layer = ZMK_KEYMAP_LAYERS_LEN - 1; layer >= _zmk_keymap_layer_default; layer--) {
if (((_zmk_keymap_layer_state & BIT(layer)) == BIT(layer) ||
layer == _zmk_keymap_layer_default) &&
zmk_sensor_keymap[layer] != NULL) {
struct zmk_behavior_binding *binding = &zmk_sensor_keymap[layer][sensor_number];
struct device *behavior;
const struct device *behavior;
int ret;
LOG_DBG("layer: %d sensor_number: %d, binding name: %s", layer, sensor_number,

View File

@@ -30,7 +30,8 @@ struct zmk_kscan_msg_processor {
K_MSGQ_DEFINE(zmk_kscan_msgq, sizeof(struct zmk_kscan_event), CONFIG_ZMK_KSCAN_EVENT_QUEUE_SIZE, 4);
static void zmk_kscan_callback(struct device *dev, uint32_t row, uint32_t column, bool pressed) {
static void zmk_kscan_callback(const struct device *dev, uint32_t row, uint32_t column,
bool pressed) {
struct zmk_kscan_event ev = {
.row = row,
.column = column,
@@ -58,7 +59,7 @@ void zmk_kscan_process_msgq(struct k_work *item) {
}
int zmk_kscan_init(char *name) {
struct device *dev = device_get_binding(name);
const struct device *dev = device_get_binding(name);
if (dev == NULL) {
LOG_ERR("Failed to get the KSCAN device");
return -EINVAL;

View File

@@ -46,14 +46,14 @@ struct rgb_underglow_state {
bool on;
};
static struct device *led_strip;
static const struct device *led_strip;
static struct led_rgb pixels[STRIP_NUM_PIXELS];
static struct rgb_underglow_state state;
#if IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW_EXT_POWER)
static struct device *ext_power;
static const struct device *ext_power;
#endif
static struct led_rgb hsb_to_rgb(struct led_hsb hsb) {
@@ -238,7 +238,7 @@ static void zmk_rgb_underglow_save_state_work() {
static struct k_delayed_work underglow_save_work;
#endif
static int zmk_rgb_underglow_init(struct device *_arg) {
static int zmk_rgb_underglow_init(const struct device *_arg) {
led_strip = device_get_binding(STRIP_LABEL);
if (led_strip) {
LOG_INF("Found LED strip device %s", STRIP_LABEL);

View File

@@ -20,7 +20,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
struct sensors_data_item {
uint8_t sensor_number;
struct device *dev;
const struct device *dev;
struct sensor_trigger trigger;
};
@@ -32,7 +32,7 @@ struct sensors_data_item {
static struct sensors_data_item sensors[] = {UTIL_LISTIFY(ZMK_KEYMAP_SENSORS_LEN, SENSOR_ITEM, 0)};
static void zmk_sensors_trigger_handler(struct device *dev, struct sensor_trigger *trigger) {
static void zmk_sensors_trigger_handler(const struct device *dev, struct sensor_trigger *trigger) {
int err;
struct sensors_data_item *item = CONTAINER_OF(trigger, struct sensors_data_item, trigger);
struct sensor_event *event;
@@ -72,7 +72,7 @@ static void zmk_sensors_init_item(const char *node, uint8_t i, uint8_t abs_i) {
COND_CODE_1(DT_NODE_HAS_STATUS(ZMK_KEYMAP_SENSORS_BY_IDX(idx), okay), \
(_SENSOR_INIT(ZMK_KEYMAP_SENSORS_BY_IDX(idx))), (absolute_index++;))
static int zmk_sensors_init(struct device *_arg) {
static int zmk_sensors_init(const struct device *_arg) {
int local_index = 0;
int absolute_index = 0;

View File

@@ -3,6 +3,6 @@
#include <kernel.h>
#include <settings/settings.h>
static int zmk_settings_init(struct device *_arg) { return settings_load(); }
static int zmk_settings_init(const struct device *_arg) { return settings_load(); }
SYS_INIT(zmk_settings_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);

View File

@@ -315,7 +315,7 @@ static struct bt_conn_cb conn_callbacks = {
.disconnected = split_central_disconnected,
};
int zmk_split_bt_central_init(struct device *_arg) {
int zmk_split_bt_central_init(const struct device *_arg) {
bt_conn_cb_register(&conn_callbacks);
return start_scan();

View File

@@ -21,7 +21,7 @@ static enum usb_dc_status_code usb_status = USB_DC_UNKNOWN;
#ifdef CONFIG_ZMK_USB
static struct device *hid_dev;
static const struct device *hid_dev;
static K_SEM_DEFINE(hid_sem, 1, 1);
@@ -83,7 +83,7 @@ void usb_status_cb(enum usb_dc_status_code status, const uint8_t *params) {
raise_usb_status_changed_event();
};
static int zmk_usb_init(struct device *_arg) {
static int zmk_usb_init(const struct device *_arg) {
int usb_enable_ret;
#ifdef CONFIG_ZMK_USB