MAX6955 LED driver
Revision 1:8936ddb97551, committed 2018-06-24
- Comitter:
- Kentaro Okuda
- Date:
- Sun Jun 24 09:40:19 2018 -0400
- Parent:
- 0:8c7de3096cac
- Child:
- 2:f6c4ed9cbf0e
- Commit message:
- initial commit
Changed in this revision
MAX6955.cpp | Show annotated file Show diff for this revision Revisions of this file |
MAX6955.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/MAX6955.cpp Tue Aug 02 14:10:14 2011 +0000 +++ b/MAX6955.cpp Sun Jun 24 09:40:19 2018 -0400 @@ -1,8 +1,13 @@ +/** + * @file MAX6955.cpp + */ + #include "MAX6955.h" MAX6955::MAX6955(PinName sda, PinName scl, char driver): i2c_(sda, scl), driver_(driver){} -int MAX6955::write(char command, char data){ + +int MAX6955::write(char command, char data) { char i2cData[2]; i2cData[0] = command; i2cData[1] = data; @@ -11,13 +16,23 @@ return result; } -int MAX6955::writeS(char* buffer){ - int result = i2c_.write(driver_, (char *) buffer, 8); +int MAX6955::writeS(char* buffer) { + int i; + char i2cData[9]; + i2cData[0] = 0x20; // first digit + for (i = 0; i < 8; i++) { + if (buffer[i] < 32 || buffer[i] > 126) { // make sure its printable + i2cData[i+1] = 32; // if not, replace it with "space" + } else { + i2cData[i+1] = buffer[i]; + } + } + int result = i2c_.write(driver_, (char *) i2cData, 9); wait(0.07); return result; } -int MAX6955::init(){ +int MAX6955::init(void) { int result = 0; result = result + write(reg_decodeMode, 0x00); result = result + write(reg_scanLimit, 0x07);
--- a/MAX6955.h Tue Aug 02 14:10:14 2011 +0000 +++ b/MAX6955.h Sun Jun 24 09:40:19 2018 -0400 @@ -1,8 +1,15 @@ +/** + * @file MAX6955.h + * @brief MAX6955 I2C driver + * + */ + #ifndef MAX6955_H #define MAX6955_H #include "mbed.h" +// max6955 commands #define reg_noOp 0x00 #define reg_decodeMode 0x01 #define reg_globalIntensity 0x02 @@ -42,16 +49,44 @@ #define reg_digit6a 0x6E #define reg_digit7a 0x6F -class MAX6955{ + +class MAX6955 { public: /* * @param sda mbed pin for I2C SDA * @param scl mbed pin for I2C SCL * @param driver I2C device address */ - MAX6955(PinName sda, PinName scl, char driver); + MAX6955(PinName sda, PinName scl, char driver); + + /** + * @brief This function writes command and data. + * + * @param command + * MAX6955 command. + * @param data + * data to write. + * + * @return[int] result + */ int write(char command, char data); + + + /** + * @brief This function writes string. + * + * @param pointer to buffer + * + * @return result + */ int writeS(char* buffer); + + + /** + * @brief init function. + * + * @return result + */ int init(void); private: