use simple 8-bit counter for LED PWM
This commit is contained in:
@@ -78,8 +78,6 @@ struct pwm_descriptor {
|
||||
struct _pwm_device device;
|
||||
/** PWM callback structure */
|
||||
struct pwm_callbacks pwm_cb;
|
||||
/** PWM HPL interface pointer */
|
||||
struct _pwm_hpl_interface *func;
|
||||
};
|
||||
|
||||
/** \brief Initialize the PWM HAL instance and hardware
|
||||
|
||||
@@ -97,6 +97,94 @@ struct _pwm_hpl_interface {
|
||||
uint32_t (*pwm_get_duty)(const struct _pwm_device *const device);
|
||||
void (*set_irq_state)(struct _pwm_device *const device, const enum _pwm_callback_type type, const bool disable);
|
||||
};
|
||||
/**
|
||||
* \brief Initialize TC
|
||||
*
|
||||
* This function does low level TC configuration.
|
||||
*
|
||||
* \param[in] device The pointer to PWM device instance
|
||||
* \param[in] hw The pointer to hardware instance
|
||||
*
|
||||
* \return Initialization status.
|
||||
*/
|
||||
int32_t _pwm_init(struct _pwm_device *const device, void *const hw);
|
||||
|
||||
/**
|
||||
* \brief Deinitialize TC
|
||||
*
|
||||
* \param[in] device The pointer to PWM device instance
|
||||
*/
|
||||
void _pwm_deinit(struct _pwm_device *const device);
|
||||
|
||||
/**
|
||||
* \brief Retrieve offset of the given tc hardware instance
|
||||
*
|
||||
* \param[in] device The pointer to PWM device instance
|
||||
*
|
||||
* \return The offset of the given tc hardware instance
|
||||
*/
|
||||
uint8_t _pwm_get_hardware_offset(const struct _pwm_device *const device);
|
||||
|
||||
/**
|
||||
* \brief Start hardware pwm
|
||||
*
|
||||
* \param[in] device The pointer to PWM device instance
|
||||
*/
|
||||
void _pwm_enable(struct _pwm_device *const device);
|
||||
|
||||
/**
|
||||
* \brief Stop hardware pwm
|
||||
*
|
||||
* \param[in] device The pointer to PWM device instance
|
||||
*/
|
||||
void _pwm_disable(struct _pwm_device *const device);
|
||||
|
||||
/**
|
||||
* \brief Set pwm parameter
|
||||
*
|
||||
* \param[in] device The pointer to PWM device instance
|
||||
* \param[in] period Total period of one PWM cycle.
|
||||
* \param[in] duty_cycle Period of PWM first half during one cycle.
|
||||
*/
|
||||
void _pwm_set_param(struct _pwm_device *const device, const pwm_period_t period, const pwm_period_t duty_cycle);
|
||||
|
||||
/**
|
||||
* \brief Check if pwm is working
|
||||
*
|
||||
* \param[in] device The pointer to PWM device instance
|
||||
*
|
||||
* \return Check status.
|
||||
* \retval true The given pwm is working
|
||||
* \retval false The given pwm is not working
|
||||
*/
|
||||
bool _pwm_is_enabled(const struct _pwm_device *const device);
|
||||
|
||||
/**
|
||||
* \brief Get pwm waveform period value
|
||||
*
|
||||
* \param[in] device The pointer to PWM device instance
|
||||
*
|
||||
* \return Period value.
|
||||
*/
|
||||
pwm_period_t _pwm_get_period(const struct _pwm_device *const device);
|
||||
|
||||
/**
|
||||
* \brief Get pwm waveform duty cycle value
|
||||
*
|
||||
* \param[in] device The pointer to PWM device instance
|
||||
*
|
||||
* \return Duty cycle value
|
||||
*/
|
||||
uint32_t _pwm_get_duty(const struct _pwm_device *const device);
|
||||
|
||||
/**
|
||||
* \brief Enable/disable PWM interrupt
|
||||
*
|
||||
* param[in] device The pointer to PWM device instance
|
||||
* param[in] type The type of interrupt to disable/enable if applicable
|
||||
* param[in] disable Enable or disable
|
||||
*/
|
||||
void _pwm_set_irq_state(struct _pwm_device *const device, const enum _pwm_callback_type type, const bool disable);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -48,9 +48,8 @@ static void pwm_detect_fault(struct _pwm_device *device);
|
||||
*/
|
||||
int32_t pwm_init(struct pwm_descriptor *const descr, void *const hw, struct _pwm_hpl_interface *const func)
|
||||
{
|
||||
ASSERT(descr && hw && func);
|
||||
descr->func = func;
|
||||
descr->func->init(&descr->device, hw);
|
||||
ASSERT(descr && hw);
|
||||
_pwm_init(&descr->device, hw);
|
||||
descr->device.callback.pwm_period_cb = pwm_period_expired;
|
||||
descr->device.callback.pwm_error_cb = pwm_detect_fault;
|
||||
return ERR_NONE;
|
||||
@@ -61,8 +60,8 @@ int32_t pwm_init(struct pwm_descriptor *const descr, void *const hw, struct _pwm
|
||||
*/
|
||||
int32_t pwm_deinit(struct pwm_descriptor *const descr)
|
||||
{
|
||||
ASSERT(descr && descr->func);
|
||||
descr->func->deinit(&descr->device);
|
||||
ASSERT(descr);
|
||||
_pwm_deinit(&descr->device);
|
||||
|
||||
return ERR_NONE;
|
||||
}
|
||||
@@ -72,11 +71,11 @@ int32_t pwm_deinit(struct pwm_descriptor *const descr)
|
||||
*/
|
||||
int32_t pwm_enable(struct pwm_descriptor *const descr)
|
||||
{
|
||||
ASSERT(descr && descr->func);
|
||||
if (descr->func->is_pwm_enabled(&descr->device)) {
|
||||
ASSERT(descr);
|
||||
if (_pwm_is_enabled(&descr->device)) {
|
||||
return ERR_DENIED;
|
||||
}
|
||||
descr->func->start_pwm(&descr->device);
|
||||
_pwm_enable(&descr->device);
|
||||
|
||||
return ERR_NONE;
|
||||
}
|
||||
@@ -86,11 +85,11 @@ int32_t pwm_enable(struct pwm_descriptor *const descr)
|
||||
*/
|
||||
int32_t pwm_disable(struct pwm_descriptor *const descr)
|
||||
{
|
||||
ASSERT(descr && descr->func);
|
||||
if (!descr->func->is_pwm_enabled(&descr->device)) {
|
||||
ASSERT(descr);
|
||||
if (!_pwm_is_enabled(&descr->device)) {
|
||||
return ERR_DENIED;
|
||||
}
|
||||
descr->func->stop_pwm(&descr->device);
|
||||
_pwm_disable(&descr->device);
|
||||
|
||||
return ERR_NONE;
|
||||
}
|
||||
@@ -112,8 +111,8 @@ int32_t pwm_register_callback(struct pwm_descriptor *const descr, enum pwm_callb
|
||||
default:
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
ASSERT(descr && descr->func);
|
||||
descr->func->set_irq_state(&descr->device, (enum _pwm_callback_type)type, NULL != cb);
|
||||
ASSERT(descr);
|
||||
_pwm_set_irq_state(&descr->device, (enum _pwm_callback_type)type, NULL != cb);
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
@@ -122,8 +121,8 @@ int32_t pwm_register_callback(struct pwm_descriptor *const descr, enum pwm_callb
|
||||
*/
|
||||
int32_t pwm_set_parameters(struct pwm_descriptor *const descr, const pwm_period_t period, const pwm_period_t duty_cycle)
|
||||
{
|
||||
ASSERT(descr && descr->func);
|
||||
descr->func->set_pwm_param(&descr->device, period, duty_cycle);
|
||||
ASSERT(descr);
|
||||
_pwm_set_param(&descr->device, period, duty_cycle);
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user