Skip to content

Commit

Permalink
外部変数を整理
Browse files Browse the repository at this point in the history
  • Loading branch information
YusukeKato committed Nov 5, 2024
1 parent 71aa661 commit b2d7b7d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 43 deletions.
22 changes: 3 additions & 19 deletions src/drivers/rtmouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,35 +252,18 @@ struct rtcnt_device_info {
int raw_pulse_count;
};

/* --- extern --- */
extern unsigned int NUM_DEV[ID_DEV_SIZE];
extern char *NAME_DEV[ID_DEV_SIZE];
extern char *NAME_DEV_U[ID_DEV_SIZE];
extern int _major_dev[ID_DEV_SIZE];
extern int _minor_dev[ID_DEV_SIZE];
extern struct cdev *cdev_array;
extern struct class *class_dev[ID_DEV_SIZE];
/* --- rtmouse_dev_fops.c extern --- */
extern volatile void __iomem *pwm_base;
extern volatile void __iomem *clk_base;
extern volatile uint32_t *gpio_base;
extern volatile int cdev_index;
extern struct mutex lock;
extern struct spi_device_id mcp3204_id[];
extern struct spi_board_info mcp3204_info;
extern struct spi_driver mcp3204_driver;
extern struct i2c_client *i2c_client_r;
extern struct i2c_client *i2c_client_l;
extern unsigned int motor_l_freq_is_positive;
extern unsigned int motor_r_freq_is_positive;
extern struct i2c_device_id i2c_counter_id[];
extern struct i2c_driver i2c_counter_driver;
extern struct file_operations dev_fops[ID_DEV_SIZE];

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

/* --- function --- */
/* --- rtmouse_dev_fops.c function --- */
int dev_open(struct inode *inode, struct file *filep);
int dev_release(struct inode *inode, struct file *filep);
int i2c_dev_open(struct inode *inode, struct file *filep);
Expand All @@ -302,5 +285,6 @@ void rpi_gpio_set32(uint32_t mask, uint32_t val);
void rpi_gpio_clear32(uint32_t mask, uint32_t val);
void rpi_pwm_write32(uint32_t offset, uint32_t val);
int buzzer_init(void);
unsigned int mcp3204_get_value(int channel);

#endif // RTMOUSE_H
9 changes: 6 additions & 3 deletions src/drivers/rtmouse_dev_fops.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

#include "rtmouse.h"

static unsigned int motor_l_freq_is_positive = 1;
static unsigned int motor_r_freq_is_positive = 1;

