gps.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Copyright (c) 2022 Actions Technology Co., Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef _GPS_H_
  7. #define _GPS_H_
  8. #include <stddef.h>
  9. #include <stdint.h>
  10. #include <sys/types.h>
  11. #include <zephyr/types.h>
  12. #include <device.h>
  13. #include <drivers/cfg_drv/dev_config.h>
  14. #include <minmea.h>
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. struct gps_value {
  19. uint8_t *gps_nmea_data;
  20. };
  21. enum GPS_MSG_ID {
  22. MSG_GPS_ENABLE,
  23. MSG_GPS_DISABLE,
  24. MSG_GPS_NMEA_DATA,
  25. MSG_GPS_ADD_CB,
  26. MSG_GPS_REMOVE_CB,
  27. };
  28. typedef struct {
  29. #ifdef CONFIG_GPS_PARSE_RMC_ENABLE
  30. /* minmea_sentence_rmc */
  31. struct minmea_sentence_rmc rmc_data;
  32. #endif
  33. #ifdef CONFIG_GPS_PARSE_GGA_ENABLE
  34. /* minmea_sentence_gga */
  35. struct minmea_sentence_gga gga_data;
  36. #endif
  37. #ifdef CONFIG_GPS_PARSE_GST_ENABLE
  38. /* minmea_sentence_gst */
  39. struct minmea_sentence_gst gst_data;
  40. #endif
  41. #ifdef CONFIG_GPS_PARSE_GSV_ENABLE
  42. /* minmea_sentence_gsv */
  43. struct minmea_sentence_gsv gsv_data;
  44. #endif
  45. #ifdef CONFIG_GPS_PARSE_VTG_ENABLE
  46. /* minmea_sentence_vtg */
  47. struct minmea_sentence_vtg vtg_data;
  48. #endif
  49. #ifdef CONFIG_GPS_PARSE_ZDA_ENABLE
  50. /* minmea_sentence_zda */
  51. struct minmea_sentence_zda zda_data;
  52. #endif
  53. /* reserve */
  54. }gps_res_t;
  55. typedef void (*gps_notify_t) (struct device *dev, struct gps_value *val);
  56. struct gps_dev_driver_api {
  57. void (*enable)(const struct device *dev);
  58. void (*disable)(const struct device *dev);
  59. void (*inquiry)(const struct device *dev, struct gps_value *val);
  60. void (*register_notify)(const struct device *dev, gps_notify_t notify);
  61. void (*unregister_notify)(const struct device *dev, gps_notify_t notify);
  62. };
  63. static inline void gps_dev_enable(const struct device *dev)
  64. {
  65. const struct gps_dev_driver_api *api = dev->api;
  66. if (api->enable)
  67. api->enable(dev);
  68. }
  69. static inline void gps_dev_disable(const struct device *dev)
  70. {
  71. const struct gps_dev_driver_api *api = dev->api;
  72. if (api->disable)
  73. api->disable(dev);
  74. }
  75. static inline void gps_dev_inquiry(const struct device *dev,
  76. struct gps_value *val)
  77. {
  78. const struct gps_dev_driver_api *api = dev->api;
  79. if (api->inquiry)
  80. api->inquiry(dev, val);
  81. }
  82. static inline void gps_dev_register_notify(const struct device *dev,
  83. gps_notify_t notify)
  84. {
  85. const struct gps_dev_driver_api *api = dev->api;
  86. if (api->register_notify)
  87. api->register_notify(dev, notify);
  88. }
  89. static inline void gps_dev_unregister_notify(const struct device *dev,
  90. gps_notify_t notify)
  91. {
  92. const struct gps_dev_driver_api *api = dev->api;
  93. if (api->unregister_notify)
  94. api->unregister_notify(dev, notify);
  95. }
  96. #ifdef __cplusplus
  97. }
  98. #endif
  99. #endif