diff options
Diffstat (limited to 'tmk_core/common/avr')
-rw-r--r-- | tmk_core/common/avr/bootloader.c | 15 | ||||
-rw-r--r-- | tmk_core/common/avr/sleep_led.c | 19 | ||||
-rw-r--r-- | tmk_core/common/avr/suspend.c | 20 | ||||
-rw-r--r-- | tmk_core/common/avr/timer.c | 24 |
4 files changed, 67 insertions, 11 deletions
diff --git a/tmk_core/common/avr/bootloader.c b/tmk_core/common/avr/bootloader.c index ee150817c..d89c8d768 100644 --- a/tmk_core/common/avr/bootloader.c +++ b/tmk_core/common/avr/bootloader.c | |||
@@ -13,12 +13,11 @@ | |||
13 | #endif | 13 | #endif |
14 | 14 | ||
15 | 15 | ||
16 | /* Bootloader Size in *bytes* | 16 | /** \brief Bootloader Size in *bytes* |
17 | * | 17 | * |
18 | * AVR Boot section size are defined by setting BOOTSZ fuse in fact. Consult with your MCU datasheet. | 18 | * AVR Boot section size are defined by setting BOOTSZ fuse in fact. Consult with your MCU datasheet. |
19 | * Note that 'Word'(2 bytes) size and address are used in datasheet while TMK uses 'Byte'. | 19 | * Note that 'Word'(2 bytes) size and address are used in datasheet while TMK uses 'Byte'. |
20 | * | 20 | * |
21 | * | ||
22 | * Size of Bootloaders in bytes: | 21 | * Size of Bootloaders in bytes: |
23 | * Atmel DFU loader(ATmega32U4) 4096 | 22 | * Atmel DFU loader(ATmega32U4) 4096 |
24 | * Atmel DFU loader(AT90USB128) 8192 | 23 | * Atmel DFU loader(AT90USB128) 8192 |
@@ -28,10 +27,8 @@ | |||
28 | * Teensy halfKay(ATmega32U4) 512 | 27 | * Teensy halfKay(ATmega32U4) 512 |
29 | * Teensy++ halfKay(AT90USB128) 1024 | 28 | * Teensy++ halfKay(AT90USB128) 1024 |
30 | * | 29 | * |
31 | * | ||
32 | * AVR Boot section is located at the end of Flash memory like the followings. | 30 | * AVR Boot section is located at the end of Flash memory like the followings. |
33 | * | 31 | * |
34 | * | ||
35 | * byte Atmel/LUFA(ATMega32u4) byte Atmel(AT90SUB128) | 32 | * byte Atmel/LUFA(ATMega32u4) byte Atmel(AT90SUB128) |
36 | * 0x0000 +---------------+ 0x00000 +---------------+ | 33 | * 0x0000 +---------------+ 0x00000 +---------------+ |
37 | * | | | | | 34 | * | | | | |
@@ -57,7 +54,6 @@ | |||
57 | * | Bootloader | 512B | Bootloader | 1KB | 54 | * | Bootloader | 512B | Bootloader | 1KB |
58 | * 0x7FFF +---------------+ 0x1FFFF +---------------+ | 55 | * 0x7FFF +---------------+ 0x1FFFF +---------------+ |
59 | */ | 56 | */ |
60 | |||
61 | #define FLASH_SIZE (FLASHEND + 1L) | 57 | #define FLASH_SIZE (FLASHEND + 1L) |
62 | 58 | ||
63 | #if !defined(BOOTLOADER_SIZE) | 59 | #if !defined(BOOTLOADER_SIZE) |
@@ -69,14 +65,17 @@ | |||
69 | #define BOOT_SIZE_1024 0b010 | 65 | #define BOOT_SIZE_1024 0b010 |
70 | #define BOOT_SIZE_2048 0b000 | 66 | #define BOOT_SIZE_2048 0b000 |
71 | 67 | ||
72 | /* | 68 | /** \brief Entering the Bootloader via Software |
73 | * Entering the Bootloader via Software | 69 | * |
74 | * http://www.fourwalledcubicle.com/files/LUFA/Doc/120730/html/_page__software_bootloader_start.html | 70 | * http://www.fourwalledcubicle.com/files/LUFA/Doc/120730/html/_page__software_bootloader_start.html |
75 | */ | 71 | */ |
76 | #define BOOTLOADER_RESET_KEY 0xB007B007 | 72 | #define BOOTLOADER_RESET_KEY 0xB007B007 |
77 | uint32_t reset_key __attribute__ ((section (".noinit"))); | 73 | uint32_t reset_key __attribute__ ((section (".noinit"))); |
78 | 74 | ||
79 | /* initialize MCU status by watchdog reset */ | 75 | /** \brief initialize MCU status by watchdog reset |
76 | * | ||
77 | * FIXME: needs doc | ||
78 | */ | ||
80 | void bootloader_jump(void) { | 79 | void bootloader_jump(void) { |
81 | 80 | ||
82 | #if !defined(BOOTLOADER_SIZE) | 81 | #if !defined(BOOTLOADER_SIZE) |
diff --git a/tmk_core/common/avr/sleep_led.c b/tmk_core/common/avr/sleep_led.c index dab3eb0f3..0cb774c81 100644 --- a/tmk_core/common/avr/sleep_led.c +++ b/tmk_core/common/avr/sleep_led.c | |||
@@ -18,6 +18,10 @@ | |||
18 | */ | 18 | */ |
19 | #define SLEEP_LED_TIMER_TOP F_CPU/(256*64) | 19 | #define SLEEP_LED_TIMER_TOP F_CPU/(256*64) |
20 | 20 | ||
21 | /** \brief Sleep LED initialization | ||
22 | * | ||
23 | * FIXME: needs doc | ||
24 | */ | ||
21 | void sleep_led_init(void) | 25 | void sleep_led_init(void) |
22 | { | 26 | { |
23 | /* Timer1 setup */ | 27 | /* Timer1 setup */ |
@@ -33,18 +37,30 @@ void sleep_led_init(void) | |||
33 | SREG = sreg; | 37 | SREG = sreg; |
34 | } | 38 | } |
35 | 39 | ||
40 | /** \brief Sleep LED enable | ||
41 | * | ||
42 | * FIXME: needs doc | ||
43 | */ | ||
36 | void sleep_led_enable(void) | 44 | void sleep_led_enable(void) |
37 | { | 45 | { |
38 | /* Enable Compare Match Interrupt */ | 46 | /* Enable Compare Match Interrupt */ |
39 | TIMSK1 |= _BV(OCIE1A); | 47 | TIMSK1 |= _BV(OCIE1A); |
40 | } | 48 | } |
41 | 49 | ||
50 | /** \brief Sleep LED disable | ||
51 | * | ||
52 | * FIXME: needs doc | ||
53 | */ | ||
42 | void sleep_led_disable(void) | 54 | void sleep_led_disable(void) |
43 | { | 55 | { |
44 | /* Disable Compare Match Interrupt */ | 56 | /* Disable Compare Match Interrupt */ |
45 | TIMSK1 &= ~_BV(OCIE1A); | 57 | TIMSK1 &= ~_BV(OCIE1A); |
46 | } | 58 | } |
47 | 59 | ||
60 | /** \brief Sleep LED toggle | ||
61 | * | ||
62 | * FIXME: needs doc | ||
63 | */ | ||
48 | void sleep_led_toggle(void) | 64 | void sleep_led_toggle(void) |
49 | { | 65 | { |
50 | /* Disable Compare Match Interrupt */ | 66 | /* Disable Compare Match Interrupt */ |
@@ -52,7 +68,8 @@ void sleep_led_toggle(void) | |||
52 | } | 68 | } |
53 | 69 | ||
54 | 70 | ||
55 | /* Breathing Sleep LED brighness(PWM On period) table | 71 | /** \brief Breathing Sleep LED brighness(PWM On period) table |
72 | * | ||
56 | * (64[steps] * 4[duration]) / 64[PWM periods/s] = 4 second breath cycle | 73 | * (64[steps] * 4[duration]) / 64[PWM periods/s] = 4 second breath cycle |
57 | * | 74 | * |
58 | * http://www.wolframalpha.com/input/?i=%28sin%28+x%2F64*pi%29**8+*+255%2C+x%3D0+to+63 | 75 | * http://www.wolframalpha.com/input/?i=%28sin%28+x%2F64*pi%29**8+*+255%2C+x%3D0+to+63 |
diff --git a/tmk_core/common/avr/suspend.c b/tmk_core/common/avr/suspend.c index 213f03f6f..4cdd6a420 100644 --- a/tmk_core/common/avr/suspend.c +++ b/tmk_core/common/avr/suspend.c | |||
@@ -41,6 +41,10 @@ __asm__ __volatile__ ( \ | |||
41 | ) | 41 | ) |
42 | 42 | ||
43 | 43 | ||
44 | /** \brief Suspend idle | ||
45 | * | ||
46 | * FIXME: needs doc | ||
47 | */ | ||
44 | void suspend_idle(uint8_t time) | 48 | void suspend_idle(uint8_t time) |
45 | { | 49 | { |
46 | cli(); | 50 | cli(); |
@@ -52,7 +56,8 @@ void suspend_idle(uint8_t time) | |||
52 | } | 56 | } |
53 | 57 | ||
54 | #ifndef NO_SUSPEND_POWER_DOWN | 58 | #ifndef NO_SUSPEND_POWER_DOWN |
55 | /* Power down MCU with watchdog timer | 59 | /** \brief Power down MCU with watchdog timer |
60 | * | ||
56 | * wdto: watchdog timer timeout defined in <avr/wdt.h> | 61 | * wdto: watchdog timer timeout defined in <avr/wdt.h> |
57 | * WDTO_15MS | 62 | * WDTO_15MS |
58 | * WDTO_30MS | 63 | * WDTO_30MS |
@@ -67,6 +72,10 @@ void suspend_idle(uint8_t time) | |||
67 | */ | 72 | */ |
68 | static uint8_t wdt_timeout = 0; | 73 | static uint8_t wdt_timeout = 0; |
69 | 74 | ||
75 | /** \brief Power down | ||
76 | * | ||
77 | * FIXME: needs doc | ||
78 | */ | ||
70 | static void power_down(uint8_t wdto) | 79 | static void power_down(uint8_t wdto) |
71 | { | 80 | { |
72 | #ifdef PROTOCOL_LUFA | 81 | #ifdef PROTOCOL_LUFA |
@@ -111,6 +120,10 @@ static void power_down(uint8_t wdto) | |||
111 | } | 120 | } |
112 | #endif | 121 | #endif |
113 | 122 | ||
123 | /** \brief Suspend power down | ||
124 | * | ||
125 | * FIXME: needs doc | ||
126 | */ | ||
114 | void suspend_power_down(void) | 127 | void suspend_power_down(void) |
115 | { | 128 | { |
116 | #ifndef NO_SUSPEND_POWER_DOWN | 129 | #ifndef NO_SUSPEND_POWER_DOWN |
@@ -131,7 +144,10 @@ bool suspend_wakeup_condition(void) | |||
131 | return false; | 144 | return false; |
132 | } | 145 | } |
133 | 146 | ||
134 | // run immediately after wakeup | 147 | /** \brief run immediately after wakeup |
148 | * | ||
149 | * FIXME: needs doc | ||
150 | */ | ||
135 | void suspend_wakeup_init(void) | 151 | void suspend_wakeup_init(void) |
136 | { | 152 | { |
137 | // clear keyboard state | 153 | // clear keyboard state |
diff --git a/tmk_core/common/avr/timer.c b/tmk_core/common/avr/timer.c index 369015200..b7d4f060e 100644 --- a/tmk_core/common/avr/timer.c +++ b/tmk_core/common/avr/timer.c | |||
@@ -27,6 +27,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
27 | // NOTE: union { uint32_t timer32; struct { uint16_t dummy; uint16_t timer16; }} | 27 | // NOTE: union { uint32_t timer32; struct { uint16_t dummy; uint16_t timer16; }} |
28 | volatile uint32_t timer_count; | 28 | volatile uint32_t timer_count; |
29 | 29 | ||
30 | /** \brief timer initialization | ||
31 | * | ||
32 | * FIXME: needs doc | ||
33 | */ | ||
30 | void timer_init(void) | 34 | void timer_init(void) |
31 | { | 35 | { |
32 | #if TIMER_PRESCALER == 1 | 36 | #if TIMER_PRESCALER == 1 |
@@ -60,6 +64,10 @@ void timer_init(void) | |||
60 | #endif | 64 | #endif |
61 | } | 65 | } |
62 | 66 | ||
67 | /** \brief timer clear | ||
68 | * | ||
69 | * FIXME: needs doc | ||
70 | */ | ||
63 | inline | 71 | inline |
64 | void timer_clear(void) | 72 | void timer_clear(void) |
65 | { | 73 | { |
@@ -68,6 +76,10 @@ void timer_clear(void) | |||
68 | } | 76 | } |
69 | } | 77 | } |
70 | 78 | ||
79 | /** \brief timer read | ||
80 | * | ||
81 | * FIXME: needs doc | ||
82 | */ | ||
71 | inline | 83 | inline |
72 | uint16_t timer_read(void) | 84 | uint16_t timer_read(void) |
73 | { | 85 | { |
@@ -80,6 +92,10 @@ uint16_t timer_read(void) | |||
80 | return (t & 0xFFFF); | 92 | return (t & 0xFFFF); |
81 | } | 93 | } |
82 | 94 | ||
95 | /** \brief timer read32 | ||
96 | * | ||
97 | * FIXME: needs doc | ||
98 | */ | ||
83 | inline | 99 | inline |
84 | uint32_t timer_read32(void) | 100 | uint32_t timer_read32(void) |
85 | { | 101 | { |
@@ -92,6 +108,10 @@ uint32_t timer_read32(void) | |||
92 | return t; | 108 | return t; |
93 | } | 109 | } |
94 | 110 | ||
111 | /** \brief timer elapsed | ||
112 | * | ||
113 | * FIXME: needs doc | ||
114 | */ | ||
95 | inline | 115 | inline |
96 | uint16_t timer_elapsed(uint16_t last) | 116 | uint16_t timer_elapsed(uint16_t last) |
97 | { | 117 | { |
@@ -104,6 +124,10 @@ uint16_t timer_elapsed(uint16_t last) | |||
104 | return TIMER_DIFF_16((t & 0xFFFF), last); | 124 | return TIMER_DIFF_16((t & 0xFFFF), last); |
105 | } | 125 | } |
106 | 126 | ||
127 | /** \brief timer elapsed32 | ||
128 | * | ||
129 | * FIXME: needs doc | ||
130 | */ | ||
107 | inline | 131 | inline |
108 | uint32_t timer_elapsed32(uint32_t last) | 132 | uint32_t timer_elapsed32(uint32_t last) |
109 | { | 133 | { |