コード例 #1
0
	void goToPos(int32_t new_pos){
		if(new_pos == position)
			return;
		config.frequency = clk_freq;
		config.period = clk_freq / initial_freq;
		config.callback = cb;
		current_freq = initial_freq;
		config.channels[0] = {PWM_OUTPUT_DISABLED, NULL};
		config.channels[1] = {PWM_OUTPUT_DISABLED, NULL};
		config.channels[2] = {PWM_OUTPUT_DISABLED, NULL};
		config.channels[3] = {PWM_OUTPUT_DISABLED, NULL};
		config.channels[channel] = {PWM_OUTPUT_ACTIVE_HIGH, NULL};
		config.cr2 = 0;
		config.dier = 0;

		dir_positive = new_pos > position;
		target_position = new_pos;

		dir_pin.assign(dir_positive);

		ramp_length = (new_pos > position) ?
			((max_pos_freq - initial_freq) / ramp) :
			((max_neg_freq - initial_freq) / ramp);

		pwmStart(driver, &config);
		pwmEnableChannel(driver, channel, 10);
		pwmEnablePeriodicNotificationI(driver);
	}
コード例 #2
0
ファイル: hal_onewire.c プロジェクト: awygle/ChibiOS-Contrib
/**
 * @brief     Read some bites from slave device.
 *
 * @param[in] owp           pointer to the @p onewireDriver object
 * @param[in] txbuf         pointer to the buffer with data to be written
 * @param[in] txbytes       amount of data to be written
 * @param[in] pullup_time   how long strong pull up must be activated. Set
 *                          it to 0 if not needed.
 */
void onewireWrite(onewireDriver *owp, uint8_t *txbuf,
                  size_t txbytes, systime_t pullup_time) {
  PWMDriver *pwmd;
  PWMConfig *pwmcfg;
  size_t mch, sch;

  osalDbgCheck((NULL != owp) && (NULL != txbuf));
  osalDbgCheck((txbytes > 0) && (txbytes <= ONEWIRE_MAX_TRANSACTION_LEN));
  osalDbgAssert(owp->reg.state == ONEWIRE_READY, "Invalid state");
#if !ONEWIRE_USE_STRONG_PULLUP
  osalDbgAssert(0 == pullup_time,
      "Non zero time is valid only when strong pull enabled");
#endif

  pwmd = owp->config->pwmd;
  pwmcfg = owp->config->pwmcfg;
  mch = owp->config->master_channel;
  sch = owp->config->sample_channel;

  owp->buf = txbuf;
  owp->reg.bit = 0;
  owp->reg.final_timeslot = false;
  owp->reg.bytes = txbytes;

  pwmcfg->period = ONEWIRE_ZERO_WIDTH + ONEWIRE_RECOVERY_WIDTH;
  pwmcfg->callback = pwm_write_bit_cb;
  pwmcfg->channels[mch].callback = NULL;
  pwmcfg->channels[mch].mode = owp->config->pwmmode;
  pwmcfg->channels[sch].callback = NULL;
  pwmcfg->channels[sch].mode = PWM_OUTPUT_DISABLED;

#if ONEWIRE_USE_STRONG_PULLUP
  if (pullup_time > 0) {
    owp->reg.state = ONEWIRE_PULL_UP;
    owp->reg.need_pullup = true;
  }
#endif

  ow_bus_active(owp);
  osalSysLock();
  pwmEnablePeriodicNotificationI(pwmd);
  osalThreadSuspendS(&owp->thread);
  osalSysUnlock();

  pwmDisablePeriodicNotification(pwmd);
  ow_bus_idle(owp);

#if ONEWIRE_USE_STRONG_PULLUP
  if (pullup_time > 0) {
    osalThreadSleep(pullup_time);
    owp->config->pullup_release();
    owp->reg.state = ONEWIRE_READY;
  }
#endif
}
コード例 #3
0
ファイル: pwm.c プロジェクト: hmchen1/ChibiOS
/**
 * @brief   Enables the periodic activation edge notification.
 * @pre     The PWM unit must have been activated using @p pwmStart().
 * @note    If the notification is already enabled then the call has no effect.
 *
 * @param[in] pwmp      pointer to a @p PWMDriver object
 *
 * @api
 */
void pwmEnablePeriodicNotification(PWMDriver *pwmp) {

  osalDbgCheck(pwmp != NULL);

  osalSysLock();

  osalDbgAssert(pwmp->state == PWM_READY, "not ready");
  osalDbgAssert(pwmp->config->callback != NULL, "undefined periodic callback");

  pwmEnablePeriodicNotificationI(pwmp);

  osalSysUnlock();
}