From e434a3de081c608bc59494bc3dd070be22c35df2 Mon Sep 17 00:00:00 2001 From: YusukeKato Date: Mon, 28 Oct 2024 16:41:21 +0900 Subject: [PATCH 01/16] =?UTF-8?q?define=E3=81=A7=E5=AE=9A=E7=BE=A9?= =?UTF-8?q?=E3=81=97=E3=81=9F=E5=AE=9A=E6=95=B0=E3=82=92rtmouse.h=E3=81=B8?= =?UTF-8?q?=E7=A7=BB=E5=8B=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/drivers/Makefile.header_from_apt | 3 +- src/drivers/Makefile.header_from_source | 3 +- src/drivers/include/rtmouse.h | 179 ++++++++++++++++++++++++ src/drivers/rtmouse.c | 179 +----------------------- 4 files changed, 184 insertions(+), 180 deletions(-) create mode 100644 src/drivers/include/rtmouse.h diff --git a/src/drivers/Makefile.header_from_apt b/src/drivers/Makefile.header_from_apt index 7844404..41ae094 100644 --- a/src/drivers/Makefile.header_from_apt +++ b/src/drivers/Makefile.header_from_apt @@ -1,4 +1,5 @@ MODULE:= rtmouse +EXTRA_CFLAGS := -I$(PWD)/include obj-m:= $(MODULE).o clean-files:= *.o *.ko *.mod.[co] *~ @@ -17,4 +18,4 @@ install: rtmouse.ko uninstall: rm /etc/udev/rules.d/50-rtmouse.rules -#Reference: http://www.devdrv.co.jp/linux/kernel26-makefile.htm \ No newline at end of file +#Reference: http://www.devdrv.co.jp/linux/kernel26-makefile.htm diff --git a/src/drivers/Makefile.header_from_source b/src/drivers/Makefile.header_from_source index 2222e8d..0f8793c 100644 --- a/src/drivers/Makefile.header_from_source +++ b/src/drivers/Makefile.header_from_source @@ -1,4 +1,5 @@ MODULE:= rtmouse +EXTRA_CFLAGS := -I$(PWD)/include obj-m:= $(MODULE).o clean-files:= *.o *.ko *.mod.[co] *~ @@ -9,4 +10,4 @@ rtmouse.ko: rtmouse.c make -C $(LINUX_SRC_DIR) M=$(shell pwd) V=$(VERBOSE) modules clean: - make -C $(LINUX_SRC_DIR) M=$(shell pwd) V=$(VERBOSE) clean \ No newline at end of file + make -C $(LINUX_SRC_DIR) M=$(shell pwd) V=$(VERBOSE) clean diff --git a/src/drivers/include/rtmouse.h b/src/drivers/include/rtmouse.h new file mode 100644 index 0000000..e92c11b --- /dev/null +++ b/src/drivers/include/rtmouse.h @@ -0,0 +1,179 @@ +// define the Raspberry Pi version here +// Raspberry Pi 1 B/A/B+/A+: 1 +// Raspberry Pi 2 B : 2 +// Raspberry Pi 3 B/A+/B+ : 2 +// Raspberry Pi 4 B : 4 +#define RASPBERRYPI 4 + +/* --- Device ID --- */ +#define ID_DEV_LED 0 +#define ID_DEV_SWITCH 1 +#define ID_DEV_SENSOR 2 +#define ID_DEV_BUZZER 3 +#define ID_DEV_MOTORRAWR 4 +#define ID_DEV_MOTORRAWL 5 +#define ID_DEV_MOTOREN 6 +#define ID_DEV_MOTOR 7 +#define ID_DEV_CNT 8 +#define ID_DEV_SIZE 9 + +#define NUM_DEV_TOTAL \ + (NUM_DEV[ID_DEV_LED] + NUM_DEV[ID_DEV_SWITCH] + \ + NUM_DEV[ID_DEV_SENSOR] + NUM_DEV[ID_DEV_BUZZER] + \ + NUM_DEV[ID_DEV_MOTORRAWR] + NUM_DEV[ID_DEV_MOTORRAWL] + \ + NUM_DEV[ID_DEV_MOTOREN] + NUM_DEV[ID_DEV_MOTOR]) + +#define DEVNAME_SENSOR "rtlightsensor" +#define DEVNAME_CNTR "rtcounter_r" +#define DEVNAME_CNTL "rtcounter_l" +#define DRIVER_NAME "rtmouse" + +/* --- Device Major and Minor Numbers --- */ +#define DEV_MAJOR 0 +#define DEV_MINOR 0 + +/* --- GPIO Pin Definitions --- */ +#define R_AD_CH 3 +#define L_AD_CH 0 +#define RF_AD_CH 2 +#define LF_AD_CH 1 + +#define R_LED_BASE 22 +#define L_LED_BASE 4 +#define RF_LED_BASE 27 +#define LF_LED_BASE 17 + +#define LED0_BASE 25 +#define LED1_BASE 24 +#define LED2_BASE 23 +#define LED3_BASE 18 + +#define SW1_PIN 20 +#define SW2_PIN 26 +#define SW3_PIN 21 + +#define BUZZER_BASE 19 + +#define MOTCLK_L_BASE 12 +#define MOTDIR_L_BASE 16 + +#define MOTCLK_R_BASE 13 +#define MOTDIR_R_BASE 6 + +#define MOTEN_BASE 5 + +#define PWM_ORG0_BASE 40 +#define PWM_ORG1_BASE 45 + +/* --- Register Address --- */ +/* Base Addr */ +#if RASPBERRYPI == 1 +#define RPI_REG_BASE 0x20000000 +#elif RASPBERRYPI == 2 +#define RPI_REG_BASE 0x3f000000 +#elif RASPBERRYPI == 4 +#define RPI_REG_BASE 0xfe000000 +/* 2711 has a different mechanism for pin pull-up/down/enable */ +#define GPPUPPDN0 57 /* Pin pull-up/down for pins 15:0 */ +#define GPPUPPDN1 58 /* Pin pull-up/down for pins 31:16 */ +#define GPPUPPDN2 59 /* Pin pull-up/down for pins 47:32 */ +#define GPPUPPDN3 60 /* Pin pull-up/down for pins 57:48 */ +#endif + +/* GPIO Addr */ +#define RPI_GPIO_OFFSET 0x200000 +#define RPI_GPIO_SIZE 0xC0 +#define RPI_GPIO_BASE (RPI_REG_BASE + RPI_GPIO_OFFSET) +#define REG_GPIO_NAME "RPi mouse GPIO" + +/* Pwm Addr */ +#define RPI_PWM_OFFSET 0x20C000 +#define RPI_PWM_SIZE 0xC0 +#define RPI_PWM_BASE (RPI_REG_BASE + RPI_PWM_OFFSET) +#define REG_PWM_NAME "RPi mouse PWM" + +/* Clock Addr */ +#define RPI_CLK_OFFSET 0x101000 +#define RPI_CLK_SIZE 0x100 +#define RPI_CLK_BASE (RPI_REG_BASE + RPI_CLK_OFFSET) +#define REG_CLK_NAME "RPi mouse CLK" + +/* --- General Options --- */ +/* Clock Offset */ +#define CLK_PWM_INDEX 0xa0 +#define CLK_PWMDIV_INDEX 0xa4 + +/* GPIO PUPD select */ +#if RASPBERRYPI == 4 +#define GPIO_PULLNONE 0x0 +#define GPIO_PULLUP 0x1 +#define GPIO_PULLDOWN 0x2 +#else +#define GPIO_PULLNONE 0x0 +#define GPIO_PULLDOWN 0x1 +#define GPIO_PULLUP 0x2 +#endif + +/* GPIO Function */ +#define RPI_GPF_INPUT 0x00 +#define RPI_GPF_OUTPUT 0x01 +#define RPI_GPF_ALT0 0x04 +#define RPI_GPF_ALT5 0x02 + +/* GPIO Register Index */ +#define RPI_GPFSEL0_INDEX 0 +#define RPI_GPFSEL1_INDEX 1 +#define RPI_GPFSEL2_INDEX 2 +#define RPI_GPFSEL3_INDEX 3 + +#define RPI_GPSET0_INDEX 7 +#define RPI_GPCLR0_INDEX 10 + +/* GPIO Mask */ +#define RPI_GPIO_P1MASK \ + (uint32_t)((0x01 << 2) | (0x01 << 3) | (0x01 << 4) | (0x01 << 7) | \ + (0x01 << 8) | (0x01 << 9) | (0x01 << 10) | (0x01 << 11) | \ + (0x01 << 14) | (0x01 << 15) | (0x01 << 17) | (0x01 << 18) | \ + (0x01 << 22) | (0x01 << 23) | (0x01 << 24) | (0x01 << 25) | \ + (0x01 << 27)) +#define RPI_GPIO_P2MASK (uint32_t)0xffffffff + +/* PWM Index */ +#define RPI_PWM_CTRL 0x0 +#define RPI_PWM_STA 0x4 +#define RPI_PWM_DMAC 0x8 +#define RPI_PWM_RNG1 0x10 +#define RPI_PWM_DAT1 0x14 +#define RPI_PWM_FIF1 0x18 +#define RPI_PWM_RNG2 0x20 +#define RPI_PWM_DAT2 0x24 + +#if RASPBERRYPI == 4 +#define PWM_BASECLK 27000000 +#else +#define PWM_BASECLK 9600000 +#endif + +/* A/D Parameter */ +#define MCP320X_PACKET_SIZE 3 +#define MCP320X_DIFF 0 +#define MCP320X_SINGLE 1 +#define MCP3204_CHANNELS 4 + +/* I2C Parameter */ +#define DEV_ADDR_CNTL 0x10 +#define DEV_ADDR_CNTR 0x11 +#define CNT_ADDR_MSB 0x10 +#define CNT_ADDR_LSB 0x11 + +/* Motor Parameter */ +#define MOTOR_UNCONTROLLABLE_FREQ 5 + +/* I2C */ +#define SIGNED_COUNT_SIZE 32767 +#define MAX_PULSE_COUNT 65535 + +/* -- Buffer -- */ +#define MAX_BUFLEN 64 +// static int buflen = 0; + diff --git a/src/drivers/rtmouse.c b/src/drivers/rtmouse.c index caa4270..6a52012 100644 --- a/src/drivers/rtmouse.c +++ b/src/drivers/rtmouse.c @@ -46,42 +46,19 @@ #include #include -// define the Raspberry Pi version here -// Raspberry Pi 1 B/A/B+/A+: 1 -// Raspberry Pi 2 B : 2 -// Raspberry Pi 3 B/A+/B+ : 2 -// Raspberry Pi 4 B : 4 -#define RASPBERRYPI 2 +#include "rtmouse.h" MODULE_AUTHOR("RT Corporation"); MODULE_LICENSE("GPL"); MODULE_VERSION("3.3.1"); MODULE_DESCRIPTION("Raspberry Pi Mouse device driver"); -/* --- Device ID --- */ -#define ID_DEV_LED 0 -#define ID_DEV_SWITCH 1 -#define ID_DEV_SENSOR 2 -#define ID_DEV_BUZZER 3 -#define ID_DEV_MOTORRAWR 4 -#define ID_DEV_MOTORRAWL 5 -#define ID_DEV_MOTOREN 6 -#define ID_DEV_MOTOR 7 -#define ID_DEV_CNT 8 -#define ID_DEV_SIZE 9 - /* --- Device Numbers --- */ 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}; -#define NUM_DEV_TOTAL \ - (NUM_DEV[ID_DEV_LED] + NUM_DEV[ID_DEV_SWITCH] + \ - NUM_DEV[ID_DEV_SENSOR] + NUM_DEV[ID_DEV_BUZZER] + \ - NUM_DEV[ID_DEV_MOTORRAWR] + NUM_DEV[ID_DEV_MOTORRAWL] + \ - NUM_DEV[ID_DEV_MOTOREN] + NUM_DEV[ID_DEV_MOTOR]) - /* --- Device Names --- */ static const char *NAME_DEV[ID_DEV_SIZE] = { [ID_DEV_LED] = "rtled", @@ -103,16 +80,6 @@ static const char *NAME_DEV_U[ID_DEV_SIZE] = { [ID_DEV_MOTOREN] = "rtmotoren%u", [ID_DEV_MOTOR] = "rtmotor%u"}; -#define DEVNAME_SENSOR "rtlightsensor" -#define DEVNAME_CNTR "rtcounter_r" -#define DEVNAME_CNTL "rtcounter_l" - -#define DRIVER_NAME "rtmouse" - -/* --- Device Major and Minor Numbers --- */ -#define DEV_MAJOR 0 -#define DEV_MINOR 0 - static int spi_bus_num = 0; static int spi_chip_select = 0; @@ -144,143 +111,6 @@ static volatile int cdev_index = 0; static struct mutex lock; -/* --- GPIO Pin Definitions --- */ -#define R_AD_CH 3 -#define L_AD_CH 0 -#define RF_AD_CH 2 -#define LF_AD_CH 1 - -#define R_LED_BASE 22 -#define L_LED_BASE 4 -#define RF_LED_BASE 27 -#define LF_LED_BASE 17 - -#define LED0_BASE 25 -#define LED1_BASE 24 -#define LED2_BASE 23 -#define LED3_BASE 18 - -#define SW1_PIN 20 -#define SW2_PIN 26 -#define SW3_PIN 21 - -#define BUZZER_BASE 19 - -#define MOTCLK_L_BASE 12 -#define MOTDIR_L_BASE 16 - -#define MOTCLK_R_BASE 13 -#define MOTDIR_R_BASE 6 - -#define MOTEN_BASE 5 - -#define PWM_ORG0_BASE 40 -#define PWM_ORG1_BASE 45 - -/* --- Register Address --- */ -/* Base Addr */ -#if RASPBERRYPI == 1 -#define RPI_REG_BASE 0x20000000 -#elif RASPBERRYPI == 2 -#define RPI_REG_BASE 0x3f000000 -#elif RASPBERRYPI == 4 -#define RPI_REG_BASE 0xfe000000 -/* 2711 has a different mechanism for pin pull-up/down/enable */ -#define GPPUPPDN0 57 /* Pin pull-up/down for pins 15:0 */ -#define GPPUPPDN1 58 /* Pin pull-up/down for pins 31:16 */ -#define GPPUPPDN2 59 /* Pin pull-up/down for pins 47:32 */ -#define GPPUPPDN3 60 /* Pin pull-up/down for pins 57:48 */ -#endif - -/* GPIO Addr */ -#define RPI_GPIO_OFFSET 0x200000 -#define RPI_GPIO_SIZE 0xC0 -#define RPI_GPIO_BASE (RPI_REG_BASE + RPI_GPIO_OFFSET) -#define REG_GPIO_NAME "RPi mouse GPIO" - -/* Pwm Addr */ -#define RPI_PWM_OFFSET 0x20C000 -#define RPI_PWM_SIZE 0xC0 -#define RPI_PWM_BASE (RPI_REG_BASE + RPI_PWM_OFFSET) -#define REG_PWM_NAME "RPi mouse PWM" - -/* Clock Addr */ -#define RPI_CLK_OFFSET 0x101000 -#define RPI_CLK_SIZE 0x100 -#define RPI_CLK_BASE (RPI_REG_BASE + RPI_CLK_OFFSET) -#define REG_CLK_NAME "RPi mouse CLK" - -/* --- General Options --- */ -/* Clock Offset */ -#define CLK_PWM_INDEX 0xa0 -#define CLK_PWMDIV_INDEX 0xa4 - -/* GPIO PUPD select */ -#if RASPBERRYPI == 4 -#define GPIO_PULLNONE 0x0 -#define GPIO_PULLUP 0x1 -#define GPIO_PULLDOWN 0x2 -#else -#define GPIO_PULLNONE 0x0 -#define GPIO_PULLDOWN 0x1 -#define GPIO_PULLUP 0x2 -#endif - -/* GPIO Function */ -#define RPI_GPF_INPUT 0x00 -#define RPI_GPF_OUTPUT 0x01 -#define RPI_GPF_ALT0 0x04 -#define RPI_GPF_ALT5 0x02 - -/* GPIO Register Index */ -#define RPI_GPFSEL0_INDEX 0 -#define RPI_GPFSEL1_INDEX 1 -#define RPI_GPFSEL2_INDEX 2 -#define RPI_GPFSEL3_INDEX 3 - -#define RPI_GPSET0_INDEX 7 -#define RPI_GPCLR0_INDEX 10 - -/* GPIO Mask */ -#define RPI_GPIO_P1MASK \ - (uint32_t)((0x01 << 2) | (0x01 << 3) | (0x01 << 4) | (0x01 << 7) | \ - (0x01 << 8) | (0x01 << 9) | (0x01 << 10) | (0x01 << 11) | \ - (0x01 << 14) | (0x01 << 15) | (0x01 << 17) | (0x01 << 18) | \ - (0x01 << 22) | (0x01 << 23) | (0x01 << 24) | (0x01 << 25) | \ - (0x01 << 27)) -#define RPI_GPIO_P2MASK (uint32_t)0xffffffff - -/* PWM Index */ -#define RPI_PWM_CTRL 0x0 -#define RPI_PWM_STA 0x4 -#define RPI_PWM_DMAC 0x8 -#define RPI_PWM_RNG1 0x10 -#define RPI_PWM_DAT1 0x14 -#define RPI_PWM_FIF1 0x18 -#define RPI_PWM_RNG2 0x20 -#define RPI_PWM_DAT2 0x24 - -#if RASPBERRYPI == 4 -#define PWM_BASECLK 27000000 -#else -#define PWM_BASECLK 9600000 -#endif - -/* A/D Parameter */ -#define MCP320X_PACKET_SIZE 3 -#define MCP320X_DIFF 0 -#define MCP320X_SINGLE 1 -#define MCP3204_CHANNELS 4 - -/* I2C Parameter */ -#define DEV_ADDR_CNTL 0x10 -#define DEV_ADDR_CNTR 0x11 -#define CNT_ADDR_MSB 0x10 -#define CNT_ADDR_LSB 0x11 - -/* Motor Parameter */ -#define MOTOR_UNCONTROLLABLE_FREQ 5 - /* --- Function Declarations --- */ static void set_motor_r_freq(int freq); static void set_motor_l_freq(int freq); @@ -366,8 +196,6 @@ 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; -#define SIGNED_COUNT_SIZE 32767 -#define MAX_PULSE_COUNT 65535 /* I2C Device ID */ static struct i2c_device_id i2c_counter_id[] = { @@ -390,13 +218,8 @@ static struct i2c_driver i2c_counter_driver = { /* -- Device Addition -- */ MODULE_DEVICE_TABLE(spi, mcp3204_id); - MODULE_DEVICE_TABLE(i2c, i2c_counter_id); -/* -- Buffer -- */ -#define MAX_BUFLEN 64 -// static int buflen = 0; - #define MOTOR_MOTION 0 #if MOTOR_MOTION /* Variable Type Definition for motor motion */ From 28ed7e5efb106304ccbb30dd5cf3bd41d3ceabfb Mon Sep 17 00:00:00 2001 From: YusukeKato Date: Mon, 28 Oct 2024 17:25:34 +0900 Subject: [PATCH 02/16] =?UTF-8?q?include/rtmouse.h=E3=81=AE=E8=AA=AD?= =?UTF-8?q?=E3=81=BF=E8=BE=BC=E3=81=BF=E6=96=B9=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/drivers/Makefile.header_from_apt | 4 +++- src/drivers/Makefile.header_from_source | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/drivers/Makefile.header_from_apt b/src/drivers/Makefile.header_from_apt index 41ae094..60c0c43 100644 --- a/src/drivers/Makefile.header_from_apt +++ b/src/drivers/Makefile.header_from_apt @@ -1,11 +1,13 @@ MODULE:= rtmouse -EXTRA_CFLAGS := -I$(PWD)/include obj-m:= $(MODULE).o clean-files:= *.o *.ko *.mod.[co] *~ LINUX_SRC_DIR:=/usr/src/linux-headers-$(shell uname -r) VERBOSE:=0 +EXTRA_CFLAGS += -I$(PWD)/include +ccflags-y += -I$(PWD)/include + rtmouse.ko: rtmouse.c make -C $(LINUX_SRC_DIR) M=$(shell pwd) V=$(VERBOSE) modules diff --git a/src/drivers/Makefile.header_from_source b/src/drivers/Makefile.header_from_source index 0f8793c..9ff784c 100644 --- a/src/drivers/Makefile.header_from_source +++ b/src/drivers/Makefile.header_from_source @@ -1,11 +1,13 @@ MODULE:= rtmouse -EXTRA_CFLAGS := -I$(PWD)/include obj-m:= $(MODULE).o clean-files:= *.o *.ko *.mod.[co] *~ LINUX_SRC_DIR:=/usr/src/linux VERBOSE:=0 +EXTRA_CFLAGS += -I$(PWD)/include +ccflags-y += -I$(PWD)/include + rtmouse.ko: rtmouse.c make -C $(LINUX_SRC_DIR) M=$(shell pwd) V=$(VERBOSE) modules From b9fe2a2e4d2eecbc21f27327788211a55e97b886 Mon Sep 17 00:00:00 2001 From: YusukeKato Date: Mon, 28 Oct 2024 17:35:39 +0900 Subject: [PATCH 03/16] =?UTF-8?q?rtmouse.h=E3=81=AE=E3=83=91=E3=82=B9?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/drivers/Makefile.header_from_apt | 2 ++ src/drivers/Makefile.header_from_source | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/drivers/Makefile.header_from_apt b/src/drivers/Makefile.header_from_apt index 60c0c43..a048451 100644 --- a/src/drivers/Makefile.header_from_apt +++ b/src/drivers/Makefile.header_from_apt @@ -6,7 +6,9 @@ LINUX_SRC_DIR:=/usr/src/linux-headers-$(shell uname -r) VERBOSE:=0 EXTRA_CFLAGS += -I$(PWD)/include +EXTRA_CFLAGS += -I$(shell pwd)/include ccflags-y += -I$(PWD)/include +ccflags-y += -I$(shell pwd)/include rtmouse.ko: rtmouse.c make -C $(LINUX_SRC_DIR) M=$(shell pwd) V=$(VERBOSE) modules diff --git a/src/drivers/Makefile.header_from_source b/src/drivers/Makefile.header_from_source index 9ff784c..c283c52 100644 --- a/src/drivers/Makefile.header_from_source +++ b/src/drivers/Makefile.header_from_source @@ -6,7 +6,9 @@ LINUX_SRC_DIR:=/usr/src/linux VERBOSE:=0 EXTRA_CFLAGS += -I$(PWD)/include +EXTRA_CFLAGS += -I$(shell pwd)/include ccflags-y += -I$(PWD)/include +ccflags-y += -I$(shell pwd)/include rtmouse.ko: rtmouse.c make -C $(LINUX_SRC_DIR) M=$(shell pwd) V=$(VERBOSE) modules From 504f26040516e1a043d156aaf57a00e69ac0f9ce Mon Sep 17 00:00:00 2001 From: YusukeKato Date: Mon, 28 Oct 2024 18:02:36 +0900 Subject: [PATCH 04/16] =?UTF-8?q?rtmouse.h=E3=82=92rtmouse.c=E3=81=A8?= =?UTF-8?q?=E5=90=8C=E3=81=98=E9=9A=8E=E5=B1=A4=E3=81=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/drivers/Makefile.header_from_apt | 7 +- src/drivers/Makefile.header_from_source | 7 +- src/drivers/rtmouse.h | 179 ++++++++++++++++++++++++ 3 files changed, 181 insertions(+), 12 deletions(-) create mode 100644 src/drivers/rtmouse.h diff --git a/src/drivers/Makefile.header_from_apt b/src/drivers/Makefile.header_from_apt index a048451..c43215a 100644 --- a/src/drivers/Makefile.header_from_apt +++ b/src/drivers/Makefile.header_from_apt @@ -5,12 +5,7 @@ clean-files:= *.o *.ko *.mod.[co] *~ LINUX_SRC_DIR:=/usr/src/linux-headers-$(shell uname -r) VERBOSE:=0 -EXTRA_CFLAGS += -I$(PWD)/include -EXTRA_CFLAGS += -I$(shell pwd)/include -ccflags-y += -I$(PWD)/include -ccflags-y += -I$(shell pwd)/include - -rtmouse.ko: rtmouse.c +rtmouse.ko: rtmouse.c rtmouse.h make -C $(LINUX_SRC_DIR) M=$(shell pwd) V=$(VERBOSE) modules clean: diff --git a/src/drivers/Makefile.header_from_source b/src/drivers/Makefile.header_from_source index c283c52..8d43e03 100644 --- a/src/drivers/Makefile.header_from_source +++ b/src/drivers/Makefile.header_from_source @@ -5,12 +5,7 @@ clean-files:= *.o *.ko *.mod.[co] *~ LINUX_SRC_DIR:=/usr/src/linux VERBOSE:=0 -EXTRA_CFLAGS += -I$(PWD)/include -EXTRA_CFLAGS += -I$(shell pwd)/include -ccflags-y += -I$(PWD)/include -ccflags-y += -I$(shell pwd)/include - -rtmouse.ko: rtmouse.c +rtmouse.ko: rtmouse.c rtmouse.h make -C $(LINUX_SRC_DIR) M=$(shell pwd) V=$(VERBOSE) modules clean: diff --git a/src/drivers/rtmouse.h b/src/drivers/rtmouse.h new file mode 100644 index 0000000..e92c11b --- /dev/null +++ b/src/drivers/rtmouse.h @@ -0,0 +1,179 @@ +// define the Raspberry Pi version here +// Raspberry Pi 1 B/A/B+/A+: 1 +// Raspberry Pi 2 B : 2 +// Raspberry Pi 3 B/A+/B+ : 2 +// Raspberry Pi 4 B : 4 +#define RASPBERRYPI 4 + +/* --- Device ID --- */ +#define ID_DEV_LED 0 +#define ID_DEV_SWITCH 1 +#define ID_DEV_SENSOR 2 +#define ID_DEV_BUZZER 3 +#define ID_DEV_MOTORRAWR 4 +#define ID_DEV_MOTORRAWL 5 +#define ID_DEV_MOTOREN 6 +#define ID_DEV_MOTOR 7 +#define ID_DEV_CNT 8 +#define ID_DEV_SIZE 9 + +#define NUM_DEV_TOTAL \ + (NUM_DEV[ID_DEV_LED] + NUM_DEV[ID_DEV_SWITCH] + \ + NUM_DEV[ID_DEV_SENSOR] + NUM_DEV[ID_DEV_BUZZER] + \ + NUM_DEV[ID_DEV_MOTORRAWR] + NUM_DEV[ID_DEV_MOTORRAWL] + \ + NUM_DEV[ID_DEV_MOTOREN] + NUM_DEV[ID_DEV_MOTOR]) + +#define DEVNAME_SENSOR "rtlightsensor" +#define DEVNAME_CNTR "rtcounter_r" +#define DEVNAME_CNTL "rtcounter_l" +#define DRIVER_NAME "rtmouse" + +/* --- Device Major and Minor Numbers --- */ +#define DEV_MAJOR 0 +#define DEV_MINOR 0 + +/* --- GPIO Pin Definitions --- */ +#define R_AD_CH 3 +#define L_AD_CH 0 +#define RF_AD_CH 2 +#define LF_AD_CH 1 + +#define R_LED_BASE 22 +#define L_LED_BASE 4 +#define RF_LED_BASE 27 +#define LF_LED_BASE 17 + +#define LED0_BASE 25 +#define LED1_BASE 24 +#define LED2_BASE 23 +#define LED3_BASE 18 + +#define SW1_PIN 20 +#define SW2_PIN 26 +#define SW3_PIN 21 + +#define BUZZER_BASE 19 + +#define MOTCLK_L_BASE 12 +#define MOTDIR_L_BASE 16 + +#define MOTCLK_R_BASE 13 +#define MOTDIR_R_BASE 6 + +#define MOTEN_BASE 5 + +#define PWM_ORG0_BASE 40 +#define PWM_ORG1_BASE 45 + +/* --- Register Address --- */ +/* Base Addr */ +#if RASPBERRYPI == 1 +#define RPI_REG_BASE 0x20000000 +#elif RASPBERRYPI == 2 +#define RPI_REG_BASE 0x3f000000 +#elif RASPBERRYPI == 4 +#define RPI_REG_BASE 0xfe000000 +/* 2711 has a different mechanism for pin pull-up/down/enable */ +#define GPPUPPDN0 57 /* Pin pull-up/down for pins 15:0 */ +#define GPPUPPDN1 58 /* Pin pull-up/down for pins 31:16 */ +#define GPPUPPDN2 59 /* Pin pull-up/down for pins 47:32 */ +#define GPPUPPDN3 60 /* Pin pull-up/down for pins 57:48 */ +#endif + +/* GPIO Addr */ +#define RPI_GPIO_OFFSET 0x200000 +#define RPI_GPIO_SIZE 0xC0 +#define RPI_GPIO_BASE (RPI_REG_BASE + RPI_GPIO_OFFSET) +#define REG_GPIO_NAME "RPi mouse GPIO" + +/* Pwm Addr */ +#define RPI_PWM_OFFSET 0x20C000 +#define RPI_PWM_SIZE 0xC0 +#define RPI_PWM_BASE (RPI_REG_BASE + RPI_PWM_OFFSET) +#define REG_PWM_NAME "RPi mouse PWM" + +/* Clock Addr */ +#define RPI_CLK_OFFSET 0x101000 +#define RPI_CLK_SIZE 0x100 +#define RPI_CLK_BASE (RPI_REG_BASE + RPI_CLK_OFFSET) +#define REG_CLK_NAME "RPi mouse CLK" + +/* --- General Options --- */ +/* Clock Offset */ +#define CLK_PWM_INDEX 0xa0 +#define CLK_PWMDIV_INDEX 0xa4 + +/* GPIO PUPD select */ +#if RASPBERRYPI == 4 +#define GPIO_PULLNONE 0x0 +#define GPIO_PULLUP 0x1 +#define GPIO_PULLDOWN 0x2 +#else +#define GPIO_PULLNONE 0x0 +#define GPIO_PULLDOWN 0x1 +#define GPIO_PULLUP 0x2 +#endif + +/* GPIO Function */ +#define RPI_GPF_INPUT 0x00 +#define RPI_GPF_OUTPUT 0x01 +#define RPI_GPF_ALT0 0x04 +#define RPI_GPF_ALT5 0x02 + +/* GPIO Register Index */ +#define RPI_GPFSEL0_INDEX 0 +#define RPI_GPFSEL1_INDEX 1 +#define RPI_GPFSEL2_INDEX 2 +#define RPI_GPFSEL3_INDEX 3 + +#define RPI_GPSET0_INDEX 7 +#define RPI_GPCLR0_INDEX 10 + +/* GPIO Mask */ +#define RPI_GPIO_P1MASK \ + (uint32_t)((0x01 << 2) | (0x01 << 3) | (0x01 << 4) | (0x01 << 7) | \ + (0x01 << 8) | (0x01 << 9) | (0x01 << 10) | (0x01 << 11) | \ + (0x01 << 14) | (0x01 << 15) | (0x01 << 17) | (0x01 << 18) | \ + (0x01 << 22) | (0x01 << 23) | (0x01 << 24) | (0x01 << 25) | \ + (0x01 << 27)) +#define RPI_GPIO_P2MASK (uint32_t)0xffffffff + +/* PWM Index */ +#define RPI_PWM_CTRL 0x0 +#define RPI_PWM_STA 0x4 +#define RPI_PWM_DMAC 0x8 +#define RPI_PWM_RNG1 0x10 +#define RPI_PWM_DAT1 0x14 +#define RPI_PWM_FIF1 0x18 +#define RPI_PWM_RNG2 0x20 +#define RPI_PWM_DAT2 0x24 + +#if RASPBERRYPI == 4 +#define PWM_BASECLK 27000000 +#else +#define PWM_BASECLK 9600000 +#endif + +/* A/D Parameter */ +#define MCP320X_PACKET_SIZE 3 +#define MCP320X_DIFF 0 +#define MCP320X_SINGLE 1 +#define MCP3204_CHANNELS 4 + +/* I2C Parameter */ +#define DEV_ADDR_CNTL 0x10 +#define DEV_ADDR_CNTR 0x11 +#define CNT_ADDR_MSB 0x10 +#define CNT_ADDR_LSB 0x11 + +/* Motor Parameter */ +#define MOTOR_UNCONTROLLABLE_FREQ 5 + +/* I2C */ +#define SIGNED_COUNT_SIZE 32767 +#define MAX_PULSE_COUNT 65535 + +/* -- Buffer -- */ +#define MAX_BUFLEN 64 +// static int buflen = 0; + From 6250f88c3b1d4dbb466c47b55f901f984de65dd1 Mon Sep 17 00:00:00 2001 From: YusukeKato Date: Mon, 28 Oct 2024 18:06:55 +0900 Subject: [PATCH 05/16] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AAinclude?= =?UTF-8?q?=E3=83=87=E3=82=A3=E3=83=AC=E3=82=AF=E3=83=88=E3=83=AA=E3=82=92?= =?UTF-8?q?=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/drivers/include/rtmouse.h | 179 ---------------------------------- 1 file changed, 179 deletions(-) delete mode 100644 src/drivers/include/rtmouse.h diff --git a/src/drivers/include/rtmouse.h b/src/drivers/include/rtmouse.h deleted file mode 100644 index e92c11b..0000000 --- a/src/drivers/include/rtmouse.h +++ /dev/null @@ -1,179 +0,0 @@ -// define the Raspberry Pi version here -// Raspberry Pi 1 B/A/B+/A+: 1 -// Raspberry Pi 2 B : 2 -// Raspberry Pi 3 B/A+/B+ : 2 -// Raspberry Pi 4 B : 4 -#define RASPBERRYPI 4 - -/* --- Device ID --- */ -#define ID_DEV_LED 0 -#define ID_DEV_SWITCH 1 -#define ID_DEV_SENSOR 2 -#define ID_DEV_BUZZER 3 -#define ID_DEV_MOTORRAWR 4 -#define ID_DEV_MOTORRAWL 5 -#define ID_DEV_MOTOREN 6 -#define ID_DEV_MOTOR 7 -#define ID_DEV_CNT 8 -#define ID_DEV_SIZE 9 - -#define NUM_DEV_TOTAL \ - (NUM_DEV[ID_DEV_LED] + NUM_DEV[ID_DEV_SWITCH] + \ - NUM_DEV[ID_DEV_SENSOR] + NUM_DEV[ID_DEV_BUZZER] + \ - NUM_DEV[ID_DEV_MOTORRAWR] + NUM_DEV[ID_DEV_MOTORRAWL] + \ - NUM_DEV[ID_DEV_MOTOREN] + NUM_DEV[ID_DEV_MOTOR]) - -#define DEVNAME_SENSOR "rtlightsensor" -#define DEVNAME_CNTR "rtcounter_r" -#define DEVNAME_CNTL "rtcounter_l" -#define DRIVER_NAME "rtmouse" - -/* --- Device Major and Minor Numbers --- */ -#define DEV_MAJOR 0 -#define DEV_MINOR 0 - -/* --- GPIO Pin Definitions --- */ -#define R_AD_CH 3 -#define L_AD_CH 0 -#define RF_AD_CH 2 -#define LF_AD_CH 1 - -#define R_LED_BASE 22 -#define L_LED_BASE 4 -#define RF_LED_BASE 27 -#define LF_LED_BASE 17 - -#define LED0_BASE 25 -#define LED1_BASE 24 -#define LED2_BASE 23 -#define LED3_BASE 18 - -#define SW1_PIN 20 -#define SW2_PIN 26 -#define SW3_PIN 21 - -#define BUZZER_BASE 19 - -#define MOTCLK_L_BASE 12 -#define MOTDIR_L_BASE 16 - -#define MOTCLK_R_BASE 13 -#define MOTDIR_R_BASE 6 - -#define MOTEN_BASE 5 - -#define PWM_ORG0_BASE 40 -#define PWM_ORG1_BASE 45 - -/* --- Register Address --- */ -/* Base Addr */ -#if RASPBERRYPI == 1 -#define RPI_REG_BASE 0x20000000 -#elif RASPBERRYPI == 2 -#define RPI_REG_BASE 0x3f000000 -#elif RASPBERRYPI == 4 -#define RPI_REG_BASE 0xfe000000 -/* 2711 has a different mechanism for pin pull-up/down/enable */ -#define GPPUPPDN0 57 /* Pin pull-up/down for pins 15:0 */ -#define GPPUPPDN1 58 /* Pin pull-up/down for pins 31:16 */ -#define GPPUPPDN2 59 /* Pin pull-up/down for pins 47:32 */ -#define GPPUPPDN3 60 /* Pin pull-up/down for pins 57:48 */ -#endif - -/* GPIO Addr */ -#define RPI_GPIO_OFFSET 0x200000 -#define RPI_GPIO_SIZE 0xC0 -#define RPI_GPIO_BASE (RPI_REG_BASE + RPI_GPIO_OFFSET) -#define REG_GPIO_NAME "RPi mouse GPIO" - -/* Pwm Addr */ -#define RPI_PWM_OFFSET 0x20C000 -#define RPI_PWM_SIZE 0xC0 -#define RPI_PWM_BASE (RPI_REG_BASE + RPI_PWM_OFFSET) -#define REG_PWM_NAME "RPi mouse PWM" - -/* Clock Addr */ -#define RPI_CLK_OFFSET 0x101000 -#define RPI_CLK_SIZE 0x100 -#define RPI_CLK_BASE (RPI_REG_BASE + RPI_CLK_OFFSET) -#define REG_CLK_NAME "RPi mouse CLK" - -/* --- General Options --- */ -/* Clock Offset */ -#define CLK_PWM_INDEX 0xa0 -#define CLK_PWMDIV_INDEX 0xa4 - -/* GPIO PUPD select */ -#if RASPBERRYPI == 4 -#define GPIO_PULLNONE 0x0 -#define GPIO_PULLUP 0x1 -#define GPIO_PULLDOWN 0x2 -#else -#define GPIO_PULLNONE 0x0 -#define GPIO_PULLDOWN 0x1 -#define GPIO_PULLUP 0x2 -#endif - -/* GPIO Function */ -#define RPI_GPF_INPUT 0x00 -#define RPI_GPF_OUTPUT 0x01 -#define RPI_GPF_ALT0 0x04 -#define RPI_GPF_ALT5 0x02 - -/* GPIO Register Index */ -#define RPI_GPFSEL0_INDEX 0 -#define RPI_GPFSEL1_INDEX 1 -#define RPI_GPFSEL2_INDEX 2 -#define RPI_GPFSEL3_INDEX 3 - -#define RPI_GPSET0_INDEX 7 -#define RPI_GPCLR0_INDEX 10 - -/* GPIO Mask */ -#define RPI_GPIO_P1MASK \ - (uint32_t)((0x01 << 2) | (0x01 << 3) | (0x01 << 4) | (0x01 << 7) | \ - (0x01 << 8) | (0x01 << 9) | (0x01 << 10) | (0x01 << 11) | \ - (0x01 << 14) | (0x01 << 15) | (0x01 << 17) | (0x01 << 18) | \ - (0x01 << 22) | (0x01 << 23) | (0x01 << 24) | (0x01 << 25) | \ - (0x01 << 27)) -#define RPI_GPIO_P2MASK (uint32_t)0xffffffff - -/* PWM Index */ -#define RPI_PWM_CTRL 0x0 -#define RPI_PWM_STA 0x4 -#define RPI_PWM_DMAC 0x8 -#define RPI_PWM_RNG1 0x10 -#define RPI_PWM_DAT1 0x14 -#define RPI_PWM_FIF1 0x18 -#define RPI_PWM_RNG2 0x20 -#define RPI_PWM_DAT2 0x24 - -#if RASPBERRYPI == 4 -#define PWM_BASECLK 27000000 -#else -#define PWM_BASECLK 9600000 -#endif - -/* A/D Parameter */ -#define MCP320X_PACKET_SIZE 3 -#define MCP320X_DIFF 0 -#define MCP320X_SINGLE 1 -#define MCP3204_CHANNELS 4 - -/* I2C Parameter */ -#define DEV_ADDR_CNTL 0x10 -#define DEV_ADDR_CNTR 0x11 -#define CNT_ADDR_MSB 0x10 -#define CNT_ADDR_LSB 0x11 - -/* Motor Parameter */ -#define MOTOR_UNCONTROLLABLE_FREQ 5 - -/* I2C */ -#define SIGNED_COUNT_SIZE 32767 -#define MAX_PULSE_COUNT 65535 - -/* -- Buffer -- */ -#define MAX_BUFLEN 64 -// static int buflen = 0; - From 71e86519dcd91f65f6f901675bb734902bf41f5f Mon Sep 17 00:00:00 2001 From: YusukeKato Date: Mon, 28 Oct 2024 18:18:18 +0900 Subject: [PATCH 06/16] =?UTF-8?q?RASPBERRYPI=E3=81=AE=E5=A4=89=E6=9B=B4?= =?UTF-8?q?=E5=87=A6=E7=90=86=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/drivers/rtmouse.h | 4 +--- utils/build_install_header_from_apt_raspi4.bash | 2 +- utils/build_install_header_from_source_raspi4.bash | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/drivers/rtmouse.h b/src/drivers/rtmouse.h index e92c11b..fa8c87e 100644 --- a/src/drivers/rtmouse.h +++ b/src/drivers/rtmouse.h @@ -3,7 +3,7 @@ // Raspberry Pi 2 B : 2 // Raspberry Pi 3 B/A+/B+ : 2 // Raspberry Pi 4 B : 4 -#define RASPBERRYPI 4 +#define RASPBERRYPI 2 /* --- Device ID --- */ #define ID_DEV_LED 0 @@ -175,5 +175,3 @@ /* -- Buffer -- */ #define MAX_BUFLEN 64 -// static int buflen = 0; - diff --git a/utils/build_install_header_from_apt_raspi4.bash b/utils/build_install_header_from_apt_raspi4.bash index 482d675..5977601 100755 --- a/utils/build_install_header_from_apt_raspi4.bash +++ b/utils/build_install_header_from_apt_raspi4.bash @@ -11,7 +11,7 @@ rm Makefile ln -s Makefile.header_from_apt Makefile make clean # Update for Raspberry Pi 4 -sed -i -e "s/#define RASPBERRYPI 2/#define RASPBERRYPI 4/g" rtmouse.c +sed -i -e "s/#define RASPBERRYPI 2/#define RASPBERRYPI 4/g" rtmouse.h make sudo insmod rtmouse.ko diff --git a/utils/build_install_header_from_source_raspi4.bash b/utils/build_install_header_from_source_raspi4.bash index a09aabb..9a14ecf 100755 --- a/utils/build_install_header_from_source_raspi4.bash +++ b/utils/build_install_header_from_source_raspi4.bash @@ -11,7 +11,7 @@ rm Makefile ln -s Makefile.header_from_source Makefile make clean # Update for Raspberry Pi 4 -sed -i -e "s/#define RASPBERRYPI 2/#define RASPBERRYPI 4/g" rtmouse.c +sed -i -e "s/#define RASPBERRYPI 2/#define RASPBERRYPI 4/g" rtmouse.h make sudo insmod rtmouse.ko From c889dba342de3e71f3a31a17ff3c403fbdf89e63 Mon Sep 17 00:00:00 2001 From: YusukeKato Date: Mon, 28 Oct 2024 18:27:44 +0900 Subject: [PATCH 07/16] =?UTF-8?q?const=E3=81=AE=E5=AE=9A=E6=95=B0=E3=82=92?= =?UTF-8?q?rtmouse.h=E3=81=B8=E7=A7=BB=E5=8B=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/drivers/rtmouse.c | 34 ++-------------------------------- src/drivers/rtmouse.h | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/drivers/rtmouse.c b/src/drivers/rtmouse.c index 6a52012..14a362d 100644 --- a/src/drivers/rtmouse.c +++ b/src/drivers/rtmouse.c @@ -53,36 +53,6 @@ MODULE_LICENSE("GPL"); MODULE_VERSION("3.3.1"); MODULE_DESCRIPTION("Raspberry Pi Mouse device driver"); -/* --- Device Numbers --- */ -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 --- */ -static const char *NAME_DEV[ID_DEV_SIZE] = { - [ID_DEV_LED] = "rtled", - [ID_DEV_SWITCH] = "rtswitch", - [ID_DEV_SENSOR] = "rtlightsensor", - [ID_DEV_BUZZER] = "rtbuzzer", - [ID_DEV_MOTORRAWR] = "rtmotor_raw_r", - [ID_DEV_MOTORRAWL] = "rtmotor_raw_l", - [ID_DEV_MOTOREN] = "rtmotoren", - [ID_DEV_MOTOR] = "rtmotor"}; - -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", - [ID_DEV_MOTORRAWR] = "rtmotor_raw_r%u", - [ID_DEV_MOTORRAWL] = "rtmotor_raw_l%u", - [ID_DEV_MOTOREN] = "rtmotoren%u", - [ID_DEV_MOTOR] = "rtmotor%u"}; - -static int spi_bus_num = 0; -static int spi_chip_select = 0; - 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, @@ -1354,8 +1324,8 @@ static int mcp3204_init(void) spi_register_driver(&mcp3204_driver); - mcp3204_info.bus_num = spi_bus_num; - mcp3204_info.chip_select = spi_chip_select; + mcp3204_info.bus_num = SPI_BUS_NUM; + mcp3204_info.chip_select = SPI_CHIP_SELECT; master = spi_busnum_to_master(mcp3204_info.bus_num); diff --git a/src/drivers/rtmouse.h b/src/drivers/rtmouse.h index fa8c87e..8d2e01f 100644 --- a/src/drivers/rtmouse.h +++ b/src/drivers/rtmouse.h @@ -3,7 +3,7 @@ // Raspberry Pi 2 B : 2 // Raspberry Pi 3 B/A+/B+ : 2 // Raspberry Pi 4 B : 4 -#define RASPBERRYPI 2 +#define RASPBERRYPI 4 /* --- Device ID --- */ #define ID_DEV_LED 0 @@ -17,6 +17,33 @@ #define ID_DEV_CNT 8 #define ID_DEV_SIZE 9 +/* --- Device Numbers --- */ +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 --- */ +const char *NAME_DEV[ID_DEV_SIZE] = { + [ID_DEV_LED] = "rtled", + [ID_DEV_SWITCH] = "rtswitch", + [ID_DEV_SENSOR] = "rtlightsensor", + [ID_DEV_BUZZER] = "rtbuzzer", + [ID_DEV_MOTORRAWR] = "rtmotor_raw_r", + [ID_DEV_MOTORRAWL] = "rtmotor_raw_l", + [ID_DEV_MOTOREN] = "rtmotoren", + [ID_DEV_MOTOR] = "rtmotor"}; + +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", + [ID_DEV_MOTORRAWR] = "rtmotor_raw_r%u", + [ID_DEV_MOTORRAWL] = "rtmotor_raw_l%u", + [ID_DEV_MOTOREN] = "rtmotoren%u", + [ID_DEV_MOTOR] = "rtmotor%u"}; + #define NUM_DEV_TOTAL \ (NUM_DEV[ID_DEV_LED] + NUM_DEV[ID_DEV_SWITCH] + \ NUM_DEV[ID_DEV_SENSOR] + NUM_DEV[ID_DEV_BUZZER] + \ @@ -28,6 +55,10 @@ #define DEVNAME_CNTL "rtcounter_l" #define DRIVER_NAME "rtmouse" +/* SPI */ +#define SPI_BUS_NUM 0 +#define SPI_CHIP_SELECT 0 + /* --- Device Major and Minor Numbers --- */ #define DEV_MAJOR 0 #define DEV_MINOR 0 From 748f08953b4560ad4d9671929896b5f0c58ec4a7 Mon Sep 17 00:00:00 2001 From: YusukeKato Date: Mon, 28 Oct 2024 18:34:20 +0900 Subject: [PATCH 08/16] =?UTF-8?q?motor=5Fmotion=5F*=E9=96=A2=E6=95=B0?= =?UTF-8?q?=E3=81=AF=E4=BD=BF=E7=94=A8=E3=81=95=E3=82=8C=E3=81=A6=E3=81=84?= =?UTF-8?q?=E3=81=AA=E3=81=84=E3=81=AE=E3=81=A7=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/drivers/rtmouse.c | 54 ------------------------------------------- 1 file changed, 54 deletions(-) diff --git a/src/drivers/rtmouse.c b/src/drivers/rtmouse.c index 14a362d..32ecc16 100644 --- a/src/drivers/rtmouse.c +++ b/src/drivers/rtmouse.c @@ -190,60 +190,6 @@ static struct i2c_driver i2c_counter_driver = { MODULE_DEVICE_TABLE(spi, mcp3204_id); MODULE_DEVICE_TABLE(i2c, i2c_counter_id); -#define MOTOR_MOTION 0 -#if MOTOR_MOTION -/* Variable Type Definition for motor motion */ -typedef struct { - signed int r_hz; - signed int l_hz; - unsigned int time; -} t_motor_motion; - -#define MAX_MOTORBUFLEN 16 -static t_motor_motion motor_motion[MAX_MOTORBUFLEN]; -static unsigned int motor_motion_head = 0, motor_motion_tail = 0; - -static int motor_motion_push(int r_hz, int l_hz, int time) -{ - unsigned int next_tail = motor_motion_tail + 1; - - if (next_tail >= MAX_MOTORBUFLEN) { - next_tail = 0; - } - - if (next_tail == motor_motion_head) { - return -1; - } - - motor_motion[motor_motion_tail].r_hz = r_hz; - motor_motion[motor_motion_tail].l_hz = l_hz; - motor_motion[motor_motion_tail].time = time; - - motor_motion_tail = next_tail; - - return 0; -} - -static int motor_motion_pop(t_motor_motion **ret) -{ - unsigned int next_head = motor_motion_head + 1; - - if (motor_motion_tail == motor_motion_head) { - return -1; - } - - if (next_head >= MAX_MOTORBUFLEN) { - next_head = 0; - } - - *ret = (motor_motion + motor_motion_head); - - motor_motion_head = next_head; - - return 0; -} -#endif - /* --- GPIO Operation --- */ /* getPWMCount function for GPIO Operation */ static int getPWMCount(int freq) From 8fcd99d5f66cc4fc8a9ae8305b97b16baa287cc9 Mon Sep 17 00:00:00 2001 From: YusukeKato Date: Mon, 28 Oct 2024 18:39:24 +0900 Subject: [PATCH 09/16] =?UTF-8?q?=E3=83=98=E3=83=83=E3=83=80=E3=83=95?= =?UTF-8?q?=E3=82=A1=E3=82=A4=E3=83=AB=E3=82=92=E8=A4=87=E6=95=B0=E3=81=AE?= =?UTF-8?q?=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=81=8B=E3=82=89=E8=AA=AD?= =?UTF-8?q?=E3=81=BF=E8=BE=BC=E3=82=80=E3=81=93=E3=81=A8=E3=82=92=E6=83=B3?= =?UTF-8?q?=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/drivers/rtmouse.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/drivers/rtmouse.h b/src/drivers/rtmouse.h index 8d2e01f..651bc51 100644 --- a/src/drivers/rtmouse.h +++ b/src/drivers/rtmouse.h @@ -1,3 +1,6 @@ +#ifndef RTMOUSE_H +#define RTMOUSE_H + // define the Raspberry Pi version here // Raspberry Pi 1 B/A/B+/A+: 1 // Raspberry Pi 2 B : 2 @@ -206,3 +209,5 @@ const char *NAME_DEV_U[ID_DEV_SIZE] = { /* -- Buffer -- */ #define MAX_BUFLEN 64 + +#endif // RTMOUSE_H From c392972982bd3804c9fe57c0b236179ea70330e2 Mon Sep 17 00:00:00 2001 From: YusukeKato Date: Tue, 29 Oct 2024 10:35:47 +0900 Subject: [PATCH 10/16] =?UTF-8?q?RASPBERRYPI=E3=82=92=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=EF=BC=88Ubuntu=2024.04=20LTS=E3=81=A7=E5=8B=95=E4=BD=9C?= =?UTF-8?q?=E7=A2=BA=E8=AA=8DOK=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/drivers/rtmouse.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drivers/rtmouse.h b/src/drivers/rtmouse.h index 651bc51..a1993c2 100644 --- a/src/drivers/rtmouse.h +++ b/src/drivers/rtmouse.h @@ -6,7 +6,7 @@ // Raspberry Pi 2 B : 2 // Raspberry Pi 3 B/A+/B+ : 2 // Raspberry Pi 4 B : 4 -#define RASPBERRYPI 4 +#define RASPBERRYPI 2 /* --- Device ID --- */ #define ID_DEV_LED 0 From 1fcc938b560cc532e379180d404a017cbc9e8258 Mon Sep 17 00:00:00 2001 From: YusukeKato Date: Tue, 29 Oct 2024 14:18:36 +0900 Subject: [PATCH 11/16] update version 3.3.2 --- src/drivers/rtmouse.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/drivers/rtmouse.c b/src/drivers/rtmouse.c index 32ecc16..5a59604 100644 --- a/src/drivers/rtmouse.c +++ b/src/drivers/rtmouse.c @@ -3,7 +3,7 @@ * rtmouse.c * Raspberry Pi Mouse device driver * - * Version: 3.3.1 + * Version: 3.3.2 * * Copyright (C) 2015-2021 RT Corporation * @@ -50,7 +50,7 @@ MODULE_AUTHOR("RT Corporation"); MODULE_LICENSE("GPL"); -MODULE_VERSION("3.3.1"); +MODULE_VERSION("3.3.2"); MODULE_DESCRIPTION("Raspberry Pi Mouse device driver"); static int _major_dev[ID_DEV_SIZE] = { From b4f6b5628337ba8eb95731840db663045156a121 Mon Sep 17 00:00:00 2001 From: YusukeKato Date: Tue, 29 Oct 2024 16:56:32 +0900 Subject: [PATCH 12/16] =?UTF-8?q?rtmouse.c=E3=81=AE=E3=83=98=E3=83=83?= =?UTF-8?q?=E3=83=80=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=82=92rtmouse.h?= =?UTF-8?q?=E3=81=B8=E7=A7=BB=E5=8B=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/drivers/rtmouse.c | 24 ------------------------ src/drivers/rtmouse.h | 26 +++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/drivers/rtmouse.c b/src/drivers/rtmouse.c index 5a59604..6947435 100644 --- a/src/drivers/rtmouse.c +++ b/src/drivers/rtmouse.c @@ -22,30 +22,6 @@ * MA 02110-1301, USA. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include "rtmouse.h" MODULE_AUTHOR("RT Corporation"); diff --git a/src/drivers/rtmouse.h b/src/drivers/rtmouse.h index a1993c2..d88c0e2 100644 --- a/src/drivers/rtmouse.h +++ b/src/drivers/rtmouse.h @@ -1,12 +1,36 @@ #ifndef RTMOUSE_H #define RTMOUSE_H +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + // define the Raspberry Pi version here // Raspberry Pi 1 B/A/B+/A+: 1 // Raspberry Pi 2 B : 2 // Raspberry Pi 3 B/A+/B+ : 2 // Raspberry Pi 4 B : 4 -#define RASPBERRYPI 2 +#define RASPBERRYPI 4 /* --- Device ID --- */ #define ID_DEV_LED 0 From 9e2bd613c94b8400fe89d3d9944a908d46bad475 Mon Sep 17 00:00:00 2001 From: YusukeKato Date: Tue, 29 Oct 2024 16:57:52 +0900 Subject: [PATCH 13/16] update Copyright --- src/drivers/rtmouse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drivers/rtmouse.c b/src/drivers/rtmouse.c index 6947435..5b2d447 100644 --- a/src/drivers/rtmouse.c +++ b/src/drivers/rtmouse.c @@ -5,7 +5,7 @@ * * Version: 3.3.2 * - * Copyright (C) 2015-2021 RT Corporation + * Copyright (C) 2015-2024 RT Corporation * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by From f197d936facbadb6badb0c63ad6b63202ea218ce Mon Sep 17 00:00:00 2001 From: YusukeKato Date: Tue, 29 Oct 2024 17:13:29 +0900 Subject: [PATCH 14/16] =?UTF-8?q?rtmouse.h=E3=82=92lint=E3=81=AE=E5=AF=BE?= =?UTF-8?q?=E8=B1=A1=E3=81=AB=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .test/lint.sh | 3 ++- src/drivers/rtmouse.h | 44 +++++++++++++++++++++---------------------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/.test/lint.sh b/.test/lint.sh index 5ae2bd1..c445865 100755 --- a/.test/lint.sh +++ b/.test/lint.sh @@ -7,6 +7,7 @@ SRC_DIR=$(cd $(dirname ${BASH_SOURCE:-$0}); cd ../; pwd) lint_driver () { pushd $SRC_DIR/src/drivers python3 $SRC_DIR/.test/bin/run-clang-format.py rtmouse.c + python3 $SRC_DIR/.test/bin/run-clang-format.py rtmouse.h popd } @@ -25,4 +26,4 @@ check_driver_version () { lint_driver -check_driver_version \ No newline at end of file +check_driver_version diff --git a/src/drivers/rtmouse.h b/src/drivers/rtmouse.h index d88c0e2..a228d6b 100644 --- a/src/drivers/rtmouse.h +++ b/src/drivers/rtmouse.h @@ -51,31 +51,29 @@ const unsigned int NUM_DEV[ID_DEV_SIZE] = { [ID_DEV_MOTOREN] = 1, [ID_DEV_MOTOR] = 1, [ID_DEV_CNT] = 2}; /* --- Device Names --- */ -const char *NAME_DEV[ID_DEV_SIZE] = { - [ID_DEV_LED] = "rtled", - [ID_DEV_SWITCH] = "rtswitch", - [ID_DEV_SENSOR] = "rtlightsensor", - [ID_DEV_BUZZER] = "rtbuzzer", - [ID_DEV_MOTORRAWR] = "rtmotor_raw_r", - [ID_DEV_MOTORRAWL] = "rtmotor_raw_l", - [ID_DEV_MOTOREN] = "rtmotoren", - [ID_DEV_MOTOR] = "rtmotor"}; - -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", - [ID_DEV_MOTORRAWR] = "rtmotor_raw_r%u", - [ID_DEV_MOTORRAWL] = "rtmotor_raw_l%u", - [ID_DEV_MOTOREN] = "rtmotoren%u", - [ID_DEV_MOTOR] = "rtmotor%u"}; +const char *NAME_DEV[ID_DEV_SIZE] = {[ID_DEV_LED] = "rtled", + [ID_DEV_SWITCH] = "rtswitch", + [ID_DEV_SENSOR] = "rtlightsensor", + [ID_DEV_BUZZER] = "rtbuzzer", + [ID_DEV_MOTORRAWR] = "rtmotor_raw_r", + [ID_DEV_MOTORRAWL] = "rtmotor_raw_l", + [ID_DEV_MOTOREN] = "rtmotoren", + [ID_DEV_MOTOR] = "rtmotor"}; + +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", + [ID_DEV_MOTORRAWR] = "rtmotor_raw_r%u", + [ID_DEV_MOTORRAWL] = "rtmotor_raw_l%u", + [ID_DEV_MOTOREN] = "rtmotoren%u", + [ID_DEV_MOTOR] = "rtmotor%u"}; #define NUM_DEV_TOTAL \ - (NUM_DEV[ID_DEV_LED] + NUM_DEV[ID_DEV_SWITCH] + \ - NUM_DEV[ID_DEV_SENSOR] + NUM_DEV[ID_DEV_BUZZER] + \ - NUM_DEV[ID_DEV_MOTORRAWR] + NUM_DEV[ID_DEV_MOTORRAWL] + \ - NUM_DEV[ID_DEV_MOTOREN] + NUM_DEV[ID_DEV_MOTOR]) + (NUM_DEV[ID_DEV_LED] + NUM_DEV[ID_DEV_SWITCH] + \ + NUM_DEV[ID_DEV_SENSOR] + NUM_DEV[ID_DEV_BUZZER] + \ + NUM_DEV[ID_DEV_MOTORRAWR] + NUM_DEV[ID_DEV_MOTORRAWL] + \ + NUM_DEV[ID_DEV_MOTOREN] + NUM_DEV[ID_DEV_MOTOR]) #define DEVNAME_SENSOR "rtlightsensor" #define DEVNAME_CNTR "rtcounter_r" From c7ecc1373c1d993c086d0930f055289bf6e9d8c0 Mon Sep 17 00:00:00 2001 From: YusukeKato Date: Tue, 29 Oct 2024 17:39:22 +0900 Subject: [PATCH 15/16] Add Copyright and LICENSE Co-authored-by: Kazushi Kurasawa --- src/drivers/rtmouse.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/drivers/rtmouse.h b/src/drivers/rtmouse.h index a228d6b..8650fde 100644 --- a/src/drivers/rtmouse.h +++ b/src/drivers/rtmouse.h @@ -1,3 +1,25 @@ +/* + * + * rtmouse.h + * Raspberry Pi Mouse device driver header + * + * Copyright (C) 2024 RT Corporation + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + #ifndef RTMOUSE_H #define RTMOUSE_H From a9264d3f527b81d40aa86fa6b8963ac83f1de207 Mon Sep 17 00:00:00 2001 From: YusukeKato Date: Tue, 29 Oct 2024 17:41:54 +0900 Subject: [PATCH 16/16] =?UTF-8?q?lint=E3=81=AE=E3=83=81=E3=82=A7=E3=83=83?= =?UTF-8?q?=E3=82=AF=E3=82=92=E9=80=9A=E3=81=99=E3=81=9F=E3=82=81=E3=81=AE?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/drivers/rtmouse.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drivers/rtmouse.h b/src/drivers/rtmouse.h index 8650fde..573e762 100644 --- a/src/drivers/rtmouse.h +++ b/src/drivers/rtmouse.h @@ -19,7 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. */ - + #ifndef RTMOUSE_H #define RTMOUSE_H