Skip to content

Commit

Permalink
sun_usb: Add build option for sun mouse support
Browse files Browse the repository at this point in the history
  • Loading branch information
tmk committed Sep 28, 2024
1 parent ff1b743 commit cf85efc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions converter/sun_usb/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ COMMAND_ENABLE ?= yes # Commands for debug and configuration
UNIMAP_ENABLE = yes
KEYMAP_SECTION_ENABLE = yes

SUN_MOUSE_ENABLE ?= yes # Sun mouse support


# Boot Section Size in bytes
# Teensy halfKay 512
Expand Down Expand Up @@ -89,6 +91,12 @@ else
SRC := $(KEYMAP_FILE).c $(SRC)
endif

ifeq (yes,$(strip $(SUN_MOUSE_ENABLE)))
OPT_DEFS += -DSUN_MOUSE_ENABLE=1
else
OPT_DEFS += -DSUN_MOUSE_ENABLE=0
endif


# Search Path
VPATH += $(TARGET_DIR)
Expand Down
2 changes: 2 additions & 0 deletions converter/sun_usb/Makefile.atmega32u4
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
TARGET = sun_usb_atmega32u4
MCU = atmega32u4

SUN_MOUSE_ENABLE = no # Sun mouse support

include Makefile

10 changes: 10 additions & 0 deletions converter/sun_usb/sun_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "host.h"


#if !defined(SUN_MOUSE_ENABLE)
# define SUN_MOUSE_ENABLE 1
#endif

// Timer count
#define BAUD 1200
#define PRESCALE 8
Expand Down Expand Up @@ -156,6 +160,7 @@ ISR(TIMER1_COMPA_vect)
}


#if SUN_MOUSE_ENABLE
//
// mouse uart
//
Expand Down Expand Up @@ -224,6 +229,7 @@ ISR(TIMER1_COMPC_vect)
break;
}
}
#endif


void hook_early_init(void)
Expand Down Expand Up @@ -265,11 +271,13 @@ void hook_early_init(void)
EICRA |= (1 << ISC21) | (1 << ISC20);
EIMSK |= (1 << INT2);

#if SUN_MOUSE_ENABLE
// mouse init
suart_init(&ms_suart);
// enable interrupt on rising edge for mouse
EICRB |= (1 << ISC51) |(1 << ISC50);
EIMSK |= (1 << INT5);
#endif

sei();
}
Expand All @@ -296,6 +304,7 @@ void hook_late_init(void)
* the device seems to fail to follow movement and send wrong value when dragging it rapidly.
* it causes opposite direction movement in the result. encoder speed limit? if not a bug in my code.
*/
#if SUN_MOUSE_ENABLE
void hook_main_loop(void)
{
static uint8_t n = 0;
Expand Down Expand Up @@ -338,6 +347,7 @@ void hook_main_loop(void)
}
n = (n + 1) % 5;
}
#endif


/*
Expand Down

0 comments on commit cf85efc

Please sign in to comment.