Commit 004b9394a11b8da612750b2a9697aa227b22cb48

Authored by pfrison
1 parent b08b30f4

Avant début piste

tests/atmega2560/ledControl/ledControl.c
@@ -2,8 +2,10 @@ @@ -2,8 +2,10 @@
2 #include <util/delay.h> 2 #include <util/delay.h>
3 #include <math.h> 3 #include <math.h>
4 4
  5 +#include "tlc5947.h"
  6 +
5 #define NB_DRIVERS 3 7 #define NB_DRIVERS 3
6 -#define MAX_VALUE 85 //TODO tbd ! 8 +#define MAX_VALUE 80 //TODO tbd !
7 #define DELAY 100 9 #define DELAY 100
8 10
9 int main(void){ 11 int main(void){
@@ -16,15 +18,15 @@ int main(void){ @@ -16,15 +18,15 @@ int main(void){
16 while(1){ 18 while(1){
17 // Build animation 19 // Build animation
18 for(int i=0; i<NB_DRIVERS * DLED_CHANNELS; i++){ 20 for(int i=0; i<NB_DRIVERS * DLED_CHANNELS; i++){
19 - double sinIn = (double) animTick / 8;  
20 - unsigned int val = (unsigned int) (0.5 + (sin(sinIn) * 0.5));  
21 - ledValues[i] = val * MAX_VALUE; 21 + double val = (double) (animTick % 21) / 20;
  22 + ledValues[i] = (unsigned int) (val * MAX_VALUE);
22 } 23 }
  24 +
23 animTick++; 25 animTick++;
24 if(animTick >= 10000) 26 if(animTick >= 10000)
25 animTick = 0; 27 animTick = 0;
26 28
27 - set_LED_Drivers(groupes, NB_DRIVERS); 29 + set_LED_Drivers(ledValues, NB_DRIVERS);
28 _delay_ms(100); 30 _delay_ms(100);
29 } 31 }
30 return 0; 32 return 0;
tests/atmega2560/ledControl/makefile
@@ -21,7 +21,7 @@ clean: @@ -21,7 +21,7 @@ clean:
21 rm -f *.o *.hex *.elf 21 rm -f *.o *.hex *.elf
22 22
23 %.o:%.c 23 %.o:%.c
24 - $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@ 24 + $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@ -lm
25 25
26 $(TARGET).elf: $(OBJS) 26 $(TARGET).elf: $(OBJS)
27 $(CC) $(LDFLAGS) -o $@ $(OBJS) 27 $(CC) $(LDFLAGS) -o $@ $(OBJS)
tests/atmega2560/ledControl/tlc5947.c
1 #include <avr/io.h> 1 #include <avr/io.h>
  2 +
2 #include "tlc5947.h" 3 #include "tlc5947.h"
3 4
4 -#define DLED_CHANNELS 24 5 +#define DDR_DLED_CLOCK DDRE
  6 +#define PORT_DLED_CLOCK PORTE
  7 +
  8 +#define DDR_DLED_DATA DDRG
  9 +#define PORT_DLED_DATA PORTG
5 10
6 -#define DDR_DLED DDRD  
7 -#define PORT_DLED PORTD 11 +#define DDR_DLED_LATCH DDRB
  12 +#define PORT_DLED_LATCH PORTB
8 13
9 -#define PIN_DLED_CLOCK 5  
10 -#define PIN_DLED_DATA 4  
11 -#define PIN_DLED_LATCH 6 14 +#define PIN_DLED_CLOCK 0x08
  15 +#define PIN_DLED_DATA 0x20
  16 +#define PIN_DLED_LATCH 0x10
12 17
13 void init_LED_Drivers(int nb){ 18 void init_LED_Drivers(int nb){
14 // LED drivers I/O as outputs 19 // LED drivers I/O as outputs
15 - DDR_DLED |= (1<<PIN_DLED_CLOCK) | (1<<PIN_DLED_DATA) | (1<<PIN_DLED_LATCH); 20 + DDR_DLED_CLOCK |= PIN_DLED_CLOCK;
  21 + DDR_DLED_DATA |= PIN_DLED_DATA;
  22 + DDR_DLED_LATCH |= PIN_DLED_LATCH;
16 // Set LATCH output low 23 // Set LATCH output low
17 - PORT_DLED &= ~(1<<PIN_DLED_LATCH); 24 + PORT_DLED_LATCH &= ~PIN_DLED_LATCH;
18 } 25 }
19 26
20 27
21 void set_LED_Drivers(unsigned int pwm[], int nb){ 28 void set_LED_Drivers(unsigned int pwm[], int nb){
22 // Set LATCH output low 29 // Set LATCH output low
23 - PORT_DLED &= ~(1<<PIN_DLED_LATCH); 30 + PORT_DLED_LATCH &= ~PIN_DLED_LATCH;
24 // 24 channels per TLC5947 31 // 24 channels per TLC5947
25 int i; 32 int i;
26 for(i=DLED_CHANNELS*nb-1; i>=0; i--){ 33 for(i=DLED_CHANNELS*nb-1; i>=0; i--){
@@ -29,24 +36,24 @@ void set_LED_Drivers(unsigned int pwm[], int nb){ @@ -29,24 +36,24 @@ void set_LED_Drivers(unsigned int pwm[], int nb){
29 int j; 36 int j;
30 for(j=0; j<12; j++){ 37 for(j=0; j<12; j++){
31 // Set CLOCK output low 38 // Set CLOCK output low
32 - PORT_DLED &= ~(1<<PIN_DLED_CLOCK); 39 + PORT_DLED_CLOCK &= ~PIN_DLED_CLOCK;
33 40
34 // Set DATA as stated by bit #j of i 41 // Set DATA as stated by bit #j of i
35 if(v & 0x0800) 42 if(v & 0x0800)
36 - PORT_DLED |= (1<<PIN_DLED_DATA); 43 + PORT_DLED_DATA |= PIN_DLED_DATA;
37 else 44 else
38 - PORT_DLED &= ~(1<<PIN_DLED_DATA); 45 + PORT_DLED_DATA &= ~PIN_DLED_DATA;
39 46
40 // Set CLOCK output HIGH 47 // Set CLOCK output HIGH
41 - PORT_DLED |= (1<<PIN_DLED_CLOCK); 48 + PORT_DLED_CLOCK |= PIN_DLED_CLOCK;
42 v <<= 1; 49 v <<= 1;
43 } 50 }
44 } 51 }
45 // Set CLOCK output low 52 // Set CLOCK output low
46 - PORT_DLED &= ~(1<<PIN_DLED_CLOCK); 53 + PORT_DLED_CLOCK &= ~PIN_DLED_CLOCK;
47 54
48 // Set LATCH output high 55 // Set LATCH output high
49 - PORT_DLED |= (1<<PIN_DLED_LATCH); 56 + PORT_DLED_LATCH |= PIN_DLED_LATCH;
50 // Set LATCH output low 57 // Set LATCH output low
51 - PORT_DLED &= ~(1<<PIN_DLED_LATCH); 58 + PORT_DLED_LATCH &= ~PIN_DLED_LATCH;
52 } 59 }
tests/atmega2560/ledControl/tlc5947.h
1 #ifndef TLC5947 1 #ifndef TLC5947
2 #define TLC5947 2 #define TLC5947
3 3
  4 +#define DLED_CHANNELS 24
  5 +
4 void init_LED_Drivers(int nb); 6 void init_LED_Drivers(int nb);
5 void set_LED_Drivers(unsigned int pwm[], int nb); 7 void set_LED_Drivers(unsigned int pwm[], int nb);
6 8