Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
3.5 KiB

  1. // $Header: G:/SwDev/WDM/Video/bt848/rcs/Bti2c.h 1.4 1998/04/29 22:43:27 tomz Exp $
  2. #ifndef __I2C_H
  3. #define __I2C_H
  4. #include "regField.h"
  5. #include "viddefs.h"
  6. #include "retcode.h"
  7. #include "i2cerr.h"
  8. //#define HAUPPAUGEI2CPROVIDER
  9. #ifdef HAUPPAUGEI2CPROVIDER
  10. // #include "hcwWDM.h"
  11. // Need to define for brooktree i2c calls
  12. /* Type: Level
  13. * Purpose: used to define a pin state
  14. */
  15. typedef enum { LevelLow, LevelHi } Level;
  16. #endif
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CLASS I2C
  19. //
  20. // Description:
  21. // This class encapsulates the register fields in the I2C register of the
  22. // Bt848. A complete set of functions are developed to manipulate all the
  23. // register fields in the I2C for the Bt848.
  24. //
  25. /////////////////////////////////////////////////////////////////////////////
  26. class I2C
  27. {
  28. private:
  29. // define which mode the I2C is selected
  30. enum I2CMode { I2CMode_None, I2CMode_HW, I2CMode_SW };
  31. bool initOK; // initialization is successful?
  32. DWORD cycle; // software control of frequency
  33. int errNum; // error number
  34. I2CMode mode; // which mode the I2C is running in
  35. //**************************************************************************
  36. // Structures
  37. //**************************************************************************
  38. union shadow
  39. {
  40. struct _i2c_reg // I2C register structure
  41. {
  42. unsigned int sda:1;
  43. unsigned int scl:1;
  44. unsigned int w3b:1;
  45. unsigned int sync:1;
  46. unsigned int div:4;
  47. unsigned int byte2:8;
  48. unsigned int byte1:8;
  49. unsigned int addr_rw:8;
  50. } i2cShadow;
  51. DWORD Initer;
  52. } sh;
  53. protected:
  54. RegisterDW decRegINT_STAT;
  55. RegField decFieldI2CDONE;
  56. RegField decFieldRACK;
  57. RegisterDW decRegI2C;
  58. RegField decFieldI2CDB0;
  59. RegField decFieldI2CDB1;
  60. RegField decFieldI2CDB2;
  61. RegField decFieldI2CDIV;
  62. RegField decFieldSYNC;
  63. RegField decFieldW3B;
  64. RegField decFieldSCL;
  65. RegField decFieldSDA;
  66. public:
  67. // constructor and destructor
  68. I2C( void );
  69. ~I2C();
  70. // member functions
  71. bool IsInitOK( void );
  72. #ifdef HARDWAREI2C
  73. ErrorCode I2CInitHWMode( long freq );
  74. int I2CReadDiv( void );
  75. ErrorCode I2CHWRead( BYTE address, BYTE *value );
  76. ErrorCode I2CHWWrite2( BYTE address, BYTE value1 );
  77. ErrorCode I2CHWWrite3( BYTE address, BYTE value1, BYTE value2 );
  78. ErrorCode I2CSetSync( State );
  79. int I2CReadSync( void );
  80. #endif
  81. void I2CSetFreq( long freq );
  82. int I2CGetLastError( void );
  83. #ifdef HAUPPAUGEI2CPROVIDER
  84. ErrorCode I2CInitSWMode( long freq );
  85. ErrorCode I2CSWStart( void );
  86. ErrorCode I2CSWStop( void );
  87. ErrorCode I2CSWRead( BYTE * value );
  88. ErrorCode I2CSWWrite( BYTE value );
  89. ErrorCode I2CSWSendACK( void );
  90. ErrorCode I2CSWSendNACK( void );
  91. ErrorCode I2CSWSetSCL( Level );
  92. int I2CSWReadSCL( void );
  93. ErrorCode I2CSWSetSDA( Level );
  94. int I2CSWReadSDA( void );
  95. #endif
  96. private:
  97. void I2CResetShadow( void ); // reset register shadow
  98. ErrorCode I2CHWWaitUntilDone( int ); // wait until I2C completes operation
  99. bool I2CHWIsDone( void ); // check interrupt bit for operation done
  100. bool I2CHWReceivedACK( void ); // check interrupt bit for received ACK
  101. void I2CSWBitDelay( void ); // insert delay to simulate frequency
  102. ErrorCode I2CSWWaitForACK( void ); // wait for ACK from receiver using software
  103. };
  104. #endif // __I2C_H