summaryrefslogtreecommitdiff
path: root/tmk_core/common/avr
diff options
context:
space:
mode:
authorfauxpark <fauxpark@gmail.com>2019-09-08 01:12:46 +1000
committerFlorian Didron <fdidron@users.noreply.github.com>2019-09-26 10:08:39 +0900
commit9c70eceec188b9b11004ede85ef44040756c66bf (patch)
tree6b9647d5b4ea409a7f40301acd252d0b8674e4fd /tmk_core/common/avr
parent74d97c7c1d8b9578ad5a352ae3cf2cd010f6ce6e (diff)
Banish some more magic numbers (#6662)
Diffstat (limited to 'tmk_core/common/avr')
-rw-r--r--tmk_core/common/avr/bootloader.c11
-rw-r--r--tmk_core/common/avr/timer.c21
2 files changed, 13 insertions, 19 deletions
diff --git a/tmk_core/common/avr/bootloader.c b/tmk_core/common/avr/bootloader.c
index 5f9ecc5101..ca9746f327 100644
--- a/tmk_core/common/avr/bootloader.c
+++ b/tmk_core/common/avr/bootloader.c
@@ -59,11 +59,6 @@
uint16_t bootloader_start;
#endif
-#define BOOT_SIZE_256 0b110
-#define BOOT_SIZE_512 0b100
-#define BOOT_SIZE_1024 0b010
-#define BOOT_SIZE_2048 0b000
-
// compatibility between ATMega8 and ATMega88
#if !defined(MCUCSR)
# if defined(MCUSR)
@@ -86,11 +81,11 @@ void bootloader_jump(void) {
#if !defined(BOOTLOADER_SIZE)
uint8_t high_fuse = boot_lock_fuse_bits_get(GET_HIGH_FUSE_BITS);
- if (high_fuse & BOOT_SIZE_256) {
+ if (high_fuse & ~(FUSE_BOOTSZ0 & FUSE_BOOTSZ1)) {
bootloader_start = (FLASH_SIZE - 512) >> 1;
- } else if (high_fuse & BOOT_SIZE_512) {
+ } else if (high_fuse & ~(FUSE_BOOTSZ1)) {
bootloader_start = (FLASH_SIZE - 1024) >> 1;
- } else if (high_fuse & BOOT_SIZE_1024) {
+ } else if (high_fuse & ~(FUSE_BOOTSZ0)) {
bootloader_start = (FLASH_SIZE - 2048) >> 1;
} else {
bootloader_start = (FLASH_SIZE - 4096) >> 1;
diff --git a/tmk_core/common/avr/timer.c b/tmk_core/common/avr/timer.c
index 63ec549dff..88fa1dfa65 100644
--- a/tmk_core/common/avr/timer.c
+++ b/tmk_core/common/avr/timer.c
@@ -32,33 +32,32 @@ volatile uint32_t timer_count;
*/
void timer_init(void) {
#if TIMER_PRESCALER == 1
- uint8_t prescaler = 0x01;
+ uint8_t prescaler = _BV(CS00);
#elif TIMER_PRESCALER == 8
- uint8_t prescaler = 0x02;
+ uint8_t prescaler = _BV(CS01);
#elif TIMER_PRESCALER == 64
- uint8_t prescaler = 0x03;
+ uint8_t prescaler = _BV(CS00) | _BV(CS01);
#elif TIMER_PRESCALER == 256
- uint8_t prescaler = 0x04;
+ uint8_t prescaler = _BV(CS02);
#elif TIMER_PRESCALER == 1024
- uint8_t prescaler = 0x05;
+ uint8_t prescaler = _BV(CS00) | _BV(CS02);
#else
-# error "Timer prescaler value is NOT vaild."
+# error "Timer prescaler value is not valid"
#endif
#ifndef __AVR_ATmega32A__
// Timer0 CTC mode
- TCCR0A = 0x02;
-
+ TCCR0A = _BV(WGM01);
TCCR0B = prescaler;
OCR0A = TIMER_RAW_TOP;
- TIMSK0 = (1 << OCIE0A);
+ TIMSK0 = _BV(OCIE0A);
#else
// Timer0 CTC mode
- TCCR0 = (1 << WGM01) | prescaler;
+ TCCR0 = _BV(WGM01) | prescaler;
OCR0 = TIMER_RAW_TOP;
- TIMSK = (1 << OCIE0);
+ TIMSK = _BV(OCIE0);
#endif
}