Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Max32630_One_Wire_Interface
Diff: Masters/DS248x/DS248x.cpp
- Revision:
- 91:e80108bc870a
- Parent:
- 84:708b7be59fb2
- Child:
- 104:3f48daed532b
--- a/Masters/DS248x/DS248x.cpp Fri Jun 17 15:24:37 2016 -0500
+++ b/Masters/DS248x/DS248x.cpp Mon Jun 20 19:39:21 2016 +0000
@@ -88,21 +88,13 @@
setAPU(true);
}
-DS248x::DS248x(mbed::I2C & i2c_bus, uint8_t adrs)
- :m_p_i2c_bus(&i2c_bus), m_adrs(adrs), m_i2c_owner(false)
+
+DS248x::DS248x(mbed::I2C & i2c_bus, uint8_t adrs):
+m_i2c_bus(i2c_bus), m_adrs(adrs)
{
-
}
-DS248x::~DS248x()
-{
- if (m_i2c_owner)
- {
- delete m_p_i2c_bus;
- }
-}
-
OneWireMaster::CmdResult DS248x::OWInitMaster(void)
{
OneWireMaster::CmdResult result;
@@ -153,99 +145,6 @@
return result;
}
-OneWireMaster::CmdResult DS248x::selectChannel(uint8_t channel)
-{
- OneWireMaster::CmdResult result;
- uint8_t ch, ch_read;
-
- // Channel Select (Case A)
- // S AD,0 [A] CHSL [A] CC [A] Sr AD,1 [A] [RR] A\ P
- // [] indicates from slave
- // CC channel value
- // RR channel read back
-
- switch (channel)
- {
- default:
- case 0:
- ch = 0xF0;
- ch_read = 0xB8;
- break;
- case 1:
- ch = 0xE1;
- ch_read = 0xB1;
- break;
- case 2:
- ch = 0xD2;
- ch_read = 0xAA;
- break;
- case 3:
- ch = 0xC3;
- ch_read = 0xA3;
- break;
- case 4:
- ch = 0xB4;
- ch_read = 0x9C;
- break;
- case 5:
- ch = 0xA5;
- ch_read = 0x95;
- break;
- case 6:
- ch = 0x96;
- ch_read = 0x8E;
- break;
- case 7:
- ch = 0x87;
- ch_read = 0x87;
- break;
- };
-
- result = sendCommand(ChannelSelectCmd, ch);
- if (result == OneWireMaster::Success)
- {
- result = readRegister(ChannelSelectReg, ch, true);
- if (result == OneWireMaster::Success)
- {
- // check for failure due to incorrect read back of channel
- if (ch != ch_read)
- {
- result = OneWireMaster::OperationFailure;
- }
- }
- }
-
- return result;
-}
-
-OneWireMaster::CmdResult DS248x::adjustOwPort(OwAdjustParam param, uint8_t val)
-{
- OneWireMaster::CmdResult result;
-
- uint8_t read_port_config;
- uint8_t control_byte;
-
- control_byte = (((param & 0x0F) << 4) | (val & 0x0F));
-
- result = sendCommand(AdjustOwPortCmd, control_byte);
- if (result != Success)
- {
- return result;
- }
-
- result = readRegister(PortConfigReg, read_port_config, true);
- if (result != Success)
- {
- return result;
- }
-
- if ((control_byte & 0x0F) != read_port_config)
- {
- result = OneWireMaster::OperationFailure;
- }
-
- return result;
-}
OneWireMaster::CmdResult DS248x::OWTriplet(SearchDirection & searchDirection, uint8_t & sbr, uint8_t & tsb)
{
@@ -465,7 +364,7 @@
result = sendCommand(SetReadPointerCmd, reg);
if (result == Success)
{
- if (m_p_i2c_bus->read(m_adrs, reinterpret_cast<char *>(&buf), 1) != I2C_READ_OK)
+ if (m_i2c_bus.read(m_adrs, reinterpret_cast<char *>(&buf), 1) != I2C_READ_OK)
{
result = CommunicationReadError;
}
@@ -520,7 +419,7 @@
OneWireMaster::CmdResult DS248x::sendCommand(Command cmd) const
{
CmdResult result;
- if (m_p_i2c_bus->write(m_adrs, reinterpret_cast<const char *>(&cmd), 1) == I2C_WRITE_OK)
+ if (m_i2c_bus.write(m_adrs, reinterpret_cast<const char *>(&cmd), 1) == I2C_WRITE_OK)
{
result = Success;
}
@@ -535,7 +434,7 @@
{
CmdResult result;
uint8_t buf[2] = { cmd, param };
- if (m_p_i2c_bus->write(m_adrs, reinterpret_cast<const char *>(buf), 2) == I2C_WRITE_OK)
+ if (m_i2c_bus.write(m_adrs, reinterpret_cast<const char *>(buf), 2) == I2C_WRITE_OK)
{
result = Success;
}