Skip to content

Commit c482fcf

Browse files
committed
定数DEV_LEFTとDEV_RIGHTを定義して条件分岐
1 parent 2ddf4cf commit c482fcf

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

src/drivers/rtmouse.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@
5454
// Raspberry Pi 4 B : 4
5555
#define RASPBERRYPI 2
5656

57+
#define DEV_RIGHT 0
58+
#define DEV_LEFT 1
59+
5760
/* --- Device ID --- */
5861
#define ID_DEV_LED 0
5962
#define ID_DEV_SWITCH 1

src/drivers/rtmouse_i2c.c

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,21 @@ static struct i2c_driver i2c_counter_driver = {
6969
MODULE_DEVICE_TABLE(i2c, i2c_counter_id);
7070

7171
// called by rtcnt_i2c_probe()
72-
static int rtcnt_i2c_create_cdev(struct rtcnt_device_info *dev_info, const char *devname_cnt)
72+
static int rtcnt_i2c_create_cdev(struct rtcnt_device_info *dev_info, const int dev_side)
7373
{
7474
int minor;
7575
int alloc_ret = 0;
7676
int cdev_err = 0;
7777
dev_t dev;
7878

7979
/* 空いているメジャー番号を確保する */
80-
alloc_ret = alloc_chrdev_region(&dev, DEV_MINOR, NUM_DEV[ID_DEV_CNT],
81-
devname_cnt);
80+
if (dev_side == DEV_LEFT) {
81+
alloc_ret = alloc_chrdev_region(&dev, DEV_MINOR, NUM_DEV[ID_DEV_CNT],
82+
DEVNAME_CNTL);
83+
} else if (dev_side == DEV_RIGHT) {
84+
alloc_ret = alloc_chrdev_region(&dev, DEV_MINOR, NUM_DEV[ID_DEV_CNT],
85+
DEVNAME_CNTR);
86+
}
8287
if (alloc_ret != 0) {
8388
printk(KERN_ERR "alloc_chrdev_region = %d\n", alloc_ret);
8489
return -1;
@@ -103,9 +108,17 @@ static int rtcnt_i2c_create_cdev(struct rtcnt_device_info *dev_info, const char
103108

104109
/* このデバイスのクラス登録をする(/sys/class/mydevice/ を作る) */
105110
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0)
106-
dev_info->device_class = class_create(THIS_MODULE, devname_cnt);
111+
if (dev_side == DEV_LEFT) {
112+
dev_info->device_class = class_create(THIS_MODULE, DEVNAME_CNTL);
113+
} else if (dev_side == DEV_RIGHT) {
114+
dev_info->device_class = class_create(THIS_MODULE, DEVNAME_CNTR);
115+
}
107116
#else
108-
dev_info->device_class = class_create(devname_cnt);
117+
if (dev_side == DEV_LEFT) {
118+
dev_info->device_class = class_create(DEVNAME_CNTL);
119+
} else if (dev_side == DEV_RIGHT) {
120+
dev_info->device_class = class_create(DEVNAME_CNTR);
121+
}
109122
#endif
110123

111124
if (IS_ERR(dev_info->device_class)) {
@@ -120,11 +133,11 @@ static int rtcnt_i2c_create_cdev(struct rtcnt_device_info *dev_info, const char
120133
minor++) {
121134

122135
struct device *dev_ret;
123-
if (devname_cnt == DEVNAME_CNTL) {
136+
if (dev_side == DEV_LEFT) {
124137
dev_ret = device_create(dev_info->device_class, NULL,
125138
MKDEV(dev_info->device_major, minor),
126139
NULL, "rtcounter_l%d", minor);
127-
} else if (devname_cnt == DEVNAME_CNTR) {
140+
} else if (dev_side == DEV_RIGHT) {
128141
dev_ret = device_create(dev_info->device_class, NULL,
129142
MKDEV(dev_info->device_major, minor),
130143
NULL, "rtcounter_r%d", minor);

0 commit comments

Comments
 (0)