Skip to content

Commit b2d7b7d

Browse files
committed
外部変数を整理
1 parent 71aa661 commit b2d7b7d

File tree

3 files changed

+27
-43
lines changed

3 files changed

+27
-43
lines changed

src/drivers/rtmouse.h

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -252,35 +252,18 @@ struct rtcnt_device_info {
252252
int raw_pulse_count;
253253
};
254254

255-
/* --- extern --- */
256-
extern unsigned int NUM_DEV[ID_DEV_SIZE];
257-
extern char *NAME_DEV[ID_DEV_SIZE];
258-
extern char *NAME_DEV_U[ID_DEV_SIZE];
259-
extern int _major_dev[ID_DEV_SIZE];
260-
extern int _minor_dev[ID_DEV_SIZE];
261-
extern struct cdev *cdev_array;
262-
extern struct class *class_dev[ID_DEV_SIZE];
255+
/* --- rtmouse_dev_fops.c extern --- */
263256
extern volatile void __iomem *pwm_base;
264-
extern volatile void __iomem *clk_base;
265257
extern volatile uint32_t *gpio_base;
266-
extern volatile int cdev_index;
267258
extern struct mutex lock;
268-
extern struct spi_device_id mcp3204_id[];
269259
extern struct spi_board_info mcp3204_info;
270-
extern struct spi_driver mcp3204_driver;
271-
extern struct i2c_client *i2c_client_r;
272-
extern struct i2c_client *i2c_client_l;
273-
extern unsigned int motor_l_freq_is_positive;
274-
extern unsigned int motor_r_freq_is_positive;
275-
extern struct i2c_device_id i2c_counter_id[];
276-
extern struct i2c_driver i2c_counter_driver;
277260
extern struct file_operations dev_fops[ID_DEV_SIZE];
278261

279262
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 16, 0)
280263
extern struct device *mcp320x_dev;
281264
#endif
282265

283-
/* --- function --- */
266+
/* --- rtmouse_dev_fops.c function --- */
284267
int dev_open(struct inode *inode, struct file *filep);
285268
int dev_release(struct inode *inode, struct file *filep);
286269
int i2c_dev_open(struct inode *inode, struct file *filep);
@@ -302,5 +285,6 @@ void rpi_gpio_set32(uint32_t mask, uint32_t val);
302285
void rpi_gpio_clear32(uint32_t mask, uint32_t val);
303286
void rpi_pwm_write32(uint32_t offset, uint32_t val);
304287
int buzzer_init(void);
288+
unsigned int mcp3204_get_value(int channel);
305289

306290
#endif // RTMOUSE_H

src/drivers/rtmouse_dev_fops.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
#include "rtmouse.h"
2424

