Contiki-NG
tlc59116.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013, Jelmer Tiete.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote
14  * products derived from this software without specific prior
15  * written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
18  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  * This file is part of the Contiki operating system.
30  *
31  */
32 
33 /**
34  * \file
35  * Device drivers header file for TLC59116 i2c led driver on Zolertia Z1.
36  * See http://www.ti.com/product/tlc59116 for datasheet.
37  * \author
38  * Jelmer Tiete, VUB <jelmer@tiete.be>
39  */
40 
41 #ifndef TLC59116_H_
42 #define TLC59116_H_
43 #include <stdio.h>
44 #include "dev/i2cmaster.h"
45 
46 #if 0
47 #include <stdio.h>
48 #define PRINTFDEBUG(...) printf(__VA_ARGS__)
49 #else
50 #define PRINTFDEBUG(...)
51 #endif
52 
53 
54 /* -------------------------------------------------------------------------- */
55 /* Init the led driver: ports, pins, registers, I2C*/
56 void tlc59116_init(void);
57 
58 /* Write to a register.
59  * args:
60  * reg register to write to
61  * val value to write
62  */
63 void tlc59116_write_reg(uint8_t reg, uint8_t val);
64 
65 /* Write several registers from a stream.
66  * args:
67  * len number of bytes to read
68  * data pointer to where the data is read from
69  * First byte in stream must be the register address to begin writing to.
70  * The data is then written from the second byte and increasing. The address byte
71  * is not included in length len.
72  */
73 void tlc59116_write_stream(uint8_t len, uint8_t * data);
74 
75 /* Read one register.
76  * args:
77  * reg what register to read
78  * returns the value of the read register
79  */
80 uint8_t tlc59116_read_reg(uint8_t reg);
81 
82 /* Read several registers in a stream.
83  * args:
84  * reg what register to start reading from
85  * len number of bytes to read
86  * whereto pointer to where the data is saved
87  */
88 void tlc59116_read_stream(uint8_t reg, uint8_t len, uint8_t * whereto);
89 
90 /* Set pwm value for individual led
91  * args:
92  * led led output -> 0 till 15
93  * pwm led pwm value
94  */
95 void tlc59116_led(uint8_t led, uint8_t pwm);
96 
97 
98 /* -------------------------------------------------------------------------- */
99 /* Application definitions, change if required by application. */
100 
101 /* Suggested defaults according to the data sheet etc */
102 #define TLC59116_MODE1_DEFAULT 0x00 /* Default (no sub or all call) + OSC on */
103 #define TLC59116_MODE2_DEFAULT 0x00 /* Default (output change on stop) */
104 
105 #define TLC59116_LEDOUT_PWM 0xAA /* LDRx = 01 -> PWM; 4 leds per reg: 01010101b -> 0xAA */
106 
107 /* -------------------------------------------------------------------------- */
108 /* Reference definitions, should not be changed */
109 /* TLC59116 slave address */
110 #define TLC59116_ADDR 0x60 /* 7bit adress, 8bit write adress: 0xC0 */
111  /* address with all address pins pulled to ground */
112 /* TLC59116 registers */
113 #define TLC59116_MODE1 0x00
114 #define TLC59116_MODE2 0x01
115 #define TLC59116_PWM0_AUTOINCR 0xA2 /* auto increment address for first pwm register */
116 #define TLC59116_PWM0 0x02
117 #define TLC59116_PWM1 0x03
118 #define TLC59116_PWM2 0x04
119 #define TLC59116_PWM3 0x05
120 #define TLC59116_PWM4 0x06
121 #define TLC59116_PWM5 0x07
122 #define TLC59116_PWM6 0x08
123 #define TLC59116_PWM7 0x09
124 #define TLC59116_PWM8 0x0A
125 #define TLC59116_PWM9 0x0B
126 #define TLC59116_PWM10 0x0C
127 #define TLC59116_PWM11 0x0D
128 #define TLC59116_PWM12 0x0E
129 #define TLC59116_PWM13 0x0F
130 #define TLC59116_PWM14 0x10
131 #define TLC59116_PWM15 0x11
132 #define TLC59116_GRPPWM 0x12
133 #define TLC59116_GRPFREQ 0x13
134 #define TLC59116_LEDOUT0 0x14
135 #define TLC59116_LEDOUT1 0x15
136 #define TLC59116_LEDOUT2 0x16
137 #define TLC59116_LEDOUT3 0x17
138 
139 /* More registers follow, but not used in this implementation */
140 
141 /* -------------------------------------------------------------------------- */
142 #endif /* ifndef TLC59116_H_ */
I2C communication device driver header file for Zolertia Z1 sensor node.