/*
* i2c_counter_set - set value to I2C pulse counter
* called by rtcnt_write()
Expand Down Expand Up @@ -95,7 +98,7 @@ static int i2c_counter_read(struct rtcnt_device_info *dev_info, int *ret)
* update_signed_count - update signed pulse count of dev_info
* called by rtcnt_read()
*/
void update_signed_count(struct rtcnt_device_info *dev_info, int rtcnt_count)
static void update_signed_count(struct rtcnt_device_info *dev_info, int rtcnt_count)
{
int diff_count = rtcnt_count - dev_info->raw_pulse_count;

Expand Down Expand Up @@ -131,7 +134,7 @@ void update_signed_count(struct rtcnt_device_info *dev_info, int rtcnt_count)
* reset_signed_count - reset signed pulse count of dev_info
* called by rtcnt_write()
*/
void reset_signed_count(struct rtcnt_device_info *dev_info, int rtcnt_count)
static void reset_signed_count(struct rtcnt_device_info *dev_info, int rtcnt_count)
{
int raw_count;

Expand All @@ -149,7 +152,7 @@ void reset_signed_count(struct rtcnt_device_info *dev_info, int rtcnt_count)
* mcp3204_get_value - get sensor data from MCP3204
* called by sensor_read()
*/
static unsigned int mcp3204_get_value(int channel)
unsigned int mcp3204_get_value(int channel)
{
struct device *dev;
struct mcp3204_drvdata *data;
Expand Down
39 changes: 18 additions & 21 deletions src/drivers/rtmouse_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ MODULE_VERSION("3.3.3");
MODULE_DESCRIPTION("Raspberry Pi Mouse device driver");

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

/* --- Device Names --- */
char *NAME_DEV[ID_DEV_SIZE] = {[ID_DEV_LED] = "rtled",
static const char *NAME_DEV[ID_DEV_SIZE] = {[ID_DEV_LED] = "rtled",
[ID_DEV_SWITCH] = "rtswitch",
[ID_DEV_SENSOR] = "rtlightsensor",
[ID_DEV_BUZZER] = "rtbuzzer",
Expand All @@ -45,7 +45,7 @@ char *NAME_DEV[ID_DEV_SIZE] = {[ID_DEV_LED] = "rtled",
[ID_DEV_MOTOREN] = "rtmotoren",
[ID_DEV_MOTOR] = "rtmotor"};

char *NAME_DEV_U[ID_DEV_SIZE] = {[ID_DEV_LED] = "rtled%u",
static const char *NAME_DEV_U[ID_DEV_SIZE] = {[ID_DEV_LED] = "rtled%u",
[ID_DEV_SWITCH] = "rtswitch%u",
[ID_DEV_SENSOR] = "rtlightsensor%u",
[ID_DEV_BUZZER] = "rtbuzzer%u",
Expand All @@ -55,31 +55,31 @@ char *NAME_DEV_U[ID_DEV_SIZE] = {[ID_DEV_LED] = "rtled%u",
[ID_DEV_MOTOR] = "rtmotor%u"};

// used in by register_dev() and cleanup_each_dev()
int _major_dev[ID_DEV_SIZE] = {
static int _major_dev[ID_DEV_SIZE] = {
[ID_DEV_LED] = DEV_MAJOR, [ID_DEV_SWITCH] = DEV_MAJOR,
[ID_DEV_SENSOR] = DEV_MAJOR, [ID_DEV_BUZZER] = DEV_MAJOR,
[ID_DEV_MOTORRAWR] = DEV_MAJOR, [ID_DEV_MOTORRAWL] = DEV_MAJOR,
[ID_DEV_MOTOREN] = DEV_MAJOR, [ID_DEV_MOTOR] = DEV_MAJOR};

// used in register_dev() and cleanup_each_dev()
int _minor_dev[ID_DEV_SIZE] = {
static int _minor_dev[ID_DEV_SIZE] = {
[ID_DEV_LED] = DEV_MINOR, [ID_DEV_SWITCH] = DEV_MINOR,
[ID_DEV_SENSOR] = DEV_MINOR, [ID_DEV_BUZZER] = DEV_MINOR,
[ID_DEV_MOTORRAWR] = DEV_MINOR, [ID_DEV_MOTORRAWL] = DEV_MINOR,
[ID_DEV_MOTOREN] = DEV_MINOR, [ID_DEV_MOTOR] = DEV_MINOR};

/* --- General Options --- */
struct cdev *cdev_array = NULL;
struct class *class_dev[ID_DEV_SIZE] = {
static struct cdev *cdev_array = NULL;
static struct class *class_dev[ID_DEV_SIZE] = {
[ID_DEV_LED] = NULL, [ID_DEV_SWITCH] = NULL,
[ID_DEV_SENSOR] = NULL, [ID_DEV_BUZZER] = NULL,
[ID_DEV_MOTORRAWR] = NULL, [ID_DEV_MOTORRAWL] = NULL,
[ID_DEV_MOTOREN] = NULL, [ID_DEV_MOTOR] = NULL};

volatile void __iomem *pwm_base;
volatile void __iomem *clk_base;
static volatile void __iomem *clk_base;
volatile uint32_t *gpio_base;
volatile int cdev_index = 0;
static volatile int cdev_index = 0;
struct mutex lock;

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

static int mcp3204_probe(struct spi_device *spi);
static unsigned int mcp3204_get_value(int channel);

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

/* --- Static variables --- */
/* SPI device ID */
struct spi_device_id mcp3204_id[] = {
static struct spi_device_id mcp3204_id[] = {
{"mcp3204", 0},
{},
};
Expand All @@ -126,7 +125,7 @@ struct device *mcp320x_dev;
#endif

/* SPI Dirver Info */
struct spi_driver mcp3204_driver = {
static struct spi_driver mcp3204_driver = {
.driver =
{
.name = DEVNAME_SENSOR,
Expand All @@ -137,20 +136,18 @@ struct spi_driver mcp3204_driver = {
.remove = mcp3204_remove,
};

struct i2c_client *i2c_client_r = NULL;
struct i2c_client *i2c_client_l = NULL;
unsigned int motor_l_freq_is_positive = 1;
unsigned int motor_r_freq_is_positive = 1;
static struct i2c_client *i2c_client_r = NULL;
static struct i2c_client *i2c_client_l = NULL;

/* I2C Device ID */
struct i2c_device_id i2c_counter_id[] = {
static struct i2c_device_id i2c_counter_id[] = {
{DEVNAME_CNTL, 0},
{DEVNAME_CNTR, 1},
{},
};

/* I2C Dirver Info */
struct i2c_driver i2c_counter_driver = {
static struct i2c_driver i2c_counter_driver = {
.driver =
{
.name = "rtcounter",
Expand Down Expand Up @@ -829,7 +826,7 @@ static void rtcnt_i2c_remove(struct i2c_client *client)
* dev_init_module - register driver module
* called by module_init(dev_init_module)
*/
int dev_init_module(void)
static int dev_init_module(void)
{
int retval, i;
int registered_devices = 0;
Expand Down Expand Up @@ -939,7 +936,7 @@ int dev_init_module(void)
* dev_cleanup_module - cleanup driver module
* called by module_exit(dev_cleanup_module)
*/
void cleanup_each_dev(int id_dev)
static void cleanup_each_dev(int id_dev)
{
int i;
dev_t devno;
Expand All @@ -953,7 +950,7 @@ void cleanup_each_dev(int id_dev)
unregister_chrdev_region(devno_top, NUM_DEV[id_dev]);
}

void dev_cleanup_module(void)
static void dev_cleanup_module(void)
{
int i;

Expand Down

0 comments on commit b2d7b7d

Please sign in to comment.