tlc59116 for zolertia, added 0 values at init and code clean-up
This commit is contained in:
parent
cc2567b988
commit
ed8be502db
3 changed files with 38 additions and 32 deletions
|
@ -33,6 +33,7 @@
|
||||||
/**
|
/**
|
||||||
* \file
|
* \file
|
||||||
* A simple program for testing the TLC59116 I2C led driver.
|
* A simple program for testing the TLC59116 I2C led driver.
|
||||||
|
* All 16 outputs will sequencially light up.
|
||||||
* \author
|
* \author
|
||||||
* Jelmer Tiete, VUB <jelmer@tiete.be>
|
* Jelmer Tiete, VUB <jelmer@tiete.be>
|
||||||
*/
|
*/
|
||||||
|
@ -57,7 +58,7 @@ PROCESS_THREAD(tlc59116_process, ev, data) {
|
||||||
PROCESS_BEGIN();
|
PROCESS_BEGIN();
|
||||||
{
|
{
|
||||||
|
|
||||||
/* Start and setup the led driver with default values, eg outputs on and pwm enabled. */
|
/* Start and setup the led driver with default values, eg outputs on and pwm enabled and 0. */
|
||||||
tlc59116_init();
|
tlc59116_init();
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
@ -78,4 +79,3 @@ PROCESS_THREAD(tlc59116_process, ev, data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \file
|
* \file
|
||||||
* Device drivers for tlc5916 led driver in Zolertia Z1.
|
* Device drivers for tlc5916 i2c led driver on Zolertia Z1.
|
||||||
* \author
|
* \author
|
||||||
* Jelmer Tiete, VUB <jelmer@tiete.be>
|
* Jelmer Tiete, VUB <jelmer@tiete.be>
|
||||||
*/
|
*/
|
||||||
|
@ -44,14 +44,6 @@
|
||||||
#include "i2cmaster.h"
|
#include "i2cmaster.h"
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
#include <stdio.h>
|
|
||||||
#define PRINTFDEBUG(...) printf(__VA_ARGS__)
|
|
||||||
#else
|
|
||||||
#define PRINTFDEBUG(...)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/* Write to a register.
|
/* Write to a register.
|
||||||
args:
|
args:
|
||||||
|
@ -74,8 +66,8 @@ tlc59116_write_reg(uint8_t reg, uint8_t val) {
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/* Write several registers from a stream.
|
/* Write several registers from a stream.
|
||||||
args:
|
args:
|
||||||
len number of bytes to read
|
len number of bytes to write
|
||||||
data pointer to where the data is read from
|
data pointer to where the data is written from
|
||||||
|
|
||||||
First byte in stream must be the register address to begin writing to.
|
First byte in stream must be the register address to begin writing to.
|
||||||
The data is then written from second byte and increasing. */
|
The data is then written from second byte and increasing. */
|
||||||
|
@ -146,21 +138,22 @@ tlc59116_read_stream(uint8_t reg, uint8_t len, uint8_t *whereto) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/* Set pwm value for individual led
|
/* Set pwm value for individual led. Make sure PWM mode is enabled.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
tlc59116_led(uint8_t led, uint8_t pwm) {
|
tlc59116_led(uint8_t led, uint8_t pwm) {
|
||||||
if (led<0 | led>15) {
|
if (led<0 | led>15) {
|
||||||
PRINTFDEBUG("TLC59116: wrong led value.");
|
PRINTFDEBUG("TLC59116: wrong led value.");
|
||||||
}//else{
|
}else{
|
||||||
tlc59116_write_reg(led+TLC59116_PWM0, pwm);
|
tlc59116_write_reg(led+TLC59116_PWM0, pwm);
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/* Init the led driver: ports, pins, registers, interrupts (none enabled), I2C,
|
/* Init the led driver: ports, pins, registers, interrupts (none enabled), I2C,
|
||||||
default threshold values etc. */
|
default threshold values etc.
|
||||||
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
tlc59116_init(void) {
|
tlc59116_init(void) {
|
||||||
|
@ -171,10 +164,14 @@ tlc59116_init(void) {
|
||||||
tlc59116_write_reg(TLC59116_MODE1, TLC59116_MODE1_DEFAULT);
|
tlc59116_write_reg(TLC59116_MODE1, TLC59116_MODE1_DEFAULT);
|
||||||
tlc59116_write_reg(TLC59116_MODE2, TLC59116_MODE2_DEFAULT);
|
tlc59116_write_reg(TLC59116_MODE2, TLC59116_MODE2_DEFAULT);
|
||||||
|
|
||||||
|
/*Set all PWM values to 0x00 (off)*/
|
||||||
|
//This would maybe be better with a SWRST
|
||||||
|
uint8_t tx_buf[] = {TLC59116_PWM0_AUTOINCR,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
||||||
|
tlc59116_write_stream(17,&tx_buf);
|
||||||
|
|
||||||
/* set all leds to PWM control */
|
/* set all leds to PWM control */
|
||||||
tlc59116_write_reg(TLC59116_LEDOUT0,TLC59116_LEDOUT_PWM);
|
tlc59116_write_reg(TLC59116_LEDOUT0,TLC59116_LEDOUT_PWM);
|
||||||
tlc59116_write_reg(TLC59116_LEDOUT1,TLC59116_LEDOUT_PWM);
|
tlc59116_write_reg(TLC59116_LEDOUT1,TLC59116_LEDOUT_PWM);
|
||||||
tlc59116_write_reg(TLC59116_LEDOUT2,TLC59116_LEDOUT_PWM);
|
tlc59116_write_reg(TLC59116_LEDOUT2,TLC59116_LEDOUT_PWM);
|
||||||
tlc59116_write_reg(TLC59116_LEDOUT3,TLC59116_LEDOUT_PWM);
|
tlc59116_write_reg(TLC59116_LEDOUT3,TLC59116_LEDOUT_PWM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \file
|
* \file
|
||||||
* Device drivers header file for TLC59116 led driver in Zolertia Z1.
|
* Device drivers header file for TLC59116 i2c led driver on Zolertia Z1.
|
||||||
* \author
|
* \author
|
||||||
* Jelmer Tiete, VUB <jelmer@tiete.be>
|
* Jelmer Tiete, VUB <jelmer@tiete.be>
|
||||||
*/
|
*/
|
||||||
|
@ -42,6 +42,14 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "dev/i2cmaster.h"
|
#include "dev/i2cmaster.h"
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
#include <stdio.h>
|
||||||
|
#define PRINTFDEBUG(...) printf(__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define PRINTFDEBUG(...)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
/* Init the led driver: ports, pins, registers, I2C*/
|
/* Init the led driver: ports, pins, registers, I2C*/
|
||||||
void tlc59116_init(void);
|
void tlc59116_init(void);
|
||||||
|
@ -59,7 +67,8 @@ void tlc59116_write_reg(uint8_t reg, uint8_t val);
|
||||||
data pointer to where the data is read from
|
data pointer to where the data is read from
|
||||||
First byte in stream must be the register address to begin writing to.
|
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
|
The data is then written from the second byte and increasing. The address byte
|
||||||
is not included in length len. */
|
is not included in length len.
|
||||||
|
*/
|
||||||
void tlc59116_write_stream(uint8_t len, uint8_t *data);
|
void tlc59116_write_stream(uint8_t len, uint8_t *data);
|
||||||
|
|
||||||
/* Read one register.
|
/* Read one register.
|
||||||
|
@ -79,10 +88,9 @@ void tlc59116_read_stream(uint8_t reg, uint8_t len, uint8_t *whereto);
|
||||||
|
|
||||||
/* Set pwm value for individual led
|
/* Set pwm value for individual led
|
||||||
args:
|
args:
|
||||||
led led output -> 1 till 16
|
led led output -> 0 till 15
|
||||||
pwm led pwm value
|
pwm led pwm value
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void tlc59116_led(uint8_t led, uint8_t pwm);
|
void tlc59116_led(uint8_t led, uint8_t pwm);
|
||||||
|
|
||||||
|
|
||||||
|
@ -93,16 +101,17 @@ void tlc59116_led(uint8_t led, uint8_t pwm);
|
||||||
#define TLC59116_MODE1_DEFAULT 0x80 //
|
#define TLC59116_MODE1_DEFAULT 0x80 //
|
||||||
#define TLC59116_MODE2_DEFAULT 0x00 //
|
#define TLC59116_MODE2_DEFAULT 0x00 //
|
||||||
|
|
||||||
|
#define TLC59116_LEDOUT_PWM 0xAA // LDRx = 01 -> PWM, 4 leds per reg: 01010101 -> 0xAA
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
/* Reference definitions, should not be changed */
|
/* Reference definitions, should not be changed */
|
||||||
/* TLC59116 slave address */
|
/* TLC59116 slave address */
|
||||||
#define TLC59116_ADDR 0x60 //7bit adress 0xC0 8bit adress; adress with all adress pins pulled to ground
|
#define TLC59116_ADDR 0x60 //7bit adress, 8bit write adress: 0xC0
|
||||||
//#define TLC59116_ALLCALL 0xD0
|
//address with all address pins pulled to ground
|
||||||
#define TLC59116_LEDOUT_PWM 0xAA // LDRx = 01 -> PWM, 4 leds per reg: 01010101 -> 0xAA
|
|
||||||
|
|
||||||
/* TLC59116 registers */
|
/* TLC59116 registers */
|
||||||
#define TLC59116_MODE1 0x00
|
#define TLC59116_MODE1 0x00
|
||||||
#define TLC59116_MODE2 0x01
|
#define TLC59116_MODE2 0x01
|
||||||
|
#define TLC59116_PWM0_AUTOINCR 0xA2 //
|
||||||
#define TLC59116_PWM0 0x02
|
#define TLC59116_PWM0 0x02
|
||||||
#define TLC59116_PWM1 0x03
|
#define TLC59116_PWM1 0x03
|
||||||
#define TLC59116_PWM2 0x04
|
#define TLC59116_PWM2 0x04
|
||||||
|
@ -126,7 +135,7 @@ void tlc59116_led(uint8_t led, uint8_t pwm);
|
||||||
#define TLC59116_LEDOUT2 0x16
|
#define TLC59116_LEDOUT2 0x16
|
||||||
#define TLC59116_LEDOUT3 0x17
|
#define TLC59116_LEDOUT3 0x17
|
||||||
|
|
||||||
/* More registers, but not used in this implementation */
|
/* More registers follow, but not used in this implementation */
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
#endif /* ifndef __ADXL345_H__ */
|
#endif /* ifndef __ADXL345_H__ */
|
||||||
|
|
Loading…
Reference in a new issue