Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-dev by
targets/TARGET_NORDIC/TARGET_NRF5/TARGET_SDK11/libraries/pwm/app_pwm.h@165:e614a9f1c9e2, 2017-05-26 (annotated)
- Committer:
- AnnaBridge
- Date:
- Fri May 26 12:39:01 2017 +0100
- Revision:
- 165:e614a9f1c9e2
- Parent:
- targets/TARGET_NORDIC/TARGET_NRF5/sdk/libraries/pwm/app_pwm.h@149:156823d33999
This updates the lib to the mbed lib v 143
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| <> | 144:ef7eb2e8f9f7 | 1 | /* |
| <> | 144:ef7eb2e8f9f7 | 2 | * Copyright (c) 2015 Nordic Semiconductor ASA |
| <> | 144:ef7eb2e8f9f7 | 3 | * All rights reserved. |
| <> | 144:ef7eb2e8f9f7 | 4 | * |
| <> | 144:ef7eb2e8f9f7 | 5 | * Redistribution and use in source and binary forms, with or without modification, |
| <> | 144:ef7eb2e8f9f7 | 6 | * are permitted provided that the following conditions are met: |
| <> | 144:ef7eb2e8f9f7 | 7 | * |
| <> | 144:ef7eb2e8f9f7 | 8 | * 1. Redistributions of source code must retain the above copyright notice, this list |
| <> | 144:ef7eb2e8f9f7 | 9 | * of conditions and the following disclaimer. |
| <> | 144:ef7eb2e8f9f7 | 10 | * |
| <> | 144:ef7eb2e8f9f7 | 11 | * 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA |
| <> | 144:ef7eb2e8f9f7 | 12 | * integrated circuit in a product or a software update for such product, must reproduce |
| <> | 144:ef7eb2e8f9f7 | 13 | * the above copyright notice, this list of conditions and the following disclaimer in |
| <> | 144:ef7eb2e8f9f7 | 14 | * the documentation and/or other materials provided with the distribution. |
| <> | 144:ef7eb2e8f9f7 | 15 | * |
| <> | 144:ef7eb2e8f9f7 | 16 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be |
| <> | 144:ef7eb2e8f9f7 | 17 | * used to endorse or promote products derived from this software without specific prior |
| <> | 144:ef7eb2e8f9f7 | 18 | * written permission. |
| <> | 144:ef7eb2e8f9f7 | 19 | * |
| <> | 144:ef7eb2e8f9f7 | 20 | * 4. This software, with or without modification, must only be used with a |
| <> | 144:ef7eb2e8f9f7 | 21 | * Nordic Semiconductor ASA integrated circuit. |
| <> | 144:ef7eb2e8f9f7 | 22 | * |
| <> | 144:ef7eb2e8f9f7 | 23 | * 5. Any software provided in binary or object form under this license must not be reverse |
| <> | 144:ef7eb2e8f9f7 | 24 | * engineered, decompiled, modified and/or disassembled. |
| <> | 144:ef7eb2e8f9f7 | 25 | * |
| <> | 144:ef7eb2e8f9f7 | 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| <> | 144:ef7eb2e8f9f7 | 27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| <> | 144:ef7eb2e8f9f7 | 28 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| <> | 144:ef7eb2e8f9f7 | 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
| <> | 144:ef7eb2e8f9f7 | 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| <> | 144:ef7eb2e8f9f7 | 31 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| <> | 144:ef7eb2e8f9f7 | 32 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
| <> | 144:ef7eb2e8f9f7 | 33 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| <> | 144:ef7eb2e8f9f7 | 34 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| <> | 144:ef7eb2e8f9f7 | 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| <> | 144:ef7eb2e8f9f7 | 36 | * |
| <> | 144:ef7eb2e8f9f7 | 37 | */ |
| <> | 144:ef7eb2e8f9f7 | 38 | |
| <> | 144:ef7eb2e8f9f7 | 39 | |
| <> | 144:ef7eb2e8f9f7 | 40 | /** @file |
| <> | 144:ef7eb2e8f9f7 | 41 | * |
| <> | 144:ef7eb2e8f9f7 | 42 | * @defgroup app_pwm Pulse-width modulation (PWM) |
| <> | 144:ef7eb2e8f9f7 | 43 | * @{ |
| <> | 144:ef7eb2e8f9f7 | 44 | * @ingroup app_common |
| <> | 144:ef7eb2e8f9f7 | 45 | * |
| <> | 144:ef7eb2e8f9f7 | 46 | * @brief Module for generating a pulse-width modulated output signal. |
| <> | 144:ef7eb2e8f9f7 | 47 | * |
| <> | 144:ef7eb2e8f9f7 | 48 | * @details This module provides a PWM implementation using timers, GPIOTE, and PPI. |
| <> | 144:ef7eb2e8f9f7 | 49 | * |
| <> | 144:ef7eb2e8f9f7 | 50 | * Resource usage: |
| <> | 144:ef7eb2e8f9f7 | 51 | * - 2 PPI channels per instance + 2 PPI channels per PWM channel. |
| <> | 144:ef7eb2e8f9f7 | 52 | * - 1 PPI group per instance. |
| <> | 144:ef7eb2e8f9f7 | 53 | * - 1 GPIOTE channel per PWM channel. |
| <> | 144:ef7eb2e8f9f7 | 54 | * |
| <> | 144:ef7eb2e8f9f7 | 55 | * For example, a PWM instance with two channels will consume 2+4 PPI channels, 1 PPI group, and 2 GPIOTE channels. |
| <> | 144:ef7eb2e8f9f7 | 56 | * |
| <> | 144:ef7eb2e8f9f7 | 57 | * The maximum number of PWM channels per instance is 2. |
| <> | 144:ef7eb2e8f9f7 | 58 | */ |
| <> | 144:ef7eb2e8f9f7 | 59 | |
| <> | 144:ef7eb2e8f9f7 | 60 | #ifndef APP_PWM_H__ |
| <> | 144:ef7eb2e8f9f7 | 61 | #define APP_PWM_H__ |
| <> | 144:ef7eb2e8f9f7 | 62 | |
| <> | 144:ef7eb2e8f9f7 | 63 | #include <stdint.h> |
| <> | 144:ef7eb2e8f9f7 | 64 | #include "sdk_errors.h" |
| <> | 144:ef7eb2e8f9f7 | 65 | #include "nrf_drv_timer.h" |
| <> | 144:ef7eb2e8f9f7 | 66 | #include "nrf_drv_common.h" |
| <> | 144:ef7eb2e8f9f7 | 67 | #include "nrf_drv_ppi.h" |
| <> | 144:ef7eb2e8f9f7 | 68 | |
| <> | 144:ef7eb2e8f9f7 | 69 | |
| <> | 144:ef7eb2e8f9f7 | 70 | #define APP_PWM_NOPIN 0xFFFFFFFF |
| <> | 144:ef7eb2e8f9f7 | 71 | |
| <> | 144:ef7eb2e8f9f7 | 72 | /** @brief Number of channels for one timer instance (fixed to 2 due to timer properties).*/ |
| <> | 144:ef7eb2e8f9f7 | 73 | #define APP_PWM_CHANNELS_PER_INSTANCE 2 |
| <> | 144:ef7eb2e8f9f7 | 74 | |
| <> | 144:ef7eb2e8f9f7 | 75 | /**@brief Macro for creating a PWM instance. */ |
| <> | 144:ef7eb2e8f9f7 | 76 | #define APP_PWM_INSTANCE(name, num) \ |
| <> | 144:ef7eb2e8f9f7 | 77 | const nrf_drv_timer_t m_pwm_##name##_timer = NRF_DRV_TIMER_INSTANCE(num); \ |
| <> | 144:ef7eb2e8f9f7 | 78 | app_pwm_cb_t m_pwm_##name##_cb; \ |
| <> | 144:ef7eb2e8f9f7 | 79 | /*lint -e{545}*/ \ |
| <> | 144:ef7eb2e8f9f7 | 80 | const app_pwm_t name = { \ |
| <> | 144:ef7eb2e8f9f7 | 81 | .p_cb = &m_pwm_##name##_cb, \ |
| <> | 144:ef7eb2e8f9f7 | 82 | .p_timer = &m_pwm_##name##_timer, \ |
| <> | 144:ef7eb2e8f9f7 | 83 | } |
| <> | 144:ef7eb2e8f9f7 | 84 | |
| <> | 144:ef7eb2e8f9f7 | 85 | |
| <> | 144:ef7eb2e8f9f7 | 86 | /**@brief PWM instance default configuration (1 channel). */ |
| <> | 144:ef7eb2e8f9f7 | 87 | #define APP_PWM_DEFAULT_CONFIG_1CH(period_in_us, pin) \ |
| <> | 144:ef7eb2e8f9f7 | 88 | { \ |
| <> | 144:ef7eb2e8f9f7 | 89 | .pins = {pin, APP_PWM_NOPIN}, \ |
| <> | 144:ef7eb2e8f9f7 | 90 | .pin_polarity = {APP_PWM_POLARITY_ACTIVE_LOW, APP_PWM_POLARITY_ACTIVE_LOW}, \ |
| <> | 144:ef7eb2e8f9f7 | 91 | .num_of_channels = 1, \ |
| <> | 144:ef7eb2e8f9f7 | 92 | .period_us = period_in_us \ |
| <> | 144:ef7eb2e8f9f7 | 93 | } |
| <> | 144:ef7eb2e8f9f7 | 94 | |
| <> | 144:ef7eb2e8f9f7 | 95 | /**@brief PWM instance default configuration (2 channels). */ |
| <> | 144:ef7eb2e8f9f7 | 96 | #define APP_PWM_DEFAULT_CONFIG_2CH(period_in_us, pin0, pin1) \ |
| <> | 144:ef7eb2e8f9f7 | 97 | { \ |
| <> | 144:ef7eb2e8f9f7 | 98 | .pins = {pin0, pin1}, \ |
| <> | 144:ef7eb2e8f9f7 | 99 | .pin_polarity = {APP_PWM_POLARITY_ACTIVE_LOW, APP_PWM_POLARITY_ACTIVE_LOW}, \ |
| <> | 144:ef7eb2e8f9f7 | 100 | .num_of_channels = 2, \ |
| <> | 144:ef7eb2e8f9f7 | 101 | .period_us = period_in_us \ |
| <> | 144:ef7eb2e8f9f7 | 102 | } |
| <> | 144:ef7eb2e8f9f7 | 103 | |
| <> | 144:ef7eb2e8f9f7 | 104 | typedef uint16_t app_pwm_duty_t; |
| <> | 144:ef7eb2e8f9f7 | 105 | |
| <> | 144:ef7eb2e8f9f7 | 106 | /** |
| <> | 144:ef7eb2e8f9f7 | 107 | * @brief PWM callback that is executed when a PWM duty change has been completed. |
| <> | 144:ef7eb2e8f9f7 | 108 | * |
| <> | 144:ef7eb2e8f9f7 | 109 | * @param[in] pwm_id PWM instance ID. |
| <> | 144:ef7eb2e8f9f7 | 110 | */ |
| <> | 144:ef7eb2e8f9f7 | 111 | typedef void (* app_pwm_callback_t)(uint32_t); |
| <> | 144:ef7eb2e8f9f7 | 112 | |
| <> | 144:ef7eb2e8f9f7 | 113 | /** |
| <> | 144:ef7eb2e8f9f7 | 114 | * @brief Channel polarity. |
| <> | 144:ef7eb2e8f9f7 | 115 | */ |
| <> | 144:ef7eb2e8f9f7 | 116 | typedef enum |
| <> | 144:ef7eb2e8f9f7 | 117 | { |
| <> | 144:ef7eb2e8f9f7 | 118 | APP_PWM_POLARITY_ACTIVE_LOW = 0, |
| <> | 144:ef7eb2e8f9f7 | 119 | APP_PWM_POLARITY_ACTIVE_HIGH = 1 |
| <> | 144:ef7eb2e8f9f7 | 120 | } app_pwm_polarity_t; |
| <> | 144:ef7eb2e8f9f7 | 121 | |
| <> | 144:ef7eb2e8f9f7 | 122 | /**@brief PWM configuration structure used for initialization. */ |
| <> | 144:ef7eb2e8f9f7 | 123 | typedef struct |
| <> | 144:ef7eb2e8f9f7 | 124 | { |
| <> | 144:ef7eb2e8f9f7 | 125 | uint32_t pins[APP_PWM_CHANNELS_PER_INSTANCE]; //!< Pins configured as PWM output. |
| <> | 144:ef7eb2e8f9f7 | 126 | app_pwm_polarity_t pin_polarity[APP_PWM_CHANNELS_PER_INSTANCE]; //!< Polarity of active state on pin. |
| <> | 144:ef7eb2e8f9f7 | 127 | uint32_t num_of_channels; //!< Number of channels that can be used. |
| <> | 144:ef7eb2e8f9f7 | 128 | uint32_t period_us; //!< PWM signal output period to configure (in microseconds). |
| <> | 144:ef7eb2e8f9f7 | 129 | } app_pwm_config_t; |
| <> | 144:ef7eb2e8f9f7 | 130 | |
| <> | 144:ef7eb2e8f9f7 | 131 | |
| <> | 144:ef7eb2e8f9f7 | 132 | /** |
| <> | 144:ef7eb2e8f9f7 | 133 | * @cond (NODOX) |
| <> | 144:ef7eb2e8f9f7 | 134 | * @defgroup app_pwm_internal Auxiliary internal types declarations |
| <> | 144:ef7eb2e8f9f7 | 135 | * @{ |
| <> | 144:ef7eb2e8f9f7 | 136 | * @internal |
| <> | 144:ef7eb2e8f9f7 | 137 | * |
| <> | 144:ef7eb2e8f9f7 | 138 | * @brief Module for internal usage inside the library only |
| <> | 144:ef7eb2e8f9f7 | 139 | * |
| <> | 144:ef7eb2e8f9f7 | 140 | * There are some definitions that must be included in the header file because |
| <> | 144:ef7eb2e8f9f7 | 141 | * of the way the library is set up. In this way, the are accessible to the user. |
| <> | 144:ef7eb2e8f9f7 | 142 | * However, any functions and variables defined here may change at any time |
| <> | 144:ef7eb2e8f9f7 | 143 | * without a warning, so you should not access them directly. |
| <> | 144:ef7eb2e8f9f7 | 144 | */ |
| <> | 144:ef7eb2e8f9f7 | 145 | |
| <> | 144:ef7eb2e8f9f7 | 146 | /** |
| <> | 144:ef7eb2e8f9f7 | 147 | * @brief PWM channel instance |
| <> | 144:ef7eb2e8f9f7 | 148 | * |
| <> | 144:ef7eb2e8f9f7 | 149 | * This structure holds all data needed by a single PWM channel. |
| <> | 144:ef7eb2e8f9f7 | 150 | */ |
| <> | 144:ef7eb2e8f9f7 | 151 | typedef struct |
| <> | 144:ef7eb2e8f9f7 | 152 | { |
| <> | 144:ef7eb2e8f9f7 | 153 | uint32_t gpio_pin; //!< Pin that is used by this PWM channel. |
| <> | 144:ef7eb2e8f9f7 | 154 | uint32_t pulsewidth; //!< The copy of duty currently set (in ticks). |
| <> | 144:ef7eb2e8f9f7 | 155 | nrf_ppi_channel_t ppi_channels[2]; //!< PPI channels used by the PWM channel to clear and set the output. |
| <> | 144:ef7eb2e8f9f7 | 156 | app_pwm_polarity_t polarity; //!< The active state of the pin. |
| <> | 144:ef7eb2e8f9f7 | 157 | uint8_t initialized; //!< The internal information if the selected channel was initialized. |
| <> | 144:ef7eb2e8f9f7 | 158 | } app_pwm_channel_cb_t; |
| <> | 144:ef7eb2e8f9f7 | 159 | |
| <> | 144:ef7eb2e8f9f7 | 160 | /** |
| <> | 144:ef7eb2e8f9f7 | 161 | * @brief Variable part of PWM instance |
| <> | 144:ef7eb2e8f9f7 | 162 | * |
| <> | 144:ef7eb2e8f9f7 | 163 | * This structure holds instance data that may change. |
| <> | 144:ef7eb2e8f9f7 | 164 | */ |
| <> | 144:ef7eb2e8f9f7 | 165 | typedef struct |
| <> | 144:ef7eb2e8f9f7 | 166 | { |
| <> | 144:ef7eb2e8f9f7 | 167 | app_pwm_channel_cb_t channels_cb[APP_PWM_CHANNELS_PER_INSTANCE]; //!< Channels data |
| <> | 144:ef7eb2e8f9f7 | 168 | uint32_t period; //!< Selected period in ticks |
| <> | 144:ef7eb2e8f9f7 | 169 | app_pwm_callback_t p_ready_callback; //!< Callback function called on PWM readiness |
| <> | 144:ef7eb2e8f9f7 | 170 | nrf_ppi_channel_t ppi_channels[2]; //!< PPI channels used temporary while changing duty |
| <> | 144:ef7eb2e8f9f7 | 171 | nrf_ppi_channel_group_t ppi_group; //!< PPI group used to synchronize changes on channels |
| <> | 144:ef7eb2e8f9f7 | 172 | nrf_drv_state_t state; //!< Current driver status |
| <> | 144:ef7eb2e8f9f7 | 173 | } app_pwm_cb_t; |
| <> | 144:ef7eb2e8f9f7 | 174 | /** @} |
| <> | 144:ef7eb2e8f9f7 | 175 | * @endcond |
| <> | 144:ef7eb2e8f9f7 | 176 | */ |
| <> | 144:ef7eb2e8f9f7 | 177 | |
| <> | 144:ef7eb2e8f9f7 | 178 | |
| <> | 144:ef7eb2e8f9f7 | 179 | /**@brief PWM instance structure. */ |
| <> | 144:ef7eb2e8f9f7 | 180 | typedef struct |
| <> | 144:ef7eb2e8f9f7 | 181 | { |
| <> | 144:ef7eb2e8f9f7 | 182 | app_pwm_cb_t *p_cb; //!< Pointer to control block internals. |
| <> | 144:ef7eb2e8f9f7 | 183 | nrf_drv_timer_t const * const p_timer; //!< Timer used by this PWM instance. |
| <> | 144:ef7eb2e8f9f7 | 184 | } app_pwm_t; |
| <> | 144:ef7eb2e8f9f7 | 185 | |
| <> | 144:ef7eb2e8f9f7 | 186 | /** |
| <> | 144:ef7eb2e8f9f7 | 187 | * @brief Function for checking if the PWM instance is busy updating the duty cycle. |
| <> | 144:ef7eb2e8f9f7 | 188 | * |
| <> | 144:ef7eb2e8f9f7 | 189 | * @param[in] p_instance PWM instance. |
| <> | 144:ef7eb2e8f9f7 | 190 | * |
| <> | 144:ef7eb2e8f9f7 | 191 | * @retval True If the PWM instance is ready for duty cycle changes. |
| <> | 144:ef7eb2e8f9f7 | 192 | * @retval False If a change operation is in progress. |
| <> | 144:ef7eb2e8f9f7 | 193 | */ |
| <> | 144:ef7eb2e8f9f7 | 194 | bool app_pwm_busy_check(app_pwm_t const * const p_instance); |
| <> | 144:ef7eb2e8f9f7 | 195 | |
| <> | 144:ef7eb2e8f9f7 | 196 | /** |
| <> | 144:ef7eb2e8f9f7 | 197 | * @brief Function for initializing a PWM instance. |
| <> | 144:ef7eb2e8f9f7 | 198 | * |
| <> | 144:ef7eb2e8f9f7 | 199 | * @param[in] p_instance PWM instance. |
| <> | 144:ef7eb2e8f9f7 | 200 | * @param[in] p_config Initial configuration. |
| <> | 144:ef7eb2e8f9f7 | 201 | * @param[in] p_ready_callback Pointer to ready callback function (or NULL to disable). |
| <> | 144:ef7eb2e8f9f7 | 202 | * |
| <> | 144:ef7eb2e8f9f7 | 203 | * @retval NRF_SUCCESS If initialization was successful. |
| <> | 144:ef7eb2e8f9f7 | 204 | * @retval NRF_ERROR_NO_MEM If there were not enough free resources. |
| <> | 144:ef7eb2e8f9f7 | 205 | * @retval NRF_ERROR_INVALID_PARAM If an invalid configuration structure was passed. |
| <> | 144:ef7eb2e8f9f7 | 206 | * @retval NRF_ERROR_INVALID_STATE If the timer/PWM is already in use or if initialization failed. |
| <> | 144:ef7eb2e8f9f7 | 207 | */ |
| <> | 144:ef7eb2e8f9f7 | 208 | ret_code_t app_pwm_init(app_pwm_t const * const p_instance, app_pwm_config_t const * const p_config, |
| <> | 144:ef7eb2e8f9f7 | 209 | app_pwm_callback_t p_ready_callback); |
| <> | 144:ef7eb2e8f9f7 | 210 | |
| <> | 144:ef7eb2e8f9f7 | 211 | |
| <> | 144:ef7eb2e8f9f7 | 212 | /** |
| <> | 144:ef7eb2e8f9f7 | 213 | * @brief Function for uninitializing a PWM instance and releasing the allocated resources. |
| <> | 144:ef7eb2e8f9f7 | 214 | * |
| <> | 144:ef7eb2e8f9f7 | 215 | * @param[in] p_instance PWM instance. |
| <> | 144:ef7eb2e8f9f7 | 216 | * |
| <> | 144:ef7eb2e8f9f7 | 217 | * @retval NRF_SUCCESS If uninitialization was successful. |
| <> | 144:ef7eb2e8f9f7 | 218 | * @retval NRF_ERROR_INVALID_STATE If the given instance was not initialized. |
| <> | 144:ef7eb2e8f9f7 | 219 | */ |
| <> | 144:ef7eb2e8f9f7 | 220 | ret_code_t app_pwm_uninit(app_pwm_t const * const p_instance); |
| <> | 144:ef7eb2e8f9f7 | 221 | |
| <> | 144:ef7eb2e8f9f7 | 222 | /** |
| <> | 144:ef7eb2e8f9f7 | 223 | * @brief Function for enabling a PWM instance after initialization. |
| <> | 144:ef7eb2e8f9f7 | 224 | * |
| <> | 144:ef7eb2e8f9f7 | 225 | * @param[in] p_instance PWM instance. |
| <> | 144:ef7eb2e8f9f7 | 226 | */ |
| <> | 144:ef7eb2e8f9f7 | 227 | void app_pwm_enable(app_pwm_t const * const p_instance); |
| <> | 144:ef7eb2e8f9f7 | 228 | |
| <> | 144:ef7eb2e8f9f7 | 229 | /** |
| <> | 144:ef7eb2e8f9f7 | 230 | * @brief Function for disabling a PWM instance after initialization. |
| <> | 144:ef7eb2e8f9f7 | 231 | * |
| <> | 144:ef7eb2e8f9f7 | 232 | * @param[in] p_instance PWM instance. |
| <> | 144:ef7eb2e8f9f7 | 233 | */ |
| <> | 144:ef7eb2e8f9f7 | 234 | void app_pwm_disable(app_pwm_t const * const p_instance); |
| <> | 144:ef7eb2e8f9f7 | 235 | |
| <> | 144:ef7eb2e8f9f7 | 236 | /** |
| <> | 144:ef7eb2e8f9f7 | 237 | * @brief Function for setting the PWM channel duty cycle in percents. |
| <> | 144:ef7eb2e8f9f7 | 238 | * |
| <> | 144:ef7eb2e8f9f7 | 239 | * A duty cycle change requires one full PWM clock period to finish. |
| <> | 144:ef7eb2e8f9f7 | 240 | * If another change is attempted for any channel of given instance before |
| <> | 144:ef7eb2e8f9f7 | 241 | * the current change is complete, the new attempt will result in the error |
| <> | 144:ef7eb2e8f9f7 | 242 | * NRF_ERROR_BUSY. |
| <> | 144:ef7eb2e8f9f7 | 243 | * |
| <> | 144:ef7eb2e8f9f7 | 244 | * @param[in] p_instance PWM instance. |
| <> | 144:ef7eb2e8f9f7 | 245 | * @param[in] channel Channel number. |
| <> | 144:ef7eb2e8f9f7 | 246 | * @param[in] duty Duty cycle (0 - 100). |
| <> | 144:ef7eb2e8f9f7 | 247 | * |
| <> | 144:ef7eb2e8f9f7 | 248 | * @retval NRF_SUCCESS If the operation was successful. |
| <> | 144:ef7eb2e8f9f7 | 249 | * @retval NRF_ERROR_BUSY If the PWM is not ready yet. |
| <> | 144:ef7eb2e8f9f7 | 250 | * @retval NRF_ERROR_INVALID_STATE If the given instance was not initialized. |
| <> | 144:ef7eb2e8f9f7 | 251 | * |
| <> | 144:ef7eb2e8f9f7 | 252 | */ |
| <> | 144:ef7eb2e8f9f7 | 253 | ret_code_t app_pwm_channel_duty_set(app_pwm_t const * const p_instance, |
| <> | 144:ef7eb2e8f9f7 | 254 | uint8_t channel, app_pwm_duty_t duty); |
| <> | 144:ef7eb2e8f9f7 | 255 | |
| <> | 144:ef7eb2e8f9f7 | 256 | /** |
| <> | 144:ef7eb2e8f9f7 | 257 | * @brief Function for retrieving the PWM channel duty cycle in percents. |
| <> | 144:ef7eb2e8f9f7 | 258 | * |
| <> | 144:ef7eb2e8f9f7 | 259 | * @param[in] p_instance PWM instance. |
| <> | 144:ef7eb2e8f9f7 | 260 | * @param[in] channel Channel number. |
| <> | 144:ef7eb2e8f9f7 | 261 | * |
| <> | 144:ef7eb2e8f9f7 | 262 | * @return Duty cycle value. |
| <> | 144:ef7eb2e8f9f7 | 263 | */ |
| <> | 144:ef7eb2e8f9f7 | 264 | app_pwm_duty_t app_pwm_channel_duty_get(app_pwm_t const * const p_instance, uint8_t channel); |
| <> | 144:ef7eb2e8f9f7 | 265 | |
| <> | 144:ef7eb2e8f9f7 | 266 | |
| <> | 144:ef7eb2e8f9f7 | 267 | /** |
| <> | 144:ef7eb2e8f9f7 | 268 | * @name Functions accessing values in ticks |
| <> | 144:ef7eb2e8f9f7 | 269 | * |
| <> | 144:ef7eb2e8f9f7 | 270 | * Auxiliary functions that allow to get values in actual timer ticks. |
| <> | 144:ef7eb2e8f9f7 | 271 | * @{ |
| <> | 144:ef7eb2e8f9f7 | 272 | */ |
| <> | 144:ef7eb2e8f9f7 | 273 | |
| <> | 144:ef7eb2e8f9f7 | 274 | /** |
| <> | 144:ef7eb2e8f9f7 | 275 | * @brief Function for setting PWM channel duty cycle in clock ticks. |
| <> | 144:ef7eb2e8f9f7 | 276 | * |
| <> | 144:ef7eb2e8f9f7 | 277 | * @note Duty cycle changes require one full PWM clock period to finish. |
| <> | 144:ef7eb2e8f9f7 | 278 | * Until that, the next change attempt (for any channel of given instance) |
| <> | 144:ef7eb2e8f9f7 | 279 | * will result in an NRF_ERROR_BUSY error. |
| <> | 144:ef7eb2e8f9f7 | 280 | * |
| <> | 144:ef7eb2e8f9f7 | 281 | * @param[in] p_instance PWM instance. |
| <> | 144:ef7eb2e8f9f7 | 282 | * @param[in] channel Channel number. |
| <> | 144:ef7eb2e8f9f7 | 283 | * @param[in] ticks Number of PWM clock ticks. |
| <> | 144:ef7eb2e8f9f7 | 284 | * |
| <> | 144:ef7eb2e8f9f7 | 285 | * @retval NRF_SUCCESS If the operation was successful. |
| <> | 144:ef7eb2e8f9f7 | 286 | * @retval NRF_ERROR_BUSY If PWM is not ready yet. |
| <> | 144:ef7eb2e8f9f7 | 287 | * @retval NRF_ERROR_INVALID_STATE If the given instance was not initialized. |
| <> | 144:ef7eb2e8f9f7 | 288 | */ |
| <> | 144:ef7eb2e8f9f7 | 289 | ret_code_t app_pwm_channel_duty_ticks_set(app_pwm_t const * const p_instance, |
| <> | 144:ef7eb2e8f9f7 | 290 | uint8_t channel, |
| <> | 144:ef7eb2e8f9f7 | 291 | uint16_t ticks); |
| <> | 144:ef7eb2e8f9f7 | 292 | |
| <> | 144:ef7eb2e8f9f7 | 293 | |
| <> | 144:ef7eb2e8f9f7 | 294 | /** |
| <> | 144:ef7eb2e8f9f7 | 295 | * @brief Function for retrieving the PWM channel duty cycle in ticks. |
| <> | 144:ef7eb2e8f9f7 | 296 | * |
| <> | 144:ef7eb2e8f9f7 | 297 | * This function retrieves the real, currently set duty cycle in ticks. |
| <> | 144:ef7eb2e8f9f7 | 298 | * For one full PWM cycle the value might be different than the value set by the last |
| <> | 144:ef7eb2e8f9f7 | 299 | * @ref app_pwm_channel_duty_ticks_set function call. |
| <> | 144:ef7eb2e8f9f7 | 300 | * |
| <> | 144:ef7eb2e8f9f7 | 301 | * @param[in] p_instance PWM instance. |
| <> | 144:ef7eb2e8f9f7 | 302 | * @param[in] channel Channel number. |
| <> | 144:ef7eb2e8f9f7 | 303 | * |
| <> | 144:ef7eb2e8f9f7 | 304 | * @return Number of ticks set for selected channel. |
| <> | 144:ef7eb2e8f9f7 | 305 | * |
| <> | 144:ef7eb2e8f9f7 | 306 | */ |
| <> | 144:ef7eb2e8f9f7 | 307 | uint16_t app_pwm_channel_duty_ticks_get(app_pwm_t const * const p_instance, uint8_t channel); |
| <> | 144:ef7eb2e8f9f7 | 308 | |
| <> | 144:ef7eb2e8f9f7 | 309 | /** |
| <> | 144:ef7eb2e8f9f7 | 310 | * @brief Function for returning the number of ticks in a whole cycle. |
| <> | 144:ef7eb2e8f9f7 | 311 | * |
| <> | 144:ef7eb2e8f9f7 | 312 | * @param[in] p_instance PWM instance. |
| <> | 144:ef7eb2e8f9f7 | 313 | * |
| <> | 144:ef7eb2e8f9f7 | 314 | * @return Number of ticks that corresponds to 100% of the duty cycle. |
| <> | 144:ef7eb2e8f9f7 | 315 | */ |
| <> | 144:ef7eb2e8f9f7 | 316 | uint16_t app_pwm_cycle_ticks_get(app_pwm_t const * const p_instance); |
| <> | 144:ef7eb2e8f9f7 | 317 | /** @} */ |
| <> | 144:ef7eb2e8f9f7 | 318 | |
| <> | 144:ef7eb2e8f9f7 | 319 | |
| <> | 144:ef7eb2e8f9f7 | 320 | #endif |
| <> | 144:ef7eb2e8f9f7 | 321 | |
| <> | 144:ef7eb2e8f9f7 | 322 | /** @} */ |
