2009-12-07 16:13:01 +00:00
|
|
|
/*
|
2013-03-30 10:32:37 +00:00
|
|
|
ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio
|
2009-12-07 16:13:01 +00:00
|
|
|
|
2013-03-30 10:32:37 +00:00
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
2009-12-07 16:13:01 +00:00
|
|
|
|
2013-03-30 10:32:37 +00:00
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
2009-12-07 16:13:01 +00:00
|
|
|
|
2013-03-30 10:32:37 +00:00
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
2009-12-07 16:13:01 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
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. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2013-02-25 13:10:39 +00:00
|
|
|
/**
|
|
|
|
* @brief Number of PWM channels per PWM driver.
|
|
|
|
*/
|
|
|
|
#define PWM_CHANNELS 4
|
|
|
|
|
2009-12-07 16:13:01 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver pre-compile time settings. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/**
|
2013-02-25 13:10:39 +00:00
|
|
|
* @name Configuration options
|
|
|
|
* @{
|
2009-12-07 16:13:01 +00:00
|
|
|
*/
|
2013-02-25 13:10:39 +00:00
|
|
|
/**
|
|
|
|
* @brief XXX driver enable switch.
|
|
|
|
* @details If set to @p TRUE the support for XXX1 is included.
|
|
|
|
*/
|
|
|
|
#if !defined(PLATFORM_XXX_USE_XXX1) || defined(__DOXYGEN__)
|
|
|
|
#define PLATFORM_XXX_USE_XXX1 FALSE
|
2009-12-07 16:13:01 +00:00
|
|
|
#endif
|
2013-02-25 13:10:39 +00:00
|
|
|
/** @} */
|
2009-12-07 16:13:01 +00:00
|
|
|
|
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. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2013-02-25 13:10:39 +00:00
|
|
|
#if PLATFORM_XXX_USE_XXX1 && !defined(__DOXYGEN__)
|
|
|
|
extern XXXDriver XXXD1;
|
|
|
|
#endif
|
|
|
|
|
2009-12-07 16:13:01 +00:00
|
|
|
#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_ */
|
|
|
|
|
|
|
|
/** @} */
|