summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoritsnoteasy <pyrosoma1@yahoo.ie>2020-06-10 22:23:11 +0100
committerGitHub <noreply@github.com>2020-06-10 22:23:11 +0100
commit7aa4cc9603b8cdb0ea3ede753eff7d07a86a18b0 (patch)
treec48255b3861208d8b85e341b68bbc827b5f06711
parente26bc21d1452dcf04332d300a874dacc8d74862d (diff)
adds support for the atmega328 (#9043)0.9.9
Co-authored-by: Ryan <fauxpark@gmail.com>
-rw-r--r--docs/adc_driver.md4
-rw-r--r--docs/compatible_microcontrollers.md1
-rw-r--r--docs/feature_backlight.md2
-rw-r--r--docs/spi_driver.md2
-rw-r--r--drivers/avr/analog.c4
-rw-r--r--drivers/avr/spi_master.c2
-rw-r--r--drivers/avr/spi_master.h2
-rw-r--r--quantum/backlight/backlight_avr.c2
-rw-r--r--quantum/config_common.h2
-rw-r--r--quantum/mcu_selection.mk18
-rw-r--r--tmk_core/common/avr/bootloader.c2
-rw-r--r--tmk_core/common/uart.c2
12 files changed, 31 insertions, 12 deletions
diff --git a/docs/adc_driver.md b/docs/adc_driver.md
index 7c4e05efc4..f8fb94094e 100644
--- a/docs/adc_driver.md
+++ b/docs/adc_driver.md
@@ -22,7 +22,7 @@ Then place this include at the top of your code:
### AVR
-|Channel|AT90USB64/128|ATmega16/32U4|ATmega32A|ATmega328P|
+|Channel|AT90USB64/128|ATmega16/32U4|ATmega32A|ATmega328/P|
|-------|-------------|-------------|---------|----------|
|0 |`F0` |`F0` |`A0` |`C0` |
|1 |`F1` |`F1` |`A1` |`C1` |
@@ -39,7 +39,7 @@ Then place this include at the top of your code:
|12 | |`B5` | | |
|13 | |`B6` | | |
-<sup>\* The ATmega328P possesses two extra ADC channels; however, they are not present on the DIP pinout, and are not shared with GPIO pins. You can use `adc_read()` directly to gain access to these.</sup>
+<sup>\* The ATmega328/P possesses two extra ADC channels; however, they are not present on the DIP pinout, and are not shared with GPIO pins. You can use `adc_read()` directly to gain access to these.</sup>
### ARM
diff --git a/docs/compatible_microcontrollers.md b/docs/compatible_microcontrollers.md
index 85dd440d37..ac90ed7464 100644
--- a/docs/compatible_microcontrollers.md
+++ b/docs/compatible_microcontrollers.md
@@ -14,6 +14,7 @@ Certain MCUs which do not have native USB will use [V-USB](https://www.obdev.at/
* [ATmega32A](https://www.microchip.com/wwwproducts/en/ATmega32A)
* [ATmega328P](https://www.microchip.com/wwwproducts/en/ATmega328P)
+* [ATmega328](https://www.microchip.com/wwwproducts/en/ATmega328)
## ARM
diff --git a/docs/feature_backlight.md b/docs/feature_backlight.md
index 5f69468c34..7e4401b40f 100644
--- a/docs/feature_backlight.md
+++ b/docs/feature_backlight.md
@@ -89,7 +89,7 @@ BACKLIGHT_DRIVER = pwm
Hardware PWM is supported according to the following table:
-|Backlight Pin|AT90USB64/128|ATmega16/32U4|ATmega16/32U2|ATmega32A|ATmega328P|
+|Backlight Pin|AT90USB64/128|ATmega16/32U4|ATmega16/32U2|ATmega32A|ATmega328/P|
|-------------|-------------|-------------|-------------|---------|----------|
|`B1` | | | | |Timer 1 |
|`B2` | | | | |Timer 1 |
diff --git a/docs/spi_driver.md b/docs/spi_driver.md
index c170bf1dfc..1d432432ad 100644
--- a/docs/spi_driver.md
+++ b/docs/spi_driver.md
@@ -11,7 +11,7 @@ No special setup is required - just connect the `SS`, `SCK`, `MOSI` and `MISO` p
|ATMega16/32U2/4|`B0`|`B1` |`B2` |`B3` |
|AT90USB64/128 |`B0`|`B1` |`B2` |`B3` |
|ATmega32A |`B4`|`B7` |`B5` |`B6` |
-|ATmega328P |`B2`|`B5` |`B3` |`B4` |
+|ATmega328/P |`B2`|`B5` |`B3` |`B4` |
You may use more than one slave select pin, not just the `SS` pin. This is useful when you have multiple devices connected and need to communicate with them individually.
`SPI_SS_PIN` can be passed to `spi_start()` to refer to `SS`.
diff --git a/drivers/avr/analog.c b/drivers/avr/analog.c
index abe478b712..9b8397b933 100644
--- a/drivers/avr/analog.c
+++ b/drivers/avr/analog.c
@@ -38,7 +38,7 @@ int16_t analogRead(uint8_t pin) {
// clang-format on
if (pin >= 12) return 0;
return adc_read(pgm_read_byte(pin_to_mux + pin));
-#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) || defined(__AVR_ATmega328P__)
+#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__)
if (pin >= 8) return 0;
return adc_read(pin);
#else
@@ -85,7 +85,7 @@ uint8_t pinToMux(pin_t pin) {
case A6: return _BV(MUX2) | _BV(MUX1); // ADC6
case A7: return _BV(MUX2) | _BV(MUX1) | _BV(MUX0); // ADC7
default: return _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1) | _BV(MUX0); // 0V
-#elif defined(__AVR_ATmega328P__)
+#elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__)
case C0: return 0; // ADC0
case C1: return _BV(MUX0); // ADC1
case C2: return _BV(MUX1); // ADC2
diff --git a/drivers/avr/spi_master.c b/drivers/avr/spi_master.c
index 32cc55c836..f91baf70ba 100644
--- a/drivers/avr/spi_master.c
+++ b/drivers/avr/spi_master.c
@@ -28,7 +28,7 @@
# define SPI_SCK_PIN B7
# define SPI_MOSI_PIN B5
# define SPI_MISO_PIN B6
-#elif defined(__AVR_ATmega328P__)
+#elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__)
# define SPI_SCK_PIN B5
# define SPI_MOSI_PIN B3
# define SPI_MISO_PIN B4
diff --git a/drivers/avr/spi_master.h b/drivers/avr/spi_master.h
index b69c1cbd66..e36a7c21c0 100644
--- a/drivers/avr/spi_master.h
+++ b/drivers/avr/spi_master.h
@@ -25,7 +25,7 @@ typedef int16_t spi_status_t;
# define SPI_SS_PIN B0
#elif defined(__AVR_ATmega32A__)
# define SPI_SS_PIN B4
-#elif defined(__AVR_ATmega328P__)
+#elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__)
# define SPI_SS_PIN B2
#endif
diff --git a/quantum/backlight/backlight_avr.c b/quantum/backlight/backlight_avr.c
index ce13f11184..b3e882ffe1 100644
--- a/quantum/backlight/backlight_avr.c
+++ b/quantum/backlight/backlight_avr.c
@@ -103,7 +103,7 @@
# define COMxx1 COM1A1
# define OCRxx OCR1A
# endif
-#elif defined(__AVR_ATmega328P__) && (BACKLIGHT_PIN == B1 || BACKLIGHT_PIN == B2)
+#elif (defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__)) && (BACKLIGHT_PIN == B1 || BACKLIGHT_PIN == B2)
# define HARDWARE_PWM
# define ICRx ICR1
# define TCCRxA TCCR1A
diff --git a/quantum/config_common.h b/quantum/config_common.h
index 9861c86780..9b28e8d63f 100644
--- a/quantum/config_common.h
+++ b/quantum/config_common.h
@@ -58,7 +58,7 @@
# define PINC_ADDRESS 0x3
# define PINB_ADDRESS 0x6
# define PINA_ADDRESS 0x9
-# elif defined(__AVR_ATmega328P__)
+# elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__)
# define ADDRESS_BASE 0x00
# define PINB_ADDRESS 0x3
# define PINC_ADDRESS 0x6
diff --git a/quantum/mcu_selection.mk b/quantum/mcu_selection.mk
index 33de162bb1..a1d2c5fbf6 100644
--- a/quantum/mcu_selection.mk
+++ b/quantum/mcu_selection.mk
@@ -288,6 +288,24 @@ ifneq (,$(filter $(MCU),atmega328p))
NO_SUSPEND_POWER_DOWN ?= yes
endif
+ifneq (,$(filter $(MCU),atmega328))
+ # MCU name for avrdude
+ AVRDUDE_MCU = m328
+
+ PROTOCOL = VUSB
+
+ # Processor frequency.
+ # This will define a symbol, F_CPU, in all source code files equal to the
+ # processor frequency in Hz. You can then use this symbol in your source code to
+ # calculate timings. Do NOT tack on a 'UL' at the end, this will be done
+ # automatically to create a 32-bit value in your source code.
+ F_CPU ?= 16000000
+
+ # unsupported features for now
+ NO_UART ?= yes
+ NO_SUSPEND_POWER_DOWN ?= yes
+endif
+
ifneq (,$(filter $(MCU),attiny85))
PROTOCOL = VUSB
diff --git a/tmk_core/common/avr/bootloader.c b/tmk_core/common/avr/bootloader.c
index 7e5d2b0579..a1db55da93 100644
--- a/tmk_core/common/avr/bootloader.c
+++ b/tmk_core/common/avr/bootloader.c
@@ -247,7 +247,7 @@ void bootloader_jump(void) {
#else // Assume remaining boards are DFU, even if the flag isn't set
-# if !(defined(__AVR_ATmega32A__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATtiny85__)) // no USB - maybe BOOTLOADER_BOOTLOADHID instead though?
+# if !(defined(__AVR_ATmega32A__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__) || defined(__AVR_ATtiny85__)) // no USB - maybe BOOTLOADER_BOOTLOADHID instead though?
UDCON = 1;
USBCON = (1 << FRZCLK); // disable USB
UCSR1B = 0;
diff --git a/tmk_core/common/uart.c b/tmk_core/common/uart.c
index b29d3bbb94..150e256c8f 100644
--- a/tmk_core/common/uart.c
+++ b/tmk_core/common/uart.c
@@ -31,7 +31,7 @@
#include "uart.h"
-#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || defined(__AVR_ATmega328P__)
+#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__)
# define UDRn UDR0
# define UBRRnL UBRR0L
# define UCSRnA UCSR0A