sunxi_hal_gpadc.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * drivers/input/sensor/sunxi_gpadc.h
  3. *
  4. * Copyright (C) 2016 Allwinner.
  5. * fuzhaoke <fuzhaoke@allwinnertech.com>
  6. *
  7. * SUNXI GPADC Controller Driver Header
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. */
  14. #ifndef HAL_GPADC_H
  15. #define HAL_GPADC_H
  16. #include "hal_clk.h"
  17. #include "sunxi_hal_common.h"
  18. #include <hal_log.h>
  19. #include <interrupt.h>
  20. #include <gpadc/platform_gpadc.h>
  21. #include <gpadc/common_gpadc.h>
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. #define CONFIG_DRIVERS_GPADC_DEBUG
  26. #ifdef CONFIG_DRIVERS_GPADC_DEBUG
  27. #define GPADC_INFO(fmt, arg...) hal_log_info(fmt, ##arg)
  28. #else
  29. #define GPADC_INFO(fmt, arg...) do {}while(0)
  30. #endif
  31. #define GPADC_ERR(fmt, arg...) hal_log_err(fmt, ##arg)
  32. enum
  33. {
  34. GPADC_DOWN,
  35. GPADC_UP
  36. };
  37. typedef enum
  38. {
  39. GP_CH_0 = 0,
  40. GP_CH_1,
  41. GP_CH_2,
  42. GP_CH_3,
  43. GP_CH_4,
  44. GP_CH_5,
  45. GP_CH_6,
  46. GP_CH_7,
  47. GP_CH_MAX
  48. } hal_gpadc_channel_t;
  49. typedef enum
  50. {
  51. GPADC_IRQ_ERROR = -4,
  52. GPADC_CHANNEL_ERROR = -3,
  53. GPADC_CLK_ERROR = -2,
  54. GPADC_ERROR = -1,
  55. GPADC_OK = 0,
  56. } hal_gpadc_status_t;
  57. typedef enum gp_select_mode
  58. {
  59. GP_SINGLE_MODE = 0,
  60. GP_SINGLE_CYCLE_MODE,
  61. GP_CONTINUOUS_MODE,
  62. GP_BURST_MODE,
  63. } hal_gpadc_mode_t;
  64. typedef int (*gpadc_callback_t)(uint32_t data_type, uint32_t data);
  65. typedef struct
  66. {
  67. uint32_t reg_base;
  68. uint32_t channel_num;
  69. uint32_t irq_num;
  70. uint32_t sample_rate;
  71. #if defined(CONFIG_SOC_SUN20IW1)
  72. hal_clk_id_t bus_clk;
  73. hal_clk_id_t rst_clk;
  74. hal_clk_t mbus_clk;
  75. #else
  76. hal_clk_id_t mclk;
  77. hal_clk_id_t pclk;
  78. #endif
  79. hal_gpadc_mode_t mode;
  80. gpadc_callback_t callback[CHANNEL_MAX_NUM];
  81. } hal_gpadc_t;
  82. int hal_gpadc_init(void);
  83. hal_gpadc_status_t hal_gpadc_deinit(void);
  84. hal_gpadc_status_t hal_gpadc_channel_init(hal_gpadc_channel_t channal);
  85. hal_gpadc_status_t hal_gpadc_channel_exit(hal_gpadc_channel_t channal);
  86. hal_gpadc_status_t hal_gpadc_register_callback(hal_gpadc_channel_t channal,
  87. gpadc_callback_t user_callback);
  88. #ifdef __cplusplus
  89. }
  90. #endif
  91. #endif