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 4f0ef43 commit 93ad739
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 26 deletions.
35 changes: 30 additions & 5 deletions src/drivers/rtmouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@
#define ID_DEV_CNT 8
#define ID_DEV_SIZE 9

extern unsigned int NUM_DEV[ID_DEV_SIZE];
extern char *NAME_DEV[ID_DEV_SIZE];
extern char *NAME_DEV_U[ID_DEV_SIZE];

#define NUM_DEV_TOTAL \
(NUM_DEV[ID_DEV_LED] + NUM_DEV[ID_DEV_SWITCH] + \
NUM_DEV[ID_DEV_SENSOR] + NUM_DEV[ID_DEV_BUZZER] + \
Expand Down Expand Up @@ -230,7 +226,36 @@ extern char *NAME_DEV_U[ID_DEV_SIZE];
#define SIGNED_COUNT_SIZE 32767
#define MAX_PULSE_COUNT 65535

/* -- Buffer -- */
/* --- Buffer --- */
#define MAX_BUFLEN 64

/* --- 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];
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;

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

void tmp_func(void);

#endif // RTMOUSE_H
42 changes: 21 additions & 21 deletions src/drivers/rtmouse_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,34 +55,32 @@ 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()
static int _major_dev[ID_DEV_SIZE] = {
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()
static int _minor_dev[ID_DEV_SIZE] = {
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 --- */
static struct cdev *cdev_array = NULL;
static struct class *class_dev[ID_DEV_SIZE] = {
struct cdev *cdev_array = NULL;
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};

static volatile void __iomem *pwm_base;
static volatile void __iomem *clk_base;
static volatile uint32_t *gpio_base;

static volatile int cdev_index = 0;

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

/* --- Function Declarations --- */
static void set_motor_r_freq(int freq);
Expand Down Expand Up @@ -123,13 +121,13 @@ struct mcp3204_drvdata {

/* --- Static variables --- */
/* SPI device ID */
static struct spi_device_id mcp3204_id[] = {
struct spi_device_id mcp3204_id[] = {
{"mcp3204", 0},
{},
};

/* SPI Info */
static struct spi_board_info mcp3204_info = {
struct spi_board_info mcp3204_info = {
.modalias = "mcp3204",
.max_speed_hz = 100000,
.bus_num = 0,
Expand All @@ -138,11 +136,11 @@ static struct spi_board_info mcp3204_info = {
};

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

/* SPI Dirver Info */
static struct spi_driver mcp3204_driver = {
struct spi_driver mcp3204_driver = {
.driver =
{
.name = DEVNAME_SENSOR,
Expand All @@ -165,20 +163,20 @@ struct rtcnt_device_info {
int raw_pulse_count;
};

static struct i2c_client *i2c_client_r = NULL;
static struct i2c_client *i2c_client_l = NULL;
static unsigned int motor_l_freq_is_positive = 1;
static unsigned int motor_r_freq_is_positive = 1;
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;

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

/* I2C Dirver Info */
static struct i2c_driver i2c_counter_driver = {
struct i2c_driver i2c_counter_driver = {
.driver =
{
.name = "rtcounter",
Expand Down Expand Up @@ -1673,6 +1671,8 @@ int dev_init_module(void)
int registered_devices = 0;
size_t size;

tmp_func();

/* log loding message */
printk(KERN_INFO "%s: loading driver...\n", DRIVER_NAME);

Expand Down

0 comments on commit 93ad739

Please sign in to comment.