switch to Timer0 for wait() on LoL Shield platform

This commit is contained in:
Christian Kroll 2014-05-15 21:20:39 +02:00
parent dc0402251c
commit 56a267bada
3 changed files with 26 additions and 19 deletions

View File

@ -19,6 +19,7 @@ BORG_HW=HW_LOLSHIELD
# #
# lolshield setup # lolshield setup
# #
USER_TIMER0_FOR_WAIT=1
# #
# Features # Features
@ -26,7 +27,7 @@ BORG_HW=HW_LOLSHIELD
RANDOM_SUPPORT=y RANDOM_SUPPORT=y
# LAP_TIME_EXTENSION is not set # LAP_TIME_EXTENSION is not set
SCROLLTEXT_SUPPORT=y SCROLLTEXT_SUPPORT=y
SCROLLTEXT_FONT=FONT_SMALL6 SCROLLTEXT_FONT=FONT_C64
SCROLLTEXT_BUFFER_SIZE=128 SCROLLTEXT_BUFFER_SIZE=128
SCROLL_X_SPEED=20 SCROLL_X_SPEED=20
SCROLL_Y_SPEED=20 SCROLL_Y_SPEED=20

View File

@ -1,4 +1,6 @@
mainmenu_option next_comment mainmenu_option next_comment
comment "lolshield setup" comment "lolshield setup"
define_int USER_TIMER0_FOR_WAIT 1
endmenu endmenu

View File

@ -22,22 +22,19 @@ extern jmp_buf newmode_jmpbuf;
void wait(int ms){ void wait(int ms){
/* TCCR2: FOC2 WGM20 COM21 COM20 WGM21 CS22 CS21 CS20 /* Always use Timer1 except for the Arduino/LoL Shield platform. */
CS22 CS21 CS20 #ifndef USER_TIMER0_FOR_WAIT
0 0 0 stop TCCR1B = _BV(WGM12) | _BV(CS12); //CTC Mode, clk/256
0 0 1 clk OCR1A = (F_CPU/256000); //1000Hz
0 1 0 clk/8 /* Some Arduino/LoL Shield variants require Timer1 for multiplexing. Timer0, on
0 1 1 clk/32 * the other hand, is free to use, which makes it a perfect candidate for our
1 0 0 clk/64 * wait() function. */
1 0 1 clk/128 #else
1 1 0 clk/256 // disconnect OC0A and OC0B pins, turn on CTC mode, clk/256
1 1 1 clk/1024 TCCR0A = _BV(WGM01);
*/ TCCR0B = _BV(CS02);
//TCCR2 = 0x0D; //CTC Mode, clk/128 OCR0A = (F_CPU/256000); //1000Hz
//OCR2 = (F_CPU/128000); //1000Hz #endif
TCCR1B = (1<<WGM12) | 4;//CTC Mode, clk/256
OCR1A = (F_CPU/256000); //1000Hz
for(;ms>0;ms--){ for(;ms>0;ms--){
@ -61,8 +58,15 @@ void wait(int ms){
#endif #endif
#if defined (__AVR_ATmega644P__) || defined (__AVR_ATmega644__) || defined (__AVR_ATmega328__) || defined (__AVR_ATmega328P__) || (__AVR_ATmega1284P__) || defined (__AVR_ATmega1284__) #if defined (__AVR_ATmega644P__) || defined (__AVR_ATmega644__) || defined (__AVR_ATmega328__) || defined (__AVR_ATmega328P__) || (__AVR_ATmega1284P__) || defined (__AVR_ATmega1284__)
while(!(TIFR1&(1<<OCF1A))); //wait for compare match flag /* Timer1 for the masses */
TIFR1=(1<<OCF1A); //reset flag # ifndef USER_TIMER0_FOR_WAIT
while(!(TIFR1 & _BV(OCF1A))); //wait for compare match flag
TIFR1 |= _BV(OCF1A); //reset flag
/* Timer0 for e.g. Arduino/LoL Shield */
# else
while(!(TIFR0 & _BV(OCF0A))); //wait for compare match flag
TIFR0 |= _BV(OCF0A); //reset flag
# endif
#else #else
while(!(TIFR&(1<<OCF1A))); //wait for compare match flag while(!(TIFR&(1<<OCF1A))); //wait for compare match flag
TIFR=(1<<OCF1A); //reset flag TIFR=(1<<OCF1A); //reset flag