summaryrefslogtreecommitdiff
path: root/platforms/avr
diff options
context:
space:
mode:
Diffstat (limited to 'platforms/avr')
-rw-r--r--platforms/avr/bootloader.c293
-rw-r--r--platforms/avr/bootloaders/bootloadhid.c33
-rw-r--r--platforms/avr/bootloaders/caterina.c39
-rw-r--r--platforms/avr/bootloaders/custom.c19
-rw-r--r--platforms/avr/bootloaders/dfu.c52
-rw-r--r--platforms/avr/bootloaders/halfkay.c128
-rw-r--r--platforms/avr/bootloaders/usbasploader.c56
-rw-r--r--platforms/avr/drivers/analog.c8
-rw-r--r--platforms/avr/drivers/analog.h18
-rw-r--r--platforms/avr/drivers/audio_pwm_hardware.c8
-rw-r--r--platforms/avr/drivers/glcdfont.c18
-rw-r--r--platforms/avr/drivers/hd44780.c22
-rw-r--r--platforms/avr/drivers/i2c_master.c13
-rw-r--r--platforms/avr/drivers/i2c_slave.c12
-rw-r--r--platforms/avr/drivers/i2c_slave.h6
-rw-r--r--platforms/avr/drivers/ps2/ps2_io.c8
-rw-r--r--platforms/avr/drivers/ps2/ps2_usart.c8
-rw-r--r--platforms/avr/drivers/serial.c162
-rw-r--r--platforms/avr/drivers/spi_master.c2
-rw-r--r--platforms/avr/drivers/ssd1306.c22
-rw-r--r--platforms/avr/drivers/uart.c4
-rw-r--r--platforms/avr/drivers/ws2812.c14
-rw-r--r--platforms/avr/drivers/ws2812_i2c.c4
-rw-r--r--platforms/avr/gpio.h17
-rw-r--r--platforms/avr/pin_defs.h2
-rw-r--r--platforms/avr/platform.mk2
-rw-r--r--platforms/avr/printf.c4
-rw-r--r--platforms/avr/sleep_led.c2
-rw-r--r--platforms/avr/suspend.c55
-rw-r--r--platforms/avr/timer.c24
30 files changed, 540 insertions, 515 deletions
diff --git a/platforms/avr/bootloader.c b/platforms/avr/bootloader.c
deleted file mode 100644
index c0272903b8..0000000000
--- a/platforms/avr/bootloader.c
+++ /dev/null
@@ -1,293 +0,0 @@
-#include <stdint.h>
-#include <stdbool.h>
-#include <avr/io.h>
-#include <avr/eeprom.h>
-#include <avr/interrupt.h>
-#include <avr/wdt.h>
-#include <util/delay.h>
-#include "bootloader.h"
-#include <avr/boot.h>
-
-#ifdef PROTOCOL_LUFA
-# include <LUFA/Drivers/USB/USB.h>
-#endif
-
-/** \brief Bootloader Size in *bytes*
- *
- * AVR Boot section size are defined by setting BOOTSZ fuse in fact. Consult with your MCU datasheet.
- * Note that 'Word'(2 bytes) size and address are used in datasheet while TMK uses 'Byte'.
- *
- * Size of Bootloaders in bytes:
- * Atmel DFU loader(ATmega32U4) 4096
- * Atmel DFU loader(AT90USB128) 8192
- * LUFA bootloader(ATmega32U4) 4096
- * Arduino Caterina(ATmega32U4) 4096
- * USBaspLoader(ATmega***) 2048
- * Teensy halfKay(ATmega32U4) 512
- * Teensy++ halfKay(AT90USB128) 1024
- *
- * AVR Boot section is located at the end of Flash memory like the followings.
- *
- * byte Atmel/LUFA(ATMega32u4) byte Atmel(AT90SUB128)
- * 0x0000 +---------------+ 0x00000 +---------------+
- * | | | |
- * | | | |
- * | Application | | Application |
- * | | | |
- * = = = =
- * | | 32KB-4KB | | 128KB-8KB
- * 0x7000 +---------------+ 0x1E000 +---------------+
- * | Bootloader | 4KB | Bootloader | 8KB
- * 0x7FFF +---------------+ 0x1FFFF +---------------+
- *
- *
- * byte Teensy(ATMega32u4) byte Teensy++(AT90SUB128)
- * 0x0000 +---------------+ 0x00000 +---------------+
- * | | | |
- * | | | |
- * | Application | | Application |
- * | | | |
- * = = = =
- * | | 32KB-512B | | 128KB-1KB
- * 0x7E00 +---------------+ 0x1FC00 +---------------+
- * | Bootloader | 512B | Bootloader | 1KB
- * 0x7FFF +---------------+ 0x1FFFF +---------------+
- */
-#define FLASH_SIZE (FLASHEND + 1L)
-
-#if !defined(BOOTLOADER_SIZE)
-uint16_t bootloader_start;
-#endif
-
-// compatibility between ATMega8 and ATMega88
-#if !defined(MCUCSR)
-# if defined(MCUSR)
-# define MCUCSR MCUSR
-# endif
-#endif
-
-/** \brief Entering the Bootloader via Software
- *
- * http://www.fourwalledcubicle.com/files/LUFA/Doc/120730/html/_page__software_bootloader_start.html
- */
-#define BOOTLOADER_RESET_KEY 0xB007B007
-uint32_t reset_key __attribute__((section(".noinit,\"aw\",@nobits;")));
-
-/** \brief initialize MCU status by watchdog reset
- *
- * FIXME: needs doc
- */
-__attribute__((weak)) void bootloader_jump(void) {
-#if !defined(BOOTLOADER_SIZE)
- uint8_t high_fuse = boot_lock_fuse_bits_get(GET_HIGH_FUSE_BITS);
-
- if (high_fuse & ~(FUSE_BOOTSZ0 & FUSE_BOOTSZ1)) {
- bootloader_start = (FLASH_SIZE - 512) >> 1;
- } else if (high_fuse & ~(FUSE_BOOTSZ1)) {
- bootloader_start = (FLASH_SIZE - 1024) >> 1;
- } else if (high_fuse & ~(FUSE_BOOTSZ0)) {
- bootloader_start = (FLASH_SIZE - 2048) >> 1;
- } else {
- bootloader_start = (FLASH_SIZE - 4096) >> 1;
- }
-#endif
-
- // Something like this might work, but it compiled larger than the block above
- // bootloader_start = FLASH_SIZE - (256 << (~high_fuse & 0b110 >> 1));
-
-#if defined(BOOTLOADER_HALFKAY)
- // http://www.pjrc.com/teensy/jump_to_bootloader.html
- cli();
- // disable watchdog, if enabled (it's not)
- // disable all peripherals
- // a shutdown call might make sense here
- UDCON = 1;
- USBCON = (1 << FRZCLK); // disable USB
- UCSR1B = 0;
- _delay_ms(5);
-# if defined(__AVR_AT90USB162__) // Teensy 1.0
- EIMSK = 0;
- PCICR = 0;
- SPCR = 0;
- ACSR = 0;
- EECR = 0;
- TIMSK0 = 0;
- TIMSK1 = 0;
- UCSR1B = 0;
- DDRB = 0;
- DDRC = 0;
- DDRD = 0;
- PORTB = 0;
- PORTC = 0;
- PORTD = 0;
- asm volatile("jmp 0x3E00");
-# elif defined(__AVR_ATmega32U4__) // Teensy 2.0
- EIMSK = 0;
- PCICR = 0;
- SPCR = 0;
- ACSR = 0;
- EECR = 0;
- ADCSRA = 0;
- TIMSK0 = 0;
- TIMSK1 = 0;
- TIMSK3 = 0;
- TIMSK4 = 0;
- UCSR1B = 0;
- TWCR = 0;
- DDRB = 0;
- DDRC = 0;
- DDRD = 0;
- DDRE = 0;
- DDRF = 0;
- TWCR = 0;
- PORTB = 0;
- PORTC = 0;
- PORTD = 0;
- PORTE = 0;
- PORTF = 0;
- asm volatile("jmp 0x7E00");
-# elif defined(__AVR_AT90USB646__) // Teensy++ 1.0
- EIMSK = 0;
- PCICR = 0;
- SPCR = 0;
- ACSR = 0;
- EECR = 0;
- ADCSRA = 0;
- TIMSK0 = 0;
- TIMSK1 = 0;
- TIMSK2 = 0;
- TIMSK3 = 0;
- UCSR1B = 0;
- TWCR = 0;
- DDRA = 0;
- DDRB = 0;
- DDRC = 0;
- DDRD = 0;
- DDRE = 0;
- DDRF = 0;
- PORTA = 0;
- PORTB = 0;
- PORTC = 0;
- PORTD = 0;
- PORTE = 0;
- PORTF = 0;
- asm volatile("jmp 0xFC00");
-# elif defined(__AVR_AT90USB1286__) // Teensy++ 2.0
- EIMSK = 0;
- PCICR = 0;
- SPCR = 0;
- ACSR = 0;
- EECR = 0;
- ADCSRA = 0;
- TIMSK0 = 0;
- TIMSK1 = 0;
- TIMSK2 = 0;
- TIMSK3 = 0;
- UCSR1B = 0;
- TWCR = 0;
- DDRA = 0;
- DDRB = 0;
- DDRC = 0;
- DDRD = 0;
- DDRE = 0;
- DDRF = 0;
- PORTA = 0;
- PORTB = 0;
- PORTC = 0;
- PORTD = 0;
- PORTE = 0;
- PORTF = 0;
- asm volatile("jmp 0x1FC00");
-# endif
-
-#elif defined(BOOTLOADER_CATERINA)
- // this block may be optional
- // TODO: figure it out
-
- uint16_t *const bootKeyPtr = (uint16_t *)0x0800;
-
- // Value used by Caterina bootloader use to determine whether to run the
- // sketch or the bootloader programmer.
- uint16_t bootKey = 0x7777;
-
- *bootKeyPtr = bootKey;
-
- // setup watchdog timeout
- wdt_enable(WDTO_60MS);
-
- while (1) {
- } // wait for watchdog timer to trigger
-
-#elif defined(BOOTLOADER_USBASP)
- // Taken with permission of Stephan Baerwolf from https://github.com/tinyusbboard/API/blob/master/apipage.c
- wdt_enable(WDTO_15MS);
- wdt_reset();
- asm volatile("cli \n\t"
- "ldi r29 , %[ramendhi] \n\t"
- "ldi r28 , %[ramendlo] \n\t"
-# if (FLASHEND > 131071)
- "ldi r18 , %[bootaddrhi] \n\t"
- "st Y+, r18 \n\t"
-# endif
- "ldi r18 , %[bootaddrme] \n\t"
- "st Y+, r18 \n\t"
- "ldi r18 , %[bootaddrlo] \n\t"
- "st Y+, r18 \n\t"
- "out %[mcucsrio], __zero_reg__ \n\t"
- "bootloader_startup_loop%=: \n\t"
- "rjmp bootloader_startup_loop%= \n\t"
- :
- : [mcucsrio] "I"(_SFR_IO_ADDR(MCUCSR)),
-# if (FLASHEND > 131071)
- [ramendhi] "M"(((RAMEND - 2) >> 8) & 0xff), [ramendlo] "M"(((RAMEND - 2) >> 0) & 0xff), [bootaddrhi] "M"((((FLASH_SIZE - BOOTLOADER_SIZE) >> 1) >> 16) & 0xff),
-# else
- [ramendhi] "M"(((RAMEND - 1) >> 8) & 0xff), [ramendlo] "M"(((RAMEND - 1) >> 0) & 0xff),
-# endif
- [bootaddrme] "M"((((FLASH_SIZE - BOOTLOADER_SIZE) >> 1) >> 8) & 0xff), [bootaddrlo] "M"((((FLASH_SIZE - BOOTLOADER_SIZE) >> 1) >> 0) & 0xff));
-
-#else // Assume remaining boards are DFU, even if the flag isn't set
-
-# 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;
- _delay_ms(5); // 5 seems to work fine
-# endif
-
-# ifdef BOOTLOADER_BOOTLOADHID
- // force bootloadHID to stay in bootloader mode, so that it waits
- // for a new firmware to be flashed
- eeprom_write_byte((uint8_t *)1, 0x00);
-# endif
-
- // watchdog reset
- reset_key = BOOTLOADER_RESET_KEY;
- wdt_enable(WDTO_250MS);
- for (;;)
- ;
-#endif
-}
-
-/* this runs before main() */
-void bootloader_jump_after_watchdog_reset(void) __attribute__((used, naked, section(".init3")));
-void bootloader_jump_after_watchdog_reset(void) {
-#ifndef BOOTLOADER_HALFKAY
- if ((MCUCSR & (1 << WDRF)) && reset_key == BOOTLOADER_RESET_KEY) {
- reset_key = 0;
-
- // My custom USBasploader requires this to come up.
- MCUCSR = 0;
-
- // Seems like Teensy halfkay loader requires clearing WDRF and disabling watchdog.
- MCUCSR &= ~(1 << WDRF);
- wdt_disable();
-
-// This is compled into 'icall', address should be in word unit, not byte.
-# ifdef BOOTLOADER_SIZE
- ((void (*)(void))((FLASH_SIZE - BOOTLOADER_SIZE) >> 1))();
-# else
- asm("ijmp" ::"z"(bootloader_start));
-# endif
- }
-#endif
-}
diff --git a/platforms/avr/bootloaders/bootloadhid.c b/platforms/avr/bootloaders/bootloadhid.c
new file mode 100644
index 0000000000..ae58760d7d
--- /dev/null
+++ b/platforms/avr/bootloaders/bootloadhid.c
@@ -0,0 +1,33 @@
+/* Copyright 2021 QMK
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "bootloader.h"
+
+#include <avr/eeprom.h>
+#include <avr/wdt.h>
+
+__attribute__((weak)) void bootloader_jump(void) {
+ // force bootloadHID to stay in bootloader mode, so that it waits
+ // for a new firmware to be flashed
+ // NOTE: this byte is part of QMK's "magic number" - changing it causes the EEPROM to be re-initialized
+ // thus every time the device is flashed the EEPROM will be wiped
+ eeprom_write_byte((uint8_t *)1, 0x00);
+
+ // watchdog reset
+ wdt_enable(WDTO_250MS);
+ for (;;)
+ ;
+}
diff --git a/platforms/avr/bootloaders/caterina.c b/platforms/avr/bootloaders/caterina.c
new file mode 100644
index 0000000000..82a16a3765
--- /dev/null
+++ b/platforms/avr/bootloaders/caterina.c
@@ -0,0 +1,39 @@
+/* Copyright 2021 QMK
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "bootloader.h"
+
+#include <avr/wdt.h>
+
+__attribute__((weak)) void bootloader_jump(void) {
+ // this block may be optional
+ // TODO: figure it out
+
+ uint16_t *const bootKeyPtr = (uint16_t *)0x0800;
+
+ // Value used by Caterina bootloader use to determine whether to run the
+ // sketch or the bootloader programmer.
+ uint16_t bootKey = 0x7777;
+
+ *bootKeyPtr = bootKey;
+
+ // setup watchdog timeout
+ wdt_enable(WDTO_60MS);
+
+ // wait for watchdog timer to trigger
+ while (1) {
+ }
+}
diff --git a/platforms/avr/bootloaders/custom.c b/platforms/avr/bootloaders/custom.c
new file mode 100644
index 0000000000..624fbe242a
--- /dev/null
+++ b/platforms/avr/bootloaders/custom.c
@@ -0,0 +1,19 @@
+/* Copyright 2021 QMK
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "bootloader.h"
+
+__attribute__((weak)) void bootloader_jump(void) {}
diff --git a/platforms/avr/bootloaders/dfu.c b/platforms/avr/bootloaders/dfu.c
new file mode 100644
index 0000000000..06b2c8963a
--- /dev/null
+++ b/platforms/avr/bootloaders/dfu.c
@@ -0,0 +1,52 @@
+/* Copyright 2021 QMK
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "bootloader.h"
+
+#include <avr/wdt.h>
+#include <util/delay.h>
+
+#define FLASH_SIZE (FLASHEND + 1L)
+
+/** \brief Entering the Bootloader via Software
+ *
+ * http://www.fourwalledcubicle.com/files/LUFA/Doc/120730/html/_page__software_bootloader_start.html
+ */
+#define BOOTLOADER_RESET_KEY 0xB007B007
+uint32_t reset_key __attribute__((section(".noinit,\"aw\",@nobits;")));
+
+__attribute__((weak)) void bootloader_jump(void) {
+ UDCON = 1;
+ USBCON = (1 << FRZCLK); // disable USB
+ UCSR1B = 0;
+ _delay_ms(5); // 5 seems to work fine
+
+ // watchdog reset
+ reset_key = BOOTLOADER_RESET_KEY;
+ wdt_enable(WDTO_250MS);
+ for (;;)
+ ;
+}
+
+/* this runs before main() */
+void bootloader_jump_after_watchdog_reset(void) __attribute__((used, naked, section(".init3")));
+void bootloader_jump_after_watchdog_reset(void) {
+ if ((MCUSR & (1 << WDRF)) && reset_key == BOOTLOADER_RESET_KEY) {
+ reset_key = 0;
+
+ ((void (*)(void))((FLASH_SIZE - BOOTLOADER_SIZE) >> 1))();
+ }
+}
diff --git a/platforms/avr/bootloaders/halfkay.c b/platforms/avr/bootloaders/halfkay.c
new file mode 100644
index 0000000000..651696f988
--- /dev/null
+++ b/platforms/avr/bootloaders/halfkay.c
@@ -0,0 +1,128 @@
+/* Copyright 2021 QMK
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "bootloader.h"
+
+#include <avr/interrupt.h>
+#include <util/delay.h>
+
+__attribute__((weak)) void bootloader_jump(void) {
+ // http://www.pjrc.com/teensy/jump_to_bootloader.html
+
+ cli();
+ // disable watchdog, if enabled (it's not)
+ // disable all peripherals
+ // a shutdown call might make sense here
+ UDCON = 1;
+ USBCON = (1 << FRZCLK); // disable USB
+ UCSR1B = 0;
+ _delay_ms(5);
+
+#if defined(__AVR_AT90USB162__) // Teensy 1.0
+ EIMSK = 0;
+ PCICR = 0;
+ SPCR = 0;
+ ACSR = 0;
+ EECR = 0;
+ TIMSK0 = 0;
+ TIMSK1 = 0;
+ UCSR1B = 0;
+ DDRB = 0;
+ DDRC = 0;
+ DDRD = 0;
+ PORTB = 0;
+ PORTC = 0;
+ PORTD = 0;
+ asm volatile("jmp 0x3E00");
+#elif defined(__AVR_ATmega32U4__) // Teensy 2.0
+ EIMSK = 0;
+ PCICR = 0;
+ SPCR = 0;
+ ACSR = 0;
+ EECR = 0;
+ ADCSRA = 0;
+ TIMSK0 = 0;
+ TIMSK1 = 0;
+ TIMSK3 = 0;
+ TIMSK4 = 0;
+ UCSR1B = 0;
+ TWCR = 0;
+ DDRB = 0;
+ DDRC = 0;
+ DDRD = 0;
+ DDRE = 0;
+ DDRF = 0;
+ TWCR = 0;
+ PORTB = 0;
+ PORTC = 0;
+ PORTD = 0;
+ PORTE = 0;
+ PORTF = 0;
+ asm volatile("jmp 0x7E00");
+#elif defined(__AVR_AT90USB646__) // Teensy++ 1.0
+ EIMSK = 0;
+ PCICR = 0;
+ SPCR = 0;
+ ACSR = 0;
+ EECR = 0;
+ ADCSRA = 0;
+ TIMSK0 = 0;
+ TIMSK1 = 0;
+ TIMSK2 = 0;
+ TIMSK3 = 0;
+ UCSR1B = 0;
+ TWCR = 0;
+ DDRA = 0;
+ DDRB = 0;
+ DDRC = 0;
+ DDRD = 0;
+ DDRE = 0;
+ DDRF = 0;
+ PORTA = 0;
+ PORTB = 0;
+ PORTC = 0;
+ PORTD = 0;
+ PORTE = 0;
+ PORTF = 0;
+ asm volatile("jmp 0xFC00");
+#elif defined(__AVR_AT90USB1286__) // Teensy++ 2.0
+ EIMSK = 0;
+ PCICR = 0;
+ SPCR = 0;
+ ACSR = 0;
+ EECR = 0;
+ ADCSRA = 0;
+ TIMSK0 = 0;
+ TIMSK1 = 0;
+ TIMSK2 = 0;
+ TIMSK3 = 0;
+ UCSR1B = 0;
+ TWCR = 0;
+ DDRA = 0;
+ DDRB = 0;
+ DDRC = 0;
+ DDRD = 0;
+ DDRE = 0;
+ DDRF = 0;
+ PORTA = 0;
+ PORTB = 0;
+ PORTC = 0;
+ PORTD = 0;
+ PORTE = 0;
+ PORTF = 0;
+ asm volatile("jmp 0x1FC00");
+#endif
+}
diff --git a/platforms/avr/bootloaders/usbasploader.c b/platforms/avr/bootloaders/usbasploader.c
new file mode 100644
index 0000000000..008bd16069
--- /dev/null
+++ b/platforms/avr/bootloaders/usbasploader.c
@@ -0,0 +1,56 @@
+/* Copyright 2021 QMK
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "bootloader.h"
+
+#include <avr/wdt.h>
+
+#define FLASH_SIZE (FLASHEND + 1L)
+
+#if !defined(MCUCSR)
+# if defined(MCUSR)
+# define MCUCSR MCUSR
+# endif
+#endif
+
+__attribute__((weak)) void bootloader_jump(void) {
+ // Taken with permission of Stephan Baerwolf from https://github.com/tinyusbboard/API/blob/master/apipage.c
+
+ wdt_enable(WDTO_15MS);
+ wdt_reset();
+ asm volatile("cli \n\t"
+ "ldi r29 , %[ramendhi] \n\t"
+ "ldi r28 , %[ramendlo] \n\t"
+#if (FLASHEND > 131071)
+ "ldi r18 , %[bootaddrhi] \n\t"
+ "st Y+, r18 \n\t"
+#endif
+ "ldi r18 , %[bootaddrme] \n\t"
+ "st Y+, r18 \n\t"
+ "ldi r18 , %[bootaddrlo] \n\t"
+ "st Y+, r18 \n\t"
+ "out %[mcucsrio], __zero_reg__ \n\t"
+ "bootloader_startup_loop%=: \n\t"
+ "rjmp bootloader_startup_loop%= \n\t"
+ :
+ : [mcucsrio] "I"(_SFR_IO_ADDR(MCUCSR)),
+#if (FLASHEND > 131071)
+ [ramendhi] "M"(((RAMEND - 2) >> 8) & 0xff), [ramendlo] "M"(((RAMEND - 2) >> 0) & 0xff), [bootaddrhi] "M"((((FLASH_SIZE - BOOTLOADER_SIZE) >> 1) >> 16) & 0xff),
+#else
+ [ramendhi] "M"(((RAMEND - 1) >> 8) & 0xff), [ramendlo] "M"(((RAMEND - 1) >> 0) & 0xff),
+#endif
+ [bootaddrme] "M"((((FLASH_SIZE - BOOTLOADER_SIZE) >> 1) >> 8) & 0xff), [bootaddrlo] "M"((((FLASH_SIZE - BOOTLOADER_SIZE) >> 1) >> 0) & 0xff));
+}
diff --git a/platforms/avr/drivers/analog.c b/platforms/avr/drivers/analog.c
index 628835ccef..ed4d563609 100644
--- a/platforms/avr/drivers/analog.c
+++ b/platforms/avr/drivers/analog.c
@@ -21,9 +21,13 @@
static uint8_t aref = ADC_REF_POWER;
-void analogReference(uint8_t mode) { aref = mode & (_BV(REFS1) | _BV(REFS0)); }
+void analogReference(uint8_t mode) {
+ aref = mode & (_BV(REFS1) | _BV(REFS0));
+}
-int16_t analogReadPin(pin_t pin) { return adc_read(pinToMux(pin)); }
+int16_t analogReadPin(pin_t pin) {
+ return adc_read(pinToMux(pin));
+}
uint8_t pinToMux(pin_t pin) {
switch (pin) {
diff --git a/platforms/avr/drivers/analog.h b/platforms/avr/drivers/analog.h
index fa2fb0d89b..fb13e106ff 100644
--- a/platforms/avr/drivers/analog.h
+++ b/platforms/avr/drivers/analog.h
@@ -32,21 +32,21 @@ int16_t adc_read(uint8_t mux);
}
#endif
-#define ADC_REF_EXTERNAL 0 // AREF, Internal Vref turned off
-#define ADC_REF_POWER _BV(REFS0) // AVCC with external capacitor on AREF pin
-#define ADC_REF_INTERNAL (_BV(REFS1) | _BV(REFS0)) // Internal 2.56V Voltage Reference with external capacitor on AREF pin (1.1V for 328P)
+#define ADC_REF_EXTERNAL 0 // AREF, Internal Vref turned off
+#define ADC_REF_POWER _BV(REFS0) // AVCC with external capacitor on AREF pin
+#define ADC_REF_INTERNAL (_BV(REFS1) | _BV(REFS0)) // Internal 2.56V Voltage Reference with external capacitor on AREF pin (1.1V for 328P)
// These prescaler values are for high speed mode, ADHSM = 1
#if F_CPU == 16000000L || F_CPU == 12000000L
-# define ADC_PRESCALER (_BV(ADPS2) | _BV(ADPS1)) // /64
+# define ADC_PRESCALER (_BV(ADPS2) | _BV(ADPS1)) // /64
#elif F_CPU == 8000000L
-# define ADC_PRESCALER (_BV(ADPS2) | _BV(ADPS0)) // /32
+# define ADC_PRESCALER (_BV(ADPS2) | _BV(ADPS0)) // /32
#elif F_CPU == 4000000L
-# define ADC_PRESCALER (_BV(ADPS2)) // /16
+# define ADC_PRESCALER (_BV(ADPS2)) // /16
#elif F_CPU == 2000000L
-# define ADC_PRESCALER (_BV(ADPS1) | _BV(ADPS0)) // /8
+# define ADC_PRESCALER (_BV(ADPS1) | _BV(ADPS0)) // /8
#elif F_CPU == 1000000L
-# define ADC_PRESCALER _BV(ADPS1) // /4
+# define ADC_PRESCALER _BV(ADPS1) // /4
#else
-# define ADC_PRESCALER _BV(ADPS0) // /2
+# define ADC_PRESCALER _BV(ADPS0) // /2
#endif
diff --git a/platforms/avr/drivers/audio_pwm_hardware.c b/platforms/avr/drivers/audio_pwm_hardware.c
index df03a4558c..78776ee48a 100644
--- a/platforms/avr/drivers/audio_pwm_hardware.c
+++ b/platforms/avr/drivers/audio_pwm_hardware.c
@@ -152,7 +152,7 @@ extern uint8_t note_timbre;
#ifdef AUDIO1_PIN_SET
static float channel_1_frequency = 0.0f;
void channel_1_set_frequency(float freq) {
- if (freq == 0.0f) // a pause/rest is a valid "note" with freq=0
+ if (freq == 0.0f) // a pause/rest is a valid "note" with freq=0
{
// disable the output, but keep the pwm-ISR going (with the previous
// frequency) so the audio-state keeps getting updated
@@ -160,7 +160,7 @@ void channel_1_set_frequency(float freq) {
AUDIO1_TCCRxA &= ~(_BV(AUDIO1_COMxy1) | _BV(AUDIO1_COMxy0));
return;
} else {
- AUDIO1_TCCRxA |= _BV(AUDIO1_COMxy1); // enable output, PWM mode
+ AUDIO1_TCCRxA |= _BV(AUDIO1_COMxy1); // enable output, PWM mode
}
channel_1_frequency = freq;
@@ -202,7 +202,9 @@ void channel_2_set_frequency(float freq) {
AUDIO2_OCRxy = (uint16_t)((((float)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre / 100);
}
-float channel_2_get_frequency(void) { return channel_2_frequency; }
+float channel_2_get_frequency(void) {
+ return channel_2_frequency;
+}
void channel_2_start(void) {
AUDIO2_TIMSKx |= _BV(AUDIO2_OCIExy);
diff --git a/platforms/avr/drivers/glcdfont.c b/platforms/avr/drivers/glcdfont.c
index 5e763b054f..57a21965de 100644
--- a/platforms/avr/drivers/glcdfont.c
+++ b/platforms/avr/drivers/glcdfont.c
@@ -10,14 +10,14 @@ static const unsigned char font[] PROGMEM = {
0x30, 0x38, 0x3E, 0x38, 0x30, 0x06, 0x0E, 0x3E, 0x0E, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5F, 0x00, 0x00, 0x00, 0x07, 0x00, 0x07, 0x00, 0x14, 0x7F, 0x14, 0x7F, 0x14, 0x24, 0x2A, 0x7F, 0x2A, 0x12, 0x23, 0x13, 0x08, 0x64, 0x62, 0x36, 0x49, 0x56, 0x20, 0x50, 0x00, 0x08, 0x07, 0x03, 0x00, 0x00, 0x1C, 0x22, 0x41, 0x00, 0x00, 0x41, 0x22, 0x1C, 0x00, 0x2A, 0x1C, 0x7F, 0x1C, 0x2A, 0x08, 0x08, 0x3E, 0x08, 0x08, 0x00, 0x80, 0x70, 0x30, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x60, 0x60, 0x00, 0x20, 0x10, 0x08, 0x04, 0x02, 0x3E, 0x51, 0x49, 0x45, 0x3E, 0x00, 0x42, 0x7F, 0x40, 0x00, 0x72, 0x49, 0x49, 0x49, 0x46, 0x21, 0x41, 0x49, 0x4D, 0x33, 0x18, 0x14, 0x12, 0x7F, 0x10, 0x27, 0x45, 0x45, 0x45, 0x39, 0x3C, 0x4A, 0x49, 0x49, 0x31, 0x41, 0x21, 0x11, 0x09, 0x07, 0x36, 0x49, 0x49, 0x49, 0x36, 0x46, 0x49, 0x49, 0x29, 0x1E, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x40, 0x34, 0x00, 0x00,
0x00, 0x08, 0x14, 0x22, 0x41, 0x14, 0x14, 0x14, 0x14, 0x14, 0x00, 0x41, 0x22, 0x14, 0x08, 0x02, 0x01, 0x59, 0x09, 0x06, 0x3E, 0x41, 0x5D, 0x59, 0x4E, 0x7C, 0x12, 0x11, 0x12, 0x7C, 0x7F, 0x49, 0x49, 0x49, 0x36, 0x3E, 0x41, 0x41, 0x41, 0x22, 0x7F, 0x41, 0x41, 0x41, 0x3E, 0x7F, 0x49, 0x49, 0x49, 0x41, 0x7F, 0x09, 0x09, 0x09, 0x01, 0x3E, 0x41, 0x41, 0x51, 0x73, 0x7F, 0x08, 0x08, 0x08, 0x7F, 0x00, 0x41, 0x7F, 0x41, 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01, 0x7F, 0x08, 0x14, 0x22, 0x41, 0x7F, 0x40, 0x40, 0x40, 0x40, 0x7F, 0x02, 0x1C, 0x02, 0x7F, 0x7F, 0x04, 0x08, 0x10, 0x7F, 0x3E, 0x41, 0x41, 0x41, 0x3E, 0x7F, 0x09, 0x09, 0x09, 0x06, 0x3E, 0x41, 0x51, 0x21, 0x5E, 0x7F, 0x09, 0x19, 0x29, 0x46, 0x26, 0x49, 0x49, 0x49, 0x32, 0x03, 0x01, 0x7F, 0x01, 0x03, 0x3F, 0x40, 0x40, 0x40, 0x3F, 0x1F, 0x20, 0x40, 0x20, 0x1F, 0x3F, 0x40, 0x38, 0x40, 0x3F, 0x63, 0x14, 0x08, 0x14, 0x63, 0x03, 0x04, 0x78, 0x04, 0x03,
0x61, 0x59, 0x49, 0x4D, 0x43, 0x00, 0x7F, 0x41, 0x41, 0x41, 0x02, 0x04, 0x08, 0x10, 0x20, 0x00, 0x41, 0x41, 0x41, 0x7F, 0x04, 0x02, 0x01, 0x02, 0x04, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x03, 0x07, 0x08, 0x00, 0x20, 0x54, 0x54, 0x78, 0x40, 0x7F, 0x28, 0x44, 0x44, 0x38, 0x38, 0x44, 0x44, 0x44, 0x28, 0x38, 0x44, 0x44, 0x28, 0x7F, 0x38, 0x54, 0x54, 0x54, 0x18, 0x00, 0x08, 0x7E, 0x09, 0x02, 0x18, 0xA4, 0xA4, 0x9C, 0x78, 0x7F, 0x08, 0x04, 0x04, 0x78, 0x00, 0x44, 0x7D, 0x40, 0x00, 0x20, 0x40, 0x40, 0x3D, 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00, 0x7C, 0x04, 0x78, 0x04, 0x78, 0x7C, 0x08, 0x04, 0x04, 0x78, 0x38, 0x44, 0x44, 0x44, 0x38, 0xFC, 0x18, 0x24, 0x24, 0x18, 0x18, 0x24, 0x24, 0x18, 0xFC, 0x7C, 0x08, 0x04, 0x04, 0x08, 0x48, 0x54, 0x54, 0x54, 0x24, 0x04, 0x04, 0x3F, 0x44, 0x24, 0x3C, 0x40, 0x40, 0x20, 0x7C, 0x1C, 0x20, 0x40, 0x20, 0x1C, 0x3C, 0x40, 0x30, 0x40, 0x3C,
- 0x44, 0x28, 0x10, 0x28, 0x44, 0x4C, 0x90, 0x90, 0x90, 0x7C, 0x44, 0x64, 0x54, 0x4C, 0x44, 0x00, 0x08, 0x36, 0x41, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x41, 0x36, 0x08, 0x00, 0x02, 0x01, 0x02, 0x04, 0x02, 0x3C, 0x26, 0x23, 0x26, 0x3C, 0x1E, 0xA1, 0xA1, 0x61, 0x12, 0x3A, 0x40, 0x40, 0x20, 0x7A, 0x38, 0x54, 0x54, 0x55, 0x59, 0x21, 0x55, 0x55, 0x79, 0x41, 0x22, 0x54, 0x54, 0x78, 0x42, // a-umlaut
- 0x21, 0x55, 0x54, 0x78, 0x40, 0x20, 0x54, 0x55, 0x79, 0x40, 0x0C, 0x1E, 0x52, 0x72, 0x12, 0x39, 0x55, 0x55, 0x55, 0x59, 0x39, 0x54, 0x54, 0x54, 0x59, 0x39, 0x55, 0x54, 0x54, 0x58, 0x00, 0x00, 0x45, 0x7C, 0x41, 0x00, 0x02, 0x45, 0x7D, 0x42, 0x00, 0x01, 0x45, 0x7C, 0x40, 0x7D, 0x12, 0x11, 0x12, 0x7D, // A-umlaut
- 0xF0, 0x28, 0x25, 0x28, 0xF0, 0x7C, 0x54, 0x55, 0x45, 0x00, 0x20, 0x54, 0x54, 0x7C, 0x54, 0x7C, 0x0A, 0x09, 0x7F, 0x49, 0x32, 0x49, 0x49, 0x49, 0x32, 0x3A, 0x44, 0x44, 0x44, 0x3A, // o-umlaut
- 0x32, 0x4A, 0x48, 0x48, 0x30, 0x3A, 0x41, 0x41, 0x21, 0x7A, 0x3A, 0x42, 0x40, 0x20, 0x78, 0x00, 0x9D, 0xA0, 0xA0, 0x7D, 0x3D, 0x42, 0x42, 0x42, 0x3D, // O-umlaut
- 0x3D, 0x40, 0x40, 0x40, 0x3D, 0x3C, 0x24, 0xFF, 0x24, 0x24, 0x48, 0x7E, 0x49, 0x43, 0x66, 0x2B, 0x2F, 0xFC, 0x2F, 0x2B, 0xFF, 0x09, 0x29, 0xF6, 0x20, 0xC0, 0x88, 0x7E, 0x09, 0x03, 0x20, 0x54, 0x54, 0x79, 0x41, 0x00, 0x00, 0x44, 0x7D, 0x41, 0x30, 0x48, 0x48, 0x4A, 0x32, 0x38, 0x40, 0x40, 0x22, 0x7A, 0x00, 0x7A, 0x0A, 0x0A, 0x72, 0x7D, 0x0D, 0x19, 0x31, 0x7D, 0x26, 0x29, 0x29, 0x2F, 0x28, 0x26, 0x29, 0x29, 0x29, 0x26, 0x30, 0x48, 0x4D, 0x40, 0x20, 0x38, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x38, 0x2F, 0x10, 0xC8, 0xAC, 0xBA, 0x2F, 0x10, 0x28, 0x34, 0xFA, 0x00, 0x00, 0x7B, 0x00, 0x00, 0x08, 0x14, 0x2A, 0x14, 0x22, 0x22, 0x14, 0x2A, 0x14, 0x08, 0x55, 0x00, 0x55, 0x00, 0x55, // #176 (25% block) missing in old code
- 0xAA, 0x55, 0xAA, 0x55, 0xAA, // 50% block
- 0xFF, 0x55, 0xFF, 0x55, 0xFF, // 75% block
+ 0x44, 0x28, 0x10, 0x28, 0x44, 0x4C, 0x90, 0x90, 0x90, 0x7C, 0x44, 0x64, 0x54, 0x4C, 0x44, 0x00, 0x08, 0x36, 0x41, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x41, 0x36, 0x08, 0x00, 0x02, 0x01, 0x02, 0x04, 0x02, 0x3C, 0x26, 0x23, 0x26, 0x3C, 0x1E, 0xA1, 0xA1, 0x61, 0x12, 0x3A, 0x40, 0x40, 0x20, 0x7A, 0x38, 0x54, 0x54, 0x55, 0x59, 0x21, 0x55, 0x55, 0x79, 0x41, 0x22, 0x54, 0x54, 0x78, 0x42, // a-umlaut
+ 0x21, 0x55, 0x54, 0x78, 0x40, 0x20, 0x54, 0x55, 0x79, 0x40, 0x0C, 0x1E, 0x52, 0x72, 0x12, 0x39, 0x55, 0x55, 0x55, 0x59, 0x39, 0x54, 0x54, 0x54, 0x59, 0x39, 0x55, 0x54, 0x54, 0x58, 0x00, 0x00, 0x45, 0x7C, 0x41, 0x00, 0x02, 0x45, 0x7D, 0x42, 0x00, 0x01, 0x45, 0x7C, 0x40, 0x7D, 0x12, 0x11, 0x12, 0x7D, // A-umlaut
+ 0xF0, 0x28, 0x25, 0x28, 0xF0, 0x7C, 0x54, 0x55, 0x45, 0x00, 0x20, 0x54, 0x54, 0x7C, 0x54, 0x7C, 0x0A, 0x09, 0x7F, 0x49, 0x32, 0x49, 0x49, 0x49, 0x32, 0x3A, 0x44, 0x44, 0x44, 0x3A, // o-umlaut
+ 0x32, 0x4A, 0x48, 0x48, 0x30, 0x3A, 0x41, 0x41, 0x21, 0x7A, 0x3A, 0x42, 0x40, 0x20, 0x78, 0x00, 0x9D, 0xA0, 0xA0, 0x7D, 0x3D, 0x42, 0x42, 0x42, 0x3D, // O-umlaut
+ 0x3D, 0x40, 0x40, 0x40, 0x3D, 0x3C, 0x24, 0xFF, 0x24, 0x24, 0x48, 0x7E, 0x49, 0x43, 0x66, 0x2B, 0x2F, 0xFC, 0x2F, 0x2B, 0xFF, 0x09, 0x29, 0xF6, 0x20, 0xC0, 0x88, 0x7E, 0x09, 0x03, 0x20, 0x54, 0x54, 0x79, 0x41, 0x00, 0x00, 0x44, 0x7D, 0x41, 0x30, 0x48, 0x48, 0x4A, 0x32, 0x38, 0x40, 0x40, 0x22, 0x7A, 0x00, 0x7A, 0x0A, 0x0A, 0x72, 0x7D, 0x0D, 0x19, 0x31, 0x7D, 0x26, 0x29, 0x29, 0x2F, 0x28, 0x26, 0x29, 0x29, 0x29, 0x26, 0x30, 0x48, 0x4D, 0x40, 0x20, 0x38, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x38, 0x2F, 0x10, 0xC8, 0xAC, 0xBA, 0x2F, 0x10, 0x28, 0x34, 0xFA, 0x00, 0x00, 0x7B, 0x00, 0x00, 0x08, 0x14, 0x2A, 0x14, 0x22, 0x22, 0x14, 0x2A, 0x14, 0x08, 0x55, 0x00, 0x55, 0x00, 0x55, // #176 (25% block) missing in old code
+ 0xAA, 0x55, 0xAA, 0x55, 0xAA, // 50% block
+ 0xFF, 0x55, 0xFF, 0x55, 0xFF, // 75% block
0x00, 0x00, 0x00, 0xFF, 0x00, 0x10, 0x10, 0x10, 0xFF, 0x00, 0x14, 0x14, 0x14, 0xFF, 0x00, 0x10, 0x10, 0xFF, 0x00, 0xFF, 0x10, 0x10, 0xF0, 0x10, 0xF0, 0x14, 0x14, 0x14, 0xFC, 0x00, 0x14, 0x14, 0xF7, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x14, 0x14, 0xF4, 0x04, 0xFC, 0x14, 0x14, 0x17, 0x10, 0x1F, 0x10, 0x10, 0x1F, 0x10, 0x1F, 0x14, 0x14, 0x14, 0x1F, 0x00, 0x10, 0x10, 0x10, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x10, 0x10, 0x10, 0x10, 0x1F, 0x10, 0x10, 0x10, 0x10, 0xF0, 0x10, 0x00, 0x00, 0x00, 0xFF, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0xFF, 0x10, 0x00, 0x00, 0x00, 0xFF, 0x14, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x1F, 0x10, 0x17, 0x00, 0x00, 0xFC, 0x04, 0xF4, 0x14, 0x14, 0x17, 0x10, 0x17, 0x14, 0x14, 0xF4, 0x04, 0xF4, 0x00, 0x00, 0xFF, 0x00, 0xF7, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0xF7, 0x00, 0xF7, 0x14, 0x14, 0x14, 0x17, 0x14, 0x10, 0x10, 0x1F, 0x10, 0x1F,
- 0x14, 0x14, 0x14, 0xF4, 0x14, 0x10, 0x10, 0xF0, 0x10, 0xF0, 0x00, 0x00, 0x1F, 0x10, 0x1F, 0x00, 0x00, 0x00, 0x1F, 0x14, 0x00, 0x00, 0x00, 0xFC, 0x14, 0x00, 0x00, 0xF0, 0x10, 0xF0, 0x10, 0x10, 0xFF, 0x10, 0xFF, 0x14, 0x14, 0x14, 0xFF, 0x14, 0x10, 0x10, 0x10, 0x1F, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x10, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x38, 0x44, 0x44, 0x38, 0x44, 0xFC, 0x4A, 0x4A, 0x4A, 0x34, // sharp-s or beta
- 0x7E, 0x02, 0x02, 0x06, 0x06, 0x02, 0x7E, 0x02, 0x7E, 0x02, 0x63, 0x55, 0x49, 0x41, 0x63, 0x38, 0x44, 0x44, 0x3C, 0x04, 0x40, 0x7E, 0x20, 0x1E, 0x20, 0x06, 0x02, 0x7E, 0x02, 0x02, 0x99, 0xA5, 0xE7, 0xA5, 0x99, 0x1C, 0x2A, 0x49, 0x2A, 0x1C, 0x4C, 0x72, 0x01, 0x72, 0x4C, 0x30, 0x4A, 0x4D, 0x4D, 0x30, 0x30, 0x48, 0x78, 0x48, 0x30, 0xBC, 0x62, 0x5A, 0x46, 0x3D, 0x3E, 0x49, 0x49, 0x49, 0x00, 0x7E, 0x01, 0x01, 0x01, 0x7E, 0x2A, 0x2A, 0x2A, 0x2A, 0x2A, 0x44, 0x44, 0x5F, 0x44, 0x44, 0x40, 0x51, 0x4A, 0x44, 0x40, 0x40, 0x44, 0x4A, 0x51, 0x40, 0x00, 0x00, 0xFF, 0x01, 0x03, 0xE0, 0x80, 0xFF, 0x00, 0x00, 0x08, 0x08, 0x6B, 0x6B, 0x08, 0x36, 0x12, 0x36, 0x24, 0x36, 0x06, 0x0F, 0x09, 0x0F, 0x06, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x30, 0x40, 0xFF, 0x01, 0x01, 0x00, 0x1F, 0x01, 0x01, 0x1E, 0x00, 0x19, 0x1D, 0x17, 0x12, 0x00, 0x3C, 0x3C, 0x3C, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00 // #255 NBSP
+ 0x14, 0x14, 0x14, 0xF4, 0x14, 0x10, 0x10, 0xF0, 0x10, 0xF0, 0x00, 0x00, 0x1F, 0x10, 0x1F, 0x00, 0x00, 0x00, 0x1F, 0x14, 0x00, 0x00, 0x00, 0xFC, 0x14, 0x00, 0x00, 0xF0, 0x10, 0xF0, 0x10, 0x10, 0xFF, 0x10, 0xFF, 0x14, 0x14, 0x14, 0xFF, 0x14, 0x10, 0x10, 0x10, 0x1F, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x10, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x38, 0x44, 0x44, 0x38, 0x44, 0xFC, 0x4A, 0x4A, 0x4A, 0x34, // sharp-s or beta
+ 0x7E, 0x02, 0x02, 0x06, 0x06, 0x02, 0x7E, 0x02, 0x7E, 0x02, 0x63, 0x55, 0x49, 0x41, 0x63, 0x38, 0x44, 0x44, 0x3C, 0x04, 0x40, 0x7E, 0x20, 0x1E, 0x20, 0x06, 0x02, 0x7E, 0x02, 0x02, 0x99, 0xA5, 0xE7, 0xA5, 0x99, 0x1C, 0x2A, 0x49, 0x2A, 0x1C, 0x4C, 0x72, 0x01, 0x72, 0x4C, 0x30, 0x4A, 0x4D, 0x4D, 0x30, 0x30, 0x48, 0x78, 0x48, 0x30, 0xBC, 0x62, 0x5A, 0x46, 0x3D, 0x3E, 0x49, 0x49, 0x49, 0x00, 0x7E, 0x01, 0x01, 0x01, 0x7E, 0x2A, 0x2A, 0x2A, 0x2A, 0x2A, 0x44, 0x44, 0x5F, 0x44, 0x44, 0x40, 0x51, 0x4A, 0x44, 0x40, 0x40, 0x44, 0x4A, 0x51, 0x40, 0x00, 0x00, 0xFF, 0x01, 0x03, 0xE0, 0x80, 0xFF, 0x00, 0x00, 0x08, 0x08, 0x6B, 0x6B, 0x08, 0x36, 0x12, 0x36, 0x24, 0x36, 0x06, 0x0F, 0x09, 0x0F, 0x06, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x30, 0x40, 0xFF, 0x01, 0x01, 0x00, 0x1F, 0x01, 0x01, 0x1E, 0x00, 0x19, 0x1D, 0x17, 0x12, 0x00, 0x3C, 0x3C, 0x3C, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00 // #255 NBSP
};
diff --git a/platforms/avr/drivers/hd44780.c b/platforms/avr/drivers/hd44780.c
index f71069dece..f15d7d0da8 100644
--- a/platforms/avr/drivers/hd44780.c
+++ b/platforms/avr/drivers/hd44780.c
@@ -262,7 +262,7 @@ static uint8_t lcd_waitbusy(void)
delay(LCD_DELAY_BUSY_FLAG);
/* now read the address counter */
- return (lcd_read(0)); // return address counter
+ return (lcd_read(0)); // return address counter
} /* lcd_waitbusy */
@@ -362,17 +362,23 @@ void lcd_gotoxy(uint8_t x, uint8_t y) {
/*************************************************************************
*************************************************************************/
-int lcd_getxy(void) { return lcd_waitbusy(); }
+int lcd_getxy(void) {
+ return lcd_waitbusy();
+}
/*************************************************************************
Clear display and set cursor to home position
*************************************************************************/
-void lcd_clrscr(void) { lcd_command(1 << LCD_CLR); }
+void lcd_clrscr(void) {
+ lcd_command(1 << LCD_CLR);
+}
/*************************************************************************
Set cursor to home position
*************************************************************************/
-void lcd_home(void) { lcd_command(1 << LCD_HOME); }
+void lcd_home(void) {
+ lcd_command(1 << LCD_HOME);
+}
/*************************************************************************
Display character at current cursor position
@@ -382,7 +388,7 @@ Returns: none
void lcd_putc(char c) {
uint8_t pos;
- pos = lcd_waitbusy(); // read busy-flag and address counter
+ pos = lcd_waitbusy(); // read busy-flag and address counter
if (c == '\n') {
lcd_newline(pos);
} else {
@@ -483,8 +489,8 @@ void lcd_init(uint8_t dispAttr) {
delay(LCD_DELAY_BOOTUP); /* wait 16ms or more after power-on */
/* initial write to lcd is 8bit */
- LCD_DATA1_PORT |= _BV(LCD_DATA1_PIN); // LCD_FUNCTION>>4;
- LCD_DATA0_PORT |= _BV(LCD_DATA0_PIN); // LCD_FUNCTION_8BIT>>4;
+ LCD_DATA1_PORT |= _BV(LCD_DATA1_PIN); // LCD_FUNCTION>>4;
+ LCD_DATA0_PORT |= _BV(LCD_DATA0_PIN); // LCD_FUNCTION_8BIT>>4;
lcd_e_toggle();
delay(LCD_DELAY_INIT); /* delay, busy flag can't be checked here */
@@ -497,7 +503,7 @@ void lcd_init(uint8_t dispAttr) {
delay(LCD_DELAY_INIT_REP); /* delay, busy flag can't be checked here */
/* now configure for 4bit mode */
- LCD_DATA0_PORT &= ~_BV(LCD_DATA0_PIN); // LCD_FUNCTION_4BIT_1LINE>>4
+ LCD_DATA0_PORT &= ~_BV(LCD_DATA0_PIN); // LCD_FUNCTION_4BIT_1LINE>>4
lcd_e_toggle();
delay(LCD_DELAY_INIT_4BIT); /* some displays need this additional delay */
diff --git a/platforms/avr/drivers/i2c_master.c b/platforms/avr/drivers/i2c_master.c
index 111b55d6b0..c1a7b5f72d 100644
--- a/platforms/avr/drivers/i2c_master.c
+++ b/platforms/avr/drivers/i2c_master.c
@@ -25,12 +25,15 @@
#include "wait.h"
#ifndef F_SCL
-# define F_SCL 400000UL // SCL frequency
+# define F_SCL 400000UL // SCL frequency
#endif
#ifndef I2C_START_RETRY_COUNT
# define I2C_START_RETRY_COUNT 20
-#endif // I2C_START_RETRY_COUNT
+#endif // I2C_START_RETRY_COUNT
+
+#define I2C_ACTION_READ 0x01
+#define I2C_ACTION_WRITE 0x00
#define TWBR_val (((F_CPU / F_SCL) - 16) / 2)
@@ -95,7 +98,7 @@ static i2c_status_t i2c_start_impl(uint8_t address, uint16_t timeout) {
i2c_status_t i2c_start(uint8_t address, uint16_t timeout) {
// Retry i2c_start_impl a bunch times in case the remote side has interrupts disabled.
uint16_t timeout_timer = timer_read();
- uint16_t time_slice = MAX(1, (timeout == (I2C_TIMEOUT_INFINITE)) ? 5 : (timeout / (I2C_START_RETRY_COUNT))); // if it's infinite, wait 1ms between attempts, otherwise split up the entire timeout into the number of retries
+ uint16_t time_slice = MAX(1, (timeout == (I2C_TIMEOUT_INFINITE)) ? 5 : (timeout / (I2C_START_RETRY_COUNT))); // if it's infinite, wait 1ms between attempts, otherwise split up the entire timeout into the number of retries
i2c_status_t status;
do {
status = i2c_start_impl(address, time_slice);
@@ -154,7 +157,7 @@ int16_t i2c_read_nack(uint16_t timeout) {
}
i2c_status_t i2c_transmit(uint8_t address, const uint8_t* data, uint16_t length, uint16_t timeout) {
- i2c_status_t status = i2c_start(address | I2C_WRITE, timeout);
+ i2c_status_t status = i2c_start(address | I2C_ACTION_WRITE, timeout);
for (uint16_t i = 0; i < length && status >= 0; i++) {
status = i2c_write(data[i], timeout);
@@ -166,7 +169,7 @@ i2c_status_t i2c_transmit(uint8_t address, const uint8_t* data, uint16_t length,
}
i2c_status_t i2c_receive(uint8_t address, uint8_t* data, uint16_t length, uint16_t timeout) {
- i2c_status_t status = i2c_start(address | I2C_READ, timeout);
+ i2c_status_t status = i2c_start(address | I2C_ACTION_READ, timeout);
for (uint16_t i = 0; i < (length - 1) && status >= 0; i++) {
status = i2c_read_ack(timeout);
diff --git a/platforms/avr/drivers/i2c_slave.c b/platforms/avr/drivers/i2c_slave.c
index 2907f164c0..660d271be2 100644
--- a/platforms/avr/drivers/i2c_slave.c
+++ b/platforms/avr/drivers/i2c_slave.c
@@ -29,7 +29,7 @@
# include "transactions.h"
static volatile bool is_callback_executor = false;
-#endif // defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
+#endif // defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
volatile uint8_t i2c_slave_reg[I2C_SLAVE_REG_COUNT];
@@ -57,7 +57,7 @@ ISR(TWI_vect) {
slave_has_register_set = false;
#if defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
is_callback_executor = false;
-#endif // defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
+#endif // defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
break;
case TW_SR_DATA_ACK:
@@ -66,16 +66,16 @@ ISR(TWI_vect) {
if (!slave_has_register_set) {
buffer_address = TWDR;
- if (buffer_address >= I2C_SLAVE_REG_COUNT) { // address out of bounds dont ack
+ if (buffer_address >= I2C_SLAVE_REG_COUNT) { // address out of bounds dont ack
ack = 0;
buffer_address = 0;
}
- slave_has_register_set = true; // address has been received now fill in buffer
+ slave_has_register_set = true; // address has been received now fill in buffer
#if defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
// Work out if we're attempting to execute a callback
is_callback_executor = buffer_address == split_transaction_table[I2C_EXECUTE_CALLBACK].initiator2target_offset;
-#endif // defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
+#endif // defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
} else {
i2c_slave_reg[buffer_address] = TWDR;
buffer_address++;
@@ -88,7 +88,7 @@ ISR(TWI_vect) {
trans->slave_callback(trans->initiator2target_buffer_size, split_trans_initiator2target_buffer(trans), trans->target2initiator_buffer_size, split_trans_target2initiator_buffer(trans));
}
}
-#endif // defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
+#endif // defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
}
break;
diff --git a/platforms/avr/drivers/i2c_slave.h b/platforms/avr/drivers/i2c_slave.h
index a8647c9da3..178b6a29df 100644
--- a/platforms/avr/drivers/i2c_slave.h
+++ b/platforms/avr/drivers/i2c_slave.h
@@ -27,11 +27,11 @@
# if defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
# include "transport.h"
# define I2C_SLAVE_REG_COUNT sizeof(split_shared_memory_t)
-# else // defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
+# else // defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
# define I2C_SLAVE_REG_COUNT 30
-# endif // defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
+# endif // defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
-#endif // I2C_SLAVE_REG_COUNT
+#endif // I2C_SLAVE_REG_COUNT
_Static_assert(I2C_SLAVE_REG_COUNT < 256, "I2C target registers must be single byte");
diff --git a/platforms/avr/drivers/ps2/ps2_io.c b/platforms/avr/drivers/ps2/ps2_io.c
index 7c826fbf1a..b75a1ab0be 100644
--- a/platforms/avr/drivers/ps2/ps2_io.c
+++ b/platforms/avr/drivers/ps2/ps2_io.c
@@ -23,7 +23,9 @@ void clock_lo(void) {
setPinOutput(PS2_CLOCK_PIN);
}
-void clock_hi(void) { setPinInputHigh(PS2_CLOCK_PIN); }
+void clock_hi(void) {
+ setPinInputHigh(PS2_CLOCK_PIN);
+}
bool clock_in(void) {
setPinInputHigh(PS2_CLOCK_PIN);
@@ -42,7 +44,9 @@ void data_lo(void) {
setPinOutput(PS2_DATA_PIN);
}
-void data_hi(void) { setPinInputHigh(PS2_DATA_PIN); }
+void data_hi(void) {
+ setPinInputHigh(PS2_DATA_PIN);
+}
bool data_in(void) {
setPinInputHigh(PS2_DATA_PIN);
diff --git a/platforms/avr/drivers/ps2/ps2_usart.c b/platforms/avr/drivers/ps2/ps2_usart.c
index 151cfcd68f..39ec930d4a 100644
--- a/platforms/avr/drivers/ps2/ps2_usart.c
+++ b/platforms/avr/drivers/ps2/ps2_usart.c
@@ -76,7 +76,7 @@ static inline bool pbuf_has_data(void);
static inline void pbuf_clear(void);
void ps2_host_init(void) {
- idle(); // without this many USART errors occur when cable is disconnected
+ idle(); // without this many USART errors occur when cable is disconnected
PS2_USART_INIT();
PS2_USART_RX_INT_ON();
// POR(150-2000ms) plus BAT(300-500ms) may take 2.5sec([3]p.20)
@@ -91,12 +91,12 @@ uint8_t ps2_host_send(uint8_t data) {
/* terminate a transmission if we have */
inhibit();
- _delay_us(100); // [4]p.13
+ _delay_us(100); // [4]p.13
/* 'Request to Send' and Start bit */
data_lo();
clock_hi();
- WAIT(clock_lo, 10000, 10); // 10ms [5]p.50
+ WAIT(clock_lo, 10000, 10); // 10ms [5]p.50
/* Data bit[2-9] */
for (uint8_t i = 0; i < 8; i++) {
@@ -165,7 +165,7 @@ uint8_t ps2_host_recv(void) {
ISR(PS2_USART_RX_VECT) {
// TODO: request RESEND when error occurs?
- uint8_t error = PS2_USART_ERROR; // USART error should be read before data
+ uint8_t error = PS2_USART_ERROR; // USART error should be read before data
uint8_t data = PS2_USART_RX_DATA;
if (!error) {
pbuf_enqueue(data);
diff --git a/platforms/avr/drivers/serial.c b/platforms/avr/drivers/serial.c
index 9a7345a53d..6a36aa5f7f 100644
--- a/platforms/avr/drivers/serial.c
+++ b/platforms/avr/drivers/serial.c
@@ -16,6 +16,7 @@
#include <util/delay.h>
#include <stddef.h>
#include <stdbool.h>
+#include "gpio.h"
#include "serial.h"
#ifdef SOFT_SERIAL_PIN
@@ -119,12 +120,6 @@
# error invalid SOFT_SERIAL_PIN value
# endif
-# define setPinInputHigh(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) |= _BV((pin)&0xF))
-# define setPinOutput(pin) (DDRx_ADDRESS(pin) |= _BV((pin)&0xF))
-# define writePinHigh(pin) (PORTx_ADDRESS(pin) |= _BV((pin)&0xF))
-# define writePinLow(pin) (PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF))
-# define readPin(pin) ((bool)(PINx_ADDRESS(pin) & _BV((pin)&0xF)))
-
# define ALWAYS_INLINE __attribute__((always_inline))
# define NO_INLINE __attribute__((noinline))
# define _delay_sub_us(x) __builtin_avr_delay_cycles(x)
@@ -161,59 +156,59 @@
# if SELECT_SOFT_SERIAL_SPEED == 0
// Very High speed
-# define SERIAL_DELAY 4 // micro sec
+# define SERIAL_DELAY 4 // micro sec
# if __GNUC__ < 6
-# define READ_WRITE_START_ADJUST 33 // cycles
-# define READ_WRITE_WIDTH_ADJUST 3 // cycles
+# define READ_WRITE_START_ADJUST 33 // cycles
+# define READ_WRITE_WIDTH_ADJUST 3 // cycles
# else
-# define READ_WRITE_START_ADJUST 34 // cycles
-# define READ_WRITE_WIDTH_ADJUST 7 // cycles
+# define READ_WRITE_START_ADJUST 34 // cycles
+# define READ_WRITE_WIDTH_ADJUST 7 // cycles
# endif
# elif SELECT_SOFT_SERIAL_SPEED == 1
// High speed
-# define SERIAL_DELAY 6 // micro sec
+# define SERIAL_DELAY 6 // micro sec
# if __GNUC__ < 6
-# define READ_WRITE_START_ADJUST 30 // cycles
-# define READ_WRITE_WIDTH_ADJUST 3 // cycles
+# define READ_WRITE_START_ADJUST 30 // cycles
+# define READ_WRITE_WIDTH_ADJUST 3 // cycles
# else
-# define READ_WRITE_START_ADJUST 33 // cycles
-# define READ_WRITE_WIDTH_ADJUST 7 // cycles
+# define READ_WRITE_START_ADJUST 33 // cycles
+# define READ_WRITE_WIDTH_ADJUST 7 // cycles
# endif
# elif SELECT_SOFT_SERIAL_SPEED == 2
// Middle speed
-# define SERIAL_DELAY 12 // micro sec
-# define READ_WRITE_START_ADJUST 30 // cycles
+# define SERIAL_DELAY 12 // micro sec
+# define READ_WRITE_START_ADJUST 30 // cycles
# if __GNUC__ < 6
-# define READ_WRITE_WIDTH_ADJUST 3 // cycles
+# define READ_WRITE_WIDTH_ADJUST 3 // cycles
# else
-# define READ_WRITE_WIDTH_ADJUST 7 // cycles
+# define READ_WRITE_WIDTH_ADJUST 7 // cycles
# endif
# elif SELECT_SOFT_SERIAL_SPEED == 3
// Low speed
-# define SERIAL_DELAY 24 // micro sec
-# define READ_WRITE_START_ADJUST 30 // cycles
+# define SERIAL_DELAY 24 // micro sec
+# define READ_WRITE_START_ADJUST 30 // cycles
# if __GNUC__ < 6
-# define READ_WRITE_WIDTH_ADJUST 3 // cycles
+# define READ_WRITE_WIDTH_ADJUST 3 // cycles
# else
-# define READ_WRITE_WIDTH_ADJUST 7 // cycles
+# define READ_WRITE_WIDTH_ADJUST 7 // cycles
# endif
# elif SELECT_SOFT_SERIAL_SPEED == 4
// Very Low speed
-# define SERIAL_DELAY 36 // micro sec
-# define READ_WRITE_START_ADJUST 30 // cycles
+# define SERIAL_DELAY 36 // micro sec
+# define READ_WRITE_START_ADJUST 30 // cycles
# if __GNUC__ < 6
-# define READ_WRITE_WIDTH_ADJUST 3 // cycles
+# define READ_WRITE_WIDTH_ADJUST 3 // cycles
# else
-# define READ_WRITE_WIDTH_ADJUST 7 // cycles
+# define READ_WRITE_WIDTH_ADJUST 7 // cycles
# endif
# elif SELECT_SOFT_SERIAL_SPEED == 5
// Ultra Low speed
-# define SERIAL_DELAY 48 // micro sec
-# define READ_WRITE_START_ADJUST 30 // cycles
+# define SERIAL_DELAY 48 // micro sec
+# define READ_WRITE_START_ADJUST 30 // cycles
# if __GNUC__ < 6
-# define READ_WRITE_WIDTH_ADJUST 3 // cycles
+# define READ_WRITE_WIDTH_ADJUST 3 // cycles
# else
-# define READ_WRITE_WIDTH_ADJUST 7 // cycles
+# define READ_WRITE_WIDTH_ADJUST 7 // cycles
# endif
# else
# error invalid SELECT_SOFT_SERIAL_SPEED value
@@ -228,29 +223,45 @@
# define SLAVE_INT_ACK_WIDTH 4
inline static void serial_delay(void) ALWAYS_INLINE;
-inline static void serial_delay(void) { _delay_us(SERIAL_DELAY); }
+inline static void serial_delay(void) {
+ _delay_us(SERIAL_DELAY);
+}
inline static void serial_delay_half1(void) ALWAYS_INLINE;
-inline static void serial_delay_half1(void) { _delay_us(SERIAL_DELAY_HALF1); }
+inline static void serial_delay_half1(void) {
+ _delay_us(SERIAL_DELAY_HALF1);
+}
inline static void serial_delay_half2(void) ALWAYS_INLINE;
-inline static void serial_delay_half2(void) { _delay_us(SERIAL_DELAY_HALF2); }
+inline static void serial_delay_half2(void) {
+ _delay_us(SERIAL_DELAY_HALF2);
+}
inline static void serial_output(void) ALWAYS_INLINE;
-inline static void serial_output(void) { setPinOutput(SOFT_SERIAL_PIN); }
+inline static void serial_output(void) {
+ setPinOutput(SOFT_SERIAL_PIN);
+}
// make the serial pin an input with pull-up resistor
inline static void serial_input_with_pullup(void) ALWAYS_INLINE;
-inline static void serial_input_with_pullup(void) { setPinInputHigh(SOFT_SERIAL_PIN); }
+inline static void serial_input_with_pullup(void) {
+ setPinInputHigh(SOFT_SERIAL_PIN);
+}
inline static uint8_t serial_read_pin(void) ALWAYS_INLINE;
-inline static uint8_t serial_read_pin(void) { return !!readPin(SOFT_SERIAL_PIN); }
+inline static uint8_t serial_read_pin(void) {
+ return !!readPin(SOFT_SERIAL_PIN);
+}
inline static void serial_low(void) ALWAYS_INLINE;
-inline static void serial_low(void) { writePinLow(SOFT_SERIAL_PIN); }
+inline static void serial_low(void) {
+ writePinLow(SOFT_SERIAL_PIN);
+}
inline static void serial_high(void) ALWAYS_INLINE;
-inline static void serial_high(void) { writePinHigh(SOFT_SERIAL_PIN); }
+inline static void serial_high(void) {
+ writePinHigh(SOFT_SERIAL_PIN);
+}
void soft_serial_initiator_init(void) {
serial_output();
@@ -291,7 +302,7 @@ static uint8_t serial_read_chunk(uint8_t *pterrcount, uint8_t bit) {
_delay_sub_us(READ_WRITE_START_ADJUST);
for (i = 0, byte = 0, p = PARITY; i < bit; i++) {
- serial_delay_half1(); // read the middle of pulses
+ serial_delay_half1(); // read the middle of pulses
if (serial_read_pin()) {
byte = (byte << 1) | 1;
p ^= 1;
@@ -303,7 +314,7 @@ static uint8_t serial_read_chunk(uint8_t *pterrcount, uint8_t bit) {
serial_delay_half2();
}
/* recive parity bit */
- serial_delay_half1(); // read the middle of pulses
+ serial_delay_half1(); // read the middle of pulses
pb = serial_read_pin();
_delay_sub_us(READ_WRITE_WIDTH_ADJUST);
serial_delay_half2();
@@ -335,7 +346,7 @@ void serial_write_chunk(uint8_t data, uint8_t bit) {
}
serial_delay();
- serial_low(); // sync_send() / senc_recv() need raise edge
+ serial_low(); // sync_send() / senc_recv() need raise edge
}
static void serial_send_packet(uint8_t *buffer, uint8_t size) NO_INLINE;
@@ -361,19 +372,19 @@ static uint8_t serial_recive_packet(uint8_t *buffer, uint8_t size) {
}
inline static void change_sender2reciver(void) {
- sync_send(); // 0
- serial_delay_half1(); // 1
- serial_low(); // 2
- serial_input_with_pullup(); // 2
- serial_delay_half1(); // 3
+ sync_send(); // 0
+ serial_delay_half1(); // 1
+ serial_low(); // 2
+ serial_input_with_pullup(); // 2
+ serial_delay_half1(); // 3
}
inline static void change_reciver2sender(void) {
- sync_recv(); // 0
- serial_delay(); // 1
- serial_low(); // 3
- serial_output(); // 3
- serial_delay_half1(); // 4
+ sync_recv(); // 0
+ serial_delay(); // 1
+ serial_low(); // 3
+ serial_output(); // 3
+ serial_delay_half1(); // 4
}
static inline uint8_t nibble_bits_count(uint8_t bits) {
@@ -396,11 +407,11 @@ ISR(SERIAL_PIN_INTERRUPT) {
}
serial_delay_half1();
- serial_high(); // response step1 low->high
+ serial_high(); // response step1 low->high
serial_output();
_delay_sub_us(SLAVE_INT_ACK_WIDTH_UNIT * SLAVE_INT_ACK_WIDTH);
split_transaction_desc_t *trans = &split_transaction_table[tid];
- serial_low(); // response step2 ack high->low
+ serial_low(); // response step2 ack high->low
// If the transaction has a callback, we can execute it now
if (trans->slave_callback) {
@@ -414,34 +425,22 @@ ISR(SERIAL_PIN_INTERRUPT) {
// target recive phase
if (trans->initiator2target_buffer_size > 0) {
- if (serial_recive_packet((uint8_t *)split_trans_initiator2target_buffer(trans), trans->initiator2target_buffer_size)) {
- *trans->status = TRANSACTION_ACCEPTED;
- } else {
- *trans->status = TRANSACTION_DATA_ERROR;
- }
- } else {
- *trans->status = TRANSACTION_ACCEPTED;
+ serial_recive_packet((uint8_t *)split_trans_initiator2target_buffer(trans), trans->initiator2target_buffer_size);
}
- sync_recv(); // weit initiator output to high
+ sync_recv(); // weit initiator output to high
}
/////////
// start transaction by initiator
//
-// int soft_serial_transaction(int sstd_index)
+// bool soft_serial_transaction(int sstd_index)
//
-// Returns:
-// TRANSACTION_END
-// TRANSACTION_NO_RESPONSE
-// TRANSACTION_DATA_ERROR
// this code is very time dependent, so we need to disable interrupts
-int soft_serial_transaction(int sstd_index) {
- if (sstd_index > NUM_TOTAL_TRANSACTIONS) return TRANSACTION_TYPE_ERROR;
+bool soft_serial_transaction(int sstd_index) {
+ if (sstd_index > NUM_TOTAL_TRANSACTIONS) return false;
split_transaction_desc_t *trans = &split_transaction_table[sstd_index];
- if (!trans->status) return TRANSACTION_TYPE_ERROR; // not registered
-
cli();
// signal to the target that we want to start a transaction
@@ -468,9 +467,8 @@ int soft_serial_transaction(int sstd_index) {
// slave failed to pull the line low, assume not present
serial_output();
serial_high();
- *trans->status = TRANSACTION_NO_RESPONSE;
sei();
- return TRANSACTION_NO_RESPONSE;
+ return false;
}
_delay_sub_us(SLAVE_INT_ACK_WIDTH_UNIT);
}
@@ -481,9 +479,8 @@ int soft_serial_transaction(int sstd_index) {
if (!serial_recive_packet((uint8_t *)split_trans_target2initiator_buffer(trans), trans->target2initiator_buffer_size)) {
serial_output();
serial_high();
- *trans->status = TRANSACTION_DATA_ERROR;
sei();
- return TRANSACTION_DATA_ERROR;
+ return false;
}
}
@@ -498,19 +495,8 @@ int soft_serial_transaction(int sstd_index) {
// always, release the line when not in use
sync_send();
- *trans->status = TRANSACTION_END;
- sei();
- return TRANSACTION_END;
-}
-
-int soft_serial_get_and_clean_status(int sstd_index) {
- split_transaction_desc_t *trans = &split_transaction_table[sstd_index];
- cli();
- int retval = *trans->status;
- *trans->status = 0;
- ;
sei();
- return retval;
+ return true;
}
#endif
diff --git a/platforms/avr/drivers/spi_master.c b/platforms/avr/drivers/spi_master.c
index 4e8fd3bcdf..ae9df03c02 100644
--- a/platforms/avr/drivers/spi_master.c
+++ b/platforms/avr/drivers/spi_master.c
@@ -125,7 +125,7 @@ spi_status_t spi_write(uint8_t data) {
}
spi_status_t spi_read() {
- SPDR = 0x00; // Dummy
+ SPDR = 0x00; // Dummy
uint16_t timeout_timer = timer_read();
while (!(SPSR & _BV(SPIF))) {
diff --git a/platforms/avr/drivers/ssd1306.c b/platforms/avr/drivers/ssd1306.c
index 1a09a2bcb7..7afbc09f00 100644
--- a/platforms/avr/drivers/ssd1306.c
+++ b/platforms/avr/drivers/ssd1306.c
@@ -161,7 +161,7 @@ bool iota_gfx_init(void) {
send_cmd1(DeActivateScroll);
send_cmd1(DisplayOn);
- send_cmd2(SetContrast, 0); // Dim
+ send_cmd2(SetContrast, 0); // Dim
clear_display();
@@ -226,7 +226,9 @@ void matrix_write_char(struct CharacterMatrix *matrix, uint8_t c) {
matrix_write_char_inner(matrix, c);
}
-void iota_gfx_write_char(uint8_t c) { matrix_write_char(&display, c); }
+void iota_gfx_write_char(uint8_t c) {
+ matrix_write_char(&display, c);
+}
void matrix_write(struct CharacterMatrix *matrix, const char *data) {
const char *end = data + strlen(data);
@@ -236,7 +238,9 @@ void matrix_write(struct CharacterMatrix *matrix, const char *data) {
}
}
-void iota_gfx_write(const char *data) { matrix_write(&display, data); }
+void iota_gfx_write(const char *data) {
+ matrix_write(&display, data);
+}
void matrix_write_P(struct CharacterMatrix *matrix, const char *data) {
while (true) {
@@ -249,7 +253,9 @@ void matrix_write_P(struct CharacterMatrix *matrix, const char *data) {
}
}
-void iota_gfx_write_P(const char *data) { matrix_write_P(&display, data); }
+void iota_gfx_write_P(const char *data) {
+ matrix_write_P(&display, data);
+}
void matrix_clear(struct CharacterMatrix *matrix) {
memset(matrix->display, ' ', sizeof(matrix->display));
@@ -257,7 +263,9 @@ void matrix_clear(struct CharacterMatrix *matrix) {
matrix->dirty = true;
}
-void iota_gfx_clear_screen(void) { matrix_clear(&display); }
+void iota_gfx_clear_screen(void) {
+ matrix_clear(&display);
+}
void matrix_render(struct CharacterMatrix *matrix) {
last_flush = timer_read();
@@ -301,7 +309,9 @@ done:
# endif
}
-void iota_gfx_flush(void) { matrix_render(&display); }
+void iota_gfx_flush(void) {
+ matrix_render(&display);
+}
__attribute__((weak)) void iota_gfx_task_user(void) {}
diff --git a/platforms/avr/drivers/uart.c b/platforms/avr/drivers/uart.c
index 01cf6b1fb8..fd5caf9a78 100644
--- a/platforms/avr/drivers/uart.c
+++ b/platforms/avr/drivers/uart.c
@@ -108,7 +108,7 @@ void uart_write(uint8_t data) {
// return immediately to avoid deadlock when interrupt is disabled(called from ISR)
if (tx_buffer_tail == i && (SREG & (1 << SREG_I)) == 0) return;
while (tx_buffer_tail == i)
- ; // wait until space in buffer
+ ; // wait until space in buffer
// cli();
tx_buffer[i] = data;
tx_buffer_head = i;
@@ -121,7 +121,7 @@ uint8_t uart_read(void) {
uint8_t data, i;
while (rx_buffer_head == rx_buffer_tail)
- ; // wait for character
+ ; // wait for character
i = rx_buffer_tail + 1;
if (i >= RX_BUFFER_SIZE) i = 0;
data = rx_buffer[i];
diff --git a/platforms/avr/drivers/ws2812.c b/platforms/avr/drivers/ws2812.c
index 9150b3c520..c461ab3ba7 100644
--- a/platforms/avr/drivers/ws2812.c
+++ b/platforms/avr/drivers/ws2812.c
@@ -110,7 +110,7 @@ static inline void ws2812_sendarray_mask(uint8_t *data, uint16_t datlen, uint8_t
asm volatile(" ldi %0,8 \n\t"
"loop%=: \n\t"
- " out %2,%3 \n\t" // '1' [01] '0' [01] - re
+ " out %2,%3 \n\t" // '1' [01] '0' [01] - re
#if (w1_nops & 1)
w_nop1
#endif
@@ -126,9 +126,9 @@ static inline void ws2812_sendarray_mask(uint8_t *data, uint16_t datlen, uint8_t
#if (w1_nops & 16)
w_nop16
#endif
- " sbrs %1,7 \n\t" // '1' [03] '0' [02]
- " out %2,%4 \n\t" // '1' [--] '0' [03] - fe-low
- " lsl %1 \n\t" // '1' [04] '0' [04]
+ " sbrs %1,7 \n\t" // '1' [03] '0' [02]
+ " out %2,%4 \n\t" // '1' [--] '0' [03] - fe-low
+ " lsl %1 \n\t" // '1' [04] '0' [04]
#if (w2_nops & 1)
w_nop1
#endif
@@ -144,7 +144,7 @@ static inline void ws2812_sendarray_mask(uint8_t *data, uint16_t datlen, uint8_t
#if (w2_nops & 16)
w_nop16
#endif
- " out %2,%4 \n\t" // '1' [+1] '0' [+1] - fe-high
+ " out %2,%4 \n\t" // '1' [+1] '0' [+1] - fe-high
#if (w3_nops & 1)
w_nop1
#endif
@@ -161,8 +161,8 @@ static inline void ws2812_sendarray_mask(uint8_t *data, uint16_t datlen, uint8_t
w_nop16
#endif
- " dec %0 \n\t" // '1' [+2] '0' [+2]
- " brne loop%=\n\t" // '1' [+3] '0' [+4]
+ " dec %0 \n\t" // '1' [+2] '0' [+2]
+ " brne loop%=\n\t" // '1' [+3] '0' [+4]
: "=&d"(ctr)
: "r"(curbyte), "I"(_SFR_IO_ADDR(PORTx_ADDRESS(RGB_DI_PIN))), "r"(maskhi), "r"(masklo));
}
diff --git a/platforms/avr/drivers/ws2812_i2c.c b/platforms/avr/drivers/ws2812_i2c.c
index 1c332e24b6..709f382254 100644
--- a/platforms/avr/drivers/ws2812_i2c.c
+++ b/platforms/avr/drivers/ws2812_i2c.c
@@ -13,7 +13,9 @@
# define WS2812_TIMEOUT 100
#endif
-void ws2812_init(void) { i2c_init(); }
+void ws2812_init(void) {
+ i2c_init();
+}
// Setleds for standard RGB
void ws2812_setleds(LED_TYPE *ledarray, uint16_t leds) {
diff --git a/platforms/avr/gpio.h b/platforms/avr/gpio.h
index e9be68491d..95f15c28dc 100644
--- a/platforms/avr/gpio.h
+++ b/platforms/avr/gpio.h
@@ -25,7 +25,9 @@ typedef uint8_t pin_t;
#define setPinInput(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF))
#define setPinInputHigh(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) |= _BV((pin)&0xF))
#define setPinInputLow(pin) _Static_assert(0, "AVR processors cannot implement an input as pull low")
-#define setPinOutput(pin) (DDRx_ADDRESS(pin) |= _BV((pin)&0xF))
+#define setPinOutputPushPull(pin) (DDRx_ADDRESS(pin) |= _BV((pin)&0xF))
+#define setPinOutputOpenDrain(pin) _Static_assert(0, "AVR platform does not implement an open-drain output")
+#define setPinOutput(pin) setPinOutputPushPull(pin)
#define writePinHigh(pin) (PORTx_ADDRESS(pin) |= _BV((pin)&0xF))
#define writePinLow(pin) (PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF))
@@ -34,16 +36,3 @@ typedef uint8_t pin_t;
#define readPin(pin) ((bool)(PINx_ADDRESS(pin) & _BV((pin)&0xF)))
#define togglePin(pin) (PORTx_ADDRESS(pin) ^= _BV((pin)&0xF))
-
-/* Operation of GPIO by port. */
-
-typedef uint8_t port_data_t;
-
-#define readPort(port) PINx_ADDRESS(port)
-
-#define setPortBitInput(port, bit) (DDRx_ADDRESS(port) &= ~_BV((bit)&0xF), PORTx_ADDRESS(port) &= ~_BV((bit)&0xF))
-#define setPortBitInputHigh(port, bit) (DDRx_ADDRESS(port) &= ~_BV((bit)&0xF), PORTx_ADDRESS(port) |= _BV((bit)&0xF))
-#define setPortBitOutput(port, bit) (DDRx_ADDRESS(port) |= _BV((bit)&0xF))
-
-#define writePortBitLow(port, bit) (PORTx_ADDRESS(port) &= ~_BV((bit)&0xF))
-#define writePortBitHigh(port, bit) (PORTx_ADDRESS(port) |= _BV((bit)&0xF))
diff --git a/platforms/avr/pin_defs.h b/platforms/avr/pin_defs.h
index 23d948041d..3889704a87 100644
--- a/platforms/avr/pin_defs.h
+++ b/platforms/avr/pin_defs.h
@@ -17,7 +17,7 @@
#include <avr/io.h>
-#define PORT_SHIFTER 4 // this may be 4 for all AVR chips
+#define PORT_SHIFTER 4 // this may be 4 for all AVR chips
// If you want to add more to this list, reference the PINx definitions in these header
// files: https://github.com/vancegroup-mirrors/avr-libc/tree/master/avr-libc/include/avr
diff --git a/platforms/avr/platform.mk b/platforms/avr/platform.mk
index b45108736f..4d9cafaeef 100644
--- a/platforms/avr/platform.mk
+++ b/platforms/avr/platform.mk
@@ -159,7 +159,7 @@ endif
bootloader:
ifeq ($(strip $(QMK_BOOTLOADER_TYPE)),)
- $(error Please set BOOTLOADER to "qmk-dfu" or "qmk-hid" first!)
+ $(call CATASTROPHIC_ERROR,Invalid BOOTLOADER,Please set BOOTLOADER to "qmk-dfu" or "qmk-hid" first!)
else
make -C lib/lufa/Bootloaders/$(QMK_BOOTLOADER_TYPE)/ clean
$(QMK_BIN) generate-dfu-header --quiet --keyboard $(KEYBOARD) --output lib/lufa/Bootloaders/$(QMK_BOOTLOADER_TYPE)/Keyboard.h
diff --git a/platforms/avr/printf.c b/platforms/avr/printf.c
index 9ad7a38693..062f70fa0b 100644
--- a/platforms/avr/printf.c
+++ b/platforms/avr/printf.c
@@ -17,4 +17,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "xprintf.h"
#include "sendchar.h"
-void print_set_sendchar(sendchar_func_t func) { xdev_out(func); }
+void print_set_sendchar(sendchar_func_t func) {
+ xdev_out(func);
+}
diff --git a/platforms/avr/sleep_led.c b/platforms/avr/sleep_led.c
index 9a3b52abe5..b05431633b 100644
--- a/platforms/avr/sleep_led.c
+++ b/platforms/avr/sleep_led.c
@@ -12,7 +12,7 @@
#if SLEEP_LED_TIMER == 1
# define TCCRxB TCCR1B
# define TIMERx_COMPA_vect TIMER1_COMPA_vect
-# if defined(__AVR_ATmega32A__) // This MCU has only one TIMSK register
+# if defined(__AVR_ATmega32A__) // This MCU has only one TIMSK register
# define TIMSKx TIMSK
# else
# define TIMSKx TIMSK1
diff --git a/platforms/avr/suspend.c b/platforms/avr/suspend.c
index b614746e6c..1a7cd3b4ab 100644
--- a/platforms/avr/suspend.c
+++ b/platforms/avr/suspend.c
@@ -2,12 +2,9 @@
#include <avr/sleep.h>
#include <avr/wdt.h>
#include <avr/interrupt.h>
-#include "matrix.h"
-#include "action.h"
#include "suspend.h"
+#include "action.h"
#include "timer.h"
-#include "led.h"
-#include "host.h"
#ifdef PROTOCOL_LUFA
# include "lufa.h"
@@ -16,19 +13,6 @@
# include "vusb.h"
#endif
-/** \brief Suspend idle
- *
- * FIXME: needs doc
- */
-void suspend_idle(uint8_t time) {
- cli();
- set_sleep_mode(SLEEP_MODE_IDLE);
- sleep_enable();
- sei();
- sleep_cpu();
- sleep_disable();
-}
-
// TODO: This needs some cleanup
#if !defined(NO_SUSPEND_POWER_DOWN) && defined(WDT_vect)
@@ -91,6 +75,18 @@ static void power_down(uint8_t wdto) {
// Disable watchdog after sleep
wdt_disable();
}
+
+/* watchdog timeout */
+ISR(WDT_vect) {
+ // compensate timer for sleep
+ switch (wdt_timeout) {
+ case WDTO_15MS:
+ timer_count += 15 + 2; // WDTO_15MS + 2(from observation)
+ break;
+ default:;
+ }
+}
+
#endif
/** \brief Suspend power down
@@ -115,18 +111,6 @@ void suspend_power_down(void) {
#endif
}
-__attribute__((weak)) void matrix_power_up(void) {}
-__attribute__((weak)) void matrix_power_down(void) {}
-bool suspend_wakeup_condition(void) {
- matrix_power_up();
- matrix_scan();
- matrix_power_down();
- for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
- if (matrix_get_row(r)) return true;
- }
- return false;
-}
-
/** \brief run immediately after wakeup
*
* FIXME: needs doc
@@ -137,16 +121,3 @@ void suspend_wakeup_init(void) {
suspend_wakeup_init_quantum();
}
-
-#if !defined(NO_SUSPEND_POWER_DOWN) && defined(WDT_vect)
-/* watchdog timeout */
-ISR(WDT_vect) {
- // compensate timer for sleep
- switch (wdt_timeout) {
- case WDTO_15MS:
- timer_count += 15 + 2; // WDTO_15MS + 2(from observation)
- break;
- default:;
- }
-}
-#endif
diff --git a/platforms/avr/timer.c b/platforms/avr/timer.c
index c2e6c6e081..9fb671ae8d 100644
--- a/platforms/avr/timer.c
+++ b/platforms/avr/timer.c
@@ -73,7 +73,9 @@ void timer_init(void) {
* FIXME: needs doc
*/
inline void timer_clear(void) {
- ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { timer_count = 0; }
+ ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
+ timer_count = 0;
+ }
}
/** \brief timer read
@@ -83,7 +85,9 @@ inline void timer_clear(void) {
inline uint16_t timer_read(void) {
uint32_t t;
- ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { t = timer_count; }
+ ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
+ t = timer_count;
+ }
return (t & 0xFFFF);
}
@@ -95,7 +99,9 @@ inline uint16_t timer_read(void) {
inline uint32_t timer_read32(void) {
uint32_t t;
- ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { t = timer_count; }
+ ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
+ t = timer_count;
+ }
return t;
}
@@ -107,7 +113,9 @@ inline uint32_t timer_read32(void) {
inline uint16_t timer_elapsed(uint16_t last) {
uint32_t t;
- ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { t = timer_count; }
+ ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
+ t = timer_count;
+ }
return TIMER_DIFF_16((t & 0xFFFF), last);
}
@@ -119,7 +127,9 @@ inline uint16_t timer_elapsed(uint16_t last) {
inline uint32_t timer_elapsed32(uint32_t last) {
uint32_t t;
- ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { t = timer_count; }
+ ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
+ t = timer_count;
+ }
return TIMER_DIFF_32(t, last);
}
@@ -130,4 +140,6 @@ inline uint32_t timer_elapsed32(uint32_t last) {
#else
# define TIMER_INTERRUPT_VECTOR TIMER0_COMP_vect
#endif
-ISR(TIMER_INTERRUPT_VECTOR, ISR_NOBLOCK) { timer_count++; }
+ISR(TIMER_INTERRUPT_VECTOR, ISR_NOBLOCK) {
+ timer_count++;
+}