From a3dfc2cabf2219dbd27c7e82def1894b785d0cf9 Mon Sep 17 00:00:00 2001 From: Naoto Takai Date: Mon, 31 Aug 2020 06:28:25 +0900 Subject: [PATCH 1/6] Add support for soft serial to ATmega32U2 --- common_features.mk | 6 ++++-- drivers/avr/serial.c | 6 +++--- quantum/mcu_selection.mk | 3 +++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/common_features.mk b/common_features.mk index 1f110d0819dd..16cbfc1a2594 100644 --- a/common_features.mk +++ b/common_features.mk @@ -417,8 +417,10 @@ ifeq ($(strip $(SPLIT_KEYBOARD)), yes) # Functions added via QUANTUM_LIB_SRC are only included in the final binary if they're called. # Unused functions are pruned away, which is why we can add multiple drivers here without bloat. ifeq ($(PLATFORM),AVR) - QUANTUM_LIB_SRC += i2c_master.c \ - i2c_slave.c + ifneq ($(NO_I2C),yes) + QUANTUM_LIB_SRC += i2c_master.c \ + i2c_slave.c + endif endif SERIAL_DRIVER ?= bitbang diff --git a/drivers/avr/serial.c b/drivers/avr/serial.c index c27cbfdd0a79..fa6de26161ac 100644 --- a/drivers/avr/serial.c +++ b/drivers/avr/serial.c @@ -20,7 +20,7 @@ #ifdef SOFT_SERIAL_PIN -# ifdef __AVR_ATmega32U4__ +# if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega32U2__) // if using ATmega32U4 I2C, can not use PD0 and PD1 in soft serial. # ifdef USE_AVR_I2C # if SOFT_SERIAL_PIN == D0 || SOFT_SERIAL_PIN == D1 @@ -52,7 +52,7 @@ # define EICRx_BIT (~(_BV(ISC30) | _BV(ISC31))) # define SERIAL_PIN_INTERRUPT INT3_vect # endif -# elif SOFT_SERIAL_PIN == E6 +# elif defined(__AVR_ATmega32U4__) && SOFT_SERIAL_PIN == E6 # define EIMSK_BIT _BV(INT6) # define EICRx_BIT (~(_BV(ISC60) | _BV(ISC61))) # define SERIAL_PIN_INTERRUPT INT6_vect @@ -61,7 +61,7 @@ # endif # else -# error serial.c now support ATmega32U4 only +# error serial.c now support ATmega32U4 and ATmega32U2 only # endif # define ALWAYS_INLINE __attribute__((always_inline)) diff --git a/quantum/mcu_selection.mk b/quantum/mcu_selection.mk index 33a0cabc84e5..25fd9d8edd3a 100644 --- a/quantum/mcu_selection.mk +++ b/quantum/mcu_selection.mk @@ -252,6 +252,9 @@ ifneq (,$(filter $(MCU),atmega16u2 atmega32u2 atmega16u4 atmega32u4 at90usb646 a ifeq (,$(filter $(NO_INTERRUPT_CONTROL_ENDPOINT),yes)) OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT endif + ifneq (,$(filter $(MCU),atmega16u2 atmega32u2)) + NO_I2C = yes + endif endif ifneq (,$(filter $(MCU),atmega32a)) From 0eb0b129cffe34a315a7f3f19a250659cde00938 Mon Sep 17 00:00:00 2001 From: Naoto Takai Date: Tue, 1 Sep 2020 12:57:39 +0900 Subject: [PATCH 2/6] Update drivers/avr/serial.c Co-authored-by: Ryan --- drivers/avr/serial.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/avr/serial.c b/drivers/avr/serial.c index fa6de26161ac..0b0349b3d538 100644 --- a/drivers/avr/serial.c +++ b/drivers/avr/serial.c @@ -20,7 +20,7 @@ #ifdef SOFT_SERIAL_PIN -# if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega32U2__) +# if defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__) // if using ATmega32U4 I2C, can not use PD0 and PD1 in soft serial. # ifdef USE_AVR_I2C # if SOFT_SERIAL_PIN == D0 || SOFT_SERIAL_PIN == D1 From 9b357921f55fcda815fac9a2e3a86eff1c237bc4 Mon Sep 17 00:00:00 2001 From: Naoto Takai Date: Tue, 1 Sep 2020 12:57:46 +0900 Subject: [PATCH 3/6] Update drivers/avr/serial.c Co-authored-by: Ryan --- drivers/avr/serial.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/avr/serial.c b/drivers/avr/serial.c index 0b0349b3d538..281ba1a19d99 100644 --- a/drivers/avr/serial.c +++ b/drivers/avr/serial.c @@ -61,7 +61,7 @@ # endif # else -# error serial.c now support ATmega32U4 and ATmega32U2 only +# error serial.c currently only supports ATmegaxxU2 and ATmegaxxU4 # endif # define ALWAYS_INLINE __attribute__((always_inline)) From 00c7b9fa76367ab4ee810c6ac8e75eac1bebb724 Mon Sep 17 00:00:00 2001 From: Naoto Takai Date: Tue, 1 Sep 2020 13:33:28 +0900 Subject: [PATCH 4/6] Update drivers/avr/serial.c Co-authored-by: Ryan --- drivers/avr/serial.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/avr/serial.c b/drivers/avr/serial.c index 281ba1a19d99..42f499063b22 100644 --- a/drivers/avr/serial.c +++ b/drivers/avr/serial.c @@ -52,7 +52,7 @@ # define EICRx_BIT (~(_BV(ISC30) | _BV(ISC31))) # define SERIAL_PIN_INTERRUPT INT3_vect # endif -# elif defined(__AVR_ATmega32U4__) && SOFT_SERIAL_PIN == E6 +# elif defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__) && SOFT_SERIAL_PIN == E6 # define EIMSK_BIT _BV(INT6) # define EICRx_BIT (~(_BV(ISC60) | _BV(ISC61))) # define SERIAL_PIN_INTERRUPT INT6_vect From fdb63faf70ef768193b5207b432641714dda6349 Mon Sep 17 00:00:00 2001 From: Naoto Takai Date: Tue, 1 Sep 2020 13:40:56 +0900 Subject: [PATCH 5/6] Fix comment --- drivers/avr/serial.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/avr/serial.c b/drivers/avr/serial.c index 42f499063b22..95485f2ae9d5 100644 --- a/drivers/avr/serial.c +++ b/drivers/avr/serial.c @@ -21,10 +21,10 @@ #ifdef SOFT_SERIAL_PIN # if defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__) -// if using ATmega32U4 I2C, can not use PD0 and PD1 in soft serial. +// if using ATmegaxxU4 I2C, can not use PD0 and PD1 in soft serial. # ifdef USE_AVR_I2C # if SOFT_SERIAL_PIN == D0 || SOFT_SERIAL_PIN == D1 -# error Using ATmega32U4 I2C, so can not use PD0, PD1 +# error Using ATmegaxxU4 I2C, so can not use PD0, PD1 # endif # endif From 8c401bd59475d269c8316ac15723cb87abe74c63 Mon Sep 17 00:00:00 2001 From: Naoto Takai Date: Tue, 1 Sep 2020 13:59:27 +0900 Subject: [PATCH 6/6] Update drivers/avr/serial.c Co-authored-by: Ryan --- drivers/avr/serial.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/avr/serial.c b/drivers/avr/serial.c index 95485f2ae9d5..8d372d3b8b21 100644 --- a/drivers/avr/serial.c +++ b/drivers/avr/serial.c @@ -52,7 +52,7 @@ # define EICRx_BIT (~(_BV(ISC30) | _BV(ISC31))) # define SERIAL_PIN_INTERRUPT INT3_vect # endif -# elif defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__) && SOFT_SERIAL_PIN == E6 +# elif (defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)) && SOFT_SERIAL_PIN == E6 # define EIMSK_BIT _BV(INT6) # define EICRx_BIT (~(_BV(ISC60) | _BV(ISC61))) # define SERIAL_PIN_INTERRUPT INT6_vect