sigmadelta_hal.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD
  2. //
  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. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /*******************************************************************************
  15. * NOTICE
  16. * The hal is not public api, don't use in application code.
  17. * See readme.md in soc/include/hal/readme.md
  18. ******************************************************************************/
  19. // The HAL layer for SIGMADELTA.
  20. // There is no parameter check in the hal layer, so the caller must ensure the correctness of the parameters.
  21. #pragma once
  22. #include "soc/sigmadelta_periph.h"
  23. #include "hal/sigmadelta_types.h"
  24. #include "hal/sigmadelta_ll.h"
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. /**
  29. * Context that should be maintained by both the driver and the HAL
  30. */
  31. typedef struct {
  32. gpio_sd_dev_t *dev;
  33. } sigmadelta_hal_context_t;
  34. /**
  35. * @brief Set Sigma-delta channel duty.
  36. *
  37. * @param hal Context of the HAL layer
  38. * @param channel Sigma-delta channel number
  39. * @param duty Sigma-delta duty of one channel, the value ranges from -128 to 127, recommended range is -90 ~ 90.
  40. * The waveform is more like a random one in this range.
  41. */
  42. #define sigmadelta_hal_set_duty(hal, channel, duty) sigmadelta_ll_set_duty((hal)->dev, channel, duty)
  43. /**
  44. * @brief Set Sigma-delta channel's clock pre-scale value.
  45. *
  46. * @param hal Context of the HAL layer
  47. * @param channel Sigma-delta channel number
  48. * @param prescale The divider of source clock, ranges from 0 to 255
  49. */
  50. #define sigmadelta_hal_set_prescale(hal, channel, prescale) sigmadelta_ll_set_prescale((hal)->dev, channel, prescale)
  51. /**
  52. * @brief Init the SIGMADELTA hal and set the SIGMADELTA to the default configuration. This function should be called first before other hal layer function is called
  53. *
  54. * @param hal Context of the HAL layer
  55. * @param sigmadelta_num The uart port number, the max port number is (SIGMADELTA_NUM_MAX -1)
  56. */
  57. void sigmadelta_hal_init(sigmadelta_hal_context_t *hal, int sigmadelta_num);
  58. #ifdef __cplusplus
  59. }
  60. #endif