drv_iic.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /***************************************************************************//**
  2. * @file drv_iic.h
  3. * @brief IIC driver of RT-Thread RTOS for EFM32
  4. * COPYRIGHT (C) 2011, RT-Thread Development Team
  5. * @author onelife
  6. * @version 0.4 beta
  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. ******************************************************************************/
  21. #ifndef __DRV_IIC_H__
  22. #define __DRV_IIC_H__
  23. /* Includes ------------------------------------------------------------------*/
  24. /* Exported types ------------------------------------------------------------*/
  25. struct efm32_iic_int_mode_t
  26. {
  27. rt_uint8_t *data_ptr;
  28. rt_uint8_t data_size;
  29. rt_uint32_t read_index, save_index;
  30. };
  31. struct efm32_iic_device_t
  32. {
  33. /* Counter */
  34. rt_uint32_t counter;
  35. /* Lock */
  36. struct rt_semaphore *lock;
  37. /* Pointer to timer */
  38. rt_timer_t timer;
  39. /* Timeout flag */
  40. volatile rt_bool_t timeout;
  41. /* State */
  42. rt_uint8_t state;
  43. /* Pointer to IIC device structure */
  44. I2C_TypeDef *iic_device;
  45. /* Self address */
  46. rt_uint16_t address;
  47. /* RX structure */
  48. struct efm32_iic_int_mode_t *rx_buffer;
  49. };
  50. struct efm32_iic_control_t
  51. {
  52. rt_uint8_t config;
  53. rt_uint16_t address;
  54. };
  55. /* Exported constants --------------------------------------------------------*/
  56. /* Exported macro ------------------------------------------------------------*/
  57. #define IIC_STATE_MASTER (1 << 0)
  58. #define IIC_STATE_BROADCAST (1 << 1)
  59. //#define IIC_STATE_TX_BUSY (1 << 2)
  60. #define IIC_STATE_RX_BUSY (1 << 3)
  61. #define IIC_TIMEOUT_PERIOD (RT_TICK_PER_SECOND)
  62. /* Exported functions --------------------------------------------------------*/
  63. void rt_hw_iic_init(void);
  64. #endif /* __DRV_IIC_H__ */