MAX6956  1.0
MAX6956i2Clibrary
 All Data Structures Files Functions Variables Macros
MAX6956.h
Go to the documentation of this file.
1 // I2Cdev library collection - MAX6956 I2C device class header file
2 // Based on Maxim MAX6956 datasheet 19-2414; Rev 4; 6/10
3 //
4 // 2013-12-15 by Tom Beighley <tomthegeek@gmail.com>
5 // I2C Device Library hosted at http://www.i2cdevlib.com
6 //
7 // Changelog:
8 // 2013-12-15 - initial release
9 //
10 
11 /* ============================================
12 I2Cdev device library code is placed under the MIT license
13 Copyright (c) 2013 Tom Beighley
14 
15 Permission is hereby granted, free of charge, to any person obtaining a copy
16 of this software and associated documentation files (the "Software"), to deal
17 in the Software without restriction, including without limitation the rights
18 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19 copies of the Software, and to permit persons to whom the Software is
20 furnished to do so, subject to the following conditions:
21 
22 The above copyright notice and this permission notice shall be included in
23 all copies or substantial portions of the Software.
24 
25 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
31 THE SOFTWARE.
32 ===============================================
33 */
34 
35 #ifndef _MAX6956_H_
36 #define _MAX6956_H_
37 
38 #include "I2Cdev.h"
39 
40 // -----------------------------------------------------------------------------
41 // Arduino-style "Serial.print" debug constant (uncomment to enable)
42 // -----------------------------------------------------------------------------
43 // #define MAX6956_SERIAL_DEBUG
44 
71 #define MAX6956_ADDRESS 0x40 // See table 3
72 #define MAX6956_DEFAULT_ADDRESS 0x40 // AD0 and AD1 at ground.
73 
74 //==========Registers==========
75 
76 #define MAX6956_RA_NO_OP 0x00
77 
78 
102 #define MAX6956_RA_GLOBAL_CURRENT 0x02
103 
137 #define MAX6956_RA_CONFIGURATION 0x04
138 
152 #define MAX6956_RA_TRANSITION_DETECT 0x06
153 
165 #define MAX6956_RA_DISPLAY_TEST 0x07
166 
203 #define MAX6956_RA_CONFIG_P7P6P5P4 0x09
204 #define MAX6956_RA_CONFIG_P11P10P9P8 0x0A
205 #define MAX6956_RA_CONFIG_P15P14P13P12 0x0B
206 #define MAX6956_RA_CONFIG_P19P18P17P16 0x0C
207 #define MAX6956_RA_CONFIG_P23P22P21P20 0x0D
208 #define MAX6956_RA_CONFIG_P27P26P25P24 0x0E
209 #define MAX6956_RA_CONFIG_P31P30P29P28 0x0F
210 
241 #define MAX6956_RA_CURRENT_0xP5P4 0x12
242 #define MAX6956_RA_CURRENT_0xP7P6 0x13
243 #define MAX6956_RA_CURRENT_0xP9P8 0x14
244 #define MAX6956_RA_CURRENT_0xP11P10 0x15
245 #define MAX6956_RA_CURRENT_0xP13P12 0x16
246 #define MAX6956_RA_CURRENT_0xP15P14 0x17
247 #define MAX6956_RA_CURRENT_0xP17P16 0x18
248 #define MAX6956_RA_CURRENT_0xP19P18 0x19
249 #define MAX6956_RA_CURRENT_0xP21P20 0x1A
250 #define MAX6956_RA_CURRENT_0xP23P22 0x1B
251 #define MAX6956_RA_CURRENT_0xP25P24 0x1C
252 #define MAX6956_RA_CURRENT_0xP27P26 0x1D
253 #define MAX6956_RA_CURRENT_0xP29P28 0x1E
254 #define MAX6956_RA_CURRENT_0xP31P30 0x1F
255 
262 #define MAX6956_RA_PORT0 0x20
263 #define MAX6956_RA_PORT1 0x21
264 #define MAX6956_RA_PORT2 0x22
265 #define MAX6956_RA_PORT3 0x23
266 
267 #define MAX6956_RA_PORT4 0x24
268 #define MAX6956_RA_PORT5 0x25
269 #define MAX6956_RA_PORT6 0x26
270 #define MAX6956_RA_PORT7 0x27
271 #define MAX6956_RA_PORT8 0x28
272 #define MAX6956_RA_PORT9 0x29
273 #define MAX6956_RA_PORT10 0x2A
274 #define MAX6956_RA_PORT11 0x2B
275 
276 #define MAX6956_RA_PORT12 0x2C
277 #define MAX6956_RA_PORT13 0x2D
278 #define MAX6956_RA_PORT14 0x2E
279 #define MAX6956_RA_PORT15 0x2F
280 #define MAX6956_RA_PORT16 0x30
281 #define MAX6956_RA_PORT17 0x31
282 #define MAX6956_RA_PORT18 0x32
283 #define MAX6956_RA_PORT19 0x33
284 
285 #define MAX6956_RA_PORT20 0x34
286 #define MAX6956_RA_PORT21 0x35
287 #define MAX6956_RA_PORT22 0x36
288 #define MAX6956_RA_PORT23 0x37
289 #define MAX6956_RA_PORT24 0x38
290 #define MAX6956_RA_PORT25 0x39
291 #define MAX6956_RA_PORT26 0x3A
292 #define MAX6956_RA_PORT27 0x3B
293 
294 #define MAX6956_RA_PORT28 0x3C
295 #define MAX6956_RA_PORT29 0x3D
296 #define MAX6956_RA_PORT30 0x3E
297 #define MAX6956_RA_PORT31 0x3F
298 /*
299  Lower port groups
300 */
301 #define MAX6956_RA_PORTS4_7 0x40
302 #define MAX6956_RA_PORTS4_8 0x41
303 #define MAX6956_RA_PORTS4_9 0x42
304 #define MAX6956_RA_PORTS4_10 0x43
305 
306 /*
307  8 port registers. Data bits D0-D7
308 */
309 #define MAX6956_RA_PORTS4_11 0x44
310 #define MAX6956_RA_PORTS5_12 0x45
311 #define MAX6956_RA_PORTS6_13 0x46
312 #define MAX6956_RA_PORTS7_14 0x47
313 #define MAX6956_RA_PORTS8_15 0x48
314 #define MAX6956_RA_PORTS9_16 0x49
315 #define MAX6956_RA_PORTS10_17 0x4A
316 #define MAX6956_RA_PORTS11_18 0x4B
317 #define MAX6956_RA_PORTS12_19 0x4C
318 #define MAX6956_RA_PORTS13_20 0x4D
319 #define MAX6956_RA_PORTS14_21 0x4E
320 #define MAX6956_RA_PORTS15_22 0x4F
321 #define MAX6956_RA_PORTS16_23 0x50
322 #define MAX6956_RA_PORTS17_24 0x51
323 #define MAX6956_RA_PORTS18_25 0x52
324 #define MAX6956_RA_PORTS19_26 0x53
325 #define MAX6956_RA_PORTS20_27 0x54
326 #define MAX6956_RA_PORTS21_28 0x55
327 #define MAX6956_RA_PORTS22_29 0x56
328 #define MAX6956_RA_PORTS23_30 0x57
329 #define MAX6956_RA_PORTS24_31 0x58
330 /*
331  Upper port groups
332 */
333 #define MAX6956_RA_PORTS25_31 0x59
334 #define MAX6956_RA_PORTS26_31 0x5A
335 #define MAX6956_RA_PORTS27_31 0x5B
336 #define MAX6956_RA_PORTS28_31 0x5C
337 #define MAX6956_RA_PORTS29_31 0x5D
338 #define MAX6956_RA_PORTS30_31 0x5E
339 #define MAX6956_RA_PORTS31_31 0x5F
340 
341 //=========Config bits=========
342 
343 #define MAX6956_CONFIG_POWER_BIT 0
344 #define MAX6956_CONFIG_GLOBAL_CURRENT_BIT 6
345 #define MAX6956_CONFIG_TRANSITION_BIT 7
346 
347 #define MAX6956_GLOBAL_CURRENT_BIT 0
348 #define MAX6956_GLOBAL_CURRENT_LENGTH 4
349 
350 #define MAX6956_PORT12_CURRENT_BIT 3
351 #define MAX6956_PORT12_CURRENT_LENGTH 4
352 #define MAX6956_PORT13_CURRENT_BIT 7
353 #define MAX6956_PORT13_CURRENT_LENGTH 4
354 #define MAX6956_PORT14_CURRENT_BIT 3
355 #define MAX6956_PORT14_CURRENT_LENGTH 4
356 #define MAX6956_PORT15_CURRENT_BIT 7
357 #define MAX6956_PORT15_CURRENT_LENGTH 4
358 #define MAX6956_PORT16_CURRENT_BIT 3
359 #define MAX6956_PORT16_CURRENT_LENGTH 4
360 #define MAX6956_PORT17_CURRENT_BIT 7
361 #define MAX6956_PORT17_CURRENT_LENGTH 4
362 #define MAX6956_PORT18_CURRENT_BIT 3
363 #define MAX6956_PORT18_CURRENT_LENGTH 4
364 #define MAX6956_PORT19_CURRENT_BIT 7
365 #define MAX6956_PORT19_CURRENT_LENGTH 4
366 #define MAX6956_PORT23_CURRENT_BIT 3
367 #define MAX6956_PORT23_CURRENT_LENGTH 4
368 #define MAX6956_PORT21_CURRENT_BIT 7
369 #define MAX6956_PORT21_CURRENT_LENGTH 4
370 #define MAX6956_PORT22_CURRENT_BIT 3
371 #define MAX6956_PORT22_CURRENT_LENGTH 4
372 #define MAX6956_PORT23_CURRENT_BIT 7
373 #define MAX6956_PORT23_CURRENT_LENGTH 4
374 #define MAX6956_PORT24_CURRENT_BIT 3
375 #define MAX6956_PORT24_CURRENT_LENGTH 4
376 #define MAX6956_PORT25_CURRENT_BIT 7
377 #define MAX6956_PORT25_CURRENT_LENGTH 4
378 #define MAX6956_PORT26_CURRENT_BIT 3
379 #define MAX6956_PORT26_CURRENT_LENGTH 4
380 #define MAX6956_PORT27_CURRENT_BIT 7
381 #define MAX6956_PORT27_CURRENT_LENGTH 4
382 #define MAX6956_PORT28_CURRENT_BIT 3
383 #define MAX6956_PORT28_CURRENT_LENGTH 4
384 #define MAX6956_PORT29_CURRENT_BIT 7
385 #define MAX6956_PORT29_CURRENT_LENGTH 4
386 #define MAX6956_PORT33_CURRENT_BIT 3
387 #define MAX6956_PORT33_CURRENT_LENGTH 4
388 #define MAX6956_PORT31_CURRENT_BIT 7
389 #define MAX6956_PORT31_CURRENT_LENGTH 4
390 
391 #define MAX6956_DISPLAY_TEST_BIT 0
392 
393 #define MAX6956_TRANSITION_STATUS_BIT 7
394 #define MAX6956_TRANSITION_MASK_BIT 0
395 #define MAX6956_TRANSITION_MASK_LENGTH 7
396 #define MAX6956_TRANSITION_MASK_PORT30_BIT 6
397 #define MAX6956_TRANSITION_MASK_PORT29_BIT 5
398 #define MAX6956_TRANSITION_MASK_PORT28_BIT 4
399 #define MAX6956_TRANSITION_MASK_PORT27_BIT 3
400 #define MAX6956_TRANSITION_MASK_PORT26_BIT 2
401 #define MAX6956_TRANSITION_MASK_PORT25_BIT 1
402 #define MAX6956_TRANSITION_MASK_PORT24_BIT 0
403 
404 //=========Values=========
405 
406 #define MAX6956_OUTPUT_LED 0x00
407 #define MAX6956_OUTPUT_GPIO 0x01
408 #define MAX6956_INPUT_WO_PULL 0x02
409 #define MAX6956_INPUT_W_PULL 0x03
410 
411 #define MAX6956_OFF 0x00
412 #define MAX6956_ON 0x01
413 
414 #define MAX6956_CURRENT_0 0x00
415 #define MAX6956_CURRENT_1 0x01
416 #define MAX6956_CURRENT_2 0x02
417 #define MAX6956_CURRENT_3 0x03
418 #define MAX6956_CURRENT_4 0x04
419 #define MAX6956_CURRENT_5 0x05
420 #define MAX6956_CURRENT_6 0x06
421 #define MAX6956_CURRENT_7 0x07
422 #define MAX6956_CURRENT_8 0x08
423 #define MAX6956_CURRENT_9 0x09
424 #define MAX6956_CURRENT_10 0x0A
425 #define MAX6956_CURRENT_11 0x0B
426 #define MAX6956_CURRENT_12 0x0C
427 #define MAX6956_CURRENT_13 0x0D
428 #define MAX6956_CURRENT_14 0x0E
429 #define MAX6956_CURRENT_15 0x0F
430 
456 class MAX6956 {
457  public:
458  MAX6956();
459  MAX6956(uint8_t address);
460 
461  void initialize();
462  bool testConnection();
463 
464  void reset();
465 
466  // Config register
467  uint8_t getConfigReg();
468  void setConfigReg(uint8_t config);
469 
470  bool getPower();
471  void togglePower();
472  void setPower(bool power);
473 
475  void setEnableIndividualCurrent(bool global);
476 
478  void setEnableTransitionDetection(bool transition);
479 
480  // Global current
481  uint8_t getGlobalCurrent();
482  void setGlobalCurrent(uint8_t current);
483 
484  // Test mode
485  bool getTestMode();
486  void setTestMode(bool test);
487 
488  // Input mask
489  uint8_t getInputMask();
490  void setInputMask(uint8_t mask);
491 
492  // Port config
493  void configPort(uint8_t port, uint8_t portConfig);
494  void configPorts(uint8_t lower, uint8_t upper, uint8_t portConfig);
495  void configAllPorts(uint8_t portConfig);
496 
497  void setPortLevel(uint8_t port, uint8_t power);
498  void setPortCurrent(uint8_t port, uint8_t power);
499  void setAllPortsCurrent(uint8_t power);
500  void enableAllPorts();
501  void disableAllPorts();
502 
527  uint8_t portsConfig[5];
552  uint8_t portsStatus[3];
553 
554  private:
555  uint8_t devAddr;
556  uint8_t buffer[1];
557  uint8_t portConfig;
558  uint8_t portCurrentRA;
559  uint8_t portCurrentBit;
560  uint8_t psArrayIndex;
561  uint8_t psBitPosition;
562 };
563 
564 #endif /* _MAX6956_H_ */
uint8_t devAddr
Holds the current device address.
Definition: MAX6956.h:555
uint8_t portCurrentRA
Holder for port current register.
Definition: MAX6956.h:558
uint8_t psArrayIndex
array index
Definition: MAX6956.h:560
void enableAllPorts()
Definition: MAX6956.cpp:453
bool getEnableTransitionDetection()
Definition: MAX6956.cpp:152
uint8_t getInputMask()
Definition: MAX6956.cpp:205
void disableAllPorts()
Definition: MAX6956.cpp:463
bool getEnableIndividualCurrent()
Definition: MAX6956.cpp:134
void setPower(bool power)
Definition: MAX6956.cpp:118
void configPort(uint8_t port, uint8_t portConfig)
Definition: MAX6956.cpp:265
void setAllPortsCurrent(uint8_t power)
0-15, 0 = min brightness (not off) 15 = max
Definition: MAX6956.cpp:444
void configPorts(uint8_t lower, uint8_t upper, uint8_t portConfig)
Definition: MAX6956.cpp:285
uint8_t portsConfig[5]
Definition: MAX6956.h:527
uint8_t getGlobalCurrent()
Definition: MAX6956.cpp:171
bool getTestMode()
Definition: MAX6956.cpp:188
uint8_t psBitPosition
bit position
Definition: MAX6956.h:561
uint8_t portsStatus[3]
Definition: MAX6956.h:552
void initialize()
Definition: MAX6956.cpp:54
void setConfigReg(uint8_t config)
Definition: MAX6956.cpp:102
bool getPower()
Definition: MAX6956.cpp:110
void configAllPorts(uint8_t portConfig)
Definition: MAX6956.cpp:332
void setEnableTransitionDetection(bool transition)
Definition: MAX6956.cpp:162
void setEnableIndividualCurrent(bool global)
Definition: MAX6956.cpp:144
void setPortCurrent(uint8_t port, uint8_t power)
0-15 brightness levels.
Definition: MAX6956.cpp:404
uint8_t portCurrentBit
Holder for the current bit offset.
Definition: MAX6956.h:559
void setPortLevel(uint8_t port, uint8_t power)
0 = off, 1-15 brightness levels.
Definition: MAX6956.cpp:346
MAX6956()
Definition: MAX6956.cpp:40
uint8_t buffer[1]
Buffer for reading data from the device.
Definition: MAX6956.h:556
void setGlobalCurrent(uint8_t current)
Definition: MAX6956.cpp:179
void reset()
Definition: MAX6956.cpp:80
bool testConnection()
Definition: MAX6956.cpp:72
void setTestMode(bool test)
Definition: MAX6956.cpp:196
void togglePower()
Definition: MAX6956.cpp:124
uint8_t portConfig
Holder for port config bit pair.
Definition: MAX6956.h:557
void setInputMask(uint8_t mask)
Definition: MAX6956.cpp:214
uint8_t getConfigReg()
Definition: MAX6956.cpp:94