Firmware for the i2c-dimmer. More...
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/wdt.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#include "usiTwiSlave.h"
Go to the source code of this file.
Data Structures | |
struct | Command |
Holds one command that is received via i2c. More... | |
Defines | |
#define | TWI_SLA 0x10 |
i2c slave address | |
#define | CHANNEL_COUNT 13 |
number of 'fadeable' channels | |
#define | PORT_COUNT 2 |
the channels are distributed over two ports | |
#define | OUTPORT0 PORTB |
output port 0 | |
#define | OUTDDR0 DDRB |
set port 0 to be output | |
#define | OUTMASK0 0x5F |
see channel_pin, channel_port | |
#define | OUTPORT1 PORTD |
output port 0 | |
#define | OUTDDR1 DDRD |
set port 0 to be output | |
#define | OUTMASK1 0x7F |
see channel_pin, channel_port | |
#define | STATE_COUNT 14 |
number of states for pwm | |
#define | STATE_START_COUNT 2 |
number of state groups to be treated individually | |
Enumerations | |
enum | ReadCommandState { WAIT_FOR_ADDRESS, WAIT_FOR_VALUE_LOW, WAIT_FOR_VALUE_HIGH } |
Three bytes have to be received for a full command. More... | |
Functions | |
void | timer_start () |
initialize timer | |
void | set_brightness (uint8_t channel, uint16_t brightness) |
Set brightness on one channel. | |
void | init_ports (void) |
initialize hardware | |
void | set_port (int port, uint8_t state) |
set output | |
void | evaluate_i2c_input (void) |
Check if anything has been received via i2c and evaluate the received data. | |
int | main (void) |
Main-function. | |
Variables | |
const uint8_t channel_port[CHANNEL_COUNT] | PROGMEM |
We want to drive as many channels as possible. | |
const uint8_t | switch_timer_index [STATE_START_COUNT] = { 13, 0 } |
start interval of the state groups | |
uint8_t | switch_state [STATE_COUNT][PORT_COUNT] |
contains the port assignments for each interval | |
uint8_t | switch_state_new [STATE_COUNT][PORT_COUNT] |
Command | command = {0, 0, WAIT_FOR_ADDRESS} |
the next command is built in this variable |
Firmware for the i2c-dimmer.
Permission to use, copy, modify, and distribute this software and its documentation under the terms of the GNU General Public License is hereby granted. No representations are made about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. See the GNU General Public License for more details.
Definition in file main.c.
#define CHANNEL_COUNT 13 |
#define OUTDDR0 DDRB |
#define OUTDDR1 DDRD |
#define OUTMASK0 0x5F |
see channel_pin, channel_port
Definition at line 314 of file main.c.
Referenced by init_ports(), and set_port().
#define OUTMASK1 0x7F |
see channel_pin, channel_port
Definition at line 318 of file main.c.
Referenced by init_ports(), and set_port().
#define OUTPORT0 PORTB |
#define OUTPORT1 PORTD |
#define PORT_COUNT 2 |
#define STATE_COUNT 14 |
number of states for pwm
Definition at line 340 of file main.c.
Referenced by main(), and set_brightness().
#define STATE_START_COUNT 2 |
enum ReadCommandState |
Three bytes have to be received for a full command.
This enum is used to indicate what part of the command we are waiting for.
void evaluate_i2c_input | ( | void | ) |
Check if anything has been received via i2c and evaluate the received data.
The received data is set into the command variable according to the state of the command we are waiting for.
Definition at line 449 of file main.c.
References Command::address, set_brightness(), Command::state, usiTwiDataInReceiveBuffer(), usiTwiReceiveByte(), Command::value, WAIT_FOR_ADDRESS, WAIT_FOR_VALUE_HIGH, and WAIT_FOR_VALUE_LOW.
Referenced by main().
void init_ports | ( | void | ) |
int main | ( | void | ) |
Main-function.
Initializes everything and contains the main loop which controls the actual PWM output.
Definition at line 496 of file main.c.
References CHANNEL_COUNT, evaluate_i2c_input(), init_ports(), PORT_COUNT, set_brightness(), set_port(), STATE_COUNT, STATE_START_COUNT, switch_state, switch_state_new, switch_timer_index, timer_start(), TWI_SLA, and usiTwiSlaveInit().
void set_brightness | ( | uint8_t | channel, |
uint16_t | brightness | ||
) |
Set brightness on one channel.
channel | the channel to address (0 .. CHANNEL_COUNT) |
brightness | the value to set (0 .. 16383) |
Definition at line 395 of file main.c.
References STATE_COUNT, and switch_state_new.
Referenced by evaluate_i2c_input(), and main().
void set_port | ( | int | port, |
uint8_t | state | ||
) |
const uint16_t switch_timer [STATE_COUNT] PROGMEM |
{ 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1 }
We want to drive as many channels as possible.
interval length of the states
this is used to determine the pin that is used for output
Unfortunately the usable pins aren't 'in a row', so we have to determine which channel ends up on which port and pin. this is used to determine the port that is used for output
uint8_t switch_state[STATE_COUNT][PORT_COUNT] |
uint8_t switch_state_new[STATE_COUNT][PORT_COUNT] |
Definition at line 351 of file main.c.
Referenced by main(), and set_brightness().
const uint8_t switch_timer_index[STATE_START_COUNT] = { 13, 0 } |