Browse Source

switch to Timer0 for wait() on LoL Shield platform

feature/2015
Christian Kroll 11 years ago
parent
commit
56a267bada
  1. 3
      profiles/LoL-Shield
  2. 2
      src/borg_hw/config_lolshield.in
  3. 40
      src/util.c

3
profiles/LoL-Shield

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

2
src/borg_hw/config_lolshield.in

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

40
src/util.c

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

Loading…
Cancel
Save