Example #1
0
uint16 Servo::readMicroseconds() const {
    if (!this->attached()) {
        ASSERT(0);
        return 0;
    }

    stm32_pin_info pin_info = PIN_MAP[this->pin];
    uint16 compare = timer_get_compare(pin_info.timer_device,
                                       pin_info.timer_channel);

    return COMPARE_TO_US(compare);
}
Example #2
0
uint16_t Servo::readMicroseconds() const {
  if (!this->attached()) {
//    ASSERT(0);
    return 0;
  }
  TIM_TypeDef *tdev = g_APinDescription[this->pin].ulTimerPeripheral;
  uint8_t tchan = g_APinDescription[this->pin].ulTimerChannel;
  uint16_t compare;
//  stm32_pin_info pin_info = PIN_MAP[this->pin];
  if(tchan == TIM_Channel_1) {
    compare = tdev->CCR1;
  }else if(tchan == TIM_Channel_2) {
    compare = tdev->CCR2;
  }else if(tchan == TIM_Channel_3) {
    compare = tdev->CCR3;
  }else if(tchan == TIM_Channel_4) {
    compare = tdev->CCR4;
  }
//  uint16_t compare = timer_get_compare(pin_info.timer_device,
//  pin_info.timer_channel);

  return COMPARE_TO_US(compare);
}