1-Wire® library for mbed. Complete 1-Wire library that supports our silicon masters along with a bit-bang master on the MAX32600MBED platform with one common interface for mbed. Slave support has also been included and more slaves will be added as time permits.
Dependents: MAXREFDES131_Qt_Demo MAX32630FTHR_iButton_uSD_Logger MAX32630FTHR_DS18B20_uSD_Logger MAXREFDES130_131_Demo ... more
Superseded by MaximInterface.
Diff: Bridge/DS28E17/DS28E17.h
- Revision:
- 76:84e6c4994e29
- Parent:
- 75:8b627804927c
- Child:
- 77:529edb329ee0
--- a/Bridge/DS28E17/DS28E17.h Fri May 13 14:52:50 2016 -0500 +++ b/Bridge/DS28E17/DS28E17.h Sat May 14 14:27:56 2016 -0500 @@ -39,367 +39,362 @@ namespace OneWire { - namespace Masters { class OneWireMaster; } + class OneWireMaster; - namespace Bridge + class DS28E17 : public OneWireSlave { - class DS28E17 : public OneWireSlave + public: + enum CmdResult { - public: - enum CmdResult - { - Success, - CommsReadBitError, - CommsWriteBitError, - CommsReadByteError, - CommsWriteByteError, - CommsReadBlockError, - CommsWriteBlockError, - TimeoutError, - OperationFailure - }; + Success, + CommsReadBitError, + CommsWriteBitError, + CommsReadByteError, + CommsWriteByteError, + CommsReadBlockError, + CommsWriteBlockError, + TimeoutError, + OperationFailure + }; - /**********************************************************//** - * @brief DS28E17 constructor - * - * @details - * - * On Entry: - * @param[in] p_owm - pointer to a 1-wire master of the following - * types; Ds248x, Ds2480b, OwGpio which - * inherit the base class 'OneWireInterface' - * - * On Exit: - * @return - **************************************************************/ - DS28E17(Masters::OneWireMaster &owm); + /**********************************************************//** + * @brief DS28E17 constructor + * + * @details + * + * On Entry: + * @param[in] p_owm - pointer to a 1-wire master of the following + * types; Ds248x, Ds2480b, OwGpio which + * inherit the base class 'OneWireInterface' + * + * On Exit: + * @return + **************************************************************/ + DS28E17(OneWireMaster &owm); - /**********************************************************//** - * @brief Write to selected DS28E17's I2C with Stop. - * Poll until I2C write complete and receive status info. - * - * @details Output on I2C: S, Address + Write, Write Data [1-255], P - * - * On Entry: - * @param[in] I2C_addr - - * Writes I2C address. The least significant bit of the I2C - * address is automatically cleared by the command. - * - * @param[in] length - * The number of data bytes to be written ranging from 01h to FFh. - * A value of zero will assert the Error Detected pin (ED). - * - * @param[in] *data - * User defines write data ranging from 1-255 bytes. - * - * On Exit: - * @param[out] status - * Detects the condition of the Start (bit3), N/A (bit2), - * Address(bit1) and CRC16(bit0) bits. - * b3;0=No Err|1=I2CStart prev-not issued, - * b2;0=No Err|1=I2C N/A Err, - * b1;0=No Err|1=Addr Err, - * b0;0=Valid CRC16|1=Invalid CRC16 - * - * @param[out] wr_status - * Indicates which write byte NACK’d. A value of 00h indicates - * all bytes were acknowledged by the slave. - * A non-zero value indicates the byte number that NACK’d. - * - * @return - * true if device selected and written @n - * false if failed device select - **************************************************************/ - CmdResult I2C_WriteDataWithStop(uint8_t I2C_addr, uint8_t length, - uint8_t *data, uint8_t &status, - uint8_t &wr_status); + /**********************************************************//** + * @brief Write to selected DS28E17's I2C with Stop. + * Poll until I2C write complete and receive status info. + * + * @details Output on I2C: S, Address + Write, Write Data [1-255], P + * + * On Entry: + * @param[in] I2C_addr - + * Writes I2C address. The least significant bit of the I2C + * address is automatically cleared by the command. + * + * @param[in] length + * The number of data bytes to be written ranging from 01h to FFh. + * A value of zero will assert the Error Detected pin (ED). + * + * @param[in] *data + * User defines write data ranging from 1-255 bytes. + * + * On Exit: + * @param[out] status + * Detects the condition of the Start (bit3), N/A (bit2), + * Address(bit1) and CRC16(bit0) bits. + * b3;0=No Err|1=I2CStart prev-not issued, + * b2;0=No Err|1=I2C N/A Err, + * b1;0=No Err|1=Addr Err, + * b0;0=Valid CRC16|1=Invalid CRC16 + * + * @param[out] wr_status + * Indicates which write byte NACK’d. A value of 00h indicates + * all bytes were acknowledged by the slave. + * A non-zero value indicates the byte number that NACK’d. + * + * @return + * true if device selected and written @n + * false if failed device select + **************************************************************/ + CmdResult I2C_WriteDataWithStop(uint8_t I2C_addr, uint8_t length, + uint8_t *data, uint8_t &status, + uint8_t &wr_status); - /**********************************************************//** - * @brief Write to selected DS28E17's I2C No Stop. - * Poll until I2C write complete and receive status info. - * - * @details Output on I2C: S, Address + Write, Write Data [1-255] - * - * On Entry: - * @param[in] I2C_addr - * Writes I2C address. The least significant bit of the I2C address - * is automatically cleared by the command. - * - * @param[in] length - * The number of data bytes to be written ranging from 01h to FFh. - * A value of zero will assert the Error Detected pin (ED). - * - * @param[in] *data - * User defines write data ranging from 1-255 bytes. - * - * On Exit: - * @param[out] status - * Detects the condition of the Start (bit3), N/A (bit2), - * Address(bit1) and CRC16(bit0) bits. - * b3;0=No Err|1=I2CStart prev-not issued, - * b2;0=No Err|1=I2C N/A Err, - * b1;0=No Err|1=Addr Err, - * b0;0=Valid CRC16|1=Invalid CRC16 - * - * @param[out] wr_status - * Indicates which write byte NACK’d. A value of 00h indicates - * all bytes were acknowledged by the slave. - * A non-zero value indicates the byte number that NACK’d. - * - * @return - * true if device selected and written @n - * false if failed device select - **************************************************************/ - CmdResult I2C_WriteDataNoStop(uint8_t I2C_addr, uint8_t length, - uint8_t *data, uint8_t &status, - uint8_t &wr_status); + /**********************************************************//** + * @brief Write to selected DS28E17's I2C No Stop. + * Poll until I2C write complete and receive status info. + * + * @details Output on I2C: S, Address + Write, Write Data [1-255] + * + * On Entry: + * @param[in] I2C_addr + * Writes I2C address. The least significant bit of the I2C address + * is automatically cleared by the command. + * + * @param[in] length + * The number of data bytes to be written ranging from 01h to FFh. + * A value of zero will assert the Error Detected pin (ED). + * + * @param[in] *data + * User defines write data ranging from 1-255 bytes. + * + * On Exit: + * @param[out] status + * Detects the condition of the Start (bit3), N/A (bit2), + * Address(bit1) and CRC16(bit0) bits. + * b3;0=No Err|1=I2CStart prev-not issued, + * b2;0=No Err|1=I2C N/A Err, + * b1;0=No Err|1=Addr Err, + * b0;0=Valid CRC16|1=Invalid CRC16 + * + * @param[out] wr_status + * Indicates which write byte NACK’d. A value of 00h indicates + * all bytes were acknowledged by the slave. + * A non-zero value indicates the byte number that NACK’d. + * + * @return + * true if device selected and written @n + * false if failed device select + **************************************************************/ + CmdResult I2C_WriteDataNoStop(uint8_t I2C_addr, uint8_t length, + uint8_t *data, uint8_t &status, + uint8_t &wr_status); - /**********************************************************//** - * @brief Write to selected DS28E17's I2C with Data only. - * Poll until I2C write complete and receive status info. - * - * @details Output on I2C: Write Data [1-255] - * - * On Entry: - * @param[in] length - * The number of data bytes to be written ranging from 01h to FFh. - * A value of zero will assert the Error Detected pin (ED). - * - * @param[in] *data - * User defines write data ranging from 1-255 bytes. - * - * On Exit: - * @param[out] status - * Detects the condition of the Start (bit3), N/A (bit2), - * Address(bit1) and CRC16(bit0) bits. - * b3;0=No Err|1=I2CStart prev-not issued, - * b2;0=No Err|1=I2C N/A Err, - * b1;0=No Err|1=Addr Err, - * b0;0=Valid CRC16|1=Invalid CRC16 - * - * @param[out] wr_status - * Indicates which write byte NACK’d. A value of 00h indicates all bytes were acknowledged by the slave. - * A non-zero value indicates the byte number that NACK’d. - * - * @return - * true if device selected and written @n - * false if failed device select - **************************************************************/ - CmdResult I2C_WriteDataOnly(uint8_t length, uint8_t *data, - uint8_t &status, uint8_t &wr_status); + /**********************************************************//** + * @brief Write to selected DS28E17's I2C with Data only. + * Poll until I2C write complete and receive status info. + * + * @details Output on I2C: Write Data [1-255] + * + * On Entry: + * @param[in] length + * The number of data bytes to be written ranging from 01h to FFh. + * A value of zero will assert the Error Detected pin (ED). + * + * @param[in] *data + * User defines write data ranging from 1-255 bytes. + * + * On Exit: + * @param[out] status + * Detects the condition of the Start (bit3), N/A (bit2), + * Address(bit1) and CRC16(bit0) bits. + * b3;0=No Err|1=I2CStart prev-not issued, + * b2;0=No Err|1=I2C N/A Err, + * b1;0=No Err|1=Addr Err, + * b0;0=Valid CRC16|1=Invalid CRC16 + * + * @param[out] wr_status + * Indicates which write byte NACK’d. A value of 00h indicates all bytes were acknowledged by the slave. + * A non-zero value indicates the byte number that NACK’d. + * + * @return + * true if device selected and written @n + * false if failed device select + **************************************************************/ + CmdResult I2C_WriteDataOnly(uint8_t length, uint8_t *data, + uint8_t &status, uint8_t &wr_status); - /**********************************************************//** - * @brief Write to selected DS28E17's I2C with Stop. - * Poll until I2C write complete and receive status info. - * - * @details Output on I2C: Write Data [1-255], P - * - * On Entry: - * @param[in] length - * The number of data bytes to be written ranging from 01h to FFh. - * A value of zero will assert the Error Detected pin (ED). - * - * @param[in] *data - * User defines write data ranging from 1-255 bytes. - * - * On Exit: - * @param[out] status - * Detects the condition of the Start (bit3), N/A (bit2), - * Address(bit1) and CRC16(bit0) bits. - * b3;0=No Err|1=I2CStart prev-not issued, - * b2;0=No Err|1=I2C N/A Err, - * b1;0=No Err|1=Addr Err, - * b0;0=Valid CRC16|1=Invalid CRC16 - * - * @param[out] wr_status - * Indicates which write byte NACK’d. A value of 00h indicates all bytes were acknowledged by the slave. - * A non-zero value indicates the byte number that NACK’d. - * - * @return - * true if device selected and written @n - * false if failed device select - **************************************************************/ - CmdResult I2C_WriteDataOnlyWithStop(uint8_t length, uint8_t *data, - uint8_t &status, uint8_t &wr_status); + /**********************************************************//** + * @brief Write to selected DS28E17's I2C with Stop. + * Poll until I2C write complete and receive status info. + * + * @details Output on I2C: Write Data [1-255], P + * + * On Entry: + * @param[in] length + * The number of data bytes to be written ranging from 01h to FFh. + * A value of zero will assert the Error Detected pin (ED). + * + * @param[in] *data + * User defines write data ranging from 1-255 bytes. + * + * On Exit: + * @param[out] status + * Detects the condition of the Start (bit3), N/A (bit2), + * Address(bit1) and CRC16(bit0) bits. + * b3;0=No Err|1=I2CStart prev-not issued, + * b2;0=No Err|1=I2C N/A Err, + * b1;0=No Err|1=Addr Err, + * b0;0=Valid CRC16|1=Invalid CRC16 + * + * @param[out] wr_status + * Indicates which write byte NACK’d. A value of 00h indicates all bytes were acknowledged by the slave. + * A non-zero value indicates the byte number that NACK’d. + * + * @return + * true if device selected and written @n + * false if failed device select + **************************************************************/ + CmdResult I2C_WriteDataOnlyWithStop(uint8_t length, uint8_t *data, + uint8_t &status, uint8_t &wr_status); - /**********************************************************//** - * @brief Write to selected DS28E17's I2C with Stop and poll until I2C write complete - * receive status info, and read data with a stop at the end. - * - * @details Output on I2C: - * S, Slave Address + Write, Write Data [1-255], - * Sr, Address + Read, Read Data [1-255], P (NACK last read byte) - * - * On Entry: - * @param[in] I2C_addr - * Writes I2C address. The least significant bit of the I2C address - * is automatically cleared by the command. - * - * @param[in] length - * The number of data bytes to be written ranging from 01h to FFh. - * A value of zero will assert the Error Detected pin (ED). - * - * @param[in] *data - * User defines write data ranging from 1-255 bytes. - * - * @param[in] nu_bytes_read - * Number of I2C bytes to read. A value of zero will assert the Error Detected pin (ED). - * - * On Exit: - * @param[out] status - * Detects the condition of the Start (bit3), N/A (bit2), - * Address(bit1) and CRC16(bit0) bits. - * b3;0=No Err|1=I2CStart prev-not issued, - * b2;0=No Err|1=I2C N/A Err, - * b1;0=No Err|1=Addr Err, - * b0;0=Valid CRC16|1=Invalid CRC16 - * - * @param[out] wr_status - * Indicates which write byte NACK’d. A value of 00h indicates all bytes were acknowledged by the slave. - * A non-zero value indicates the byte number that NACK’d. - * - * @param[out] *read_data - * Array of read data received from I2C. - * - * @return - * true if device selected, written and read @n - * false if failed device select or timeout occurred or CRC16 error - **************************************************************/ - CmdResult I2C_WriteReadDataWithStop(uint8_t I2C_addr, uint8_t length, - uint8_t *data, uint8_t nu_bytes_read, - uint8_t &status, uint8_t &wr_status, - uint8_t *read_data); + /**********************************************************//** + * @brief Write to selected DS28E17's I2C with Stop and poll until I2C write complete + * receive status info, and read data with a stop at the end. + * + * @details Output on I2C: + * S, Slave Address + Write, Write Data [1-255], + * Sr, Address + Read, Read Data [1-255], P (NACK last read byte) + * + * On Entry: + * @param[in] I2C_addr + * Writes I2C address. The least significant bit of the I2C address + * is automatically cleared by the command. + * + * @param[in] length + * The number of data bytes to be written ranging from 01h to FFh. + * A value of zero will assert the Error Detected pin (ED). + * + * @param[in] *data + * User defines write data ranging from 1-255 bytes. + * + * @param[in] nu_bytes_read + * Number of I2C bytes to read. A value of zero will assert the Error Detected pin (ED). + * + * On Exit: + * @param[out] status + * Detects the condition of the Start (bit3), N/A (bit2), + * Address(bit1) and CRC16(bit0) bits. + * b3;0=No Err|1=I2CStart prev-not issued, + * b2;0=No Err|1=I2C N/A Err, + * b1;0=No Err|1=Addr Err, + * b0;0=Valid CRC16|1=Invalid CRC16 + * + * @param[out] wr_status + * Indicates which write byte NACK’d. A value of 00h indicates all bytes were acknowledged by the slave. + * A non-zero value indicates the byte number that NACK’d. + * + * @param[out] *read_data + * Array of read data received from I2C. + * + * @return + * true if device selected, written and read @n + * false if failed device select or timeout occurred or CRC16 error + **************************************************************/ + CmdResult I2C_WriteReadDataWithStop(uint8_t I2C_addr, uint8_t length, + uint8_t *data, uint8_t nu_bytes_read, + uint8_t &status, uint8_t &wr_status, + uint8_t *read_data); - /**********************************************************//** - * @brief Selected DS28E17's and send I2C address and poll until - * I2C read address complete, receive status info, and read data - * with a stop at the end. - * - * @details Output on I2C: - * S, Slave Address + Read, Read Data [1-255], P (NACK last read byte) - * - * On Entry: - * @param[in] I2C_addr - * Writes I2C address. The least significant bit of the I2C address - * is automatically cleared by the command. - * - * On Exit: - * @param[out] nu_bytes_read - * Number of I2C bytes to read. A value of zero will assert the Error Detected pin (ED). - * - * @param[out] status - * Detects the condition of the Start (bit3), N/A (bit2), - * Address(bit1) and CRC16(bit0) bits. - * b3;0=No Err|1=I2CStart prev-not issued, - * b2;0=No Err|1=I2C N/A Err, - * b1;0=No Err|1=Addr Err, - * b0;0=Valid CRC16|1=Invalid CRC16 - * - * @param[out] *read_data - * Array of read data received from I2C. - * - * @return - * true if device selected, written and read @n - * false if failed device select or timeout occurred or CRC16 error - **************************************************************/ - CmdResult I2C_ReadDataWithStop(uint8_t I2C_addr, uint8_t nu_bytes_read, - uint8_t &status, uint8_t *read_data); + /**********************************************************//** + * @brief Selected DS28E17's and send I2C address and poll until + * I2C read address complete, receive status info, and read data + * with a stop at the end. + * + * @details Output on I2C: + * S, Slave Address + Read, Read Data [1-255], P (NACK last read byte) + * + * On Entry: + * @param[in] I2C_addr + * Writes I2C address. The least significant bit of the I2C address + * is automatically cleared by the command. + * + * On Exit: + * @param[out] nu_bytes_read + * Number of I2C bytes to read. A value of zero will assert the Error Detected pin (ED). + * + * @param[out] status + * Detects the condition of the Start (bit3), N/A (bit2), + * Address(bit1) and CRC16(bit0) bits. + * b3;0=No Err|1=I2CStart prev-not issued, + * b2;0=No Err|1=I2C N/A Err, + * b1;0=No Err|1=Addr Err, + * b0;0=Valid CRC16|1=Invalid CRC16 + * + * @param[out] *read_data + * Array of read data received from I2C. + * + * @return + * true if device selected, written and read @n + * false if failed device select or timeout occurred or CRC16 error + **************************************************************/ + CmdResult I2C_ReadDataWithStop(uint8_t I2C_addr, uint8_t nu_bytes_read, + uint8_t &status, uint8_t *read_data); - /**********************************************************//** - * @brief Write to Configuration Register of DS28E17. - * - * @details - * - * On Entry: - * @param[in] data - * sent to configuration register - * - * On Exit: - * - * @return - * true if device selected and written @n - * false if failed device select - **************************************************************/ - CmdResult WriteConfigReg(uint8_t data); + /**********************************************************//** + * @brief Write to Configuration Register of DS28E17. + * + * @details + * + * On Entry: + * @param[in] data + * sent to configuration register + * + * On Exit: + * + * @return + * true if device selected and written @n + * false if failed device select + **************************************************************/ + CmdResult WriteConfigReg(uint8_t data); - /**********************************************************//** - * @brief Read the Configuration Register of DS28E17. - * - * @details - * - * On Entry: - * - * On Exit: - * - * @return - * true if device selected and read correctly @n - * false if failed device select - **************************************************************/ - CmdResult ReadConfigReg(uint8_t & config); + /**********************************************************//** + * @brief Read the Configuration Register of DS28E17. + * + * @details + * + * On Entry: + * + * On Exit: + * + * @return + * true if device selected and read correctly @n + * false if failed device select + **************************************************************/ + CmdResult ReadConfigReg(uint8_t & config); - /**********************************************************//** - * @brief The Enable Sleep Mode command puts the device into a low current mode. - * All 1-Wire communication is ignored until woken up. Immediately after - * the command, the device monitors the WAKEUP input pin and - * exits sleep mode on a rising edge. - * - * @details - * - * On Entry: - * - * On Exit: - * - * @return - * true if device selected and written @n - * false if failed device select* - **************************************************************/ - CmdResult EnableSleepMode(); + /**********************************************************//** + * @brief The Enable Sleep Mode command puts the device into a low current mode. + * All 1-Wire communication is ignored until woken up. Immediately after + * the command, the device monitors the WAKEUP input pin and + * exits sleep mode on a rising edge. + * + * @details + * + * On Entry: + * + * On Exit: + * + * @return + * true if device selected and written @n + * false if failed device select* + **************************************************************/ + CmdResult EnableSleepMode(); - /**********************************************************//** - * @brief Read the Device Revision of DS28E17. The revision value - * should never be zero. The upper nibble is the major revision - * and the lower nibble is the minor revision. - * - * @details - * - * On Entry: - * - * On Exit: - * - * @return - * revision value if device selected and read correctly @n - * false if failed device select (i.e. 00h) - **************************************************************/ - CmdResult ReadDeviceRevision(uint8_t & rev); - - private: + /**********************************************************//** + * @brief Read the Device Revision of DS28E17. The revision value + * should never be zero. The upper nibble is the major revision + * and the lower nibble is the minor revision. + * + * @details + * + * On Entry: + * + * On Exit: + * + * @return + * revision value if device selected and read correctly @n + * false if failed device select (i.e. 00h) + **************************************************************/ + CmdResult ReadDeviceRevision(uint8_t & rev); - CmdResult send_packet(const uint8_t * data, uint8_t data_length, - uint8_t & status, uint8_t & wr_status); + private: - //overloaded function for I2C read only command - CmdResult send_packet(const uint8_t * data, uint8_t data_length, - uint8_t & status); + CmdResult send_packet(const uint8_t * data, uint8_t data_length, + uint8_t & status, uint8_t & wr_status); - Masters::OneWireMaster &_owm; + //overloaded function for I2C read only command + CmdResult send_packet(const uint8_t * data, uint8_t data_length, + uint8_t & status); - uint16_t _crc16; - uint8_t _i2c_speed; + uint16_t _crc16; + uint8_t _i2c_speed; - static const size_t pollLimit = 10000; - static const uint16_t _oddparity[16]; + static const size_t pollLimit = 10000; + static const uint16_t _oddparity[16]; - uint16_t docrc16(uint16_t data); - }; - } + uint16_t docrc16(uint16_t data); + }; } #endif