driver_iic.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * @File name : driver_iic.h
  3. * @Author : Bluetrum IOT Team
  4. * @Date : 2023-02-15
  5. * @Description : This file contains all the functions prototypes for the IIC library.
  6. *
  7. * Copyright (c) by Bluetrum, All Rights Reserved.
  8. */
  9. #ifndef _DRIVER_IIC_H
  10. #define _DRIVER_IIC_H
  11. #include "driver_com.h"
  12. /**
  13. * @brief IIC IT and Flag Definition
  14. */
  15. typedef enum {
  16. IIC_IT_DONE = 0x01,
  17. IIC_IT_ACK = 0x02,
  18. } IIC_IT_TYPEDEF;
  19. /**
  20. * @brief IIC Clock Source Enumeration
  21. */
  22. typedef enum {
  23. IIC_CLK_RC2M = 0x00000000,
  24. IIC_CLK_X24MDIV8 = 0x00800000,
  25. } IIC_CLK_SOURCE_TYPEDEF;
  26. /**
  27. * @brief IIC Role Mode Enumeration
  28. */
  29. typedef enum {
  30. IIC_ROLE_MODE_MASTER = 0,
  31. IIC_ROLE_MODE_SLAVE = 1,
  32. } IIC_ROLE_MODE_TYPEDEF;
  33. /**
  34. * @brief IIC Data Sample Edge Selection In Slave Mode.
  35. */
  36. typedef enum {
  37. IIC_SMP_SEL_FALLING = 0,
  38. IIC_SMP_SEL_RISING = 1,
  39. } IIC_SMP_SEL_TYPEDEF;
  40. /**
  41. * @brief IIC Transmit Direction Enumeration
  42. */
  43. typedef enum {
  44. IIC_SEND_MODE = 1,
  45. IIC_RECEIVE_MODE = 2,
  46. } IIC_TRANSMIT_MODE;
  47. /**
  48. * @brief IIC Init Structure
  49. */
  50. typedef struct {
  51. uint8_t scl_pose_div;
  52. uint8_t sda_hold_cnt;
  53. IIC_CLK_SOURCE_TYPEDEF clk_source;
  54. IIC_ROLE_MODE_TYPEDEF mode_sel;
  55. } iic_init_typedef;
  56. //--------------- Function used to configure iic or transmit data ---------------//
  57. void iic_init(iic_init_typedef *iic_init_struct);
  58. void iic_deinit(void);
  59. void iic_cmd(FUNCTIONAL_STATE state);
  60. STATUS_STATE iic_send_data(uint8_t dev_addr, uint16_t reg_addr, uint32_t data, uint8_t len, uint8_t timeout_ms);
  61. STATUS_STATE iic_receive_data(uint8_t dev_addr, uint16_t reg_addr, uint32_t *data, uint8_t len, uint8_t timeout_ms);
  62. //------------------- Function used to configure interrupt -------------------//
  63. void iic_pic_config(isr_t isr, int pr, IIC_IT_TYPEDEF interrupt_type, FUNCTIONAL_STATE state);
  64. FLAG_STATE iic_get_flag(IIC_IT_TYPEDEF interrupt_type);
  65. void iic_clear_all_flag(void);
  66. void iic_send_nack_en(FUNCTIONAL_STATE state);
  67. void iic_smp_sel(IIC_SMP_SEL_TYPEDEF edge);
  68. #endif // _DRIVER_IIC_H