Documentation added.
Some other optimizations for size.
This commit is contained in:
parent
194bb4f782
commit
8a9aaa2487
6 changed files with 92 additions and 87 deletions
|
@ -1,6 +1,6 @@
|
||||||
/* CTHN.de MiniLEDCube
|
/* CTHN.de MiniLEDCube
|
||||||
*
|
*
|
||||||
* Kai Lauterbach (klaute at web dot de)
|
* By Kai Lauterbach (klaute at web dot de) 11/2011
|
||||||
*
|
*
|
||||||
* License: General Public License (GPL v3)
|
* License: General Public License (GPL v3)
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
/* CTHN.de MiniLEDCube
|
/*
|
||||||
|
* CTHN.de MiniLEDCube
|
||||||
*
|
*
|
||||||
* Kai Lauterbach (klaute at web dot de)
|
* By Kai Lauterbach (klaute at web dot de) 11/2011
|
||||||
*
|
*
|
||||||
* Based on http://mosfetkiller.de/?s=miniledcube
|
* Based on http://mosfetkiller.de/?s=miniledcube
|
||||||
*
|
*
|
||||||
|
@ -10,16 +11,14 @@
|
||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
// Main
|
// Main loop
|
||||||
int __attribute__((OS_main))
|
int __attribute__((OS_main))
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
// Initialisierung
|
// Initialize the AVR and the USB connection.
|
||||||
init();
|
init();
|
||||||
init_usb();
|
init_usb();
|
||||||
|
|
||||||
//frame = 0x07ffffff;
|
|
||||||
mode = 2;
|
|
||||||
|
|
||||||
// Hauptschleife
|
// Hauptschleife
|
||||||
for (;;)
|
for (;;)
|
||||||
|
@ -31,74 +30,75 @@ main()
|
||||||
// Initialisierung
|
// Initialisierung
|
||||||
void init()
|
void init()
|
||||||
{
|
{
|
||||||
// Ports vorbereiten
|
// Init ports
|
||||||
DDRB = 0b11111111; // PB0-PB7: LED 1-8 (Kathoden)
|
DDRB = 0b11111111; // PB0-PB7: LED 1-8 (Kathode)
|
||||||
PORTB = 0b11111111; // HIGH
|
PORTB = 0b11111111; // HIGH
|
||||||
|
|
||||||
DDRD = 0b01111000; // PD6: LED 9 (Kathode); PD5-PD3: A-C (Anoden)
|
DDRD = 0b01111000; // PD6: LED 9 (Kathode); PD5-PD3: A-C (Anoden)
|
||||||
PORTD = 0b01000000;
|
PORTD = 0b01000000;
|
||||||
|
|
||||||
// Timer-Interrupt "TIMER1" vorbereiten
|
// Setup Timer-Interrupt "TIMER1"
|
||||||
|
TIMSK |= (1 << OCIE1A);
|
||||||
|
|
||||||
set_bit(TIMSK, OCIE1A); // Interrupt für ISR COMPA
|
// Refreshrate is 100Hz
|
||||||
//set_bit(TCCR1B, WGM12); // Überlauf wird unten gesetzt
|
// Set the compare value
|
||||||
|
|
||||||
// Animations-Geschwindigkeit
|
|
||||||
// (vergleichswert bei dem der Interrupt ausgelöst wird)
|
|
||||||
// 625d = 0x271 = 0b00000010, 0b01110001
|
// 625d = 0x271 = 0b00000010, 0b01110001
|
||||||
OCR1AH = 0b00000010;
|
OCR1AH = 0b00000010;
|
||||||
OCR1AL = 0b01110001;
|
OCR1AL = 0b01110001;
|
||||||
|
|
||||||
// anpassen auf reihenweise ausgabe
|
// anpassen auf reihenweise ausgabe
|
||||||
// Vorteiler durch 64 (0x011) ----> CS12=0, CS11=1, CS10=1
|
// prescale is 64 (0x011) ----> CS12=0, CS11=1, CS10=1
|
||||||
//clear_bit(TCCR1B, CS12); // Prescaler 64
|
|
||||||
//set_bit(TCCR1B, CS11);
|
|
||||||
//set_bit(TCCR1B, CS10);
|
|
||||||
TCCR1B |= (1 << CS11) | (1 << CS10) | (1 << WGM12);
|
TCCR1B |= (1 << CS11) | (1 << CS10) | (1 << WGM12);
|
||||||
|
|
||||||
sei(); // Set enable interrupt bit (Muss gesetzt werden damit es überhaupt aufgerufen wird)
|
sei(); // Enable interrupts global
|
||||||
}
|
}
|
||||||
|
|
||||||
// Interruptvektor von TIMER1
|
// TIMER1 Interruptvector
|
||||||
ISR (TIMER1_COMPA_vect)
|
ISR (TIMER1_COMPA_vect)
|
||||||
{
|
{
|
||||||
|
|
||||||
delay--;
|
delay--; // decrease the delay counter
|
||||||
if ( !delay )
|
if ( !delay ) // check if we are done with waiting
|
||||||
{
|
{
|
||||||
if (frmnum == 32)
|
if (frmnum == MAX_EEPROM_FRAMES)
|
||||||
{
|
{
|
||||||
if (mode == 1)
|
if (mode == MODE_ANIMATION_SINGLE)
|
||||||
mode = 0;
|
mode = MODE_ANIMATION_STOP; // stop the animation after we have reached the 31th frame
|
||||||
frmnum = 0;
|
frmnum = 0; // always start at the first frame
|
||||||
} else {
|
} else {
|
||||||
if (mode)
|
if (mode)
|
||||||
{
|
{
|
||||||
|
// if we are in an animation mode we have to load a frame out of the eeprom
|
||||||
|
// and increase the counter
|
||||||
loadEEPROMFrame(frmnum);
|
loadEEPROMFrame(frmnum);
|
||||||
frmnum++;
|
frmnum++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delay = delay_max;
|
delay = delay_max; // start counting from the top of the maximum delay
|
||||||
}
|
}
|
||||||
|
|
||||||
// PORTD = __, 9, C, B, A,D+,D-,__
|
// PORTD = __, 9, C, B, A,D+,D-,__
|
||||||
PORTD &= 0b10000111; // 7tes Bit löschen (Leitung 9) und alle Ebenen deaktivieren
|
PORTD &= 0b10000111; // delete bit 3 to 6 (bit 3 to 5 = layer 0 to 2; bit 6 = wire 9 to the LEDs)
|
||||||
PORTD |= (1 << 6) | ((1 << level) << 3); // level setzen (Ebene A=0, B=1, C=2)
|
PORTD |= (1 << 6) | ((1 << level) << 3); // set the current level and pin 6 to high (9th LEDs off)
|
||||||
|
|
||||||
uint8_t tmp = level * 9;
|
uint8_t tmp = level * 9; // calculate the position in the frame
|
||||||
|
|
||||||
// PORTB = 1..8
|
// PORTB = 1..8
|
||||||
// 0 = leuchtet, 1 = leuchtet nicht (invertiert!)
|
// 0 = led is on, 1 = led is off
|
||||||
PORTB = ~((frame >> tmp) & 0xff);
|
PORTB = ~((frame >> tmp) & 0xff);
|
||||||
|
|
||||||
if ( (((frame >> tmp) >> 8) & 0x01) )
|
if ( (((frame >> tmp) >> 8) & 0x01) )
|
||||||
PORTD &= ~(1 << 6); // 9. led setzen falls notwendig
|
PORTD &= ~(1 << 6); // turn the 9th LED on if required
|
||||||
|
|
||||||
|
// rotate through the 3 level
|
||||||
level++;
|
level++;
|
||||||
if (level > 2) level = 0;
|
if (level > 2) level = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple function to load a single frame out of the EEPROM.
|
||||||
|
*/
|
||||||
void loadEEPROMFrame(uint8_t f)
|
void loadEEPROMFrame(uint8_t f)
|
||||||
{
|
{
|
||||||
frame = eeprom_read_dword( &eep_anim[f] );
|
frame = eeprom_read_dword( &eep_anim[f] );
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
/* CTHN.de MiniLEDCube
|
/*
|
||||||
|
* CTHN.de MiniLEDCube
|
||||||
*
|
*
|
||||||
* Kai Lauterbach (klaute at web dot de)
|
* By Kai Lauterbach (klaute at web dot de) 11/2011
|
||||||
*
|
*
|
||||||
* Based on http://mosfetkiller.de/?s=miniledcube
|
* Based on http://mosfetkiller.de/?s=miniledcube
|
||||||
*
|
*
|
||||||
|
@ -14,31 +15,28 @@
|
||||||
// Includes
|
// Includes
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
|
|
||||||
//#include "type.h"
|
|
||||||
|
|
||||||
#include <avr/interrupt.h>
|
#include <avr/interrupt.h>
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
#include <avr/eeprom.h>
|
#include <avr/eeprom.h>
|
||||||
|
|
||||||
// Cube-Data
|
// Cube-Data
|
||||||
uint32_t frame = 0xffffffff;
|
uint32_t frame;
|
||||||
// Bit Offset in Cube-Data
|
|
||||||
uint8_t level; // Aktive Ebene
|
|
||||||
uint8_t mode;
|
|
||||||
uint8_t frmnum;
|
|
||||||
uint8_t delay;
|
|
||||||
uint8_t delay_max;
|
|
||||||
|
|
||||||
//cube_t *cube;
|
uint8_t level; // current layer
|
||||||
uint32_t eep_anim[32] EEMEM;
|
uint8_t mode = MODE_ANIMATION_LOOP; // firmware mode
|
||||||
|
uint8_t frmnum; // frame nummber in the animation loop
|
||||||
|
uint8_t delay; // delay in ISR calls between changing to the next animation frame
|
||||||
|
uint8_t delay_max = STARTUP_DELAY_MAX; // maximum delay between the animation frames
|
||||||
|
|
||||||
// Prototypen
|
// eeprom array of the animation
|
||||||
|
uint32_t eep_anim[MAX_EEPROM_FRAMES] EEMEM;
|
||||||
|
|
||||||
|
// function prototypes
|
||||||
void init(void);
|
void init(void);
|
||||||
|
void loadEEPROMFrame(uint8_t);
|
||||||
|
|
||||||
extern void init_usb(void);
|
extern void init_usb(void);
|
||||||
extern void usbPoll(void);
|
extern void usbPoll(void);
|
||||||
|
|
||||||
void loadEEPROMFrame(uint8_t);
|
|
||||||
|
|
||||||
#endif // __main_h__
|
#endif // __main_h__
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
/* Name: requests.h
|
/*
|
||||||
* Project: custom-class, a basic USB example
|
* CTHN.de MiniLEDCube
|
||||||
* Author: Christian Starkjohann
|
*
|
||||||
* Creation Date: 2008-04-09
|
* requests.h by Kai Lauterbach
|
||||||
* Tabsize: 4
|
*
|
||||||
* Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
|
* Based on project: hid-custom-rq example by Christian Starkjohann
|
||||||
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
* Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
|
||||||
* This Revision: $Id: requests.h 692 2008-11-07 15:07:40Z cs $
|
*
|
||||||
|
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* This header is shared between the firmware and the host software. It
|
/* This header is shared between the firmware and the host software. It
|
||||||
|
@ -18,8 +20,7 @@
|
||||||
|
|
||||||
#define CUSTOM_RQ_SET_FRAME 1
|
#define CUSTOM_RQ_SET_FRAME 1
|
||||||
#define CUSTOM_RQ_EEPROM_STORE_FRAME 2
|
#define CUSTOM_RQ_EEPROM_STORE_FRAME 2
|
||||||
#define CUSTOM_RQ_EEPROM_SET_FRAME 3
|
#define CUSTOM_RQ_SET_MODE 3
|
||||||
#define CUSTOM_RQ_SET_MODE 4
|
#define CUSTOM_RQ_SET_DELAY 4
|
||||||
#define CUSTOM_RQ_SET_DELAY 5
|
|
||||||
|
|
||||||
#endif /* __REQUESTS_H_INCLUDED__ */
|
#endif /* __REQUESTS_H_INCLUDED__ */
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
/* Name: usb.h by Kai Lauterbach
|
/*
|
||||||
* Based on Project: hid-custom-rq example
|
* CTHN.de MiniLEDCube
|
||||||
* Revision: $Id: main.c 790 2010-05-30 21:00:26Z cs $
|
*
|
||||||
* Author: Christian Starkjohann
|
* usb.h by Kai Lauterbach 11/2011
|
||||||
* Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
|
*
|
||||||
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
* Based on project: hid-custom-rq example by Christian Starkjohann
|
||||||
|
* Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
|
||||||
|
*
|
||||||
|
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "usb.h"
|
#include "usb.h"
|
||||||
|
@ -19,12 +23,16 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
||||||
if ( rq->bRequest == CUSTOM_RQ_SET_FRAME )
|
if ( rq->bRequest == CUSTOM_RQ_SET_FRAME )
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// because of the code size we have to transfer one frame in
|
||||||
|
// two steps (control messages)
|
||||||
if ( rq->wIndex.bytes[0] == 0 )
|
if ( rq->wIndex.bytes[0] == 0 )
|
||||||
{
|
{
|
||||||
|
// the lower word
|
||||||
frame = (frame & (uint32_t)0xffff0000) |
|
frame = (frame & (uint32_t)0xffff0000) |
|
||||||
( rq->wValue.bytes[0] +
|
( rq->wValue.bytes[0] +
|
||||||
(rq->wValue.bytes[1] << 8) );
|
(rq->wValue.bytes[1] << 8) );
|
||||||
} else {
|
} else {
|
||||||
|
// the high word
|
||||||
frame = (frame & (uint32_t)0x0000ffff) |
|
frame = (frame & (uint32_t)0x0000ffff) |
|
||||||
((uint32_t)( rq->wValue.bytes[0] +
|
((uint32_t)( rq->wValue.bytes[0] +
|
||||||
(rq->wValue.bytes[1] << 8) ) << 16);
|
(rq->wValue.bytes[1] << 8) ) << 16);
|
||||||
|
@ -32,13 +40,19 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
||||||
|
|
||||||
} else if ( rq->bRequest == CUSTOM_RQ_EEPROM_STORE_FRAME )
|
} else if ( rq->bRequest == CUSTOM_RQ_EEPROM_STORE_FRAME )
|
||||||
{
|
{
|
||||||
|
// save the actual frame to the eeprom
|
||||||
|
// don't forget to send a frame first
|
||||||
eeprom_write_dword( &eep_anim[ rq->wIndex.bytes[0] ], frame );
|
eeprom_write_dword( &eep_anim[ rq->wIndex.bytes[0] ], frame );
|
||||||
} else if ( rq->bRequest == CUSTOM_RQ_SET_DELAY )
|
} else if ( rq->bRequest == CUSTOM_RQ_SET_DELAY )
|
||||||
{
|
{
|
||||||
|
// set the maximum delay between two frames
|
||||||
|
// as a multiply of ISR calls
|
||||||
delay_max = rq->wValue.bytes[0];
|
delay_max = rq->wValue.bytes[0];
|
||||||
} else if ( rq->bRequest == CUSTOM_RQ_SET_MODE )
|
} else if ( rq->bRequest == CUSTOM_RQ_SET_MODE )
|
||||||
{
|
{
|
||||||
mode = rq->wValue.bytes[0]; // 0 = stop; 1 = single; 2 = loop
|
// set the firmware mode
|
||||||
|
// 0 = stop; 1 = single; 2 = loop
|
||||||
|
mode = rq->wValue.bytes[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
/* Name: usb.h by Kai Lauterbach
|
/*
|
||||||
* Based on Project: hid-custom-rq example
|
* CTHN.de MiniLEDCube
|
||||||
* Revision: $Id: main.c 790 2010-05-30 21:00:26Z cs $
|
*
|
||||||
* Author: Christian Starkjohann
|
* usb.c by Kai Lauterbach 11/2011
|
||||||
* Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
|
*
|
||||||
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
* Based on project: hid-custom-rq example by Christian Starkjohann
|
||||||
* This
|
* Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
|
||||||
|
*
|
||||||
|
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __usb_h__
|
#ifndef __usb_h__
|
||||||
|
@ -18,17 +21,6 @@
|
||||||
|
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
|
|
||||||
//#include "type.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
This example should run on most AVRs with only little changes. No special
|
|
||||||
hardware resources except INT0 are used. You may have to change usbconfig.h for
|
|
||||||
different I/O pins for USB. Please note that USB D+ must be the INT0 pin, or
|
|
||||||
at least be connected to INT0 as well.
|
|
||||||
We assume that an LED is connected to port B bit 0. If you connect it to a
|
|
||||||
different port or bit, change the macros below:
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "usbconfig.h"
|
#include "usbconfig.h"
|
||||||
#include "usbdrv.h"
|
#include "usbdrv.h"
|
||||||
#include "requests.h" /* The custom request numbers we use */
|
#include "requests.h" /* The custom request numbers we use */
|
||||||
|
@ -57,7 +49,7 @@ PROGMEM char usbHidReportDescriptor[22] = { /* USB report descriptor */
|
||||||
|
|
||||||
void init_usb(void);
|
void init_usb(void);
|
||||||
|
|
||||||
extern uint32_t eep_anim[32] EEMEM;
|
extern uint32_t eep_anim[MAX_EEPROM_FRAMES] EEMEM;
|
||||||
|
|
||||||
// usb buffer
|
// usb buffer
|
||||||
extern uint32_t frame; // Framebuffer
|
extern uint32_t frame; // Framebuffer
|
||||||
|
@ -65,7 +57,7 @@ extern uint8_t delay_max; // delay in ISR aufrufen
|
||||||
extern uint8_t mode; // FW mode
|
extern uint8_t mode; // FW mode
|
||||||
|
|
||||||
//extern cube_t *cube;
|
//extern cube_t *cube;
|
||||||
extern void loadEEPROMFrame(uint8_t f);
|
extern void loadEEPROMFrame(uint8_t);
|
||||||
|
|
||||||
#endif // __usb_h__
|
#endif // __usb_h__
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue