The below code throws an error on compilation. Not that MC_STOP and the other 
constants are defined like: 
    
    
    const MC_STOP* = (0x00000000)  # Timer A mode control: 0 - Stop
    const OUTMOD_VAL_4* = (0x00000080)  # PWM output mode: 4 - toggle
    
    
    
    proc setupTimerISR() =
      volatileStore[uint16](TA0CTL, MC_STOP)
      volatileStore[uint16](TA0CCTL0, OUTMOD_VAL_4)
      volatileStore[uint16](TA0CCR0, 0xFFFF)
      volatileStore[uint16](TA0CTL, TASSEL_SMCLK + MC_UP + TACLR)
    

Error: 
    
    
    blink.nim(8, 24) Error: type mismatch: got <ptr uint16, int32>
    but expected one of:
    template volatileStore[T](dest: ptr T; val: T)
      first type mismatch at position: 2
      required type: T
      but expression '0x0000FFFF' is of type: int32
    
    expression: volatileStore[uint16](TA0CCR0, 0x0000FFFF)
        volatileStore[uint16](TA0CCR0, 0xFFFF)
    

But then it compiles when I do this: 
    
    
    proc setupTimerISR() =
      volatileStore[uint16](TA0CTL, MC_STOP)
      volatileStore[uint16](TA0CCTL0, OUTMOD_VAL_4)
      volatileStore[uint16](TA0CCR0, 0xFFFF'u16)
      volatileStore[uint16](TA0CTL, TASSEL_SMCLK + MC_UP + TACLR)
    

Why is the 'u16 necessary? It gives the same error if I write it as 0x0000FFFF. 
Why won't the compiler coerce it to the right type? That will be very tedious.

Reply via email to