From 6dac8ae492d4e6c93e6548997696df4a3edb669a Mon Sep 17 00:00:00 2001 From: Michael Wiebusch Date: Thu, 11 Dec 2014 11:34:10 +0100 Subject: [PATCH] own module for Touchpad --- firmware/TM1001A.c | 42 +++++-------------------- firmware/TM1001A.h | 71 ++++++++++++++++++++++++++++++++++++++++++ firmware/USBtoSerial.c | 4 +-- firmware/makefile | 2 +- 4 files changed, 82 insertions(+), 37 deletions(-) create mode 100644 firmware/TM1001A.h diff --git a/firmware/TM1001A.c b/firmware/TM1001A.c index 7250b69..48a1f35 100644 --- a/firmware/TM1001A.c +++ b/firmware/TM1001A.c @@ -1,3 +1,11 @@ + + + +#include +#include +#include +#include "TM1001A.h" + // This code is based on the work of Frank H. (franky1969) from the // Mikrocontroller.net forum. // I modified the code thusly that it runs on an ATMega8 with more than 8 MHz @@ -13,43 +21,11 @@ // June 2013 -// define here the port and the pin where you cave connected -// the ADB (I/O) line from your TM1001A touchpad -#define ADB_BIT (1<<1) -#define ADB_PIN PINB -#define ADB_POUT PORTB -#define ADB_PDIR DDRB - -// when touchpad is in keypad mode the next two defines set the number -// of rows and columns of the -#define PAD_ROWS 2 -#define PAD_COLS 3 - - - - - - - - - - - #define TAKT F_CPU //Bits Makro #define BITS(H,L) (0b##H ##L) -#define MIN_ABS_X 150 -#define MAX_ABS_X 1450 -#define MIN_ABS_Y 210 -#define MAX_ABS_Y 1130 - -#define PAD_WIDTH (MAX_ABS_X-MIN_ABS_X) -#define PAD_HEIGHT (MAX_ABS_Y-MIN_ABS_Y) -#define PAD_COL_WIDTH (PAD_WIDTH/PAD_COLS) -#define PAD_ROW_HEIGHT (PAD_HEIGHT/PAD_ROWS) - //Vorteiler Timer 0 und 1 bei 2313, 8515, Mega8 (nicht Timer 2) #define TIMER_VT_1_B BITS(0000,0001) #define TIMER_VT_8_B BITS(0000,0010) @@ -65,8 +41,6 @@ -typedef unsigned char u08; -typedef unsigned short int u16; #define COM_TALK0 BITS(0011,1100) //Adresse 3, Talk, Register0 #define COM_TALK1 BITS(0011,1101) //Adresse 3, Talk, Register1 diff --git a/firmware/TM1001A.h b/firmware/TM1001A.h new file mode 100644 index 0000000..ba5de09 --- /dev/null +++ b/firmware/TM1001A.h @@ -0,0 +1,71 @@ +// This code is based on the work of Frank H. (franky1969) from the +// Mikrocontroller.net forum. +// I modified the code thusly that it runs on an ATMega8 with more than 8 MHz +// (make use of the counter 0 overflow interrupt to count to numbers greater +// than 255) and added a set of functions that make your life easy, +// i.e. spare you the work of crawling through the ADB register documentation yourself. +// +// You cannot use counter 0 for any other thing when using the touchpad! +// +// Have fun! - Michael W. (acidbourbon) +// +// acidbourbon.wordpress.com +// June 2013 + + +// define here the port and the pin where you cave connected +// the ADB (I/O) line from your TM1001A touchpad +#define ADB_BIT (1<<1) +#define ADB_PIN PINB +#define ADB_POUT PORTB +#define ADB_PDIR DDRB + +// when touchpad is in keypad mode the next two defines set the number +// of rows and columns of the +#define PAD_ROWS 2 +#define PAD_COLS 3 + + +#define MIN_ABS_X 150 +#define MAX_ABS_X 1450 +#define MIN_ABS_Y 210 +#define MAX_ABS_Y 1130 + +#define PAD_WIDTH (MAX_ABS_X-MIN_ABS_X) +#define PAD_HEIGHT (MAX_ABS_Y-MIN_ABS_Y) +#define PAD_COL_WIDTH (PAD_WIDTH/PAD_COLS) +#define PAD_ROW_HEIGHT (PAD_HEIGHT/PAD_ROWS) + +typedef unsigned char u08; +typedef unsigned short int u16; + + +ISR( TIMER0_OVF_vect); + +uint16_t t0ext(void); + +void t0rst(void); + +u08 adb(void); + +void touchpad_init(void); + +uint8_t touchpad_read(void); + +void touchpad_set_abs_mode(void); + +void touchpad_set_rel_mode_100dpi(void); + +void touchpad_set_rel_mode_200dpi(void); + +uint8_t z_pressure(void); + +uint16_t x_abs(void); + +uint16_t y_abs(void); + +int8_t delta_y(void); + +int8_t delta_x(void); + +uint8_t decode_field(void); diff --git a/firmware/USBtoSerial.c b/firmware/USBtoSerial.c index a334ba0..685511f 100644 --- a/firmware/USBtoSerial.c +++ b/firmware/USBtoSerial.c @@ -33,13 +33,13 @@ * Main source file for the USBtoSerial project. This file contains the main tasks of * the project and is responsible for the initial application hardware configuration. */ -#define F_CPU 16e6 +// #define F_CPU 16e6 #include #include #include "USBtoSerial.h" #include -#include "TM1001A.c" +#include "TM1001A.h" // #include "rfm70.c" #include "pins.h" #include "leds.c" diff --git a/firmware/makefile b/firmware/makefile index 6a9fd09..0bbdfba 100644 --- a/firmware/makefile +++ b/firmware/makefile @@ -18,7 +18,7 @@ F_CPU = 16000000 F_USB = $(F_CPU) OPTIMIZATION = s TARGET = USBtoSerial -SRC = $(TARGET).c Descriptors.c $(LUFA_SRC_USB) $(LUFA_SRC_USBCLASS) +SRC = $(TARGET).c Descriptors.c $(LUFA_SRC_USB) $(LUFA_SRC_USBCLASS) TM1001A.c LUFA_PATH = ../LUFA/LUFA-130303/LUFA CC_FLAGS = -DUSE_LUFA_CONFIG_HEADER -IConfig/ LD_FLAGS = -- 2.43.0