improved comments

This commit is contained in:
2007-01-03 12:38:55 +00:00
parent 8c0e19cf1c
commit 1f77141a10
5 changed files with 69 additions and 57 deletions

View File

@@ -2,7 +2,7 @@
* \file saa1064.c
* \brief I2C-connection to the SAA1064 LED-driver
* \author Ronald Schaten
* \version $Id: saa1064.c,v 1.1 2007/01/02 21:30:40 rschaten Exp $
* \version $Id: saa1064.c,v 1.2 2007/01/03 12:38:55 rschaten Exp $
*
* License: See documentation.
*/
@@ -13,33 +13,30 @@
#include <util/delay.h>
#include "saa1064.h"
/* The Port used for the connection */
#define LEDPORT PORTC
#define LEDPIN PINC
#define LEDDDR DDRC
#define LEDPORT PORTC /**< the Port used for the connection */
#define LEDPIN PINC /**< the Port used for the connection */
#define LEDDDR DDRC /**< the Port used for the connection */
/* Which pins of the port */
#define SDAPIN PC4
#define SCLPIN PC5
#define SDAPIN PC4 /**< which pins of the port */
#define SCLPIN PC5 /**< which pins of the port */
/* the I2C addresses of the SAA 1064 LED drivers */
#define SAA_AD1 0x70 // or 0x76?
#define SAA_ADR 0x70 /**< the I2C addresses of the SAA 1064 LED drivers */
#define I2C_READ 0x01
#define I2C_WRITE 0x00
#define I2C_READ 0x01 /**< command used to read from I2C */
#define I2C_WRITE 0x00 /**< command used to write to I2C */
/* Should be at least 27 (80 / 3) at 8 MHz */
/* This was the conservative value used for testing. However, half as much should work as well. */
#define DELAYVAL 3
#define DELAYVAL 3 /**< pause between certain actions on the bus. Should be at least (10 * freq) / 3, so we set 3 at 1 MHz */
void led_init(void) {
/* activate pullups */
LEDPORT |= (1 << SCLPIN) | (1 << SDAPIN);
}
/* Send START, defined as high-to-low SDA with SCL high.
/**
* Send START, defined as high-to-low SDA with SCL high.
* Expects SCL and SDA to be high already!
* Returns with SDA and SCL low. */
* Returns with SDA and SCL low.
*/
static void I2C_start(void) {
/* Change to output mode. */
LEDDDR |= (1 << SDAPIN) | (1 << SCLPIN);
@@ -51,9 +48,11 @@ static void I2C_start(void) {
_delay_loop_1(DELAYVAL);
}
/* Send STOP, defined as low-to-high SDA with SCL high.
/**
* Send STOP, defined as low-to-high SDA with SCL high.
* Expects SCL and SDA to be low already!
* Returns with SDA and SCL high. */
* Returns with SDA and SCL high.
*/
static void I2C_stop(void) {
/* Set SCL */
LEDPORT |= (1 << SCLPIN);
@@ -65,10 +64,13 @@ static void I2C_stop(void) {
LEDDDR &= ~((1 << SDAPIN) | (1 << SCLPIN));
}
/* Transmits the byte in what.
/**
* Transmits the byte in parameter what.
* Returns 1 if the byte was ACKed, 0 if not.
* Expects SCL and SDA to be low already!
* Returns with SDA and SCL low. */
* Returns with SDA and SCL low.
* \param what the byte to transmit
*/
static uint8_t I2C_transmit_byte(uint8_t what) {
uint8_t i;
for (i = 0; i < 8; i++) {
@@ -115,7 +117,7 @@ static uint8_t I2C_transmit_byte(uint8_t what) {
void set_led_digit(uint8_t digit, uint8_t val) {
I2C_start();
/* Address device */
I2C_transmit_byte(SAA_AD1 | I2C_WRITE);
I2C_transmit_byte(SAA_ADR | I2C_WRITE);
I2C_transmit_byte((digit & 3) + 1); /* Address Digit Register on device */
I2C_transmit_byte(val); /* Send value for Digit */
I2C_stop();
@@ -123,7 +125,7 @@ void set_led_digit(uint8_t digit, uint8_t val) {
void set_led_brightness(uint8_t led_brightness) {
I2C_start();
I2C_transmit_byte(SAA_AD1 | I2C_WRITE); /* Address first driver */
I2C_transmit_byte(SAA_ADR | I2C_WRITE); /* Address first driver */
I2C_transmit_byte(0); /* Address Config Register on device */
I2C_transmit_byte(((led_brightness & 0x07) << 4) | 0x07); /* Send Settings */
I2C_stop();