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.
Fork of ISL1208 by
Revision 7:00b8ead188f8, committed 2018-04-03
- Comitter:
- goranirnas
- Date:
- Tue Apr 03 09:08:36 2018 +0000
- Parent:
- 6:c0635401a37f
- Commit message:
- i2c object in library converted to a pointer to i2c object to more easily add several devices on i2c bus.
Changed in this revision
ISL1208.cpp | Show annotated file Show diff for this revision Revisions of this file |
ISL1208.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/ISL1208.cpp Fri May 02 17:27:38 2014 +0000 +++ b/ISL1208.cpp Tue Apr 03 09:08:36 2018 +0000 @@ -18,16 +18,25 @@ const int ISL1208::m_ADDR = (0x6F << 1); -ISL1208::ISL1208(PinName sda, PinName scl, int hz) : m_I2C(sda, scl) +ISL1208::ISL1208(I2C *p_I2C) { //Set the I2C bus frequency - m_I2C.frequency(hz); + if (p_I2C != NULL) + { + m_I2C = p_I2C; + } + else + { + //How to handle error state? + m_I2C = NULL; + } + } bool ISL1208::open() { //Probe for the ISL1208 using a Zero Length Transfer - if (!m_I2C.write(m_ADDR, NULL, 0)) { + if (!m_I2C->write(m_ADDR, NULL, 0)) { //Read the current status register char sr = read8(REG_CTL_SR); @@ -475,10 +484,10 @@ char ISL1208::read8(char reg) { //Select the register - m_I2C.write(m_ADDR, ®, 1, true); + m_I2C->write(m_ADDR, ®, 1, true); //Read the 8-bit register - m_I2C.read(m_ADDR, ®, 1); + m_I2C->read(m_ADDR, ®, 1); //Return the byte return reg; @@ -494,7 +503,7 @@ buff[1] = data; //Write the data - m_I2C.write(m_ADDR, buff, 2); + m_I2C->write(m_ADDR, buff, 2); } unsigned short ISL1208::read16(char reg) @@ -503,10 +512,10 @@ char buff[2]; //Select the register - m_I2C.write(m_ADDR, ®, 1, true); + m_I2C->write(m_ADDR, ®, 1, true); //Read the 16-bit register - m_I2C.read(m_ADDR, buff, 2); + m_I2C->read(m_ADDR, buff, 2); //Return the combined 16-bit value return (buff[0] << 8) | buff[1]; @@ -523,7 +532,7 @@ buff[2] = data; //Write the data - m_I2C.write(m_ADDR, buff, 3); + m_I2C->write(m_ADDR, buff, 3); } unsigned int ISL1208::bcd2bin(unsigned char val)
--- a/ISL1208.h Fri May 02 17:27:38 2014 +0000 +++ b/ISL1208.h Tue Apr 03 09:08:36 2018 +0000 @@ -140,7 +140,8 @@ * @param scl The I2C clock pin. * @param hz The I2C bus frequency (defaults to 400kHz). */ - ISL1208(PinName sda, PinName scl, int hz = 400000); + //ISL1208(PinName sda, PinName scl, int hz = 400000); + ISL1208(I2C *p_I2C = NULL); /** Probe for the ISL1208 and configure auto reset if present * @@ -342,7 +343,7 @@ static const int m_ADDR; //Member variables - I2C m_I2C; + I2C *m_I2C; //Internal functions char read8(char reg);