1 /***************************************************************************//**
2 * \file cyhal_quaddec_impl.h
3 *
4 * Description:
5 * Provides a high level interface for interacting with the Infineon PWM.
6 *
7 ********************************************************************************
8 * \copyright
9 * Copyright 2019-2021 Cypress Semiconductor Corporation (an Infineon company) or
10 * an affiliate of Cypress Semiconductor Corporation
11 *
12 * SPDX-License-Identifier: Apache-2.0
13 *
14 * Licensed under the Apache License, Version 2.0 (the "License");
15 * you may not use this file except in compliance with the License.
16 * You may obtain a copy of the License at
17 *
18 * http://www.apache.org/licenses/LICENSE-2.0
19 *
20 * Unless required by applicable law or agreed to in writing, software
21 * distributed under the License is distributed on an "AS IS" BASIS,
22 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 * See the License for the specific language governing permissions and
24 * limitations under the License.
25 *******************************************************************************/
26
27 #pragma once
28
29 #include "cyhal_tcpwm_common.h"
30
31 #if defined(CY_IP_MXTCPWM_INSTANCES) || defined(CY_IP_M0S8TCPWM_INSTANCES)
32
33 #if defined(__cplusplus)
34 extern "C" {
35 #endif /* __cplusplus */
36
37 /** \addtogroup group_hal_impl_quaddec Quadrature Decoder
38 * \ingroup group_hal_impl
39 * \{
40 * \section group_hal_impl_quaddec_interconnect Interconnect
41 * In PSoC™ Quadrature Decoder channels can configure multiple input and output
42 * triggers simultaneously. 1 or more input triggers can be configured to
43 * initiate different PWM actions (e.g start, stop, reload, etc) with
44 * configurable edge detection on that incoming signal. Output triggers are
45 * based on certain events (e.g overflow, cc_match, etc).
46 */
47
_cyhal_quaddec_convert_event(cyhal_quaddec_event_t event)48 __STATIC_INLINE uint32_t _cyhal_quaddec_convert_event(cyhal_quaddec_event_t event)
49 {
50 uint32_t pdl_event = 0U;
51 if (event & CYHAL_QUADDEC_IRQ_TERMINAL_COUNT)
52 {
53 pdl_event |= CY_TCPWM_INT_ON_TC;
54 }
55 if (event & CYHAL_QUADDEC_IRQ_CAPTURE)
56 {
57 pdl_event |= CY_TCPWM_INT_ON_CC;
58 }
59 return pdl_event;
60 }
61
_cyhal_quaddec_register_callback(cyhal_quaddec_t * obj,cyhal_quaddec_event_callback_t callback,void * callback_arg)62 __STATIC_INLINE void _cyhal_quaddec_register_callback(cyhal_quaddec_t *obj,
63 cyhal_quaddec_event_callback_t callback,
64 void *callback_arg)
65 {
66 _cyhal_tcpwm_register_callback(&obj->tcpwm.resource, (cy_israddress) callback, callback_arg);
67 }
68
69 #define cyhal_quaddec_register_callback(obj, callback, callback_arg) \
70 _cyhal_quaddec_register_callback(obj, callback, callback_arg)
71
_cyhal_quaddec_enable_event(cyhal_quaddec_t * obj,cyhal_quaddec_event_t event,uint8_t intr_priority,bool enable)72 __STATIC_INLINE void _cyhal_quaddec_enable_event(cyhal_quaddec_t *obj,
73 cyhal_quaddec_event_t event,
74 uint8_t intr_priority,
75 bool enable)
76 {
77 uint32_t converted = _cyhal_quaddec_convert_event(event);
78 _cyhal_tcpwm_enable_event(&obj->tcpwm, &obj->tcpwm.resource, converted, intr_priority,
79 enable);
80 }
81
82 #define cyhal_quaddec_enable_event(obj, event, intr_priority, enable) \
83 _cyhal_quaddec_enable_event(obj, event, intr_priority, enable)
84
85 /** \} group_hal_impl_quaddec */
86
87 #if defined(__cplusplus)
88 }
89 #endif /* __cplusplus */
90
91 #endif /* defined(CY_IP_MXTCPWM_INSTANCES) */
92