remove unused ASF code
This commit is contained in:
@@ -1,74 +0,0 @@
|
||||
======================
|
||||
ADC Synchronous driver
|
||||
======================
|
||||
|
||||
An ADC (Analog-to-Digital Converter) converts analog signals to digital values.
|
||||
A reference signal with a known voltage level is quantified into equally
|
||||
sized chunks, each representing a digital value from 0 to the highest number
|
||||
possible with the bit resolution supported by the ADC. The input voltage
|
||||
measured by the ADC is compared against these chunks and the chunk with the
|
||||
closest voltage level defines the digital value that can be used to represent
|
||||
the analog input voltage level.
|
||||
|
||||
Usually an ADC can operate in either differential or single-ended mode.
|
||||
In differential mode two signals (V+ and V-) are compared against each other
|
||||
and the resulting digital value represents the relative voltage level between
|
||||
V+ and V-. This means that if the input voltage level on V+ is lower than on
|
||||
V- the digital value is negative, which also means that in differential
|
||||
mode one bit is lost to the sign. In single-ended mode only V+ is compared
|
||||
against the reference voltage, and the resulting digital value can only be
|
||||
positive, but the full bit-range of the ADC can be used.
|
||||
|
||||
Usually multiple resolutions are supported by the ADC, lower resolution can
|
||||
reduce the conversion time, but lose accuracy.
|
||||
|
||||
Some ADCs has a gain stage on the input lines which can be used to increase the
|
||||
dynamic range. The default gain value is usually x1, which means that the
|
||||
conversion range is from 0V to the reference voltage.
|
||||
Applications can change the gain stage, to increase or reduce the conversion
|
||||
range.
|
||||
|
||||
The window mode allows the conversion result to be compared to a set of
|
||||
predefined threshold values. Applications can use callback function to monitor
|
||||
if the conversion result exceeds predefined threshold value.
|
||||
|
||||
Usually multiple reference voltages are supported by the ADC, both internal and
|
||||
external with difference voltage levels. The reference voltage have an impact
|
||||
on the accuracy, and should be selected to cover the full range of the analog
|
||||
input signal and never less than the expected maximum input voltage.
|
||||
|
||||
There are two conversion modes supported by ADC, single shot and free running.
|
||||
In single shot mode the ADC only make one conversion when triggered by the
|
||||
application, in free running mode it continues to make conversion from it
|
||||
is triggered until it is stopped by the application. When window monitoring,
|
||||
the ADC should be set to free running mode.
|
||||
|
||||
Features
|
||||
--------
|
||||
* Initialization and de-initialization
|
||||
* Support multiple Conversion Mode, Single or Free run
|
||||
* Start ADC Conversion
|
||||
* Read Conversion Result
|
||||
|
||||
Applications
|
||||
------------
|
||||
* Measurement of internal sensor. E.g., MCU internal temperature sensor value.
|
||||
* Measurement of external sensor. E.g., Temperature, humidity sensor value.
|
||||
* Sampling and measurement of a signal. E.g., sinusoidal wave, square wave.
|
||||
|
||||
Dependencies
|
||||
------------
|
||||
* ADC hardware
|
||||
|
||||
Concurrency
|
||||
-----------
|
||||
N/A
|
||||
|
||||
Limitations
|
||||
-----------
|
||||
N/A
|
||||
|
||||
Knows issues and workarounds
|
||||
----------------------------
|
||||
N/A
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
The PWM Driver(bare-bone)
|
||||
=========================
|
||||
|
||||
Pulse-width modulation (PWM) is used to create an analog behavior
|
||||
digitally by controlling the amount of power transferred to the
|
||||
connected peripheral. This is achieved by controlling the high period
|
||||
(duty-cycle) of a periodic signal.
|
||||
|
||||
User can change the period or duty cycle whenever PWM is running. The
|
||||
function pwm_set_parameters is used to configure these two parameters.
|
||||
Note these are raw register values and the parameter duty_cycle means
|
||||
the period of first half during one cycle, which should be not beyond
|
||||
total period value.
|
||||
|
||||
In addition, user can also get multi PWM channels output from different
|
||||
peripherals at the same time, which is implemented more flexible by the
|
||||
function pointers.
|
||||
|
||||
Features
|
||||
--------
|
||||
|
||||
* Initialization/de-initialization
|
||||
* Enabling/disabling
|
||||
* Run-time control of PWM duty-cycle and period
|
||||
* Notifications about errors and one PWM cycle is done
|
||||
|
||||
Applications
|
||||
------------
|
||||
|
||||
Motor control, ballast, LED, H-bridge, power converters, and
|
||||
other types of power control applications.
|
||||
|
||||
Dependencies
|
||||
------------
|
||||
|
||||
The peripheral which can perform waveform generation like frequency
|
||||
generation and pulse-width modulation, such as Timer/Counter.
|
||||
|
||||
Concurrency
|
||||
-----------
|
||||
|
||||
N/A
|
||||
|
||||
Limitations
|
||||
-----------
|
||||
|
||||
The current driver doesn't support the features like recoverable,
|
||||
non-recoverable faults, dithering, dead-time insertion.
|
||||
|
||||
Known issues and workarounds
|
||||
----------------------------
|
||||
|
||||
N/A
|
||||
@@ -1,277 +0,0 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief ADC functionality declaration.
|
||||
*
|
||||
* Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
|
||||
*
|
||||
* \asf_license_start
|
||||
*
|
||||
* \page License
|
||||
*
|
||||
* Subject to your compliance with these terms, you may use Microchip
|
||||
* software and any derivatives exclusively with Microchip products.
|
||||
* It is your responsibility to comply with third party license terms applicable
|
||||
* to your use of third party software (including open source software) that
|
||||
* may accompany Microchip software.
|
||||
*
|
||||
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
|
||||
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
|
||||
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
|
||||
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
|
||||
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
|
||||
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
|
||||
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
|
||||
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
|
||||
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
|
||||
*
|
||||
* \asf_license_stop
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _HAL_ADC_SYNC_H_INCLUDED
|
||||
#define _HAL_ADC_SYNC_H_INCLUDED
|
||||
|
||||
#include <hpl_adc_sync.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \addtogroup doc_driver_hal_adc_sync
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \brief ADC descriptor
|
||||
*
|
||||
* The ADC descriptor forward declaration.
|
||||
*/
|
||||
struct adc_sync_descriptor;
|
||||
|
||||
/**
|
||||
* \brief ADC descriptor
|
||||
*/
|
||||
struct adc_sync_descriptor {
|
||||
/** ADC device */
|
||||
struct _adc_sync_device device;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Initialize ADC
|
||||
*
|
||||
* This function initializes the given ADC descriptor.
|
||||
* It checks if the given hardware is not initialized and if the given hardware
|
||||
* is permitted to be initialized.
|
||||
*
|
||||
* \param[out] descr An ADC descriptor to initialize
|
||||
* \param[in] hw The pointer to hardware instance
|
||||
* \param[in] func The pointer to a set of functions pointers
|
||||
*
|
||||
* \return Initialization status.
|
||||
*/
|
||||
int32_t adc_sync_init(struct adc_sync_descriptor *const descr, void *const hw, void *const func);
|
||||
|
||||
/**
|
||||
* \brief Deinitialize ADC
|
||||
*
|
||||
* This function deinitializes the given ADC descriptor.
|
||||
* It checks if the given hardware is initialized and if the given hardware is
|
||||
* permitted to be deinitialized.
|
||||
*
|
||||
* \param[in] descr An ADC descriptor to deinitialize
|
||||
*
|
||||
* \return De-initialization status.
|
||||
*/
|
||||
int32_t adc_sync_deinit(struct adc_sync_descriptor *const descr);
|
||||
|
||||
/**
|
||||
* \brief Enable ADC
|
||||
*
|
||||
* Use this function to set the ADC peripheral to enabled state.
|
||||
*
|
||||
* \param[in] descr Pointer to the ADC descriptor
|
||||
* \param[in] channel Channel number
|
||||
*
|
||||
* \return Operation status
|
||||
*
|
||||
*/
|
||||
int32_t adc_sync_enable_channel(struct adc_sync_descriptor *const descr, const uint8_t channel);
|
||||
|
||||
/**
|
||||
* \brief Disable ADC
|
||||
*
|
||||
* Use this function to set the ADC peripheral to disabled state.
|
||||
*
|
||||
* \param[in] descr Pointer to the ADC descriptor
|
||||
* \param[in] channel Channel number
|
||||
*
|
||||
* \return Operation status
|
||||
*
|
||||
*/
|
||||
int32_t adc_sync_disable_channel(struct adc_sync_descriptor *const descr, const uint8_t channel);
|
||||
|
||||
/**
|
||||
* \brief Read data from ADC
|
||||
*
|
||||
* \param[in] descr The pointer to the ADC descriptor
|
||||
* \param[in] channel Channel number
|
||||
* \param[in] buf A buffer to read data to
|
||||
* \param[in] length The size of a buffer
|
||||
*
|
||||
* \return The number of bytes read.
|
||||
*/
|
||||
int32_t adc_sync_read_channel(struct adc_sync_descriptor *const descr, const uint8_t channel, uint8_t *const buffer,
|
||||
const uint16_t length);
|
||||
|
||||
/**
|
||||
* \brief Set ADC reference source
|
||||
*
|
||||
* This function sets ADC reference source.
|
||||
*
|
||||
* \param[in] descr The pointer to the ADC descriptor
|
||||
* \param[in] reference A reference source to set
|
||||
*
|
||||
* \return Status of the ADC reference source setting.
|
||||
*/
|
||||
int32_t adc_sync_set_reference(struct adc_sync_descriptor *const descr, const adc_reference_t reference);
|
||||
|
||||
/**
|
||||
* \brief Set ADC resolution
|
||||
*
|
||||
* This function sets ADC resolution.
|
||||
*
|
||||
* \param[in] descr The pointer to the ADC descriptor
|
||||
* \param[in] resolution A resolution to set
|
||||
*
|
||||
* \return Status of the ADC resolution setting.
|
||||
*/
|
||||
int32_t adc_sync_set_resolution(struct adc_sync_descriptor *const descr, const adc_resolution_t resolution);
|
||||
|
||||
/**
|
||||
* \brief Set ADC input source of a channel
|
||||
*
|
||||
* This function sets ADC positive and negative input sources.
|
||||
*
|
||||
* \param[in] descr The pointer to the ADC descriptor
|
||||
* \param[in] pos_input A positive input source to set
|
||||
* \param[in] neg_input A negative input source to set
|
||||
* \param[in] channel Channel number
|
||||
*
|
||||
* \return Status of the ADC channels setting.
|
||||
*/
|
||||
int32_t adc_sync_set_inputs(struct adc_sync_descriptor *const descr, const adc_pos_input_t pos_input,
|
||||
const adc_neg_input_t neg_input, const uint8_t channel);
|
||||
|
||||
/**
|
||||
* \brief Set ADC conversion mode
|
||||
*
|
||||
* This function sets ADC conversion mode.
|
||||
*
|
||||
* \param[in] descr The pointer to the ADC descriptor
|
||||
* \param[in] mode A conversion mode to set
|
||||
*
|
||||
* \return Status of the ADC conversion mode setting.
|
||||
*/
|
||||
int32_t adc_sync_set_conversion_mode(struct adc_sync_descriptor *const descr, const enum adc_conversion_mode mode);
|
||||
|
||||
/**
|
||||
* \brief Set ADC differential mode
|
||||
*
|
||||
* This function sets ADC differential mode.
|
||||
*
|
||||
* \param[in] descr The pointer to the ADC descriptor
|
||||
* \param[in] channel Channel number
|
||||
* \param[in] mode A differential mode to set
|
||||
*
|
||||
* \return Status of the ADC differential mode setting.
|
||||
*/
|
||||
int32_t adc_sync_set_channel_differential_mode(struct adc_sync_descriptor *const descr, const uint8_t channel,
|
||||
const enum adc_differential_mode mode);
|
||||
|
||||
/**
|
||||
* \brief Set ADC channel gain
|
||||
*
|
||||
* This function sets ADC channel gain.
|
||||
*
|
||||
* \param[in] descr The pointer to the ADC descriptor
|
||||
* \param[in] channel Channel number
|
||||
* \param[in] gain A gain to set
|
||||
*
|
||||
* \return Status of the ADC gain setting.
|
||||
*/
|
||||
int32_t adc_sync_set_channel_gain(struct adc_sync_descriptor *const descr, const uint8_t channel,
|
||||
const adc_gain_t gain);
|
||||
|
||||
/**
|
||||
* \brief Set ADC window mode
|
||||
*
|
||||
* This function sets ADC window mode.
|
||||
*
|
||||
* \param[in] descr The pointer to the ADC descriptor
|
||||
* \param[in] mode A window mode to set
|
||||
*
|
||||
* \return Status of the ADC window mode setting.
|
||||
*/
|
||||
int32_t adc_sync_set_window_mode(struct adc_sync_descriptor *const descr, const adc_window_mode_t mode);
|
||||
|
||||
/**
|
||||
* \brief Set ADC thresholds
|
||||
*
|
||||
* This function sets ADC positive and negative thresholds.
|
||||
*
|
||||
* \param[in] descr The pointer to the ADC descriptor
|
||||
* \param[in] low_threshold A lower thresholds to set
|
||||
* \param[in] up_threshold An upper thresholds to set
|
||||
*
|
||||
* \return Status of the ADC thresholds setting.
|
||||
*/
|
||||
int32_t adc_sync_set_thresholds(struct adc_sync_descriptor *const descr, const adc_threshold_t low_threshold,
|
||||
const adc_threshold_t up_threshold);
|
||||
|
||||
/**
|
||||
* \brief Retrieve threshold state
|
||||
*
|
||||
* This function retrieves ADC threshold state.
|
||||
*
|
||||
* \param[in] descr The pointer to the ADC descriptor
|
||||
* \param[out] state The threshold state
|
||||
*
|
||||
* \return The state of ADC thresholds state retrieving.
|
||||
*/
|
||||
int32_t adc_sync_get_threshold_state(const struct adc_sync_descriptor *const descr,
|
||||
adc_threshold_status_t *const state);
|
||||
|
||||
/**
|
||||
* \brief Check if conversion is complete
|
||||
*
|
||||
* This function checks if the ADC has finished the conversion.
|
||||
*
|
||||
* \param[in] descr The pointer to the ADC descriptor
|
||||
* \param[in] channel Channel number
|
||||
*
|
||||
* \return The status of ADC conversion completion checking.
|
||||
* \retval 1 The conversion is complete
|
||||
* \retval 0 The conversion is not complete
|
||||
*/
|
||||
int32_t adc_sync_is_channel_conversion_complete(const struct adc_sync_descriptor *const descr, const uint8_t channel);
|
||||
|
||||
/**
|
||||
* \brief Retrieve the current driver version
|
||||
*
|
||||
* \return Current driver version.
|
||||
*/
|
||||
uint32_t adc_sync_get_version(void);
|
||||
/**@}*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#include <hpl_missing_features.h>
|
||||
|
||||
#endif /* _HAL_ADC_SYNC_H_INCLUDED */
|
||||
@@ -1,153 +0,0 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief PWM functionality declaration.
|
||||
*
|
||||
* Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
|
||||
*
|
||||
* \asf_license_start
|
||||
*
|
||||
* \page License
|
||||
*
|
||||
* Subject to your compliance with these terms, you may use Microchip
|
||||
* software and any derivatives exclusively with Microchip products.
|
||||
* It is your responsibility to comply with third party license terms applicable
|
||||
* to your use of third party software (including open source software) that
|
||||
* may accompany Microchip software.
|
||||
*
|
||||
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
|
||||
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
|
||||
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
|
||||
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
|
||||
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
|
||||
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
|
||||
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
|
||||
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
|
||||
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
|
||||
*
|
||||
* \asf_license_stop
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef HAL_PWM_H_INCLUDED
|
||||
#define HAL_PWM_H_INCLUDED
|
||||
|
||||
#include <hpl_pwm.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \addtogroup doc_driver_hal_pwm_async
|
||||
*
|
||||
*@{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \brief PWM descriptor
|
||||
*
|
||||
* The PWM descriptor forward declaration.
|
||||
*/
|
||||
struct pwm_descriptor;
|
||||
|
||||
/**
|
||||
* \brief PWM callback type
|
||||
*/
|
||||
typedef void (*pwm_cb_t)(const struct pwm_descriptor *const descr);
|
||||
|
||||
/**
|
||||
* \brief PWM callback types
|
||||
*/
|
||||
enum pwm_callback_type { PWM_PERIOD_CB, PWM_ERROR_CB };
|
||||
|
||||
/**
|
||||
* \brief PWM callbacks
|
||||
*/
|
||||
struct pwm_callbacks {
|
||||
pwm_cb_t period;
|
||||
pwm_cb_t error;
|
||||
};
|
||||
|
||||
/** \brief PWM descriptor
|
||||
*/
|
||||
struct pwm_descriptor {
|
||||
/** PWM device */
|
||||
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
|
||||
*
|
||||
* \param[in] descr Pointer to the HAL PWM descriptor
|
||||
* \param[in] hw The pointer to hardware instance
|
||||
* \param[in] func The pointer to a set of functions pointers
|
||||
*
|
||||
* \return Operation status.
|
||||
*/
|
||||
int32_t pwm_init(struct pwm_descriptor *const descr, void *const hw, struct _pwm_hpl_interface *const func);
|
||||
|
||||
/** \brief Deinitialize the PWM HAL instance and hardware
|
||||
*
|
||||
* \param[in] descr Pointer to the HAL PWM descriptor
|
||||
*
|
||||
* \return Operation status.
|
||||
*/
|
||||
int32_t pwm_deinit(struct pwm_descriptor *const descr);
|
||||
|
||||
/** \brief PWM output start
|
||||
*
|
||||
* \param[in] descr Pointer to the HAL PWM descriptor
|
||||
*
|
||||
* \return Operation status.
|
||||
*/
|
||||
int32_t pwm_enable(struct pwm_descriptor *const descr);
|
||||
|
||||
/** \brief PWM output stop
|
||||
*
|
||||
* \param[in] descr Pointer to the HAL PWM descriptor
|
||||
*
|
||||
* \return Operation status.
|
||||
*/
|
||||
int32_t pwm_disable(struct pwm_descriptor *const descr);
|
||||
|
||||
/** \brief Register PWM callback
|
||||
*
|
||||
* \param[in] descr Pointer to the HAL PWM descriptor
|
||||
* \param[in] type Callback type
|
||||
* \param[in] cb A callback function, passing NULL de-registers callback
|
||||
*
|
||||
* \return Operation status.
|
||||
* \retval 0 Success
|
||||
* \retval -1 Error
|
||||
*/
|
||||
int32_t pwm_register_callback(struct pwm_descriptor *const descr, enum pwm_callback_type type, pwm_cb_t cb);
|
||||
|
||||
/** \brief Change PWM parameter
|
||||
*
|
||||
* \param[in] descr Pointer to the HAL PWM descriptor
|
||||
* \param[in] period Total period of one PWM cycle
|
||||
* \param[in] duty_cycle Period of PWM first half during one cycle
|
||||
*
|
||||
* \return Operation status.
|
||||
*/
|
||||
int32_t pwm_set_parameters(struct pwm_descriptor *const descr, const pwm_period_t period,
|
||||
const pwm_period_t duty_cycle);
|
||||
|
||||
/** \brief Get PWM driver version
|
||||
*
|
||||
* \return Current driver version.
|
||||
*/
|
||||
uint32_t pwm_get_version(void);
|
||||
/**@}*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* HAL_PWM;_H_INCLUDED */
|
||||
@@ -1,264 +0,0 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief ADC related functionality declaration.
|
||||
*
|
||||
* Copyright (c) 2015-2018 Microchip Technology Inc. and its subsidiaries.
|
||||
*
|
||||
* \asf_license_start
|
||||
*
|
||||
* \page License
|
||||
*
|
||||
* Subject to your compliance with these terms, you may use Microchip
|
||||
* software and any derivatives exclusively with Microchip products.
|
||||
* It is your responsibility to comply with third party license terms applicable
|
||||
* to your use of third party software (including open source software) that
|
||||
* may accompany Microchip software.
|
||||
*
|
||||
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
|
||||
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
|
||||
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
|
||||
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
|
||||
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
|
||||
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
|
||||
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
|
||||
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
|
||||
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
|
||||
*
|
||||
* \asf_license_stop
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _HPL_ADC_ASYNC_H_INCLUDED
|
||||
#define _HPL_ADC_ASYNC_H_INCLUDED
|
||||
|
||||
/**
|
||||
* \addtogroup HPL ADC
|
||||
*
|
||||
* \section hpl_async_adc_rev Revision History
|
||||
* - v1.0.0 Initial Release
|
||||
*
|
||||
*@{
|
||||
*/
|
||||
|
||||
#include "hpl_adc_sync.h"
|
||||
#include "hpl_irq.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief ADC device structure
|
||||
*
|
||||
* The ADC device structure forward declaration.
|
||||
*/
|
||||
struct _adc_async_device;
|
||||
|
||||
/**
|
||||
* \brief ADC callback types
|
||||
*/
|
||||
enum _adc_async_callback_type { ADC_ASYNC_DEVICE_CONVERT_CB, ADC_ASYNC_DEVICE_MONITOR_CB, ADC_ASYNC_DEVICE_ERROR_CB };
|
||||
|
||||
/**
|
||||
* \brief ADC interrupt callbacks
|
||||
*/
|
||||
struct _adc_async_callbacks {
|
||||
void (*window_cb)(struct _adc_async_device *device, const uint8_t channel);
|
||||
void (*error_cb)(struct _adc_async_device *device, const uint8_t channel);
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief ADC channel interrupt callbacks
|
||||
*/
|
||||
struct _adc_async_ch_callbacks {
|
||||
void (*convert_done)(struct _adc_async_device *device, const uint8_t channel, const uint16_t data);
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief ADC descriptor device structure
|
||||
*/
|
||||
struct _adc_async_device {
|
||||
struct _adc_async_callbacks adc_async_cb;
|
||||
struct _adc_async_ch_callbacks adc_async_ch_cb;
|
||||
struct _irq_descriptor irq;
|
||||
void * hw;
|
||||
};
|
||||
|
||||
/**
|
||||
* \name HPL functions
|
||||
*/
|
||||
//@{
|
||||
/**
|
||||
* \brief Initialize synchronous ADC
|
||||
*
|
||||
* This function does low level ADC configuration.
|
||||
*
|
||||
* param[in] device The pointer to ADC device instance
|
||||
* param[in] hw The pointer to hardware instance
|
||||
*
|
||||
* \return Initialization status
|
||||
*/
|
||||
int32_t _adc_async_init(struct _adc_async_device *const device, void *const hw);
|
||||
|
||||
/**
|
||||
* \brief Deinitialize ADC
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
*/
|
||||
void _adc_async_deinit(struct _adc_async_device *const device);
|
||||
|
||||
/**
|
||||
* \brief Enable ADC peripheral
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
* \param[in] channel Channel number
|
||||
*/
|
||||
void _adc_async_enable_channel(struct _adc_async_device *const device, const uint8_t channel);
|
||||
|
||||
/**
|
||||
* \brief Disable ADC peripheral
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
* \param[in] channel Channel number
|
||||
*/
|
||||
void _adc_async_disable_channel(struct _adc_async_device *const device, const uint8_t channel);
|
||||
|
||||
/**
|
||||
* \brief Retrieve ADC conversion data size
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
*
|
||||
* \return The data size in bytes
|
||||
*/
|
||||
uint8_t _adc_async_get_data_size(const struct _adc_async_device *const device);
|
||||
|
||||
/**
|
||||
* \brief Check if conversion is done
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
* \param[in] channel Channel number
|
||||
*
|
||||
* \return The status of conversion
|
||||
* \retval true The conversion is done
|
||||
* \retval false The conversion is not done
|
||||
*/
|
||||
bool _adc_async_is_channel_conversion_done(const struct _adc_async_device *const device, const uint8_t channel);
|
||||
|
||||
/**
|
||||
* \brief Make conversion
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
*/
|
||||
void _adc_async_convert(struct _adc_async_device *const device);
|
||||
|
||||
/**
|
||||
* \brief Retrieve the conversion result
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
* \param[in] channel Channel number
|
||||
*
|
||||
* The result value
|
||||
*/
|
||||
uint16_t _adc_async_read_channel_data(const struct _adc_async_device *const device, const uint8_t channel);
|
||||
|
||||
/**
|
||||
* \brief Set reference source
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
* \param[in] reference A reference source to set
|
||||
*/
|
||||
void _adc_async_set_reference_source(struct _adc_async_device *const device, const adc_reference_t reference);
|
||||
|
||||
/**
|
||||
* \brief Set resolution
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
* \param[in] resolution A resolution to set
|
||||
*/
|
||||
void _adc_async_set_resolution(struct _adc_async_device *const device, const adc_resolution_t resolution);
|
||||
|
||||
/**
|
||||
* \brief Set ADC input source of a channel
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
* \param[in] pos_input A positive input source to set
|
||||
* \param[in] neg_input A negative input source to set
|
||||
* \param[in] channel Channel number
|
||||
*/
|
||||
void _adc_async_set_inputs(struct _adc_async_device *const device, const adc_pos_input_t pos_input,
|
||||
const adc_neg_input_t neg_input, const uint8_t channel);
|
||||
|
||||
/**
|
||||
* \brief Set conversion mode
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
* \param[in] mode A conversion mode to set
|
||||
*/
|
||||
void _adc_async_set_conversion_mode(struct _adc_async_device *const device, const enum adc_conversion_mode mode);
|
||||
|
||||
/**
|
||||
* \brief Set differential mode
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
* \param[in] channel Channel number
|
||||
* \param[in] mode A differential mode to set
|
||||
*/
|
||||
void _adc_async_set_channel_differential_mode(struct _adc_async_device *const device, const uint8_t channel,
|
||||
const enum adc_differential_mode mode);
|
||||
|
||||
/**
|
||||
* \brief Set gain
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
* \param[in] channel Channel number
|
||||
* \param[in] gain A gain to set
|
||||
*/
|
||||
void _adc_async_set_channel_gain(struct _adc_async_device *const device, const uint8_t channel, const adc_gain_t gain);
|
||||
|
||||
/**
|
||||
* \brief Set window mode
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
* \param[in] mode A mode to set
|
||||
*/
|
||||
void _adc_async_set_window_mode(struct _adc_async_device *const device, const adc_window_mode_t mode);
|
||||
|
||||
/**
|
||||
* \brief Set lower threshold
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
* \param[in] low_threshold A lower threshold to set
|
||||
* \param[in] up_threshold An upper thresholds to set
|
||||
*/
|
||||
void _adc_async_set_thresholds(struct _adc_async_device *const device, const adc_threshold_t low_threshold,
|
||||
const adc_threshold_t up_threshold);
|
||||
|
||||
/**
|
||||
* \brief Retrieve threshold state
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
* \param[out] state The threshold state
|
||||
*/
|
||||
void _adc_async_get_threshold_state(const struct _adc_async_device *const device, adc_threshold_status_t *const state);
|
||||
|
||||
/**
|
||||
* \brief Enable/disable ADC channel interrupt
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
* \param[in] channel Channel number
|
||||
* \param[in] type The type of interrupt to disable/enable if applicable
|
||||
* \param[in] state Enable or disable
|
||||
*/
|
||||
void _adc_async_set_irq_state(struct _adc_async_device *const device, const uint8_t channel,
|
||||
const enum _adc_async_callback_type type, const bool state);
|
||||
|
||||
//@}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/**@}*/
|
||||
#endif /* _HPL_ADC_ASYNC_H_INCLUDED */
|
||||
@@ -1,243 +0,0 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief ADC related functionality declaration.
|
||||
*
|
||||
* Copyright (c) 2016-2018 Microchip Technology Inc. and its subsidiaries.
|
||||
*
|
||||
* \asf_license_start
|
||||
*
|
||||
* \page License
|
||||
*
|
||||
* Subject to your compliance with these terms, you may use Microchip
|
||||
* software and any derivatives exclusively with Microchip products.
|
||||
* It is your responsibility to comply with third party license terms applicable
|
||||
* to your use of third party software (including open source software) that
|
||||
* may accompany Microchip software.
|
||||
*
|
||||
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
|
||||
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
|
||||
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
|
||||
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
|
||||
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
|
||||
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
|
||||
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
|
||||
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
|
||||
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
|
||||
*
|
||||
* \asf_license_stop
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _HPL_ADC_DMA_H_INCLUDED
|
||||
#define _HPL_ADC_DMA_H_INCLUDED
|
||||
|
||||
/**
|
||||
* \addtogroup HPL ADC
|
||||
*
|
||||
* \section hpl_dma_adc_rev Revision History
|
||||
* - v1.0.0 Initial Release
|
||||
*
|
||||
*@{
|
||||
*/
|
||||
|
||||
#include <hpl_adc_sync.h>
|
||||
#include <hpl_irq.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief ADC device structure
|
||||
*
|
||||
* The ADC device structure forward declaration.
|
||||
*/
|
||||
struct _adc_dma_device;
|
||||
|
||||
/**
|
||||
* \brief ADC callback types
|
||||
*/
|
||||
enum _adc_dma_callback_type { ADC_DMA_DEVICE_COMPLETE_CB, ADC_DMA_DEVICE_ERROR_CB };
|
||||
|
||||
/**
|
||||
* \brief ADC interrupt callbacks
|
||||
*/
|
||||
struct _adc_dma_callbacks {
|
||||
void (*complete)(struct _adc_dma_device *device, const uint16_t data);
|
||||
void (*error)(struct _adc_dma_device *device);
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief ADC descriptor device structure
|
||||
*/
|
||||
struct _adc_dma_device {
|
||||
struct _adc_dma_callbacks adc_dma_cb;
|
||||
struct _irq_descriptor irq;
|
||||
void * hw;
|
||||
};
|
||||
|
||||
/**
|
||||
* \name HPL functions
|
||||
*/
|
||||
//@{
|
||||
/**
|
||||
* \brief Initialize synchronous ADC
|
||||
*
|
||||
* This function does low level ADC configuration.
|
||||
*
|
||||
* param[in] device The pointer to ADC device instance
|
||||
* param[in] hw The pointer to hardware instance
|
||||
*
|
||||
* \return Initialization status
|
||||
*/
|
||||
int32_t _adc_dma_init(struct _adc_dma_device *const device, void *const hw);
|
||||
|
||||
/**
|
||||
* \brief Deinitialize ADC
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
*/
|
||||
void _adc_dma_deinit(struct _adc_dma_device *const device);
|
||||
|
||||
/**
|
||||
* \brief Enable ADC peripheral
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
* \param[in] channel Channel number
|
||||
*/
|
||||
void _adc_dma_enable_channel(struct _adc_dma_device *const device, const uint8_t channel);
|
||||
|
||||
/**
|
||||
* \brief Disable ADC peripheral
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
* \param[in] channel Channel number
|
||||
*/
|
||||
void _adc_dma_disable_channel(struct _adc_dma_device *const device, const uint8_t channel);
|
||||
|
||||
/**
|
||||
* \brief Return address of ADC DMA source
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
*
|
||||
* \return ADC DMA source address
|
||||
*/
|
||||
uint32_t _adc_get_source_for_dma(struct _adc_dma_device *const device);
|
||||
|
||||
/**
|
||||
* \brief Retrieve ADC conversion data size
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
*
|
||||
* \return The data size in bytes
|
||||
*/
|
||||
uint8_t _adc_dma_get_data_size(const struct _adc_dma_device *const device);
|
||||
|
||||
/**
|
||||
* \brief Check if conversion is done
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
*
|
||||
* \return The status of conversion
|
||||
* \retval true The conversion is done
|
||||
* \retval false The conversion is not done
|
||||
*/
|
||||
bool _adc_dma_is_conversion_done(const struct _adc_dma_device *const device);
|
||||
|
||||
/**
|
||||
* \brief Make conversion
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
*/
|
||||
void _adc_dma_convert(struct _adc_dma_device *const device);
|
||||
|
||||
/**
|
||||
* \brief Set reference source
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
* \param[in] reference A reference source to set
|
||||
*/
|
||||
void _adc_dma_set_reference_source(struct _adc_dma_device *const device, const adc_reference_t reference);
|
||||
|
||||
/**
|
||||
* \brief Set resolution
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
* \param[in] resolution A resolution to set
|
||||
*/
|
||||
void _adc_dma_set_resolution(struct _adc_dma_device *const device, const adc_resolution_t resolution);
|
||||
|
||||
/**
|
||||
* \brief Set ADC input source of a channel
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
* \param[in] pos_input A positive input source to set
|
||||
* \param[in] neg_input A negative input source to set
|
||||
* \param[in] channel Channel number
|
||||
*/
|
||||
void _adc_dma_set_inputs(struct _adc_dma_device *const device, const adc_pos_input_t pos_input,
|
||||
const adc_neg_input_t neg_input, const uint8_t channel);
|
||||
|
||||
/**
|
||||
* \brief Set conversion mode
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
* \param[in] mode A conversion mode to set
|
||||
*/
|
||||
void _adc_dma_set_conversion_mode(struct _adc_dma_device *const device, const enum adc_conversion_mode mode);
|
||||
|
||||
/**
|
||||
* \brief Set differential mode
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
* \param[in] channel Channel number
|
||||
* \param[in] mode A differential mode to set
|
||||
*/
|
||||
void _adc_dma_set_channel_differential_mode(struct _adc_dma_device *const device, const uint8_t channel,
|
||||
const enum adc_differential_mode mode);
|
||||
|
||||
/**
|
||||
* \brief Set gain
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
* \param[in] channel Channel number
|
||||
* \param[in] gain A gain to set
|
||||
*/
|
||||
void _adc_dma_set_channel_gain(struct _adc_dma_device *const device, const uint8_t channel, const adc_gain_t gain);
|
||||
|
||||
/**
|
||||
* \brief Set window mode
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
* \param[in] mode A mode to set
|
||||
*/
|
||||
void _adc_dma_set_window_mode(struct _adc_dma_device *const device, const adc_window_mode_t mode);
|
||||
|
||||
/**
|
||||
* \brief Set thresholds
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
* \param[in] low_threshold A lower thresholds to set
|
||||
* \param[in] up_threshold An upper thresholds to set
|
||||
*/
|
||||
void _adc_dma_set_thresholds(struct _adc_dma_device *const device, const adc_threshold_t low_threshold,
|
||||
const adc_threshold_t up_threshold);
|
||||
|
||||
/**
|
||||
* \brief Retrieve threshold state
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
* \param[out] state The threshold state
|
||||
*/
|
||||
void _adc_dma_get_threshold_state(const struct _adc_dma_device *const device, adc_threshold_status_t *const state);
|
||||
|
||||
//@}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/**@}*/
|
||||
#endif /* _HPL_ADC_DMA_H_INCLUDED */
|
||||
@@ -1,271 +0,0 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief ADC related functionality declaration.
|
||||
*
|
||||
* Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
|
||||
*
|
||||
* \asf_license_start
|
||||
*
|
||||
* \page License
|
||||
*
|
||||
* Subject to your compliance with these terms, you may use Microchip
|
||||
* software and any derivatives exclusively with Microchip products.
|
||||
* It is your responsibility to comply with third party license terms applicable
|
||||
* to your use of third party software (including open source software) that
|
||||
* may accompany Microchip software.
|
||||
*
|
||||
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
|
||||
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
|
||||
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
|
||||
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
|
||||
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
|
||||
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
|
||||
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
|
||||
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
|
||||
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
|
||||
*
|
||||
* \asf_license_stop
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _HPL_ADC_SYNC_H_INCLUDED
|
||||
#define _HPL_ADC_SYNC_H_INCLUDED
|
||||
|
||||
/**
|
||||
* \addtogroup HPL ADC
|
||||
*
|
||||
* \section hpl_adc_sync_rev Revision History
|
||||
* - v1.0.0 Initial Release
|
||||
*
|
||||
*@{
|
||||
*/
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief ADC reference source
|
||||
*/
|
||||
typedef uint8_t adc_reference_t;
|
||||
|
||||
/**
|
||||
* \brief ADC resolution
|
||||
*/
|
||||
typedef uint8_t adc_resolution_t;
|
||||
|
||||
/**
|
||||
* \brief ADC positive input for channel
|
||||
*/
|
||||
typedef uint8_t adc_pos_input_t;
|
||||
|
||||
/**
|
||||
* \brief ADC negative input for channel
|
||||
*/
|
||||
typedef uint8_t adc_neg_input_t;
|
||||
|
||||
/**
|
||||
* \brief ADC threshold
|
||||
*/
|
||||
typedef uint16_t adc_threshold_t;
|
||||
|
||||
/**
|
||||
* \brief ADC gain
|
||||
*/
|
||||
typedef uint8_t adc_gain_t;
|
||||
|
||||
/**
|
||||
* \brief ADC conversion mode
|
||||
*/
|
||||
enum adc_conversion_mode { ADC_CONVERSION_MODE_SINGLE_CONVERSION = 0, ADC_CONVERSION_MODE_FREERUN };
|
||||
|
||||
/**
|
||||
* \brief ADC differential mode
|
||||
*/
|
||||
enum adc_differential_mode { ADC_DIFFERENTIAL_MODE_SINGLE_ENDED = 0, ADC_DIFFERENTIAL_MODE_DIFFERENTIAL };
|
||||
|
||||
/**
|
||||
* \brief ADC window mode
|
||||
*/
|
||||
typedef uint8_t adc_window_mode_t;
|
||||
|
||||
/**
|
||||
* \brief ADC threshold status
|
||||
*/
|
||||
typedef bool adc_threshold_status_t;
|
||||
|
||||
/**
|
||||
* \brief ADC sync descriptor device structure
|
||||
*/
|
||||
struct _adc_sync_device {
|
||||
void *hw;
|
||||
};
|
||||
|
||||
/**
|
||||
* \name HPL functions
|
||||
*/
|
||||
//@{
|
||||
/**
|
||||
* \brief Initialize synchronous ADC
|
||||
*
|
||||
* This function does low level ADC configuration.
|
||||
*
|
||||
* param[in] device The pointer to ADC device instance
|
||||
* param[in] hw The pointer to hardware instance
|
||||
*
|
||||
* \return Initialization status
|
||||
*/
|
||||
int32_t _adc_sync_init(struct _adc_sync_device *const device, void *const hw);
|
||||
|
||||
/**
|
||||
* \brief Deinitialize ADC
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
*/
|
||||
void _adc_sync_deinit(struct _adc_sync_device *const device);
|
||||
|
||||
/**
|
||||
* \brief Enable ADC
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
* \param[in] channel Channel number
|
||||
*/
|
||||
void _adc_sync_enable_channel(struct _adc_sync_device *const device, const uint8_t channel);
|
||||
|
||||
/**
|
||||
* \brief Disable ADC
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
* \param[in] channel Channel number
|
||||
*/
|
||||
void _adc_sync_disable_channel(struct _adc_sync_device *const device, const uint8_t channel);
|
||||
|
||||
/**
|
||||
* \brief Retrieve ADC conversion data size
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
*
|
||||
* \return The data size in bytes
|
||||
*/
|
||||
uint8_t _adc_sync_get_data_size(const struct _adc_sync_device *const device);
|
||||
|
||||
/**
|
||||
* \brief Check if conversion is done
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
* \param[in] channel Channel number
|
||||
*
|
||||
* \return The status of conversion
|
||||
* \retval true The conversion is done
|
||||
* \retval false The conversion is not done
|
||||
*/
|
||||
bool _adc_sync_is_channel_conversion_done(const struct _adc_sync_device *const device, const uint8_t channel);
|
||||
|
||||
/**
|
||||
* \brief Make conversion
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
*/
|
||||
void _adc_sync_convert(struct _adc_sync_device *const device);
|
||||
|
||||
/**
|
||||
* \brief Retrieve the conversion result
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
* \param[in] channel Channel number
|
||||
*
|
||||
* \return The result value of channel
|
||||
*/
|
||||
uint16_t _adc_sync_read_channel_data(const struct _adc_sync_device *const device, const uint8_t channel);
|
||||
|
||||
/**
|
||||
* \brief Set reference source
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
* \param[in] reference A reference source to set
|
||||
*/
|
||||
void _adc_sync_set_reference_source(struct _adc_sync_device *const device, const adc_reference_t reference);
|
||||
|
||||
/**
|
||||
* \brief Set resolution
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
* \param[in] resolution A resolution to set
|
||||
*/
|
||||
void _adc_sync_set_resolution(struct _adc_sync_device *const device, const adc_resolution_t resolution);
|
||||
|
||||
/**
|
||||
* \brief Set ADC input source of a channel
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
* \param[in] pos_input A positive input source to set
|
||||
* \param[in] neg_input A negative input source to set
|
||||
* \param[in] channel Channel number
|
||||
*/
|
||||
void _adc_sync_set_inputs(struct _adc_sync_device *const device, const adc_pos_input_t pos_input,
|
||||
const adc_neg_input_t neg_input, const uint8_t channel);
|
||||
|
||||
/**
|
||||
* \brief Set conversion mode
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
* \param[in] mode A conversion mode to set
|
||||
*/
|
||||
void _adc_sync_set_conversion_mode(struct _adc_sync_device *const device, const enum adc_conversion_mode mode);
|
||||
|
||||
/**
|
||||
* \brief Set differential mode
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
* \param[in] channel Channel number
|
||||
* \param[in] mode A differential mode to set
|
||||
*/
|
||||
void _adc_sync_set_channel_differential_mode(struct _adc_sync_device *const device, const uint8_t channel,
|
||||
const enum adc_differential_mode mode);
|
||||
|
||||
/**
|
||||
* \brief Set gain
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
* \param[in] channel Channel number
|
||||
* \param[in] gain A gain to set
|
||||
*/
|
||||
void _adc_sync_set_channel_gain(struct _adc_sync_device *const device, const uint8_t channel, const adc_gain_t gain);
|
||||
|
||||
/**
|
||||
* \brief Set window mode
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
* \param[in] mode A mode to set
|
||||
*/
|
||||
void _adc_sync_set_window_mode(struct _adc_sync_device *const device, const adc_window_mode_t mode);
|
||||
|
||||
/**
|
||||
* \brief Set threshold
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
* \param[in] low_threshold A lower threshold to set
|
||||
* \param[in] up_threshold An upper thresholds to set
|
||||
*/
|
||||
void _adc_sync_set_thresholds(struct _adc_sync_device *const device, const adc_threshold_t low_threshold,
|
||||
const adc_threshold_t up_threshold);
|
||||
|
||||
/**
|
||||
* \brief Retrieve threshold state
|
||||
*
|
||||
* \param[in] device The pointer to ADC device instance
|
||||
* \param[out] state The threshold state
|
||||
*/
|
||||
void _adc_sync_get_threshold_state(const struct _adc_sync_device *const device, adc_threshold_status_t *const state);
|
||||
//@}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/**@}*/
|
||||
#endif /* _HPL_ADC_SYNC_H_INCLUDED */
|
||||
@@ -1,105 +0,0 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief PWM related functionality declaration.
|
||||
*
|
||||
* Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
|
||||
*
|
||||
* \asf_license_start
|
||||
*
|
||||
* \page License
|
||||
*
|
||||
* Subject to your compliance with these terms, you may use Microchip
|
||||
* software and any derivatives exclusively with Microchip products.
|
||||
* It is your responsibility to comply with third party license terms applicable
|
||||
* to your use of third party software (including open source software) that
|
||||
* may accompany Microchip software.
|
||||
*
|
||||
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
|
||||
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
|
||||
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
|
||||
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
|
||||
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
|
||||
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
|
||||
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
|
||||
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
|
||||
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
|
||||
*
|
||||
* \asf_license_stop
|
||||
*
|
||||
*/
|
||||
#ifndef _HPL_PWM_H_INCLUDED
|
||||
#define _HPL_PWM_H_INCLUDED
|
||||
|
||||
/**
|
||||
* \addtogroup HPL PWM
|
||||
*
|
||||
* \section hpl_pwm_rev Revision History
|
||||
* - v1.0.0 Initial Release
|
||||
*
|
||||
*@{
|
||||
*/
|
||||
|
||||
#include <compiler.h>
|
||||
#include "hpl_irq.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief PWM callback types
|
||||
*/
|
||||
enum _pwm_callback_type { PWM_DEVICE_PERIOD_CB, PWM_DEVICE_ERROR_CB };
|
||||
|
||||
/**
|
||||
* \brief PWM pulse-width period
|
||||
*/
|
||||
typedef uint32_t pwm_period_t;
|
||||
|
||||
/**
|
||||
* \brief PWM device structure
|
||||
*
|
||||
* The PWM device structure forward declaration.
|
||||
*/
|
||||
struct _pwm_device;
|
||||
|
||||
/**
|
||||
* \brief PWM interrupt callbacks
|
||||
*/
|
||||
struct _pwm_callback {
|
||||
void (*pwm_period_cb)(struct _pwm_device *device);
|
||||
void (*pwm_error_cb)(struct _pwm_device *device);
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief PWM descriptor device structure
|
||||
*/
|
||||
struct _pwm_device {
|
||||
struct _pwm_callback callback;
|
||||
struct _irq_descriptor irq;
|
||||
void * hw;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief PWM functions, pointers to low-level functions
|
||||
*/
|
||||
struct _pwm_hpl_interface {
|
||||
int32_t (*init)(struct _pwm_device *const device, void *const hw);
|
||||
void (*deinit)(struct _pwm_device *const device);
|
||||
void (*start_pwm)(struct _pwm_device *const device);
|
||||
void (*stop_pwm)(struct _pwm_device *const device);
|
||||
void (*set_pwm_param)(struct _pwm_device *const device, const pwm_period_t period, const pwm_period_t duty_cycle);
|
||||
bool (*is_pwm_enabled)(const struct _pwm_device *const device);
|
||||
pwm_period_t (*pwm_get_period)(const struct _pwm_device *const device);
|
||||
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);
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/**@}*/
|
||||
#endif /* _HPL_PWM_H_INCLUDED */
|
||||
@@ -1,245 +0,0 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief ADC functionality implementation.
|
||||
*
|
||||
* Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
|
||||
*
|
||||
* \asf_license_start
|
||||
*
|
||||
* \page License
|
||||
*
|
||||
* Subject to your compliance with these terms, you may use Microchip
|
||||
* software and any derivatives exclusively with Microchip products.
|
||||
* It is your responsibility to comply with third party license terms applicable
|
||||
* to your use of third party software (including open source software) that
|
||||
* may accompany Microchip software.
|
||||
*
|
||||
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
|
||||
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
|
||||
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
|
||||
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
|
||||
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
|
||||
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
|
||||
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
|
||||
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
|
||||
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
|
||||
*
|
||||
* \asf_license_stop
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \brief Indicates HAL being compiled. Must be defined before including.
|
||||
*/
|
||||
#define _COMPILING_HAL
|
||||
|
||||
#include "hal_adc_sync.h"
|
||||
#include <utils_assert.h>
|
||||
|
||||
/**
|
||||
* \brief Driver version
|
||||
*/
|
||||
#define DRIVER_VERSION 0x00000001u
|
||||
|
||||
/**
|
||||
* \brief Maximum amount of ADC interface instances
|
||||
*/
|
||||
#define MAX_ADC_AMOUNT ADC_INST_NUM
|
||||
|
||||
/**
|
||||
* \brief Initialize ADC
|
||||
*/
|
||||
int32_t adc_sync_init(struct adc_sync_descriptor *const descr, void *const hw, void *const func)
|
||||
{
|
||||
ASSERT(descr && hw);
|
||||
(void)func;
|
||||
|
||||
return _adc_sync_init(&descr->device, hw);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Deinitialize ADC
|
||||
*/
|
||||
int32_t adc_sync_deinit(struct adc_sync_descriptor *const descr)
|
||||
{
|
||||
ASSERT(descr);
|
||||
_adc_sync_deinit(&descr->device);
|
||||
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Enable ADC
|
||||
*/
|
||||
int32_t adc_sync_enable_channel(struct adc_sync_descriptor *const descr, const uint8_t channel)
|
||||
{
|
||||
ASSERT(descr);
|
||||
_adc_sync_enable_channel(&descr->device, channel);
|
||||
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Disable ADC
|
||||
*/
|
||||
int32_t adc_sync_disable_channel(struct adc_sync_descriptor *const descr, const uint8_t channel)
|
||||
{
|
||||
ASSERT(descr);
|
||||
_adc_sync_disable_channel(&descr->device, channel);
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
/*
|
||||
* \brief Read data from ADC
|
||||
*/
|
||||
int32_t adc_sync_read_channel(struct adc_sync_descriptor *const descr, const uint8_t channel, uint8_t *const buffer,
|
||||
const uint16_t length)
|
||||
{
|
||||
uint8_t data_size;
|
||||
uint16_t offset = 0;
|
||||
|
||||
ASSERT(descr && buffer && length);
|
||||
data_size = _adc_sync_get_data_size(&descr->device);
|
||||
ASSERT(!(length % data_size));
|
||||
|
||||
do {
|
||||
uint16_t result;
|
||||
_adc_sync_convert(&descr->device);
|
||||
|
||||
while (!_adc_sync_is_channel_conversion_done(&descr->device, channel))
|
||||
;
|
||||
|
||||
result = _adc_sync_read_channel_data(&descr->device, channel);
|
||||
buffer[offset] = result;
|
||||
if (1 < data_size) {
|
||||
buffer[offset + 1] = result >> 8;
|
||||
}
|
||||
offset += data_size;
|
||||
} while (offset < length);
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Set ADC reference source
|
||||
*/
|
||||
int32_t adc_sync_set_reference(struct adc_sync_descriptor *const descr, const adc_reference_t reference)
|
||||
{
|
||||
ASSERT(descr);
|
||||
_adc_sync_set_reference_source(&descr->device, reference);
|
||||
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Set ADC resolution
|
||||
*/
|
||||
int32_t adc_sync_set_resolution(struct adc_sync_descriptor *const descr, const adc_resolution_t resolution)
|
||||
{
|
||||
ASSERT(descr);
|
||||
_adc_sync_set_resolution(&descr->device, resolution);
|
||||
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Set ADC input source of a channel
|
||||
*/
|
||||
int32_t adc_sync_set_inputs(struct adc_sync_descriptor *const descr, const adc_pos_input_t pos_input,
|
||||
const adc_neg_input_t neg_input, const uint8_t channel)
|
||||
{
|
||||
ASSERT(descr);
|
||||
_adc_sync_set_inputs(&descr->device, pos_input, neg_input, channel);
|
||||
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Set ADC thresholds
|
||||
*/
|
||||
int32_t adc_sync_set_thresholds(struct adc_sync_descriptor *const descr, const adc_threshold_t low_threshold,
|
||||
const adc_threshold_t up_threshold)
|
||||
{
|
||||
ASSERT(descr);
|
||||
_adc_sync_set_thresholds(&descr->device, low_threshold, up_threshold);
|
||||
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Set ADC gain
|
||||
*/
|
||||
int32_t adc_sync_set_channel_gain(struct adc_sync_descriptor *const descr, const uint8_t channel, const adc_gain_t gain)
|
||||
{
|
||||
ASSERT(descr);
|
||||
_adc_sync_set_channel_gain(&descr->device, channel, gain);
|
||||
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Set ADC conversion mode
|
||||
*/
|
||||
int32_t adc_sync_set_conversion_mode(struct adc_sync_descriptor *const descr, const enum adc_conversion_mode mode)
|
||||
{
|
||||
ASSERT(descr);
|
||||
_adc_sync_set_conversion_mode(&descr->device, mode);
|
||||
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Set ADC differential mode
|
||||
*/
|
||||
int32_t adc_sync_set_channel_differential_mode(struct adc_sync_descriptor *const descr, const uint8_t channel,
|
||||
const enum adc_differential_mode mode)
|
||||
{
|
||||
ASSERT(descr);
|
||||
_adc_sync_set_channel_differential_mode(&descr->device, channel, mode);
|
||||
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Set ADC window mode
|
||||
*/
|
||||
int32_t adc_sync_set_window_mode(struct adc_sync_descriptor *const descr, const adc_window_mode_t mode)
|
||||
{
|
||||
ASSERT(descr);
|
||||
_adc_sync_set_window_mode(&descr->device, mode);
|
||||
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Retrieve threshold state
|
||||
*/
|
||||
int32_t adc_sync_get_threshold_state(const struct adc_sync_descriptor *const descr, adc_threshold_status_t *const state)
|
||||
{
|
||||
ASSERT(descr && state);
|
||||
_adc_sync_get_threshold_state(&descr->device, state);
|
||||
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Check if conversion is complete
|
||||
*/
|
||||
int32_t adc_sync_is_channel_conversion_complete(const struct adc_sync_descriptor *const descr, const uint8_t channel)
|
||||
{
|
||||
ASSERT(descr);
|
||||
return _adc_sync_is_channel_conversion_done(&descr->device, channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Retrieve the current driver version
|
||||
*/
|
||||
uint32_t adc_sync_get_version(void)
|
||||
{
|
||||
return DRIVER_VERSION;
|
||||
}
|
||||
|
||||
//@}
|
||||
@@ -1,160 +0,0 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief PWM functionality implementation.
|
||||
*
|
||||
* Copyright (c) 2015-2018 Microchip Technology Inc. and its subsidiaries.
|
||||
*
|
||||
* \asf_license_start
|
||||
*
|
||||
* \page License
|
||||
*
|
||||
* Subject to your compliance with these terms, you may use Microchip
|
||||
* software and any derivatives exclusively with Microchip products.
|
||||
* It is your responsibility to comply with third party license terms applicable
|
||||
* to your use of third party software (including open source software) that
|
||||
* may accompany Microchip software.
|
||||
*
|
||||
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
|
||||
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
|
||||
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
|
||||
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
|
||||
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
|
||||
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
|
||||
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
|
||||
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
|
||||
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
|
||||
*
|
||||
* \asf_license_stop
|
||||
*
|
||||
*/
|
||||
|
||||
#include "hal_pwm.h"
|
||||
#include <utils_assert.h>
|
||||
#include <utils.h>
|
||||
|
||||
/**
|
||||
* \brief Driver version
|
||||
*/
|
||||
#define DRIVER_VERSION 0x00000001u
|
||||
|
||||
static void pwm_period_expired(struct _pwm_device *device);
|
||||
static void pwm_detect_fault(struct _pwm_device *device);
|
||||
|
||||
/**
|
||||
* \brief Initialize pwm
|
||||
*/
|
||||
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);
|
||||
descr->device.callback.pwm_period_cb = pwm_period_expired;
|
||||
descr->device.callback.pwm_error_cb = pwm_detect_fault;
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Deinitialize pwm
|
||||
*/
|
||||
int32_t pwm_deinit(struct pwm_descriptor *const descr)
|
||||
{
|
||||
ASSERT(descr && descr->func);
|
||||
descr->func->deinit(&descr->device);
|
||||
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Start pwm
|
||||
*/
|
||||
int32_t pwm_enable(struct pwm_descriptor *const descr)
|
||||
{
|
||||
ASSERT(descr && descr->func);
|
||||
if (descr->func->is_pwm_enabled(&descr->device)) {
|
||||
return ERR_DENIED;
|
||||
}
|
||||
descr->func->start_pwm(&descr->device);
|
||||
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Stop pwm
|
||||
*/
|
||||
int32_t pwm_disable(struct pwm_descriptor *const descr)
|
||||
{
|
||||
ASSERT(descr && descr->func);
|
||||
if (!descr->func->is_pwm_enabled(&descr->device)) {
|
||||
return ERR_DENIED;
|
||||
}
|
||||
descr->func->stop_pwm(&descr->device);
|
||||
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Register PWM callback
|
||||
*/
|
||||
int32_t pwm_register_callback(struct pwm_descriptor *const descr, enum pwm_callback_type type, pwm_cb_t cb)
|
||||
{
|
||||
switch (type) {
|
||||
case PWM_PERIOD_CB:
|
||||
descr->pwm_cb.period = cb;
|
||||
break;
|
||||
|
||||
case PWM_ERROR_CB:
|
||||
descr->pwm_cb.error = cb;
|
||||
break;
|
||||
|
||||
default:
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
ASSERT(descr && descr->func);
|
||||
descr->func->set_irq_state(&descr->device, (enum _pwm_callback_type)type, NULL != cb);
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Change PWM parameter
|
||||
*/
|
||||
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);
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Retrieve the current driver version
|
||||
*/
|
||||
uint32_t pwm_get_version(void)
|
||||
{
|
||||
return DRIVER_VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* \internal Process interrupts caused by period experied
|
||||
*/
|
||||
static void pwm_period_expired(struct _pwm_device *device)
|
||||
{
|
||||
struct pwm_descriptor *const descr = CONTAINER_OF(device, struct pwm_descriptor, device);
|
||||
|
||||
if (descr->pwm_cb.period) {
|
||||
descr->pwm_cb.period(descr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \internal Process interrupts caused by pwm fault
|
||||
*/
|
||||
static void pwm_detect_fault(struct _pwm_device *device)
|
||||
{
|
||||
struct pwm_descriptor *const descr = CONTAINER_OF(device, struct pwm_descriptor, device);
|
||||
|
||||
if (descr->pwm_cb.error) {
|
||||
descr->pwm_cb.error(descr);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user