/********************************************************************* * @fn hali2cClock * @brief Clocks the SM-Bus. If a negative edge is going out, the * I/O pin is set as an output and driven low. If a positive * edge is going out, the pin is set as an input and the pin * pull-up drives the line high. This way, the slave device * can hold the node low if longer setup time is desired. * @param dir - clock line direction * @return void */ STATIC void hali2cClock( bool dir ) { if ( dir ) { IO_DIR_PORT_PIN( OCM_CLK_PORT, OCM_CLK_PIN, IO_IN ); } else { IO_DIR_PORT_PIN( OCM_CLK_PORT, OCM_CLK_PIN, IO_OUT ); OCM_SCL = 0; } hali2cWait(1); }
/********************************************************************* * @fn hali2cClock * @brief Clocks the SM-Bus. If a negative edge is going out, the * I/O pin is set as an output and driven low. If a positive * edge is going out, the pin is set as an input and the pin * pull-up drives the line high. This way, the slave device * can hold the node low if longer setup time is desired. * @param dir - clock line direction * @return void */ STATIC void hali2cClock( bool dir ) { if ( dir ) { IO_DIR_PORT_PIN( OCM_CLK_PORT, OCM_CLK_PIN, IO_IN ); while(!OCM_SCL) /* Wait until clock is high */ hali2cWait(1); } else { IO_DIR_PORT_PIN( OCM_CLK_PORT, OCM_CLK_PIN, IO_OUT ); OCM_SCL = 0; } hali2cWait(1); }
/********************************************************************* * @fn HalI2CInit * @brief Initializes two-wire serial I/O bus * @param void * @return void */ void HalI2CInit( void ) { if (!s_xmemIsInit) { s_xmemIsInit = 1; // // Set port pins as inputs IO_DIR_PORT_PIN( OCM_CLK_PORT, OCM_CLK_PIN, IO_IN ); IO_DIR_PORT_PIN( OCM_DATA_PORT, OCM_DATA_PIN, IO_IN ); // // // Set for general I/O operation IO_FUNC_PORT_PIN( OCM_CLK_PORT, OCM_CLK_PIN, IO_GIO ); IO_FUNC_PORT_PIN( OCM_DATA_PORT, OCM_DATA_PIN, IO_GIO ); // // // Set I/O mode for pull-up/pull-down IO_IMODE_PORT_PIN( OCM_CLK_PORT, OCM_CLK_PIN, IO_PUD ); IO_IMODE_PORT_PIN( OCM_DATA_PORT, OCM_DATA_PIN, IO_PUD ); // // // Set pins to pull-up IO_PUD_PORT( OCM_CLK_PORT, IO_PUP ); IO_PUD_PORT( OCM_DATA_PORT, IO_PUP ); } }