hal_eicu.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. /*
  14. Rewritten by Emil Fresk (1/5 - 2014) for extended input capture
  15. functionality. And fix for spurious callbacks in the interrupt handler.
  16. */
  17. /*
  18. Improved by Uladzimir Pylinsky aka barthess (1/3 - 2015) for support of
  19. 32-bit timers and timers with single capture/compare channels.
  20. */
  21. #ifndef HAL_EICU_H_
  22. #define HAL_EICU_H_
  23. #if (HAL_USE_EICU == TRUE) || defined(__DOXYGEN__)
  24. /*===========================================================================*/
  25. /* Driver constants. */
  26. /*===========================================================================*/
  27. /*===========================================================================*/
  28. /* Driver pre-compile time settings. */
  29. /*===========================================================================*/
  30. /*===========================================================================*/
  31. /* Derived constants and error checks. */
  32. /*===========================================================================*/
  33. /*===========================================================================*/
  34. /* Driver data structures and types. */
  35. /*===========================================================================*/
  36. /**
  37. * @brief Driver state machine possible states.
  38. */
  39. typedef enum {
  40. EICU_UNINIT, /* Not initialized. */
  41. EICU_STOP, /* Stopped. */
  42. EICU_READY, /* Ready. */
  43. EICU_WAITING, /* Waiting for first edge. */
  44. EICU_ACTIVE, /* Active cycle phase. */
  45. EICU_IDLE /* Idle cycle phase. */
  46. } eicustate_t;
  47. /**
  48. * @brief Channel state machine possible states.
  49. */
  50. typedef enum {
  51. EICU_CH_IDLE, /* Idle cycle phase. */
  52. EICU_CH_ACTIVE /* Active cycle phase. */
  53. } eicuchannelstate_t;
  54. /**
  55. * @brief EICU channel selection definition
  56. */
  57. typedef enum {
  58. EICU_CHANNEL_1,
  59. EICU_CHANNEL_2,
  60. EICU_CHANNEL_3,
  61. EICU_CHANNEL_4,
  62. EICU_CHANNEL_ENUM_END
  63. } eicuchannel_t;
  64. /**
  65. * @brief Type of a structure representing an EICU driver.
  66. */
  67. typedef struct EICUDriver EICUDriver;
  68. /**
  69. * @brief EICU notification callback type.
  70. *
  71. * @param[in] eicup Pointer to a EICUDriver object
  72. * @param[in] channel EICU channel that fired the interrupt
  73. * @param[in] width Pulse width
  74. * @param[in] period Pulse period
  75. */
  76. typedef void (*eicucallback_t)(EICUDriver *eicup, eicuchannel_t channel);
  77. #include "hal_eicu_lld.h"
  78. /*===========================================================================*/
  79. /* Driver macros. */
  80. /*===========================================================================*/
  81. /**
  82. * @name Macro Functions
  83. * @{
  84. */
  85. /**
  86. * @brief Enables the extended input capture.
  87. *
  88. * @param[in] eicup Pointer to the @p EICUDriver object
  89. *
  90. * @iclass
  91. */
  92. #define eicuEnableI(eicup) eicu_lld_enable(eicup)
  93. /**
  94. * @brief Disables the extended input capture.
  95. *
  96. * @param[in] eicup Pointer to the @p EICUDriver object
  97. *
  98. * @iclass
  99. */
  100. #define eicuDisableI(eicup) eicu_lld_disable(eicup)
  101. /** @} */
  102. /*===========================================================================*/
  103. /* External declarations. */
  104. /*===========================================================================*/
  105. #ifdef __cplusplus
  106. extern "C" {
  107. #endif
  108. void eicuInit(void);
  109. void eicuObjectInit(EICUDriver *eicup);
  110. void eicuStart(EICUDriver *eicup, const EICUConfig *config);
  111. void eicuStop(EICUDriver *eicup);
  112. void eicuEnable(EICUDriver *eicup);
  113. void eicuDisable(EICUDriver *eicup);
  114. #ifdef __cplusplus
  115. }
  116. #endif
  117. #endif /* HAL_USE_EICU */
  118. #endif /* HAL_EICU_H_ */
  119. /** @} */