Skip to content

Commit a1b96ba

Browse files
takainoroadsleft
authored andcommitted
Add support for soft serial to ATmega32U2 (#10204)
* Add support for soft serial to ATmega32U2 * Update drivers/avr/serial.c * Update drivers/avr/serial.c * Update drivers/avr/serial.c * Fix comment * Update drivers/avr/serial.c
1 parent 9700a20 commit a1b96ba

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

common_features.mk

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,10 @@ ifeq ($(strip $(SPLIT_KEYBOARD)), yes)
417417
# Functions added via QUANTUM_LIB_SRC are only included in the final binary if they're called.
418418
# Unused functions are pruned away, which is why we can add multiple drivers here without bloat.
419419
ifeq ($(PLATFORM),AVR)
420-
QUANTUM_LIB_SRC += i2c_master.c \
421-
i2c_slave.c
420+
ifneq ($(NO_I2C),yes)
421+
QUANTUM_LIB_SRC += i2c_master.c \
422+
i2c_slave.c
423+
endif
422424
endif
423425

424426
SERIAL_DRIVER ?= bitbang

drivers/avr/serial.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020

2121
#ifdef SOFT_SERIAL_PIN
2222

23-
# ifdef __AVR_ATmega32U4__
24-
// if using ATmega32U4 I2C, can not use PD0 and PD1 in soft serial.
23+
# if defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)
24+
// if using ATmegaxxU4 I2C, can not use PD0 and PD1 in soft serial.
2525
# ifdef USE_AVR_I2C
2626
# if SOFT_SERIAL_PIN == D0 || SOFT_SERIAL_PIN == D1
27-
# error Using ATmega32U4 I2C, so can not use PD0, PD1
27+
# error Using ATmegaxxU4 I2C, so can not use PD0, PD1
2828
# endif
2929
# endif
3030

@@ -52,7 +52,7 @@
5252
# define EICRx_BIT (~(_BV(ISC30) | _BV(ISC31)))
5353
# define SERIAL_PIN_INTERRUPT INT3_vect
5454
# endif
55-
# elif SOFT_SERIAL_PIN == E6
55+
# elif (defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)) && SOFT_SERIAL_PIN == E6
5656
# define EIMSK_BIT _BV(INT6)
5757
# define EICRx_BIT (~(_BV(ISC60) | _BV(ISC61)))
5858
# define SERIAL_PIN_INTERRUPT INT6_vect
@@ -61,7 +61,7 @@
6161
# endif
6262

6363
# else
64-
# error serial.c now support ATmega32U4 only
64+
# error serial.c currently only supports ATmegaxxU2 and ATmegaxxU4
6565
# endif
6666

6767
# define ALWAYS_INLINE __attribute__((always_inline))

quantum/mcu_selection.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ ifneq (,$(filter $(MCU),atmega16u2 atmega32u2 atmega16u4 atmega32u4 at90usb646 a
252252
ifeq (,$(filter $(NO_INTERRUPT_CONTROL_ENDPOINT),yes))
253253
OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT
254254
endif
255+
ifneq (,$(filter $(MCU),atmega16u2 atmega32u2))
256+
NO_I2C = yes
257+
endif
255258
endif
256259

257260
ifneq (,$(filter $(MCU),atmega32a))

0 commit comments

Comments
 (0)