2013-05-22 15:46:12 +00:00
|
|
|
/*
|
2013-06-24 14:13:35 +00:00
|
|
|
* Copyright (c) 2013, Jelmer Tiete.
|
2013-05-22 15:46:12 +00:00
|
|
|
* All rights reserved.
|
2013-06-24 14:13:35 +00:00
|
|
|
*
|
2013-05-22 15:46:12 +00:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2013-06-24 14:13:35 +00:00
|
|
|
* 3. The name of the author may not be used to endorse or promote
|
|
|
|
* products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
|
|
|
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
|
|
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
|
|
|
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
2013-05-22 15:46:12 +00:00
|
|
|
* This file is part of the Contiki operating system.
|
2013-06-24 14:13:35 +00:00
|
|
|
*
|
2013-05-22 15:46:12 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file
|
2013-05-23 21:35:21 +00:00
|
|
|
* Device drivers header file for TLC59116 i2c led driver on Zolertia Z1.
|
2013-05-23 22:07:57 +00:00
|
|
|
* See http://www.ti.com/product/tlc59116 for datasheet.
|
2013-05-22 15:46:12 +00:00
|
|
|
* \author
|
|
|
|
* Jelmer Tiete, VUB <jelmer@tiete.be>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __TLC59116_H__
|
|
|
|
#define __TLC59116_H__
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "dev/i2cmaster.h"
|
|
|
|
|
2013-05-23 21:35:21 +00:00
|
|
|
#if 0
|
|
|
|
#include <stdio.h>
|
|
|
|
#define PRINTFDEBUG(...) printf(__VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#define PRINTFDEBUG(...)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2013-05-22 15:46:12 +00:00
|
|
|
/* -------------------------------------------------------------------------- */
|
|
|
|
/* Init the led driver: ports, pins, registers, I2C*/
|
2013-05-28 22:41:06 +00:00
|
|
|
void tlc59116_init(void);
|
2013-05-22 15:46:12 +00:00
|
|
|
|
|
|
|
/* Write to a register.
|
2013-05-28 22:41:06 +00:00
|
|
|
* args:
|
|
|
|
* reg register to write to
|
|
|
|
* val value to write
|
|
|
|
*/
|
|
|
|
void tlc59116_write_reg(uint8_t reg, uint8_t val);
|
2013-05-22 15:46:12 +00:00
|
|
|
|
|
|
|
/* Write several registers from a stream.
|
2013-05-28 22:41:06 +00:00
|
|
|
* args:
|
|
|
|
* len number of bytes to read
|
|
|
|
* data pointer to where the data is read from
|
|
|
|
* First byte in stream must be the register address to begin writing to.
|
|
|
|
* The data is then written from the second byte and increasing. The address byte
|
|
|
|
* is not included in length len.
|
|
|
|
*/
|
|
|
|
void tlc59116_write_stream(uint8_t len, uint8_t * data);
|
2013-05-22 15:46:12 +00:00
|
|
|
|
|
|
|
/* Read one register.
|
2013-05-28 22:41:06 +00:00
|
|
|
* args:
|
|
|
|
* reg what register to read
|
|
|
|
* returns the value of the read register
|
|
|
|
*/
|
|
|
|
uint8_t tlc59116_read_reg(uint8_t reg);
|
2013-05-22 15:46:12 +00:00
|
|
|
|
|
|
|
/* Read several registers in a stream.
|
2013-05-28 22:41:06 +00:00
|
|
|
* args:
|
|
|
|
* reg what register to start reading from
|
|
|
|
* len number of bytes to read
|
|
|
|
* whereto pointer to where the data is saved
|
|
|
|
*/
|
|
|
|
void tlc59116_read_stream(uint8_t reg, uint8_t len, uint8_t * whereto);
|
2013-05-22 15:46:12 +00:00
|
|
|
|
2013-05-23 21:35:21 +00:00
|
|
|
/* Set pwm value for individual led
|
2013-05-28 22:41:06 +00:00
|
|
|
* args:
|
|
|
|
* led led output -> 0 till 15
|
|
|
|
* pwm led pwm value
|
|
|
|
*/
|
|
|
|
void tlc59116_led(uint8_t led, uint8_t pwm);
|
2013-05-22 15:46:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------------- */
|
|
|
|
/* Application definitions, change if required by application. */
|
|
|
|
|
|
|
|
/* Suggested defaults according to the data sheet etc */
|
2013-05-28 22:41:06 +00:00
|
|
|
#define TLC59116_MODE1_DEFAULT 0x00 // Default (no sub or all call) + OSC on
|
|
|
|
#define TLC59116_MODE2_DEFAULT 0x00 // Default (output change on stop)
|
2013-05-23 21:35:21 +00:00
|
|
|
|
2013-05-28 22:41:06 +00:00
|
|
|
#define TLC59116_LEDOUT_PWM 0xAA // LDRx = 01 -> PWM; 4 leds per reg: 01010101b -> 0xAA
|
2013-05-22 15:46:12 +00:00
|
|
|
|
|
|
|
/* -------------------------------------------------------------------------- */
|
|
|
|
/* Reference definitions, should not be changed */
|
|
|
|
/* TLC59116 slave address */
|
2013-05-28 22:41:06 +00:00
|
|
|
#define TLC59116_ADDR 0x60 //7bit adress, 8bit write adress: 0xC0
|
|
|
|
//address with all address pins pulled to ground
|
2013-05-22 15:46:12 +00:00
|
|
|
/* TLC59116 registers */
|
|
|
|
#define TLC59116_MODE1 0x00
|
|
|
|
#define TLC59116_MODE2 0x01
|
2013-05-28 22:41:06 +00:00
|
|
|
#define TLC59116_PWM0_AUTOINCR 0xA2 //auto increment address for first pwm register
|
2013-05-22 15:46:12 +00:00
|
|
|
#define TLC59116_PWM0 0x02
|
|
|
|
#define TLC59116_PWM1 0x03
|
|
|
|
#define TLC59116_PWM2 0x04
|
|
|
|
#define TLC59116_PWM3 0x05
|
|
|
|
#define TLC59116_PWM4 0x06
|
|
|
|
#define TLC59116_PWM5 0x07
|
|
|
|
#define TLC59116_PWM6 0x08
|
|
|
|
#define TLC59116_PWM7 0x09
|
|
|
|
#define TLC59116_PWM8 0x0A
|
|
|
|
#define TLC59116_PWM9 0x0B
|
|
|
|
#define TLC59116_PWM10 0x0C
|
|
|
|
#define TLC59116_PWM11 0x0D
|
|
|
|
#define TLC59116_PWM12 0x0E
|
|
|
|
#define TLC59116_PWM13 0x0F
|
|
|
|
#define TLC59116_PWM14 0x10
|
|
|
|
#define TLC59116_PWM15 0x11
|
|
|
|
#define TLC59116_GRPPWM 0x12
|
|
|
|
#define TLC59116_GRPFREQ 0x13
|
|
|
|
#define TLC59116_LEDOUT0 0x14
|
|
|
|
#define TLC59116_LEDOUT1 0x15
|
|
|
|
#define TLC59116_LEDOUT2 0x16
|
|
|
|
#define TLC59116_LEDOUT3 0x17
|
|
|
|
|
2013-05-23 21:35:21 +00:00
|
|
|
/* More registers follow, but not used in this implementation */
|
2013-05-22 15:46:12 +00:00
|
|
|
|
|
|
|
/* -------------------------------------------------------------------------- */
|
2013-05-28 22:41:06 +00:00
|
|
|
#endif /* ifndef __TLC59116_H__ */
|