cyhal_timer.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. /***************************************************************************//**
  2. * \file cyhal_timer.c
  3. *
  4. * \brief
  5. * Provides a high level interface for interacting with the Infineon Timer/Counter.
  6. * This interface abstracts out the chip specific details. If any chip specific
  7. * functionality is necessary, or performance is critical the low level functions
  8. * can be used directly.
  9. *
  10. ********************************************************************************
  11. * \copyright
  12. * Copyright 2018-2022 Cypress Semiconductor Corporation (an Infineon company) or
  13. * an affiliate of Cypress Semiconductor Corporation
  14. *
  15. * SPDX-License-Identifier: Apache-2.0
  16. *
  17. * Licensed under the Apache License, Version 2.0 (the "License");
  18. * you may not use this file except in compliance with the License.
  19. * You may obtain a copy of the License at
  20. *
  21. * http://www.apache.org/licenses/LICENSE-2.0
  22. *
  23. * Unless required by applicable law or agreed to in writing, software
  24. * distributed under the License is distributed on an "AS IS" BASIS,
  25. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  26. * See the License for the specific language governing permissions and
  27. * limitations under the License.
  28. *******************************************************************************/
  29. #include <string.h>
  30. #if !defined(COMPONENT_CAT5)
  31. #include "cy_device_headers.h"
  32. #endif
  33. #include "cyhal_timer_impl.h"
  34. #include "cyhal_hwmgr.h"
  35. #include "cyhal_gpio.h"
  36. #include "cyhal_interconnect.h"
  37. #include "cyhal_syspm.h"
  38. #include "cyhal_clock.h"
  39. #if defined(COMPONENT_CAT5)
  40. #include "cyhal_irq_impl.h"
  41. #endif
  42. #if (CYHAL_DRIVER_AVAILABLE_TIMER)
  43. #if defined(__cplusplus)
  44. extern "C" {
  45. #endif
  46. static const cy_stc_tcpwm_counter_config_t _cyhal_timer_default_config =
  47. {
  48. .period = 32768,
  49. .clockPrescaler = CY_TCPWM_COUNTER_PRESCALER_DIVBY_1,
  50. .runMode = CY_TCPWM_COUNTER_CONTINUOUS,
  51. .countDirection = CY_TCPWM_COUNTER_COUNT_UP,
  52. .compareOrCapture = CY_TCPWM_COUNTER_MODE_CAPTURE,
  53. .compare0 = 16384,
  54. .compare1 = 16384,
  55. .enableCompareSwap = false,
  56. .interruptSources = CY_TCPWM_INT_NONE,
  57. .captureInputMode = 0x3U,
  58. .captureInput = CY_TCPWM_INPUT_0,
  59. .reloadInputMode = 0x3U,
  60. .reloadInput = CY_TCPWM_INPUT_0,
  61. .startInputMode = 0x3U,
  62. .startInput = CY_TCPWM_INPUT_0,
  63. .stopInputMode = 0x3U,
  64. .stopInput = CY_TCPWM_INPUT_0,
  65. .countInputMode = 0x3U,
  66. .countInput = CY_TCPWM_INPUT_1,
  67. #if (CY_IP_MXTCPWM_VERSION >= 2U)
  68. .capture1InputMode = 0x3U,
  69. .capture1Input = CY_TCPWM_INPUT_0,
  70. .enableCompare1Swap = false,
  71. .compare2 = 16384,
  72. .compare3 = 16384,
  73. .trigger0Event = CY_TCPWM_CNT_TRIGGER_ON_DISABLED,
  74. .trigger1Event = CY_TCPWM_CNT_TRIGGER_ON_DISABLED,
  75. #endif
  76. };
  77. /** Convert timer direction from the HAL enum to the corresponding PDL constant
  78. *
  79. * @param[in] direction The direction, as a HAL enum value
  80. * @return The direction, as a PDL constant
  81. */
  82. static inline uint32_t _cyhal_timer_convert_direction(cyhal_timer_direction_t direction)
  83. {
  84. switch (direction)
  85. {
  86. case CYHAL_TIMER_DIR_UP:
  87. return CY_TCPWM_COUNTER_COUNT_UP;
  88. case CYHAL_TIMER_DIR_DOWN:
  89. return CY_TCPWM_COUNTER_COUNT_DOWN;
  90. case CYHAL_TIMER_DIR_UP_DOWN:
  91. return CY_TCPWM_COUNTER_COUNT_UP_DOWN_2;
  92. default:
  93. CY_ASSERT(false);
  94. return CY_TCPWM_COUNTER_COUNT_UP;
  95. }
  96. }
  97. /*******************************************************************************
  98. * Timer HAL Functions
  99. *******************************************************************************/
  100. cy_rslt_t _cyhal_timer_init_hw(cyhal_timer_t *obj, const cy_stc_tcpwm_counter_config_t *config, const cyhal_clock_t *clk)
  101. {
  102. cy_rslt_t result = CY_RSLT_SUCCESS;
  103. cyhal_resource_inst_t *timer = &obj->tcpwm.resource;
  104. obj->tcpwm.base = _CYHAL_TCPWM_DATA[_CYHAL_TCPWM_ADJUST_BLOCK_INDEX(timer->block_num)].base;
  105. en_clk_dst_t pclk = (en_clk_dst_t)(_CYHAL_TCPWM_DATA[_CYHAL_TCPWM_ADJUST_BLOCK_INDEX(timer->block_num)].clock_dst + timer->channel_num);
  106. if (NULL != clk)
  107. {
  108. obj->tcpwm.clock = *clk;
  109. obj->tcpwm.clock_hz = cyhal_clock_get_frequency(&obj->tcpwm.clock);
  110. if (CY_SYSCLK_SUCCESS != _cyhal_utils_peri_pclk_assign_divider(pclk, &(obj->tcpwm.clock)))
  111. {
  112. result = CYHAL_TIMER_RSLT_ERR_CLOCK_INIT;
  113. }
  114. }
  115. else if (CY_RSLT_SUCCESS == (result = _cyhal_utils_allocate_clock(&(obj->tcpwm.clock), timer, CYHAL_CLOCK_BLOCK_PERIPHERAL_16BIT, true)))
  116. {
  117. obj->tcpwm.dedicated_clock = true;
  118. #if defined(COMPONENT_CAT5)
  119. // CAT5 lacks hardware required to divide from 96MHz to 1MHz
  120. result = cyhal_timer_set_frequency(obj, CYHAL_TIMER_DEFAULT_FREQ * 3);
  121. #else
  122. result = cyhal_timer_set_frequency(obj, CYHAL_TIMER_DEFAULT_FREQ);
  123. #endif
  124. if (CY_RSLT_SUCCESS == result)
  125. {
  126. if (CY_SYSCLK_SUCCESS != _cyhal_utils_peri_pclk_assign_divider(pclk, &(obj->tcpwm.clock)))
  127. {
  128. result = CYHAL_TIMER_RSLT_ERR_CLOCK_INIT;
  129. }
  130. }
  131. }
  132. if (CY_RSLT_SUCCESS == result)
  133. {
  134. result = Cy_TCPWM_Counter_Init(obj->tcpwm.base, _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resource), config);
  135. }
  136. if (result == CY_RSLT_SUCCESS)
  137. {
  138. _cyhal_tcpwm_init_data(&obj->tcpwm);
  139. Cy_TCPWM_Counter_Enable(obj->tcpwm.base, _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resource));
  140. }
  141. return result;
  142. }
  143. cy_rslt_t cyhal_timer_init(cyhal_timer_t *obj, cyhal_gpio_t pin, const cyhal_clock_t *clk)
  144. {
  145. CY_ASSERT(NULL != obj);
  146. // No support currently for pin connections on this device
  147. if (CYHAL_NC_PIN_VALUE != pin)
  148. return CYHAL_TIMER_RSLT_ERR_BAD_ARGUMENT;
  149. memset(obj, 0, sizeof(cyhal_timer_t));
  150. cy_rslt_t result = CY_RSLT_SUCCESS;
  151. #if defined(COMPONENT_CAT5)
  152. // T2Timer requested
  153. if((uint32_t)clk == (uint32_t)(CYHAL_CLOCK_T2TIMER))
  154. {
  155. result = cyhal_hwmgr_allocate(CYHAL_RSC_T2TIMER, &obj->t2timer.resource);
  156. if (CY_RSLT_SUCCESS == result)
  157. {
  158. obj->t2timer.which_timer = obj->t2timer.resource.block_num;
  159. result = _cyhal_t2timer_init(&obj->t2timer, NULL);
  160. if(result == CY_RSLT_SUCCESS)
  161. {
  162. obj->is_t2timer = true;
  163. }
  164. }
  165. }
  166. else
  167. {
  168. // T2Timer not specifically requested, use either TCPWM or T2Timer
  169. #endif
  170. obj->tcpwm.resource.type = CYHAL_RSC_INVALID;
  171. result = cyhal_hwmgr_allocate(CYHAL_RSC_TCPWM, &obj->tcpwm.resource);
  172. if (CY_RSLT_SUCCESS == result)
  173. {
  174. result = _cyhal_timer_init_hw(obj, &_cyhal_timer_default_config, clk);
  175. #if defined(COMPONENT_CAT5)
  176. obj->is_t2timer = false;
  177. }
  178. else
  179. {
  180. result = cyhal_hwmgr_allocate(CYHAL_RSC_T2TIMER, &obj->t2timer.resource);
  181. if (CY_RSLT_SUCCESS == result)
  182. {
  183. obj->t2timer.which_timer = obj->t2timer.resource.block_num;
  184. result = _cyhal_t2timer_init(&obj->t2timer, NULL);
  185. if(result == CY_RSLT_SUCCESS)
  186. {
  187. obj->is_t2timer = true;
  188. }
  189. }
  190. }
  191. #endif
  192. }
  193. if (CY_RSLT_SUCCESS != result)
  194. {
  195. cyhal_timer_free(obj);
  196. }
  197. return result;
  198. }
  199. cy_rslt_t cyhal_timer_init_cfg(cyhal_timer_t *obj, const cyhal_timer_configurator_t *cfg)
  200. {
  201. memset(obj, 0, sizeof(cyhal_timer_t));
  202. obj->tcpwm.resource = *cfg->resource;
  203. obj->tcpwm.owned_by_configurator = true;
  204. cy_rslt_t result = _cyhal_timer_init_hw(obj, cfg->config, cfg->clock);
  205. #if defined(COMPONENT_CAT5)
  206. // Device configurator doesn't currently support T2Timer
  207. obj->is_t2timer = false;
  208. #endif
  209. if(CY_RSLT_SUCCESS != result)
  210. {
  211. cyhal_timer_free(obj);
  212. }
  213. return result;
  214. }
  215. cy_rslt_t cyhal_timer_configure(cyhal_timer_t *obj, const cyhal_timer_cfg_t *cfg)
  216. {
  217. cy_rslt_t rslt;
  218. #if defined(COMPONENT_CAT5)
  219. if(obj->is_t2timer)
  220. {
  221. if((cfg->direction != CYHAL_TIMER_DIR_DOWN) || (cfg->is_compare != true) || (cfg->value != 0x0))
  222. {
  223. // T2Timer can only count down, it has no capture mode, and doesn't support starting values
  224. return CYHAL_TIMER_RSLT_ERR_UNSUPPORTED;
  225. }
  226. cyhal_t2timer_cfg_t t2t_cfg = {
  227. .mode = T2_ARM_TIMER_MODE_FREERUNNING,
  228. .counter_mode = T2_ARM_TIMER_COUNTER_MODE_ONESHOT,
  229. .duration = cfg->compare_value,
  230. };
  231. if(cfg->is_continuous)
  232. {
  233. t2t_cfg.counter_mode = T2_ARM_TIMER_COUNTER_MODE_WRAPPING;
  234. }
  235. rslt = _cyhal_t2timer_configure(&obj->t2timer, &t2t_cfg);
  236. }
  237. else
  238. #endif
  239. {
  240. obj->default_value = cfg->value;
  241. cy_stc_tcpwm_counter_config_t config = _cyhal_timer_default_config;
  242. config.period = cfg->period;
  243. config.compare0 = cfg->compare_value;
  244. config.runMode = cfg->is_continuous ? CY_TCPWM_COUNTER_CONTINUOUS : CY_TCPWM_COUNTER_ONESHOT;
  245. config.compareOrCapture = cfg->is_compare ? CY_TCPWM_COUNTER_MODE_COMPARE : CY_TCPWM_COUNTER_MODE_CAPTURE;
  246. config.countDirection = _cyhal_timer_convert_direction(cfg->direction);
  247. // DeInit will clear the interrupt mask; save it now and restore after we re-nit
  248. uint32_t old_mask = Cy_TCPWM_GetInterruptMask(obj->tcpwm.base, _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resource));
  249. Cy_TCPWM_Counter_DeInit(obj->tcpwm.base, _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resource), &config);
  250. rslt = (cy_rslt_t)Cy_TCPWM_Counter_Init(obj->tcpwm.base, _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resource), &config);
  251. Cy_TCPWM_Counter_Enable(obj->tcpwm.base, _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resource));
  252. Cy_TCPWM_SetInterruptMask(obj->tcpwm.base, _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resource), old_mask);
  253. // This must be called after Cy_TCPWM_Counter_Init
  254. cyhal_timer_reset(obj);
  255. }
  256. return rslt;
  257. }
  258. cy_rslt_t cyhal_timer_set_frequency(cyhal_timer_t *obj, uint32_t hz)
  259. {
  260. cy_rslt_t result = CY_RSLT_SUCCESS;
  261. #if defined(COMPONENT_CAT5)
  262. if(obj->is_t2timer)
  263. {
  264. result = _cyhal_t2timer_set_frequency(&obj->t2timer, hz);
  265. }
  266. else
  267. #endif
  268. {
  269. if(!obj->tcpwm.dedicated_clock)
  270. {
  271. result = CYHAL_TIMER_RSLT_ERR_SHARED_CLOCK;
  272. }
  273. #if !defined(COMPONENT_CAT5)
  274. const cyhal_clock_tolerance_t tolerance = {
  275. .type = CYHAL_TOLERANCE_PERCENT,
  276. .value = 2,
  277. };
  278. #endif
  279. if(CY_RSLT_SUCCESS == result)
  280. {
  281. #if defined(COMPONENT_CAT5)
  282. uint32_t current_freq = _cyhal_utils_get_peripheral_clock_frequency(&(obj->tcpwm.resource));
  283. uint32_t divider = ((current_freq + hz - 1) / hz);
  284. // _set_divider doesn't use this with CAT5, but to avoid warnings here is what it would use
  285. en_clk_dst_t clk_dst = (en_clk_dst_t)(_CYHAL_TCPWM_DATA[_CYHAL_TCPWM_ADJUST_BLOCK_INDEX(obj->tcpwm.resource.block_num)].clock_dst + obj->tcpwm.resource.channel_num);
  286. if(CY_RSLT_SUCCESS == _cyhal_utils_peri_pclk_set_divider(clk_dst, &obj->tcpwm.clock, (divider - 1)))
  287. #else
  288. if((CY_RSLT_SUCCESS == cyhal_clock_set_enabled(&obj->tcpwm.clock, false, false)) &&
  289. (CY_RSLT_SUCCESS == cyhal_clock_set_frequency(&obj->tcpwm.clock, hz, &tolerance)) &&
  290. (CY_RSLT_SUCCESS == cyhal_clock_set_enabled(&obj->tcpwm.clock, true, false)))
  291. #endif
  292. {
  293. obj->tcpwm.clock_hz = cyhal_clock_get_frequency(&obj->tcpwm.clock);
  294. }
  295. else
  296. {
  297. result = CYHAL_TIMER_RSLT_ERR_CLOCK_INIT;
  298. }
  299. }
  300. }
  301. return result;
  302. }
  303. cy_rslt_t cyhal_timer_start(cyhal_timer_t *obj)
  304. {
  305. CY_ASSERT(NULL != obj);
  306. cy_rslt_t result = CY_RSLT_SUCCESS;
  307. #if (CYHAL_DRIVER_AVAILABLE_SYSPM)
  308. #if defined(COMPONENT_CAT5)
  309. if (_cyhal_tcpwm_pm_transition_pending() || (obj->is_t2timer && obj->running))
  310. #else
  311. if (_cyhal_tcpwm_pm_transition_pending())
  312. #endif
  313. {
  314. return CYHAL_SYSPM_RSLT_ERR_PM_PENDING;
  315. }
  316. #endif
  317. #if defined(COMPONENT_CAT5)
  318. if(obj->is_t2timer)
  319. {
  320. result = _cyhal_t2timer_start(&obj->t2timer);
  321. if(result == CY_RSLT_SUCCESS)
  322. {
  323. obj->running = true;
  324. }
  325. }
  326. else
  327. #endif
  328. {
  329. Cy_TCPWM_Counter_Enable(obj->tcpwm.base, _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resource));
  330. #if defined(CY_IP_MXTCPWM) && (CY_IP_MXTCPWM_VERSION >= 2)
  331. Cy_TCPWM_TriggerStart_Single(obj->tcpwm.base, _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resource));
  332. #else
  333. Cy_TCPWM_TriggerStart(obj->tcpwm.base, (1 << _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resource)));
  334. #endif
  335. }
  336. return result;
  337. }
  338. cy_rslt_t cyhal_timer_stop(cyhal_timer_t *obj)
  339. {
  340. CY_ASSERT(NULL != obj);
  341. cy_rslt_t result = CY_RSLT_SUCCESS;
  342. #if defined(COMPONENT_CAT5)
  343. if(obj->is_t2timer)
  344. {
  345. result = _cyhal_t2timer_stop(&obj->t2timer);
  346. if(result == CY_RSLT_SUCCESS)
  347. {
  348. obj->running = false;
  349. }
  350. }
  351. else
  352. #endif
  353. {
  354. Cy_TCPWM_Counter_Disable(obj->tcpwm.base, _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resource));
  355. }
  356. return result;
  357. }
  358. cy_rslt_t cyhal_timer_reset(cyhal_timer_t *obj)
  359. {
  360. CY_ASSERT(NULL != obj);
  361. cy_rslt_t result = CY_RSLT_SUCCESS;
  362. #if defined(COMPONENT_CAT5)
  363. if(obj->is_t2timer)
  364. {
  365. result = _cyhal_t2timer_reset(&obj->t2timer);
  366. if(result == CY_RSLT_SUCCESS)
  367. {
  368. obj->running = true;
  369. }
  370. }
  371. else
  372. #endif
  373. {
  374. Cy_TCPWM_Counter_SetCounter(obj->tcpwm.base, _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resource), obj->default_value);
  375. }
  376. return result;
  377. }
  378. uint32_t cyhal_timer_read(const cyhal_timer_t *obj)
  379. {
  380. CY_ASSERT(NULL != obj);
  381. uint32_t read_value = 0;
  382. #if defined(COMPONENT_CAT5)
  383. if(obj->is_t2timer)
  384. {
  385. read_value = _cyhal_t2timer_read(&obj->t2timer);
  386. }
  387. else
  388. #endif
  389. {
  390. read_value = Cy_TCPWM_Counter_GetCounter(obj->tcpwm.base, _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resource));
  391. }
  392. return read_value;
  393. }
  394. static cyhal_tcpwm_input_t _cyhal_timer_translate_input_signal(cyhal_timer_input_t event)
  395. {
  396. switch(event)
  397. {
  398. case CYHAL_TIMER_INPUT_START:
  399. return CYHAL_TCPWM_INPUT_START;
  400. case CYHAL_TIMER_INPUT_STOP:
  401. return CYHAL_TCPWM_INPUT_STOP;
  402. case CYHAL_TIMER_INPUT_RELOAD:
  403. return CYHAL_TCPWM_INPUT_RELOAD;
  404. case CYHAL_TIMER_INPUT_COUNT:
  405. return CYHAL_TCPWM_INPUT_COUNT;
  406. case CYHAL_TIMER_INPUT_CAPTURE:
  407. return CYHAL_TCPWM_INPUT_CAPTURE;
  408. default:
  409. CY_ASSERT(false);
  410. return (cyhal_tcpwm_input_t)0;
  411. }
  412. }
  413. static cyhal_tcpwm_output_t _cyhal_timer_translate_output_signal(cyhal_timer_output_t signal)
  414. {
  415. switch(signal)
  416. {
  417. case CYHAL_TIMER_OUTPUT_OVERFLOW:
  418. return CYHAL_TCPWM_OUTPUT_OVERFLOW;
  419. case CYHAL_TIMER_OUTPUT_UNDERFLOW:
  420. return CYHAL_TCPWM_OUTPUT_UNDERFLOW;
  421. case CYHAL_TIMER_OUTPUT_COMPARE_MATCH:
  422. return CYHAL_TCPWM_OUTPUT_COMPARE_MATCH;
  423. case CYHAL_TIMER_OUTPUT_TERMINAL_COUNT:
  424. return CYHAL_TCPWM_OUTPUT_TERMINAL_COUNT;
  425. default:
  426. CY_ASSERT(false);
  427. return (cyhal_tcpwm_output_t)0;
  428. }
  429. }
  430. cy_rslt_t cyhal_timer_connect_digital2(cyhal_timer_t *obj, cyhal_source_t source, cyhal_timer_input_t signal, cyhal_edge_type_t edge_type)
  431. {
  432. #if defined(COMPONENT_CAT5)
  433. if(obj->is_t2timer)
  434. {
  435. return CYHAL_TIMER_RSLT_ERR_UNSUPPORTED;
  436. }
  437. #endif
  438. cyhal_tcpwm_input_t tcpwm_signal = _cyhal_timer_translate_input_signal(signal);
  439. return _cyhal_tcpwm_connect_digital(&(obj->tcpwm), source, tcpwm_signal, edge_type);
  440. }
  441. cy_rslt_t cyhal_timer_connect_digital(cyhal_timer_t *obj, cyhal_source_t source, cyhal_timer_input_t signal)
  442. {
  443. #if defined(COMPONENT_CAT5)
  444. if(obj->is_t2timer)
  445. {
  446. return CYHAL_TIMER_RSLT_ERR_UNSUPPORTED;
  447. }
  448. #endif
  449. #if defined(CY_IP_M0S8PERI_TR) || defined(CY_IP_MXPERI_TR) || defined(CY_IP_MXSPERI)
  450. /* Signal type just tells us edge vs. level, but TCPWM lets you customize which edge you want. So default
  451. * to rising edge. If the application cares about the edge type, it can use connect_digital2 */
  452. cyhal_signal_type_t signal_type = _CYHAL_TRIGGER_GET_SOURCE_TYPE(source);
  453. cyhal_edge_type_t edge_type = (signal_type == CYHAL_SIGNAL_TYPE_LEVEL) ? CYHAL_EDGE_TYPE_LEVEL : CYHAL_EDGE_TYPE_RISING_EDGE;
  454. return cyhal_timer_connect_digital2(obj, source, signal, edge_type);
  455. #else
  456. CY_UNUSED_PARAMETER(obj);
  457. CY_UNUSED_PARAMETER(source);
  458. CY_UNUSED_PARAMETER(signal);
  459. return CYHAL_TIMER_RSLT_ERR_BAD_ARGUMENT;
  460. #endif
  461. }
  462. cy_rslt_t cyhal_timer_enable_output(cyhal_timer_t *obj, cyhal_timer_output_t signal, cyhal_source_t *source)
  463. {
  464. #if defined(COMPONENT_CAT5)
  465. if(obj->is_t2timer)
  466. {
  467. return CYHAL_TIMER_RSLT_ERR_UNSUPPORTED;
  468. }
  469. #endif
  470. cyhal_tcpwm_output_t tcpwm_signal = _cyhal_timer_translate_output_signal(signal);
  471. return _cyhal_tcpwm_enable_output(&(obj->tcpwm), tcpwm_signal, source);
  472. }
  473. cy_rslt_t cyhal_timer_disconnect_digital(cyhal_timer_t *obj, cyhal_source_t source, cyhal_timer_input_t signal)
  474. {
  475. #if defined(COMPONENT_CAT5)
  476. if(obj->is_t2timer)
  477. {
  478. return CYHAL_TIMER_RSLT_ERR_UNSUPPORTED;
  479. }
  480. #endif
  481. return _cyhal_tcpwm_disconnect_digital(&(obj->tcpwm), source, _cyhal_timer_translate_input_signal(signal));
  482. }
  483. cy_rslt_t cyhal_timer_disable_output(cyhal_timer_t *obj, cyhal_timer_output_t signal)
  484. {
  485. #if defined(COMPONENT_CAT5)
  486. if(obj->is_t2timer)
  487. {
  488. return CYHAL_TIMER_RSLT_ERR_UNSUPPORTED;
  489. }
  490. #endif
  491. return _cyhal_tcpwm_disable_output(&(obj->tcpwm), _cyhal_timer_translate_output_signal(signal));
  492. }
  493. #if defined(__cplusplus)
  494. }
  495. #endif
  496. #endif /* CYHAL_DRIVER_AVAILABLE_TIMER */