air105_dac.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (c) 2022 OpenLuat & AirM2M
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  5. * this software and associated documentation files (the "Software"), to deal in
  6. * the Software without restriction, including without limitation the rights to
  7. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  8. * the Software, and to permit persons to whom the Software is furnished to do so,
  9. * subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in all
  12. * copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  16. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  17. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  18. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. */
  21. #ifndef __AIR105_DAC_H__
  22. #define __AIR105_DAC_H__
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. /* Include ------------------------------------------------------------------*/
  27. #include "air105.h"
  28. #define DAC_CR1_IS_RUNNING ((uint32_t)0x20000000)
  29. #define DAC_CR1_POWER_DOWN ((uint32_t)0x00000010)
  30. #define DAC_CR1_FIFO_RESET ((uint32_t)0x00000008)
  31. #define DAC_CR1_DMA_ENABLE ((uint32_t)0x00000004)
  32. #define IS_DAC_DATA(DATA) ((DATA) <= 0x3FF)
  33. #define DAC_CURR_SEL_MASK ((uint32_t)0x00000020)
  34. #define DAC_CURR_SEL_20K ((uint32_t)0x00000000)
  35. #define DAC_CURR_SEL_2K ((uint32_t)0x00000020)
  36. #define IS_DAC_CURR_SEL(CURR) (((CURR) == DAC_CURR_SEL_20K) || \
  37. ((CURR) == DAC_CURR_SEL_2K))
  38. #define IS_DAC_FIFO_THR(THR) ((THR) <= 0xF)
  39. typedef struct _DAC_InitTypeDef
  40. {
  41. uint32_t DAC_CurrSel; /* DAC mode select */
  42. uint32_t DAC_TimerExp; /* DAC timer expectation */
  43. uint32_t DAC_FIFOThr; /* DAC FIFO Threshold */
  44. } DAC_InitTypeDef;
  45. #define DAC_FIFO_DEPTH (16)
  46. #define DAC_IT_STATUS_SHIFT (30)
  47. #define DAC_IT_FIFO_THR ((uint32_t)0x0002)
  48. #define DAC_IT_FIFO_OVERFLOW ((uint32_t)0x0001)
  49. #define IS_DAC_IT(IT) (((IT) == DAC_IT_FIFO_THR) || \
  50. ((IT) == DAC_IT_FIFO_OVERFLOW))
  51. #define DAC_FLAG_RUNNING (DAC_CR1_IS_RUNNING)
  52. #define DAC_FLAG_OVERFLOW ((uint32_t)0x40000000)
  53. #define IS_DAC_FLAG(FLAG) (((FLAG) == DAC_FLAG_RUNNING) || \
  54. ((FLAG) == DAC_FLAG_OVERFLOW))
  55. /* Exported functions -------------------------------------------------------*/
  56. void DAC_Init(DAC_InitTypeDef *DAC_InitStruct);
  57. void DAC_StructInit(DAC_InitTypeDef *DAC_InitStruct);
  58. void DAC_FIFOReset(void);
  59. void DAC_Cmd(FunctionalState NewState);
  60. void DAC_DMACmd(FunctionalState NewState);
  61. void DAC_SetData(uint16_t Data);
  62. FlagStatus DAC_GetFlagStatus(uint32_t DAC_Flag);
  63. void DAC_ClearFlag(uint32_t DAC_Flag);
  64. void DAC_ITConfig(uint32_t DAC_IT, FunctionalState NewState);
  65. ITStatus DAC_GetITStatus(uint32_t DAC_IT);
  66. void DAC_ClearITPendingBit(uint32_t DAC_IT);
  67. #ifdef __cplusplus
  68. }
  69. #endif
  70. #endif /* __AIR105_DAC_H__ */