25+
static unsigned int motor_l_freq_is_positive = 1;
26+
static unsigned int motor_r_freq_is_positive = 1;
27+
2528
/*
2629
* i2c_counter_set - set value to I2C pulse counter
2730
* called by rtcnt_write()
@@ -95,7 +98,7 @@ static int i2c_counter_read(struct rtcnt_device_info *dev_info, int *ret)
9598
* update_signed_count - update signed pulse count of dev_info
9699
* called by rtcnt_read()
97100
*/
98-
void update_signed_count(struct rtcnt_device_info *dev_info, int rtcnt_count)
101+
static void update_signed_count(struct rtcnt_device_info *dev_info, int rtcnt_count)
99102
{
100103
int diff_count = rtcnt_count - dev_info->raw_pulse_count;
101104

@@ -131,7 +134,7 @@ void update_signed_count(struct rtcnt_device_info *dev_info, int rtcnt_count)
131134
* reset_signed_count - reset signed pulse count of dev_info
132135
* called by rtcnt_write()
133136
*/
134-
void reset_signed_count(struct rtcnt_device_info *dev_info, int rtcnt_count)
137+
static void reset_signed_count(struct rtcnt_device_info *dev_info, int rtcnt_count)
135138
{
136139
int raw_count;
137140

@@ -149,7 +152,7 @@ void reset_signed_count(struct rtcnt_device_info *dev_info, int rtcnt_count)
149152
* mcp3204_get_value - get sensor data from MCP3204
150153
* called by sensor_read()
151154
*/
152-
static unsigned int mcp3204_get_value(int channel)
155+
unsigned int mcp3204_get_value(int channel)
153156
{
154157
struct device *dev;
155158
struct mcp3204_drvdata *data;

src/drivers/rtmouse_main.c

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ MODULE_VERSION("3.3.3");
3030
MODULE_DESCRIPTION("Raspberry Pi Mouse device driver");
3131

3232
/* --- Device Numbers --- */
33-
unsigned int NUM_DEV[ID_DEV_SIZE] = {
33+
static const unsigned int NUM_DEV[ID_DEV_SIZE] = {
3434
[ID_DEV_LED] = 4, [ID_DEV_SWITCH] = 3, [ID_DEV_SENSOR] = 1,
3535
[ID_DEV_BUZZER] = 1, [ID_DEV_MOTORRAWR] = 1, [ID_DEV_MOTORRAWL] = 1,
3636
[ID_DEV_MOTOREN] = 1, [ID_DEV_MOTOR] = 1, [ID_DEV_CNT] = 2};
3737

3838
/* --- Device Names --- */
39-
char *NAME_DEV[ID_DEV_SIZE] = {[ID_DEV_LED] = "rtled",
39+
static const char *NAME_DEV[ID_DEV_SIZE] = {[ID_DEV_LED] = "rtled",
4040
[ID_DEV_SWITCH] = "rtswitch",
4141
[ID_DEV_SENSOR] = "rtlightsensor",
4242
[ID_DEV_BUZZER] = "rtbuzzer",
@@ -45,7 +45,7 @@ char *NAME_DEV[ID_DEV_SIZE] = {[ID_DEV_LED] = "rtled",
4545
[ID_DEV_MOTOREN] = "rtmotoren",
4646
[ID_DEV_MOTOR] = "rtmotor"};
4747

48-
char *NAME_DEV_U[ID_DEV_SIZE] = {[ID_DEV_LED] = "rtled%u",
48+
static const char *NAME_DEV_U[ID_DEV_SIZE] = {[ID_DEV_LED] = "rtled%u",
4949
[ID_DEV_SWITCH] = "rtswitch%u",
5050
[ID_DEV_SENSOR] = "rtlightsensor%u",
5151
[ID_DEV_BUZZER] = "rtbuzzer%u",
@@ -55,31 +55,31 @@ char *NAME_DEV_U[ID_DEV_SIZE] = {[ID_DEV_LED] = "rtled%u",
5555
[ID_DEV_MOTOR] = "rtmotor%u"};
5656

5757
// used in by register_dev() and cleanup_each_dev()
58-
int _major_dev[ID_DEV_SIZE] = {
58+
static int _major_dev[ID_DEV_SIZE] = {
5959
[ID_DEV_LED] = DEV_MAJOR, [ID_DEV_SWITCH] = DEV_MAJOR,
6060
[ID_DEV_SENSOR] = DEV_MAJOR, [ID_DEV_BUZZER] = DEV_MAJOR,
6161
[ID_DEV_MOTORRAWR] = DEV_MAJOR, [ID_DEV_MOTORRAWL] = DEV_MAJOR,
6262
[ID_DEV_MOTOREN] = DEV_MAJOR, [ID_DEV_MOTOR] = DEV_MAJOR};
6363

6464
// used in register_dev() and cleanup_each_dev()
65-
int _minor_dev[ID_DEV_SIZE] = {
65+
static int _minor_dev[ID_DEV_SIZE] = {
6666
[ID_DEV_LED] = DEV_MINOR, [ID_DEV_SWITCH] = DEV_MINOR,
6767
[ID_DEV_SENSOR] = DEV_MINOR, [ID_DEV_BUZZER] = DEV_MINOR,
6868
[ID_DEV_MOTORRAWR] = DEV_MINOR, [ID_DEV_MOTORRAWL] = DEV_MINOR,
6969
[ID_DEV_MOTOREN] = DEV_MINOR, [ID_DEV_MOTOR] = DEV_MINOR};
7070

7171
/* --- General Options --- */
72-
struct cdev *cdev_array = NULL;
73-
struct class *class_dev[ID_DEV_SIZE] = {
72+
static struct cdev *cdev_array = NULL;
73+
static struct class *class_dev[ID_DEV_SIZE] = {
7474
[ID_DEV_LED] = NULL, [ID_DEV_SWITCH] = NULL,
7575
[ID_DEV_SENSOR] = NULL, [ID_DEV_BUZZER] = NULL,
7676
[ID_DEV_MOTORRAWR] = NULL, [ID_DEV_MOTORRAWL] = NULL,
7777
[ID_DEV_MOTOREN] = NULL, [ID_DEV_MOTOR] = NULL};
7878

7979
volatile void __iomem *pwm_base;
80-
volatile void __iomem *clk_base;
80+
static volatile void __iomem *clk_base;
8181
volatile uint32_t *gpio_base;
82-
volatile int cdev_index = 0;
82+
static volatile int cdev_index = 0;
8383
struct mutex lock;
8484

8585
/* --- Function Declarations --- */
@@ -90,7 +90,6 @@ static void mcp3204_remove(struct spi_device *spi);
9090
#endif
9191

9292
static int mcp3204_probe(struct spi_device *spi);
93-
static unsigned int mcp3204_get_value(int channel);
9493

9594
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 2, 0)
9695
static int rtcnt_i2c_probe(struct i2c_client *client,
@@ -107,7 +106,7 @@ static void rtcnt_i2c_remove(struct i2c_client *client);
107106

108107
/* --- Static variables --- */
109108
/* SPI device ID */
110-
struct spi_device_id mcp3204_id[] = {
109+
static struct spi_device_id mcp3204_id[] = {
111110
{"mcp3204", 0},
112111
{},
113112
};
@@ -126,7 +125,7 @@ struct device *mcp320x_dev;
126125
#endif
127126

128127
/* SPI Dirver Info */
129-
struct spi_driver mcp3204_driver = {
128+
static struct spi_driver mcp3204_driver = {
130129
.driver =
131130
{
132131
.name = DEVNAME_SENSOR,
@@ -137,20 +136,18 @@ struct spi_driver mcp3204_driver = {
137136
.remove = mcp3204_remove,
138137
};
139138

140-
struct i2c_client *i2c_client_r = NULL;
141-
struct i2c_client *i2c_client_l = NULL;
142-
unsigned int motor_l_freq_is_positive = 1;
143-
unsigned int motor_r_freq_is_positive = 1;
139+
static struct i2c_client *i2c_client_r = NULL;
140+
static struct i2c_client *i2c_client_l = NULL;
144141

145142
/* I2C Device ID */
146-
struct i2c_device_id i2c_counter_id[] = {
143+
static struct i2c_device_id i2c_counter_id[] = {
147144
{DEVNAME_CNTL, 0},
148145
{DEVNAME_CNTR, 1},
149146
{},
150147
};
151148

152149
/* I2C Dirver Info */
153-
struct i2c_driver i2c_counter_driver = {
150+
static struct i2c_driver i2c_counter_driver = {
154151
.driver =
155152
{
156153
.name = "rtcounter",
@@ -829,7 +826,7 @@ static void rtcnt_i2c_remove(struct i2c_client *client)
829826
* dev_init_module - register driver module
830827
* called by module_init(dev_init_module)
831828
*/
832-
int dev_init_module(void)
829+
static int dev_init_module(void)
833830
{
834831
int retval, i;
835832
int registered_devices = 0;
@@ -939,7 +936,7 @@ int dev_init_module(void)
939936
* dev_cleanup_module - cleanup driver module
940937
* called by module_exit(dev_cleanup_module)
941938
*/
942-
void cleanup_each_dev(int id_dev)
939+
static void cleanup_each_dev(int id_dev)
943940
{
944941
int i;
945942
dev_t devno;
@@ -953,7 +950,7 @@ void cleanup_each_dev(int id_dev)
953950
unregister_chrdev_region(devno_top, NUM_DEV[id_dev]);
954951
}
955952

956-
void dev_cleanup_module(void)
953+
static void dev_cleanup_module(void)
957954
{
958955
int i;
959956

0 commit comments

Comments
 (0)