2009-12-07 16:13:01 +00:00
|
|
|
/*
|
2011-03-18 18:38:08 +00:00
|
|
|
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
2013-02-02 10:58:09 +00:00
|
|
|
2011,2012,2013 Giovanni Di Sirio.
|
2009-12-07 16:13:01 +00:00
|
|
|
|
|
|
|
This file is part of ChibiOS/RT.
|
|
|
|
|
|
|
|
ChibiOS/RT is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
ChibiOS/RT is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-02-07 11:11:45 +00:00
|
|
|
* @file templates/pwm_lld.h
|
|
|
|
* @brief PWM Driver subsystem low level driver header template.
|
|
|
|
*
|
2010-10-25 18:48:13 +00:00
|
|
|
* @addtogroup PWM
|
2009-12-07 16:13:01 +00:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _PWM_LLD_H_
|
|
|
|
#define _PWM_LLD_H_
|
|
|
|
|
2010-11-01 17:29:56 +00:00
|
|
|
#if HAL_USE_PWM || defined(__DOXYGEN__)
|
|
|
|
|
2009-12-07 16:13:01 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver constants. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver pre-compile time settings. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/**
|
2010-02-21 07:24:53 +00:00
|
|
|
* @brief Number of PWM channels per PWM driver.
|
2009-12-07 16:13:01 +00:00
|
|
|
*/
|
|
|
|
#if !defined(PWM_CHANNELS) || defined(__DOXYGEN__)
|
|
|
|
#define PWM_CHANNELS 1
|
|
|
|
#endif
|
|
|
|
|
2009-12-19 10:08:08 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Derived constants and error checks. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2009-12-07 16:13:01 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver data structures and types. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2011-04-01 13:21:02 +00:00
|
|
|
/**
|
|
|
|
* @brief PWM mode type.
|
|
|
|
*/
|
|
|
|
typedef uint32_t pwmmode_t;
|
|
|
|
|
2009-12-07 16:13:01 +00:00
|
|
|
/**
|
2010-02-21 07:24:53 +00:00
|
|
|
* @brief PWM channel type.
|
2009-12-07 16:13:01 +00:00
|
|
|
*/
|
|
|
|
typedef uint8_t pwmchannel_t;
|
|
|
|
|
|
|
|
/**
|
2010-02-21 07:24:53 +00:00
|
|
|
* @brief PWM counter type.
|
2009-12-07 16:13:01 +00:00
|
|
|
*/
|
|
|
|
typedef uint16_t pwmcnt_t;
|
|
|
|
|
2010-10-13 11:45:07 +00:00
|
|
|
/**
|
|
|
|
* @brief PWM driver channel configuration structure.
|
|
|
|
* @note Some architectures may not be able to support the channel mode
|
|
|
|
* or the callback, in this case the fields are ignored.
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
/**
|
|
|
|
* @brief Channel active logic level.
|
|
|
|
*/
|
2011-03-08 10:09:57 +00:00
|
|
|
pwmmode_t mode;
|
2010-10-13 11:45:07 +00:00
|
|
|
/**
|
|
|
|
* @brief Channel callback pointer.
|
|
|
|
* @note This callback is invoked on the channel compare event. If set to
|
|
|
|
* @p NULL then the callback is disabled.
|
|
|
|
*/
|
2011-03-08 10:09:57 +00:00
|
|
|
pwmcallback_t callback;
|
2010-10-13 11:45:07 +00:00
|
|
|
/* End of the mandatory fields.*/
|
|
|
|
} PWMChannelConfig;
|
|
|
|
|
2009-12-07 16:13:01 +00:00
|
|
|
/**
|
2010-02-07 11:11:45 +00:00
|
|
|
* @brief Driver configuration structure.
|
2010-09-07 13:37:22 +00:00
|
|
|
* @note Implementations may extend this structure to contain more,
|
|
|
|
* architecture dependent, fields.
|
2009-12-07 16:13:01 +00:00
|
|
|
*/
|
|
|
|
typedef struct {
|
2011-03-31 10:21:52 +00:00
|
|
|
/**
|
|
|
|
* @brief Timer clock in Hz.
|
|
|
|
* @note The low level can use assertions in order to catch invalid
|
|
|
|
* frequency specifications.
|
|
|
|
*/
|
|
|
|
uint32_t frequency;
|
|
|
|
/**
|
|
|
|
* @brief PWM period in ticks.
|
|
|
|
* @note The low level can use assertions in order to catch invalid
|
|
|
|
* period specifications.
|
|
|
|
*/
|
|
|
|
pwmcnt_t period;
|
2010-10-08 18:16:38 +00:00
|
|
|
/**
|
|
|
|
* @brief Periodic callback pointer.
|
|
|
|
* @note This callback is invoked on PWM counter reset. If set to
|
|
|
|
* @p NULL then the callback is disabled.
|
|
|
|
*/
|
2011-03-08 10:09:57 +00:00
|
|
|
pwmcallback_t callback;
|
2010-10-08 18:16:38 +00:00
|
|
|
/**
|
|
|
|
* @brief Channels configurations.
|
|
|
|
*/
|
2011-03-08 10:09:57 +00:00
|
|
|
PWMChannelConfig channels[PWM_CHANNELS];
|
2010-10-08 18:16:38 +00:00
|
|
|
/* End of the mandatory fields.*/
|
2009-12-07 16:13:01 +00:00
|
|
|
} PWMConfig;
|
|
|
|
|
|
|
|
/**
|
2010-02-07 11:11:45 +00:00
|
|
|
* @brief Structure representing an PWM driver.
|
2010-09-07 13:37:22 +00:00
|
|
|
* @note Implementations may extend this structure to contain more,
|
|
|
|
* architecture dependent, fields.
|
2009-12-07 16:13:01 +00:00
|
|
|
*/
|
2010-10-08 18:16:38 +00:00
|
|
|
struct PWMDriver {
|
2009-12-07 16:13:01 +00:00
|
|
|
/**
|
|
|
|
* @brief Driver state.
|
|
|
|
*/
|
2011-03-08 10:09:57 +00:00
|
|
|
pwmstate_t state;
|
2009-12-07 16:13:01 +00:00
|
|
|
/**
|
|
|
|
* @brief Current configuration data.
|
|
|
|
*/
|
2011-03-08 10:09:57 +00:00
|
|
|
const PWMConfig *config;
|
2011-03-31 10:21:52 +00:00
|
|
|
/**
|
|
|
|
* @brief Current PWM period in ticks.
|
|
|
|
*/
|
|
|
|
pwmcnt_t period;
|
2010-10-08 18:16:38 +00:00
|
|
|
#if defined(PWM_DRIVER_EXT_FIELDS)
|
|
|
|
PWM_DRIVER_EXT_FIELDS
|
|
|
|
#endif
|
2009-12-07 16:13:01 +00:00
|
|
|
/* End of the mandatory fields.*/
|
2010-10-08 18:16:38 +00:00
|
|
|
};
|
2009-12-07 16:13:01 +00:00
|
|
|
|
2009-12-29 11:12:05 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver macros. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2009-12-07 16:13:01 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* External declarations. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
void pwm_lld_init(void);
|
|
|
|
void pwm_lld_start(PWMDriver *pwmp);
|
|
|
|
void pwm_lld_stop(PWMDriver *pwmp);
|
2011-03-31 10:21:52 +00:00
|
|
|
void pwm_lld_change_period(PWMDriver *pwmp, pwmcnt_t period);
|
2010-11-21 21:31:35 +00:00
|
|
|
void pwm_lld_enable_channel(PWMDriver *pwmp,
|
|
|
|
pwmchannel_t channel,
|
|
|
|
pwmcnt_t width);
|
|
|
|
void pwm_lld_disable_channel(PWMDriver *pwmp, pwmchannel_t channel);
|
2009-12-07 16:13:01 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-11-01 17:29:56 +00:00
|
|
|
#endif /* HAL_USE_PWM */
|
|
|
|
|
2009-12-07 16:13:01 +00:00
|
|
|
#endif /* _PWM_LLD_H_ */
|
|
|
|
|
|
|
|
/** @} */
|