drv_iic.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright (c) 2006-2022, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2011-01-07 onelife Initial creation for EFM32
  9. * 2011-07-11 onelife Add lock (semaphore) to prevent simultaneously access
  10. * 2011-08-04 onelife Change the usage of the second parameter of Read
  11. * and Write functions from (seldom used) "Offset" to "Slave address"
  12. * 2011-08-04 onelife Add a timer to prevent from forever waiting
  13. * 2011-12-27 onelife Change IIC read format
  14. */
  15. #ifndef __DRV_IIC_H__
  16. #define __DRV_IIC_H__
  17. /* Includes ------------------------------------------------------------------*/
  18. /* Exported types ------------------------------------------------------------*/
  19. struct efm32_iic_int_mode_t
  20. {
  21. rt_uint8_t *data_ptr;
  22. rt_uint8_t data_size;
  23. rt_uint32_t read_index, save_index;
  24. };
  25. struct efm32_iic_device_t
  26. {
  27. /* Counter */
  28. rt_uint32_t counter;
  29. /* Lock */
  30. struct rt_semaphore *lock;
  31. /* Pointer to timer */
  32. rt_timer_t timer;
  33. /* Timeout flag */
  34. volatile rt_bool_t timeout;
  35. /* State */
  36. rt_uint8_t state;
  37. /* Pointer to IIC device structure */
  38. I2C_TypeDef *iic_device;
  39. /* Self address */
  40. rt_uint16_t address;
  41. /* RX structure */
  42. struct efm32_iic_int_mode_t *rx_buffer;
  43. };
  44. struct efm32_iic_control_t
  45. {
  46. rt_uint8_t config;
  47. rt_uint16_t address;
  48. };
  49. /* Exported constants --------------------------------------------------------*/
  50. /* Exported macro ------------------------------------------------------------*/
  51. #define IIC_STATE_MASTER (1 << 0)
  52. #define IIC_STATE_BROADCAST (1 << 1)
  53. //#define IIC_STATE_TX_BUSY (1 << 2)
  54. #define IIC_STATE_RX_BUSY (1 << 3)
  55. #define IIC_TIMEOUT_PERIOD (RT_TICK_PER_SECOND)
  56. #define IIC_OP_READ_ONLY (0xFF)
  57. /* Exported functions --------------------------------------------------------*/
  58. void rt_hw_iic_init(void);
  59. #endif /* __DRV_IIC_H__ */