fix(timer): increase accuracy of timer
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				continuous-integration/drone/push Build is passing
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	continuous-integration/drone/push Build is passing
				
			This commit is contained in:
		
							
								
								
									
										40
									
								
								src/timer.rs
									
									
									
									
									
								
							
							
						
						
									
										40
									
								
								src/timer.rs
									
									
									
									
									
								
							@@ -21,18 +21,29 @@ impl Timer {
 | 
				
			|||||||
        use State::*;
 | 
					        use State::*;
 | 
				
			||||||
        use TimerSpeed::*;
 | 
					        use TimerSpeed::*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if let TIMAOverflow(step) | AbortedTIMAOverflow(step) = self.state {
 | 
					        match self.state {
 | 
				
			||||||
            if step < 4 {
 | 
					            TIMAOverflow(_) | AbortedTIMAOverflow(_) => self.state = self.state.next(),
 | 
				
			||||||
                self.state = TIMAOverflow(step + 1);
 | 
					            LoadTMA => {
 | 
				
			||||||
                return;
 | 
					                self.counter = self.modulo;
 | 
				
			||||||
 | 
					                self.interrupt = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                self.state.next();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            Normal => {}
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if let TIMAOverflow(step) | AbortedTIMAOverflow(step) = self.state {
 | 
				
			||||||
 | 
					            if step < 3 {
 | 
				
			||||||
 | 
					                self.state = self.state.next();
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
                if self.state == TIMAOverflow(step) {
 | 
					                if self.state == TIMAOverflow(step) {
 | 
				
			||||||
                    self.counter = self.modulo;
 | 
					                    self.counter = self.modulo;
 | 
				
			||||||
                    self.interrupt = true;
 | 
					                    self.interrupt = true;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                self.state = Normal;
 | 
					                self.state = Normal;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.divider = self.divider.wrapping_add(1);
 | 
					        self.divider = self.divider.wrapping_add(1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -67,14 +78,12 @@ impl Timer {
 | 
				
			|||||||
        use State::*;
 | 
					        use State::*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        match self.state {
 | 
					        match self.state {
 | 
				
			||||||
            Normal => self.counter = byte,
 | 
					            Normal | AbortedTIMAOverflow(_) => self.counter = byte,
 | 
				
			||||||
            TIMAOverflow(step) => {
 | 
					            TIMAOverflow(step) => {
 | 
				
			||||||
                if step < 4 {
 | 
					 | 
				
			||||||
                self.counter = byte;
 | 
					                self.counter = byte;
 | 
				
			||||||
                self.state = AbortedTIMAOverflow(step);
 | 
					                self.state = AbortedTIMAOverflow(step);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            }
 | 
					            LoadTMA => {}
 | 
				
			||||||
            AbortedTIMAOverflow(_) => self.counter = byte,
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -173,4 +182,19 @@ enum State {
 | 
				
			|||||||
    TIMAOverflow(u8),
 | 
					    TIMAOverflow(u8),
 | 
				
			||||||
    AbortedTIMAOverflow(u8),
 | 
					    AbortedTIMAOverflow(u8),
 | 
				
			||||||
    Normal,
 | 
					    Normal,
 | 
				
			||||||
 | 
					    LoadTMA,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl State {
 | 
				
			||||||
 | 
					    fn next(&self) -> Self {
 | 
				
			||||||
 | 
					        use State::*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        match self {
 | 
				
			||||||
 | 
					            Normal | LoadTMA => Normal,
 | 
				
			||||||
 | 
					            TIMAOverflow(3) => LoadTMA,
 | 
				
			||||||
 | 
					            AbortedTIMAOverflow(3) => Normal,
 | 
				
			||||||
 | 
					            TIMAOverflow(step) => TIMAOverflow(step + 1),
 | 
				
			||||||
 | 
					            AbortedTIMAOverflow(step) => AbortedTIMAOverflow(step + 1),
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user