drv_iic.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /***************************************************************************//**
  2. * @file drv_iic.h
  3. * @brief IIC driver of RT-Thread RTOS for EFM32
  4. * COPYRIGHT (C) 2012, RT-Thread Development Team
  5. * @author onelife
  6. * @version 1.0
  7. *******************************************************************************
  8. * @section License
  9. * The license and distribution terms for this file may be found in the file
  10. * LICENSE in this distribution or at http://www.rt-thread.org/license/LICENSE
  11. *******************************************************************************
  12. * @section Change Logs
  13. * Date Author Notes
  14. * 2011-01-07 onelife Initial creation for EFM32
  15. * 2011-07-11 onelife Add lock (semaphore) to prevent simultaneously
  16. * access
  17. * 2011-08-04 onelife Change the usage of the second parameter of Read
  18. * and Write functions from (seldom used) "Offset" to "Slave address"
  19. * 2011-08-04 onelife Add a timer to prevent from forever waiting
  20. * 2011-12-27 onelife Change IIC read format
  21. ******************************************************************************/
  22. #ifndef __DRV_IIC_H__
  23. #define __DRV_IIC_H__
  24. /* Includes ------------------------------------------------------------------*/
  25. /* Exported types ------------------------------------------------------------*/
  26. struct efm32_iic_int_mode_t
  27. {
  28. rt_uint8_t *data_ptr;
  29. rt_uint8_t data_size;
  30. rt_uint32_t read_index, save_index;
  31. };
  32. struct efm32_iic_device_t
  33. {
  34. /* Counter */
  35. rt_uint32_t counter;
  36. /* Lock */
  37. struct rt_semaphore *lock;
  38. /* Pointer to timer */
  39. rt_timer_t timer;
  40. /* Timeout flag */
  41. volatile rt_bool_t timeout;
  42. /* State */
  43. rt_uint8_t state;
  44. /* Pointer to IIC device structure */
  45. I2C_TypeDef *iic_device;
  46. /* Self address */
  47. rt_uint16_t address;
  48. /* RX structure */
  49. struct efm32_iic_int_mode_t *rx_buffer;
  50. };
  51. struct efm32_iic_control_t
  52. {
  53. rt_uint8_t config;
  54. rt_uint16_t address;
  55. };
  56. /* Exported constants --------------------------------------------------------*/
  57. /* Exported macro ------------------------------------------------------------*/
  58. #define IIC_STATE_MASTER (1 << 0)
  59. #define IIC_STATE_BROADCAST (1 << 1)
  60. //#define IIC_STATE_TX_BUSY (1 << 2)
  61. #define IIC_STATE_RX_BUSY (1 << 3)
  62. #define IIC_TIMEOUT_PERIOD (RT_TICK_PER_SECOND)
  63. #define IIC_OP_READ_ONLY (0xFF)
  64. /* Exported functions --------------------------------------------------------*/
  65. void rt_hw_iic_init(void);
  66. #endif /* __DRV_IIC_H__ */