diff --git a/Logiciel/Firmware_testeur/Drivers/sept_segments.c b/Logiciel/Firmware_testeur/Drivers/sept_segments.c index dbb202460fa293d5ee165576f7bf86ef408f07ff..3f519f8e1e787ab1af0d48c9d8a4b316c7f169b0 100644 --- a/Logiciel/Firmware_testeur/Drivers/sept_segments.c +++ b/Logiciel/Firmware_testeur/Drivers/sept_segments.c @@ -6,6 +6,115 @@ */ #include "sept_segments.h" +#include <stddef.h> + +SeptSegment_Etat* charEnSegments(unsigned char caractere) { + static SeptSegment_Etat config[N_SEGMENTS]; + + switch(caractere) { + case '0': + config[SEG_A] = SEGMENT_ALLUME; + config[SEG_B] = SEGMENT_ALLUME; + config[SEG_C] = SEGMENT_ALLUME; + config[SEG_D] = SEGMENT_ALLUME; + config[SEG_E] = SEGMENT_ALLUME; + config[SEG_F] = SEGMENT_ALLUME; + config[SEG_G] = SEGMENT_ETEINT; + return config; + case '1': + config[SEG_A] = SEGMENT_ETEINT; + config[SEG_B] = SEGMENT_ALLUME; + config[SEG_C] = SEGMENT_ALLUME; + config[SEG_D] = SEGMENT_ETEINT; + config[SEG_E] = SEGMENT_ETEINT; + config[SEG_F] = SEGMENT_ETEINT; + config[SEG_G] = SEGMENT_ETEINT; + return config; + case '2': + config[SEG_A] = SEGMENT_ALLUME; + config[SEG_B] = SEGMENT_ALLUME; + config[SEG_C] = SEGMENT_ETEINT; + config[SEG_D] = SEGMENT_ALLUME; + config[SEG_E] = SEGMENT_ALLUME; + config[SEG_F] = SEGMENT_ETEINT; + config[SEG_G] = SEGMENT_ALLUME; + return config; + case '3': + config[SEG_A] = SEGMENT_ALLUME; + config[SEG_B] = SEGMENT_ALLUME; + config[SEG_C] = SEGMENT_ALLUME; + config[SEG_D] = SEGMENT_ALLUME; + config[SEG_E] = SEGMENT_ETEINT; + config[SEG_F] = SEGMENT_ETEINT; + config[SEG_G] = SEGMENT_ALLUME; + return config; + case '4': + config[SEG_A] = SEGMENT_ETEINT; + config[SEG_B] = SEGMENT_ALLUME; + config[SEG_C] = SEGMENT_ALLUME; + config[SEG_D] = SEGMENT_ETEINT; + config[SEG_E] = SEGMENT_ETEINT; + config[SEG_F] = SEGMENT_ALLUME; + config[SEG_G] = SEGMENT_ALLUME; + return config; + case '5': + config[SEG_A] = SEGMENT_ALLUME; + config[SEG_B] = SEGMENT_ETEINT; + config[SEG_C] = SEGMENT_ALLUME; + config[SEG_D] = SEGMENT_ALLUME; + config[SEG_E] = SEGMENT_ETEINT; + config[SEG_F] = SEGMENT_ALLUME; + config[SEG_G] = SEGMENT_ALLUME; + return config; + case '6': + config[SEG_A] = SEGMENT_ALLUME; + config[SEG_B] = SEGMENT_ETEINT; + config[SEG_C] = SEGMENT_ALLUME; + config[SEG_D] = SEGMENT_ALLUME; + config[SEG_E] = SEGMENT_ALLUME; + config[SEG_F] = SEGMENT_ALLUME; + config[SEG_G] = SEGMENT_ALLUME; + return config; + case '7': + config[SEG_A] = SEGMENT_ALLUME; + config[SEG_B] = SEGMENT_ALLUME; + config[SEG_C] = SEGMENT_ALLUME; + config[SEG_D] = SEGMENT_ETEINT; + config[SEG_E] = SEGMENT_ETEINT; + config[SEG_F] = SEGMENT_ALLUME; + config[SEG_G] = SEGMENT_ETEINT; + return config; + case '8': + config[SEG_A] = SEGMENT_ALLUME; + config[SEG_B] = SEGMENT_ALLUME; + config[SEG_C] = SEGMENT_ALLUME; + config[SEG_D] = SEGMENT_ALLUME; + config[SEG_E] = SEGMENT_ALLUME; + config[SEG_F] = SEGMENT_ALLUME; + config[SEG_G] = SEGMENT_ALLUME; + return config; + case '9': + config[SEG_A] = SEGMENT_ALLUME; + config[SEG_B] = SEGMENT_ALLUME; + config[SEG_C] = SEGMENT_ALLUME; + config[SEG_D] = SEGMENT_ALLUME; + config[SEG_E] = SEGMENT_ETEINT; + config[SEG_F] = SEGMENT_ALLUME; + config[SEG_G] = SEGMENT_ALLUME; + return config; + case '-': + config[SEG_A] = SEGMENT_ETEINT; + config[SEG_B] = SEGMENT_ETEINT; + config[SEG_C] = SEGMENT_ETEINT; + config[SEG_D] = SEGMENT_ETEINT; + config[SEG_E] = SEGMENT_ETEINT; + config[SEG_F] = SEGMENT_ETEINT; + config[SEG_G] = SEGMENT_ALLUME; + return config; + default: + return NULL; + } +} void SeptSegment_init (SeptSegment* ecran, SeptSegment_allumerSegment_ptr allumerSegments) { for (int i=0 ; i<N_SEGMENTS ; i++) { @@ -15,118 +124,16 @@ void SeptSegment_init (SeptSegment* ecran, SeptSegment_allumerSegment_ptr al // Affichage de caractères -void SeptSegment_afficher0 (SeptSegment* ecran) { - SeptSegment_allumerA(ecran, SEGMENT_ALLUME); - SeptSegment_allumerB(ecran, SEGMENT_ALLUME); - SeptSegment_allumerC(ecran, SEGMENT_ALLUME); - SeptSegment_allumerD(ecran, SEGMENT_ALLUME); - SeptSegment_allumerE(ecran, SEGMENT_ALLUME); - SeptSegment_allumerF(ecran, SEGMENT_ALLUME); - SeptSegment_allumerG(ecran, SEGMENT_ETEINT); -} - -void SeptSegment_afficher1 (SeptSegment* ecran) { - SeptSegment_allumerA(ecran, SEGMENT_ETEINT); - SeptSegment_allumerB(ecran, SEGMENT_ALLUME); - SeptSegment_allumerC(ecran, SEGMENT_ALLUME); - SeptSegment_allumerD(ecran, SEGMENT_ETEINT); - SeptSegment_allumerE(ecran, SEGMENT_ETEINT); - SeptSegment_allumerF(ecran, SEGMENT_ETEINT); - SeptSegment_allumerG(ecran, SEGMENT_ETEINT); -} - -void SeptSegment_afficher2 (SeptSegment* ecran) { - SeptSegment_allumerA(ecran, SEGMENT_ALLUME); - SeptSegment_allumerB(ecran, SEGMENT_ALLUME); - SeptSegment_allumerC(ecran, SEGMENT_ETEINT); - SeptSegment_allumerD(ecran, SEGMENT_ALLUME); - SeptSegment_allumerE(ecran, SEGMENT_ALLUME); - SeptSegment_allumerF(ecran, SEGMENT_ETEINT); - SeptSegment_allumerG(ecran, SEGMENT_ALLUME); - -} +void SeptSegment_afficher (SeptSegment* ecran, unsigned char caractere) { + SeptSegment_Etat* segmentsAAllumer = charEnSegments(caractere); -void SeptSegment_afficher3 (SeptSegment* ecran) { - SeptSegment_allumerA(ecran, SEGMENT_ALLUME); - SeptSegment_allumerB(ecran, SEGMENT_ALLUME); - SeptSegment_allumerC(ecran, SEGMENT_ALLUME); - SeptSegment_allumerD(ecran, SEGMENT_ALLUME); - SeptSegment_allumerE(ecran, SEGMENT_ETEINT); - SeptSegment_allumerF(ecran, SEGMENT_ETEINT); - SeptSegment_allumerG(ecran, SEGMENT_ALLUME); - -} - -void SeptSegment_afficher4 (SeptSegment* ecran) { - SeptSegment_allumerA(ecran, SEGMENT_ETEINT); - SeptSegment_allumerB(ecran, SEGMENT_ALLUME); - SeptSegment_allumerC(ecran, SEGMENT_ALLUME); - SeptSegment_allumerD(ecran, SEGMENT_ETEINT); - SeptSegment_allumerE(ecran, SEGMENT_ETEINT); - SeptSegment_allumerF(ecran, SEGMENT_ALLUME); - SeptSegment_allumerG(ecran, SEGMENT_ALLUME); - -} - -void SeptSegment_afficher5 (SeptSegment* ecran) { - SeptSegment_allumerA(ecran, SEGMENT_ALLUME); - SeptSegment_allumerB(ecran, SEGMENT_ETEINT); - SeptSegment_allumerC(ecran, SEGMENT_ALLUME); - SeptSegment_allumerD(ecran, SEGMENT_ALLUME); - SeptSegment_allumerE(ecran, SEGMENT_ETEINT); - SeptSegment_allumerF(ecran, SEGMENT_ALLUME); - SeptSegment_allumerG(ecran, SEGMENT_ALLUME); -} - - -void SeptSegment_afficher6 (SeptSegment* ecran) { - SeptSegment_allumerA(ecran, SEGMENT_ALLUME); - SeptSegment_allumerB(ecran, SEGMENT_ETEINT); - SeptSegment_allumerC(ecran, SEGMENT_ALLUME); - SeptSegment_allumerD(ecran, SEGMENT_ALLUME); - SeptSegment_allumerE(ecran, SEGMENT_ALLUME); - SeptSegment_allumerF(ecran, SEGMENT_ALLUME); - SeptSegment_allumerG(ecran, SEGMENT_ALLUME); -} - -void SeptSegment_afficher7 (SeptSegment* ecran) { - SeptSegment_allumerA(ecran, SEGMENT_ALLUME); - SeptSegment_allumerB(ecran, SEGMENT_ALLUME); - SeptSegment_allumerC(ecran, SEGMENT_ALLUME); - SeptSegment_allumerD(ecran, SEGMENT_ETEINT); - SeptSegment_allumerE(ecran, SEGMENT_ETEINT); - SeptSegment_allumerF(ecran, SEGMENT_ALLUME); - SeptSegment_allumerG(ecran, SEGMENT_ETEINT); -} - -void SeptSegment_afficher8 (SeptSegment* ecran) { - SeptSegment_allumerA(ecran, SEGMENT_ALLUME); - SeptSegment_allumerB(ecran, SEGMENT_ALLUME); - SeptSegment_allumerC(ecran, SEGMENT_ALLUME); - SeptSegment_allumerD(ecran, SEGMENT_ALLUME); - SeptSegment_allumerE(ecran, SEGMENT_ALLUME); - SeptSegment_allumerF(ecran, SEGMENT_ALLUME); - SeptSegment_allumerG(ecran, SEGMENT_ALLUME); -} - -void SeptSegment_afficher9 (SeptSegment* ecran) { - SeptSegment_allumerA(ecran, SEGMENT_ALLUME); - SeptSegment_allumerB(ecran, SEGMENT_ALLUME); - SeptSegment_allumerC(ecran, SEGMENT_ALLUME); - SeptSegment_allumerD(ecran, SEGMENT_ALLUME); - SeptSegment_allumerE(ecran, SEGMENT_ETEINT); - SeptSegment_allumerF(ecran, SEGMENT_ALLUME); - SeptSegment_allumerG(ecran, SEGMENT_ALLUME); -} - -void SeptSegment_afficherTiret (SeptSegment* ecran) { - SeptSegment_allumerA(ecran, SEGMENT_ETEINT); - SeptSegment_allumerB(ecran, SEGMENT_ETEINT); - SeptSegment_allumerC(ecran, SEGMENT_ETEINT); - SeptSegment_allumerD(ecran, SEGMENT_ETEINT); - SeptSegment_allumerE(ecran, SEGMENT_ETEINT); - SeptSegment_allumerF(ecran, SEGMENT_ETEINT); - SeptSegment_allumerG(ecran, SEGMENT_ALLUME); + SeptSegment_allumerA(ecran, segmentsAAllumer[SEG_A]); + SeptSegment_allumerB(ecran, segmentsAAllumer[SEG_B]); + SeptSegment_allumerC(ecran, segmentsAAllumer[SEG_C]); + SeptSegment_allumerD(ecran, segmentsAAllumer[SEG_D]); + SeptSegment_allumerE(ecran, segmentsAAllumer[SEG_E]); + SeptSegment_allumerF(ecran, segmentsAAllumer[SEG_F]); + SeptSegment_allumerG(ecran, segmentsAAllumer[SEG_G]); } void SeptSegment_eteindre(SeptSegment* ecran) { diff --git a/Logiciel/Firmware_testeur/Drivers/sept_segments.h b/Logiciel/Firmware_testeur/Drivers/sept_segments.h index a2574954a65f6357c8b5c87d4c70ad06270d6ee8..8340f48c16d11595fda97f984d3a11fa1a1accb5 100644 --- a/Logiciel/Firmware_testeur/Drivers/sept_segments.h +++ b/Logiciel/Firmware_testeur/Drivers/sept_segments.h @@ -33,18 +33,8 @@ void SeptSegment_init (SeptSegment* ecran, SeptSegment_allumerSegment_ptr al // Affichage de caractères -void SeptSegment_afficher0 (SeptSegment* ecran); -void SeptSegment_afficher1 (SeptSegment* ecran); -void SeptSegment_afficher2 (SeptSegment* ecran); -void SeptSegment_afficher3 (SeptSegment* ecran); -void SeptSegment_afficher4 (SeptSegment* ecran); -void SeptSegment_afficher5 (SeptSegment* ecran); -void SeptSegment_afficher6 (SeptSegment* ecran); -void SeptSegment_afficher7 (SeptSegment* ecran); -void SeptSegment_afficher8 (SeptSegment* ecran); -void SeptSegment_afficher9 (SeptSegment* ecran); -void SeptSegment_afficherTiret (SeptSegment* ecran); -void SeptSegment_eteindre (SeptSegment* ecran); +void SeptSegment_afficher (SeptSegment* ecran, unsigned char caractere); +void SeptSegment_eteindre (SeptSegment* ecran); // Contrôle des segments individuels diff --git a/Logiciel/Firmware_testeur/Drivers/sept_segments_port_stm32f071v8.c b/Logiciel/Firmware_testeur/Drivers/sept_segments_port_stm32f071v8.c index ab551a78cc72f3e83e3a63748d24877ed6ac7a6f..89bbd7ea5540bfdbaccfb7cbb72517d95036c746 100644 --- a/Logiciel/Firmware_testeur/Drivers/sept_segments_port_stm32f071v8.c +++ b/Logiciel/Firmware_testeur/Drivers/sept_segments_port_stm32f071v8.c @@ -35,9 +35,14 @@ void SeptSegment_Port_init (SeptSegment_Port* ecran, (void*) SeptSegment_Port_allumerG }; SeptSegment_init(&base, allumerPort); + //FIXME: La mémoire d'écran est pas allouée donc ça plante aux trois lignes suivantes: ecran->base_ = base; memcpy(ecran->ports_, ports, N_SEGMENTS*sizeof(*ports)); - memcpy(ecran->broches_, ports, N_SEGMENTS*sizeof(*broches)); + memcpy(ecran->broches_, broches, N_SEGMENTS*sizeof(*broches)); +} + +void SeptSegment_Port_afficher (SeptSegment_Port* ecran, unsigned char caractere) { + SeptSegment_afficher(&(ecran->base_), caractere); } void SeptSegment_Port_allumerA (SeptSegment_Port* ecran, SeptSegment_Etat etat) { diff --git a/Logiciel/Firmware_testeur/Drivers/sept_segments_port_stm32f071v8.h b/Logiciel/Firmware_testeur/Drivers/sept_segments_port_stm32f071v8.h index 4ceb0403b807ede40a48cf3d51872a59bfad1d94..ef5e92f6482e54c3eca9beae4944e9ed9b4cae5c 100644 --- a/Logiciel/Firmware_testeur/Drivers/sept_segments_port_stm32f071v8.h +++ b/Logiciel/Firmware_testeur/Drivers/sept_segments_port_stm32f071v8.h @@ -13,11 +13,14 @@ typedef struct { SeptSegment base_; - GPIO_TypeDef* ports_[N_SEGMENTS]; + GPIO_TypeDef* ports_[N_SEGMENTS]; uint16_t broches_[N_SEGMENTS]; } SeptSegment_Port; void SeptSegment_Port_init (SeptSegment_Port* ecran, GPIO_TypeDef** ports, uint16_t* broches); + +void SeptSegment_Port_afficher (SeptSegment_Port* ecran, unsigned char caractere); + void SeptSegment_Port_allumerA (SeptSegment_Port* ecran, SeptSegment_Etat etat); void SeptSegment_Port_allumerB (SeptSegment_Port* ecran, SeptSegment_Etat etat); void SeptSegment_Port_allumerC (SeptSegment_Port* ecran, SeptSegment_Etat etat); diff --git a/Logiciel/Firmware_testeur/Drivers/testeur.c b/Logiciel/Firmware_testeur/Drivers/testeur.c index 51e7705287d0851e25b1103a18797b2f70afd04c..5ece048ff5c2082c22ef44bc9358daa42a26850f 100644 --- a/Logiciel/Firmware_testeur/Drivers/testeur.c +++ b/Logiciel/Firmware_testeur/Drivers/testeur.c @@ -32,7 +32,7 @@ void Testeur_init (Testeur* testeur) { testeur->ethernetA_ = &connecteurA; testeur->ethernetB_ = &connecteurB; - SeptSegment_Port* ecrans[N_ECRANS]; + SeptSegment_Port ecrans[N_ECRANS]; // Liste des ports GPIO utilisés par l'ensemble des écrans GPIO_TypeDef* ports_segments[N_ECRANS][N_SEGMENTS] = { @@ -109,14 +109,29 @@ void Testeur_init (Testeur* testeur) { }; for (int i=0; i<N_ECRANS; i++) { - SeptSegment_Port_init(ecrans[i], ports_segments[i], broches_segments[i]); + SeptSegment_Port_init(&(ecrans[i]), ports_segments[i], broches_segments[i]); } memcpy(testeur->ecrans_, ecrans, N_ECRANS*sizeof(SeptSegment_Port)); } +void Testeur_reglerAlim2V (Testeur* testeur, GPIO_PinState allumeOuEteint) { + +} + +void Testeur_allumerAlim2V (Testeur* testeur) { + HAL_GPIO_WritePin(EN_2V_GPIO_Port, EN_2V_Pin, GPIO_PIN_SET); +} + +void Testeur_eteindreAlim2V (Testeur* testeur) { + HAL_GPIO_WritePin(EN_2V_GPIO_Port, EN_2V_Pin, GPIO_PIN_RESET); +} + void Testeur_testerCable (Testeur* testeur) { - for (int i=0; i<N_ECRANS; i++) { - SeptSegment_afficher0(testeur->ecrans_[i]); + for (int i=0; i<=9; i++) { + for (int j=0; j<N_ECRANS; j++) { + SeptSegment_Port_afficher(&(testeur->ecrans_[j]), i + '0'); + } + HAL_Delay(500); } } diff --git a/Logiciel/Firmware_testeur/Drivers/testeur.h b/Logiciel/Firmware_testeur/Drivers/testeur.h index d0247a1e91bd7e21fd6019dd493ce2c8095deb85..d85af8621466475bbaacbdea54c5a968b009fc01 100644 --- a/Logiciel/Firmware_testeur/Drivers/testeur.h +++ b/Logiciel/Firmware_testeur/Drivers/testeur.h @@ -20,12 +20,14 @@ typedef struct { RJ45_Entree_Port* ethernetB_; // TODO: Implémenter les classes SeptSegments et Alim2V - SeptSegment ecrans_[N_ECRANS]; + SeptSegment_Port ecrans_[N_ECRANS]; // Alim2V alimentation2V_; } Testeur; // Fonctions publiques void Testeur_init (Testeur* testeur); +void Testeur_allumerAlim2V (Testeur* testeur); +void Testeur_eteindreAlim2V (Testeur* testeur); void Testeur_testerCable (Testeur* testeur); #endif /* TESTEUR_H_ */ diff --git a/Logiciel/Firmware_testeur/Src/main.c b/Logiciel/Firmware_testeur/Src/main.c index 6bee18c88f93c8db8808e4c0e8e34ef678e6ed12..3baf72989415a881d4f38689d69b914e74e30c3e 100644 --- a/Logiciel/Firmware_testeur/Src/main.c +++ b/Logiciel/Firmware_testeur/Src/main.c @@ -89,6 +89,7 @@ int main(void) MX_GPIO_Init(); /* USER CODE BEGIN 2 */ Testeur_init(&testeur); + Testeur_allumerAlim2V(&testeur); /* USER CODE END 2 */ /* Infinite loop */ @@ -96,7 +97,7 @@ int main(void) while (1) { /* USER CODE END WHILE */ - + Testeur_testerCable(&testeur); /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */