8:4 Matrix Multiplexer
Fork of max14661 by
This is an untested driver for the MAX14724.
Diff: max14661.cpp
- Revision:
- 2:88c168ddc145
- Parent:
- 1:c1fdfe4c2354
- Child:
- 4:45fa0192f66d
--- a/max14661.cpp Mon Nov 17 23:57:52 2014 +0000 +++ b/max14661.cpp Wed Nov 19 00:56:18 2014 +0000 @@ -49,11 +49,12 @@ #include "max14661.h" -/******************************************************************//** -* Constructor for Max14661 class +/**********************************************************//** +* Constructor for Max14661 Class * * On Entry: -* @param[in] p_i2c - pointer to I2C object for bus +* @param[in] sda - sda pin of I2C bus +* @param[in] scl - scl pin of I2C bus * @param[in] i2c_adrs - 7-bit slave address of MAX14661 * * On Exit: @@ -61,18 +62,15 @@ * * Example: * @code -* -* I2C i2c_bus(D14, D15); //instantiate I2C bus -* I2C * p_i2c_bus = &i2c_bus; //create pointer to bus * -* //instantiate mux object -* Max14661 mux(p_i2c_bus, MAX14661_I2C_ADRS0); +* //declare mux object +* Max14661 mux(D14, D15, MAX14661_I2C_ADRS0); * * @endcode -**********************************************************************/ -Max14661::Max14661(I2C* ptr_i2c_bus, max14661_i2c_adrs_t i2c_adrs) +**************************************************************/ +Max14661::Max14661(PinName sda, PinName scl, max14661_i2c_adrs_t i2c_adrs) : +I2C(sda, scl) { - p_i2c = ptr_i2c_bus; w_adrs = (i2c_adrs << 1); r_adrs = (w_adrs | 0x01); } @@ -91,11 +89,8 @@ * Example: * @code * -* I2C i2c_bus(D14, D15); //instantiate I2C bus -* I2C * p_i2c_bus = &i2c_bus; //create pointer to bus -* -* //instantiate mux object -* Max14661 mux(p_i2c_bus, MAX14661_I2C_ADRS0); +* //declare mux object +* Max14661 mux(D14, D15, MAX14661_I2C_ADRS0); * * uint16_t rtn_val; * @@ -115,7 +110,7 @@ data[data_length++] = cmdA; data[data_length++] = cmdB; - rtn_val = p_i2c->write(w_adrs,(const char*) data, data_length); + rtn_val = write(w_adrs,(const char*) data, data_length); return(rtn_val); } @@ -133,11 +128,8 @@ * Example: * @code * -* I2C i2c_bus(D14, D15); //instantiate I2C bus -* I2C * p_i2c_bus = &i2c_bus; //create pointer to bus -* -* //instantiate mux object -* Max14661 mux(p_i2c_bus, MAX14661_I2C_ADRS0); +* //declare mux object +* Max14661 mux(D14, D15, MAX14661_I2C_ADRS0); * * uint8_t data[] = {1, 2, 3, 4}; * uint16_t rtn_val; @@ -160,7 +152,7 @@ local_data[data_length] = data[data_length-1]; } - rtn_val = p_i2c->write(w_adrs,(const char*) local_data, data_length); + rtn_val = write(w_adrs,(const char*) local_data, data_length); return(rtn_val); } @@ -178,11 +170,8 @@ * Example: * @code * -* I2C i2c_bus(D14, D15); //instantiate I2C bus -* I2C * p_i2c_bus = &i2c_bus; //create pointer to bus -* -* //instantiate mux object -* Max14661 mux(p_i2c_bus, MAX14661_I2C_ADRS0); +* //declare mux object +* Max14661 mux(D14, D15, MAX14661_I2C_ADRS0); * * uint8_t data[] = {1, 2, 3, 4}; * uint16_t rtn_val; @@ -205,7 +194,7 @@ local_data[data_length] = data[data_length-1]; } - rtn_val = p_i2c->write(w_adrs,(const char*) local_data, data_length); + rtn_val = write(w_adrs,(const char*) local_data, data_length); return(rtn_val); } @@ -226,11 +215,8 @@ * Example: * @code * -* I2C i2c_bus(D14, D15); //instantiate I2C bus -* I2C * p_i2c_bus = &i2c_bus; //create pointer to bus -* -* //instantiate mux object -* Max14661 mux(p_i2c_bus, MAX14661_I2C_ADRS0); +* //declare mux object +* Max14661 mux(D14, D15, MAX14661_I2C_ADRS0); * * uint16_t rtn_val; * uint8_t data[4]; @@ -245,11 +231,11 @@ uint16_t rtn_val = 1; uint8_t local_data = DIR0; - rtn_val = p_i2c->write(w_adrs,(const char*) local_data, 1); + rtn_val = write(w_adrs,(const char*) local_data, 1); if(!rtn_val) { - rtn_val = p_i2c->read(r_adrs,(char*) data, 4); + rtn_val = read(r_adrs,(char*) data, 4); } return(rtn_val); @@ -271,11 +257,8 @@ * Example: * @code * -* I2C i2c_bus(D14, D15); //instantiate I2C bus -* I2C * p_i2c_bus = &i2c_bus; //create pointer to bus -* -* //instantiate mux object -* Max14661 mux(p_i2c_bus, MAX14661_I2C_ADRS0); +* //declare mux object +* Max14661 mux(D14, D15, MAX14661_I2C_ADRS0); * * uint16_t rtn_val; * uint8_t data[4]; @@ -284,17 +267,17 @@ * rtn_val = mux.rd_shadow_registers(data); * * @endcode -**************************************************************/ +**************************************************************/ uint16_t Max14661::rd_shadow_registers(uint8_t* data) { uint16_t rtn_val = 1; uint8_t local_data = SHDW0; - rtn_val = p_i2c->write(w_adrs,(const char*) local_data, 1); + rtn_val = write(w_adrs,(const char*) local_data, 1); if(!rtn_val) { - rtn_val = p_i2c->read(r_adrs,(char*) data, 4); + rtn_val = read(r_adrs,(char*) data, 4); } return(rtn_val);