Icm20948Serif.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * ________________________________________________________________________________________________________
  3. * Copyright (c) 2015-2015 InvenSense Inc. All rights reserved.
  4. *
  5. * This software, related documentation and any modifications thereto (collectively “Software”) is subject
  6. * to InvenSense and its licensors' intellectual property rights under U.S. and international copyright
  7. * and other intellectual property rights laws.
  8. *
  9. * InvenSense and its licensors retain all intellectual property and proprietary rights in and to the Software
  10. * and any use, reproduction, disclosure or distribution of the Software without an express license agreement
  11. * from InvenSense is strictly prohibited.
  12. *
  13. * EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, THE SOFTWARE IS
  14. * PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  15. * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  16. * EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, IN NO EVENT SHALL
  17. * INVENSENSE BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
  18. * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
  19. * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  20. * OF THE SOFTWARE.
  21. * ________________________________________________________________________________________________________
  22. */
  23. /** @defgroup DriverIcm20948Serif Icm20948 driver serif
  24. * @brief Interface for low-level serial (I2C/SPI) access
  25. * @ingroup DriverIcm20948
  26. * @{
  27. */
  28. #ifndef _INV_ICM20948_SERIF_H_
  29. #define _INV_ICM20948_SERIF_H_
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. #include "InvBool.h"
  34. #include "InvError.h"
  35. #include <stdint.h>
  36. #include <assert.h>
  37. /** @brief ICM20948 serial interface
  38. */
  39. struct inv_icm20948_serif {
  40. void * context;
  41. int (*read_reg)(void * context, uint8_t reg, uint8_t * buf, uint32_t len);
  42. int (*write_reg)(void * context, uint8_t reg, const uint8_t * buf, uint32_t len);
  43. uint32_t max_read;
  44. uint32_t max_write;
  45. inv_bool_t is_spi;
  46. };
  47. static inline inv_bool_t inv_icm20948_serif_is_spi(struct inv_icm20948_serif * s)
  48. {
  49. assert(s);
  50. return s->is_spi;
  51. }
  52. static inline uint32_t inv_icm20948_serif_max_read(struct inv_icm20948_serif * s)
  53. {
  54. assert(s);
  55. return s->max_read;
  56. }
  57. static inline uint32_t inv_icm20948_serif_max_write(struct inv_icm20948_serif * s)
  58. {
  59. assert(s);
  60. return s->max_write;
  61. }
  62. static inline int inv_icm20948_serif_read_reg(struct inv_icm20948_serif * s,
  63. uint8_t reg, uint8_t * buf, uint32_t len)
  64. {
  65. assert(s);
  66. if(len > s->max_read)
  67. return INV_ERROR_SIZE;
  68. if(s->read_reg(s->context, reg, buf, len) != 0)
  69. return INV_ERROR_TRANSPORT;
  70. return 0;
  71. }
  72. static inline int inv_icm20948_serif_write_reg(struct inv_icm20948_serif * s,
  73. uint8_t reg, const uint8_t * buf, uint32_t len)
  74. {
  75. assert(s);
  76. if(len > s->max_write)
  77. return INV_ERROR_SIZE;
  78. if(s->write_reg(s->context, reg, buf, len) != 0)
  79. return INV_ERROR_TRANSPORT;
  80. return 0;
  81. }
  82. #ifdef __cplusplus
  83. }
  84. #endif
  85. #endif /* _INV_ICM20948_SERIF_H_ */
  86. /** @} */