Divers
This commit is contained in:
parent
90abb7559c
commit
be8b544963
5 changed files with 56 additions and 46 deletions
|
|
@ -45,10 +45,14 @@
|
||||||
#
|
#
|
||||||
# $Id$
|
# $Id$
|
||||||
|
|
||||||
|
#Bootloader Port
|
||||||
PORT = /dev/serial/by-id/usb-Arduino_LLC_Arduino_Micro-if00
|
PORT = /dev/serial/by-id/usb-Arduino_LLC_Arduino_Micro-if00
|
||||||
|
#Device Port (for autoreset)
|
||||||
RESETPORT = /dev/serial/by-id/usb-Loupiottes_DMXv3_Micro-if00
|
RESETPORT = /dev/serial/by-id/usb-Loupiottes_DMXv3_Micro-if00
|
||||||
|
|
||||||
|
|
||||||
TARGET = dmx512_micro
|
TARGET = dmx512_micro
|
||||||
SRC = lib/wiring.c lib/wiring_analog.c lib/wiring_digital.c
|
SRC = lib/wiring.c lib/wiring_digital.c
|
||||||
CXXSRC = dmx512_micro.cpp lib/CDC.cpp lib/USBCore.cpp
|
CXXSRC = dmx512_micro.cpp lib/CDC.cpp lib/USBCore.cpp
|
||||||
MCU = atmega32u4
|
MCU = atmega32u4
|
||||||
F_CPU = 16000000L
|
F_CPU = 16000000L
|
||||||
|
|
@ -137,7 +141,8 @@ upload: $(TARGET).hex $(TARGET).eep
|
||||||
python ./reset_and_wait.py $(RESETPORT) $(PORT)
|
python ./reset_and_wait.py $(RESETPORT) $(PORT)
|
||||||
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
|
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
|
||||||
|
|
||||||
|
manualupload: $(TARGET).hex $(TARGET).eep
|
||||||
|
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
|
||||||
|
|
||||||
|
|
||||||
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
|
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ int main(void)
|
||||||
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
|
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// déclaration des tableaux de données
|
// déclaration des tableaux de données
|
||||||
byte tab_input_pc[514]; // venant du pc
|
byte tab_input_pc[514]; // venant du pc
|
||||||
byte tab_input_dmx[518]; // données venant de l'extérieur : les 512 premiers DMX; les 4 suivant 4x8 bp ;
|
byte tab_input_dmx[518]; // données venant de l'extérieur : les 512 premiers DMX; les 4 suivant 4x8 bp ;
|
||||||
|
|
@ -38,16 +39,19 @@ volatile int index_input_dmx=513; // entrée dmx
|
||||||
volatile int index_output_dmx=0; //sortie dmx -2 en attente de fin de transmission; -1 break; 0 à 512 transmission
|
volatile int index_output_dmx=0; //sortie dmx -2 en attente de fin de transmission; -1 break; 0 à 512 transmission
|
||||||
|
|
||||||
volatile int etat_input_pc=0; // 0 raz ; 1 esc reçu ; 2 D reçu : pret à recevoir ; 3 prèt à emmetre
|
volatile int etat_input_pc=0; // 0 raz ; 1 esc reçu ; 2 D reçu : pret à recevoir ; 3 prèt à emmetre
|
||||||
volatile int start_code_rec=-1;
|
|
||||||
|
int tx1pin = 1; // pin DMX serial 1
|
||||||
|
|
||||||
int ledPin = 13; // led interne
|
int ledPin = 13; // led interne
|
||||||
int tx1pin = 1; // pin DMX serial 1
|
unsigned int blkl = 0, blkcpt=0;
|
||||||
|
volatile bool dmx_rx=0;
|
||||||
|
volatile bool pc_rx=0;
|
||||||
|
|
||||||
byte brk_timer_end=75; // def : 150us
|
byte brk_timer_end=75; // def : 150us
|
||||||
byte mab_timer_end=25; //def : 50us
|
byte mab_timer_end=25; //def : 50us
|
||||||
int nb_circuits=512;
|
int nb_circuits=512;
|
||||||
int flag_merge1=1;
|
int flag_merge1=1;
|
||||||
volatile int emissionPc=0;
|
volatile bool emissionPc=0;
|
||||||
|
|
||||||
// Fonctions
|
// Fonctions
|
||||||
|
|
||||||
|
|
@ -55,12 +59,6 @@ void litUSB(char c);
|
||||||
void ecritUSB();
|
void ecritUSB();
|
||||||
void CDC_accept();
|
void CDC_accept();
|
||||||
|
|
||||||
|
|
||||||
/* ------------ Gestion Liaison USB -------------- */
|
|
||||||
/* On a surcharge tout ca pour optimiser les temps de transfert */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// lancé par interruption USB sur reception d'un char <- Cette fonction nécessite une modif de la lib arduino
|
// lancé par interruption USB sur reception d'un char <- Cette fonction nécessite une modif de la lib arduino
|
||||||
// l'interet est de ne pas utiliser le buffer de la classe Serial, trop petit (64o)
|
// l'interet est de ne pas utiliser le buffer de la classe Serial, trop petit (64o)
|
||||||
void CDC_accept()
|
void CDC_accept()
|
||||||
|
|
@ -69,8 +67,6 @@ void CDC_accept()
|
||||||
litUSB(c);
|
litUSB(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------ Fin Gestion Liaison USB -------------- */
|
|
||||||
|
|
||||||
// lecture d'un caractere sur USB
|
// lecture d'un caractere sur USB
|
||||||
void litUSB(char c)
|
void litUSB(char c)
|
||||||
{
|
{
|
||||||
|
|
@ -120,7 +116,6 @@ void litUSB(char c)
|
||||||
tab_input_dmx[517]=65;
|
tab_input_dmx[517]=65;
|
||||||
index_output_pc=517; // on init l'index d'emmission vers le pc ( uniquement etat : 65 'A' )
|
index_output_pc=517; // on init l'index d'emmission vers le pc ( uniquement etat : 65 'A' )
|
||||||
emissionPc=1;
|
emissionPc=1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// si aucune commande n'est trouvée (toujours à 1) on repart à 0
|
// si aucune commande n'est trouvée (toujours à 1) on repart à 0
|
||||||
|
|
@ -133,10 +128,8 @@ void litUSB(char c)
|
||||||
index_input_pc++;
|
index_input_pc++;
|
||||||
// si on arrive à 512
|
// si on arrive à 512
|
||||||
if (index_input_pc > 512) {// on se prépare à emmetre vers le pc
|
if (index_input_pc > 512) {// on se prépare à emmetre vers le pc
|
||||||
|
pc_rx=1;
|
||||||
etat_input_pc=0;
|
etat_input_pc=0;
|
||||||
digitalWrite(ledPin, HIGH);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -193,10 +186,11 @@ ISR(USART1_RX_vect)
|
||||||
char c,r;
|
char c,r;
|
||||||
r = UCSR1A;
|
r = UCSR1A;
|
||||||
c = UDR1;
|
c = UDR1;
|
||||||
if (r & (1<<FE1)) {index_input_dmx=0;return;}
|
if (r & (1<<FE1)) {index_input_dmx=0;return; dmx_rx=false;;}
|
||||||
if ( index_input_dmx==0 && c!=0 ) {index_input_dmx=513; }
|
if ( index_input_dmx==0 && c!=0 ) {index_input_dmx=513; dmx_rx=false;; }
|
||||||
if ( index_input_dmx<=512 )
|
if ( index_input_dmx<=512 )
|
||||||
{
|
{
|
||||||
|
dmx_rx=true;;
|
||||||
tab_input_dmx[index_input_dmx]=c;
|
tab_input_dmx[index_input_dmx]=c;
|
||||||
index_input_dmx++;
|
index_input_dmx++;
|
||||||
}
|
}
|
||||||
|
|
@ -209,9 +203,9 @@ ISR(USART1_RX_vect)
|
||||||
ISR(USART1_TX_vect)
|
ISR(USART1_TX_vect)
|
||||||
{
|
{
|
||||||
// si l'USART 1 est vide => break
|
// si l'USART 1 est vide => break
|
||||||
if(index_output_dmx==-4)
|
if(index_output_dmx==-4){
|
||||||
index_output_dmx=-1;
|
index_output_dmx=-1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// vecteur : USART 1 transmission registre vide
|
// vecteur : USART 1 transmission registre vide
|
||||||
ISR(USART1_UDRE_vect)
|
ISR(USART1_UDRE_vect)
|
||||||
|
|
@ -229,7 +223,7 @@ ISR(USART1_UDRE_vect)
|
||||||
|
|
||||||
ISR(TIMER4_COMPA_vect) {
|
ISR(TIMER4_COMPA_vect) {
|
||||||
if (index_output_dmx==-2 ) {
|
if (index_output_dmx==-2 ) {
|
||||||
digitalWrite(tx1pin, HIGH); // on met la broche 18 à 1 pendant 10 µs
|
digitalWrite(tx1pin, HIGH); // on met la broche à 1
|
||||||
|
|
||||||
index_output_dmx=-3;
|
index_output_dmx=-3;
|
||||||
OCR4A = mab_timer_end ;
|
OCR4A = mab_timer_end ;
|
||||||
|
|
@ -241,7 +235,6 @@ ISR(TIMER4_COMPA_vect) {
|
||||||
sbi(UCSR1B, TXEN1); // on redémarre la transmission
|
sbi(UCSR1B, TXEN1); // on redémarre la transmission
|
||||||
index_output_dmx=0; // on se prépare à émmettre à partir du stat code ( 513 octets )
|
index_output_dmx=0; // on se prépare à émmettre à partir du stat code ( 513 octets )
|
||||||
sbi(UCSR1B, UDRIE1); // on réactive l'intéruption du registre
|
sbi(UCSR1B, UDRIE1); // on réactive l'intéruption du registre
|
||||||
//digitalWrite(ledPin, HIGH);
|
|
||||||
TIMSK4= 0 ; //desactivation intéruption A &B
|
TIMSK4= 0 ; //desactivation intéruption A &B
|
||||||
TCCR4B = 0;
|
TCCR4B = 0;
|
||||||
}
|
}
|
||||||
|
|
@ -289,19 +282,19 @@ void setup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// génération du break en tache principale
|
// lancement du break
|
||||||
int cpt = 0;
|
|
||||||
if (index_output_dmx==-1 ) {
|
if (index_output_dmx==-1 ) {
|
||||||
index_output_dmx=-2;
|
index_output_dmx=-2;
|
||||||
pinMode(tx1pin, OUTPUT); // on met la broche 18 en mode sortie
|
pinMode(tx1pin, OUTPUT); // on met la broche en mode sortie
|
||||||
cbi(UCSR1B, TXEN1); //on stop la transmission
|
cbi(UCSR1B, TXEN1); //on stop la transmission
|
||||||
digitalWrite(tx1pin, LOW); // on met la broche 18 à 0
|
digitalWrite(tx1pin, LOW); // on met la broche à 0
|
||||||
OCR4A = brk_timer_end ; // val 120 µs
|
OCR4A = brk_timer_end ; // val 120 µs
|
||||||
TCNT4 = 0 ;// RAZ compteur timer
|
TCNT4 = 0 ;// RAZ compteur timer
|
||||||
TIFR4 = 0 ; //Clear Flags timer
|
TIFR4 = 0 ; //Clear Flags timer
|
||||||
TIMSK4 = 64 ; //activation intéruption A &B
|
TIMSK4 = 64 ; //activation intéruption A &B
|
||||||
TCCR4B = 6; // 00000011 division par 32 de l'horloge base => 2µs
|
TCCR4B = 6; // 00000110 division par 32 de l'horloge base => 2µs
|
||||||
} // fin du break
|
dmx_rx=false;
|
||||||
|
}
|
||||||
|
|
||||||
// octets d'état. Pour le moment, tous à 0
|
// octets d'état. Pour le moment, tous à 0
|
||||||
tab_input_dmx[513]= 0;
|
tab_input_dmx[513]= 0;
|
||||||
|
|
@ -314,11 +307,19 @@ void loop() {
|
||||||
ecritUSB();
|
ecritUSB();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Si port fermé : on eteint la LED
|
pc_rx=0;
|
||||||
digitalWrite(ledPin, LOW);
|
|
||||||
// et on réinitialise l'état d'entrée USB
|
|
||||||
etat_input_pc=0;
|
etat_input_pc=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clignotement de la led a vitesse variable en fonction de l'etat
|
||||||
|
int blinkon = 15, blinkp=16;
|
||||||
|
if(pc_rx) blinkp=5, blinkon=4;
|
||||||
|
if(dmx_rx) blinkon=1;
|
||||||
|
|
||||||
|
int m = millis()>>6;
|
||||||
|
if (m-blkl) { blkcpt++; blkl = m;}
|
||||||
|
if(blkcpt>=blinkon) { digitalWrite(ledPin, HIGH); }
|
||||||
|
if(blkcpt>=blinkp){ digitalWrite(ledPin, LOW); blkcpt=0; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ typedef struct
|
||||||
u8 lineState;
|
u8 lineState;
|
||||||
} LineInfo;
|
} LineInfo;
|
||||||
*/
|
*/
|
||||||
extern LineInfo _usbLineInfo = { 57600, 0x00, 0x00, 0x00, 0x00 };
|
LineInfo _usbLineInfo = { 57600, 0x00, 0x00, 0x00, 0x00 };
|
||||||
|
|
||||||
#define WEAK __attribute__ ((weak))
|
#define WEAK __attribute__ ((weak))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,18 @@
|
||||||
|
|
||||||
/** Pulse generation counters to keep track of the number of milliseconds remaining for each pulse type */
|
/** Pulse generation counters to keep track of the number of milliseconds remaining for each pulse type */
|
||||||
#define TX_RX_LED_PULSE_MS 10
|
#define TX_RX_LED_PULSE_MS 10
|
||||||
|
|
||||||
|
/*
|
||||||
|
#undef TXLED1
|
||||||
|
#undef TXLED0
|
||||||
|
#undef RXLED1
|
||||||
|
#undef RXLED0
|
||||||
|
#define TXLED1
|
||||||
|
#define TXLED0
|
||||||
|
#define RXLED1
|
||||||
|
#define RXLED0
|
||||||
|
*/
|
||||||
|
|
||||||
volatile u8 TxLEDPulse; /**< Milliseconds remaining for data Tx LED pulse */
|
volatile u8 TxLEDPulse; /**< Milliseconds remaining for data Tx LED pulse */
|
||||||
volatile u8 RxLEDPulse; /**< Milliseconds remaining for data Rx LED pulse */
|
volatile u8 RxLEDPulse; /**< Milliseconds remaining for data Rx LED pulse */
|
||||||
|
|
||||||
|
|
@ -51,20 +63,12 @@ const u16 STRING_LANGUAGE[2] = {
|
||||||
|
|
||||||
const u16 STRING_IPRODUCT[13] = {
|
const u16 STRING_IPRODUCT[13] = {
|
||||||
(3<<8) | (2+2*12),
|
(3<<8) | (2+2*12),
|
||||||
#if USB_PID == 0x8036
|
|
||||||
'D','M','X','v','3',' ','M','i','c','r','o'
|
'D','M','X','v','3',' ','M','i','c','r','o'
|
||||||
#else
|
|
||||||
'U','S','B',' ','I','O',' ','B','o','a','r','d',' ',' ',' ',' '
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const u16 STRING_IMANUFACTURER[11] = {
|
const u16 STRING_IMANUFACTURER[11] = {
|
||||||
(3<<8) | (2+2*10),
|
(3<<8) | (2+2*10),
|
||||||
#if USB_VID == 0x2341
|
|
||||||
'L','o','u','p','i','o','t','t','e','s'
|
'L','o','u','p','i','o','t','t','e','s'
|
||||||
#else
|
|
||||||
'U','n','k','n','o','w','n',' ',' ',' ',' '
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef CDC_ENABLED
|
#ifdef CDC_ENABLED
|
||||||
|
|
|
||||||
|
|
@ -67,13 +67,13 @@ SIGNAL(TIMER0_OVF_vect)
|
||||||
unsigned long millis()
|
unsigned long millis()
|
||||||
{
|
{
|
||||||
unsigned long m;
|
unsigned long m;
|
||||||
uint8_t oldSREG = SREG;
|
//uint8_t oldSREG = SREG;
|
||||||
|
|
||||||
// disable interrupts while we read timer0_millis or we might get an
|
// disable interrupts while we read timer0_millis or we might get an
|
||||||
// inconsistent value (e.g. in the middle of a write to timer0_millis)
|
// inconsistent value (e.g. in the middle of a write to timer0_millis)
|
||||||
cli();
|
//cli();
|
||||||
m = timer0_millis;
|
m = timer0_millis;
|
||||||
SREG = oldSREG;
|
//SREG = oldSREG;
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue