remy 4 سال پیش
والد
کامیت
87aa0f0cfe
6فایلهای تغییر یافته به همراه153 افزوده شده و 52 حذف شده
  1. 7 8
      Include/FIFO_COM.h
  2. 32 0
      Include/PCF8574.h
  3. 6 6
      Include/RTC.h
  4. 21 24
      Source/FIFO_COM.c
  5. 68 0
      Source/PCF8574.c
  6. 19 14
      Source/RTC.c

+ 7 - 8
Include/FIFO_COM.h

@@ -1,29 +1,28 @@
 #ifndef _FIFO_COM_H_
 #define _FIFO_COM_H_
 
+// ne fonctionne pas a ne pas utiliser
+
 #include <stdint.h>
 
-#define NBFIFO 128
+#define NBFIFO 16*8 //Toujours un multiple de 8
 
 typedef struct{
 	uint8_t Fifo[NBFIFO];
-
 	uint8_t pt_read;
-
 	uint8_t pt_write;
+	uint8_t nb_Element;
 }FIFO_COM;
 
 
 void initFIFO(FIFO_COM *f);
 
 /*
- * lit le premiere element de la fifo, n'avance pas le pointeur de Fifo
+ * lit dans la fifo (toujours 8 caractere)
  */
-uint8_t readFirst(FIFO_COM *f);
-
-void readFifo(FIFO_COM *f, uint8_t *r, uint8_t nb);
+void readFifo(FIFO_COM *f, uint8_t *r);
 
-void writeFifo(FIFO_COM *f, uint8_t *r, uint8_t nb);
+void writeFifo(FIFO_COM *f, uint8_t *r);
 
 /*
  * retourne le nombre d'element a lire dans la fifo

+ 32 - 0
Include/PCF8574.h

@@ -0,0 +1,32 @@
+#ifndef _PCF8474__H_
+#define _PCF8474__H_
+
+#include "i2c.h"
+#include <stdint.h>
+
+
+
+I2C_HandleTypeDef *I2C_PCF8574;
+
+/** Private Fonction*/
+HAL_StatusTypeDef read_I2C_PCF8574(uint8_t add, uint8_t *tab);
+
+HAL_StatusTypeDef write_I2C_PCF8574(uint8_t addresse, uint8_t *tab);
+/** Public Fonction*/
+
+void initPCF8574(I2C_HandleTypeDef *typ);
+
+/*
+ * PAram addBit : la valeurs des bit A1 A2 A3:
+ * 	0 0 0 = 0;
+ * 	0 0 1 = 1;
+ * 	0 1 0 = 2;
+ * 	...
+ */
+HAL_StatusTypeDef Read_PCF8574(uint8_t addBit, uint8_t* val);
+HAL_StatusTypeDef Write_PCF8574(uint8_t addBit,uint8_t val);
+HAL_StatusTypeDef Write_One_Bit_PCF8574(uint8_t addBit, uint8_t val, uint8_t Local);
+
+
+
+#endif

+ 6 - 6
Include/RTC.h

@@ -60,22 +60,22 @@ void writeRTC(uint8_t add, uint8_t *tab, int len){
 I2C_HandleTypeDef *I2C_RTC;
 
 /****Private fonction */
-void readRTC(uint8_t reg, uint8_t *tab, int len);
+HAL_StatusTypeDef readRTC(uint8_t reg, uint8_t *tab, int len);
 
-void writeRTC(uint8_t reg, uint8_t *tab, int len);
+HAL_StatusTypeDef writeRTC(uint8_t reg, uint8_t *tab, int len);
 
 /** Public Fonction*/
 void initRTC(I2C_HandleTypeDef *typ);
 
-void readHeure(Heure *heure);
+HAL_StatusTypeDef readHeure(Heure *heure);
 
 uint16_t HeureEnMinute();
 
-void readDate(Date *date);
+HAL_StatusTypeDef readDate(Date *date);
 
-void redemareRTC();
+HAL_StatusTypeDef redemareRTC();
 
-void writeDate(Date *date);
+HAL_StatusTypeDef writeDate(Date *date);
 
 /**
  * Fonction qui permet de tester le mat�riel

+ 21 - 24
Source/FIFO_COM.c

@@ -1,51 +1,48 @@
 /*
  * FIFO_COM.c
+
+
  *
  *  Created on: 14 mai 2019
  *      Author: e_rcluze
  */
 
-#include "FIFO_COM.h"
 
+// ne fonctionne pas a ne pas utiliser
+#include "FIFO_COM.h"
+/*
 void initFIFO(FIFO_COM *f){
 	f->pt_read = 0;
 	f->pt_write = 0;
+	f->nb_Element =0;
 }
 
-uint8_t readFirst(FIFO_COM *f) {
-	return f->Fifo[f->pt_read];
-}
-
-void readFifo(FIFO_COM *f, uint8_t *r, uint8_t nb) {
-	for (uint8_t i = 0; i < nb;i++) {
+void readFifo(FIFO_COM *f, uint8_t *r) {
+	for (uint8_t i = 0; i < 8 ; i++) {
 		if (f->pt_read + i >= NBFIFO)
 			r[i] = f->Fifo[f->pt_read + i - NBFIFO];
 		else
 			r[i] = f->Fifo[f->pt_read + i];
 	}
-	if (f->pt_read + nb >= NBFIFO)
-		f->pt_read = f->pt_read + nb - NBFIFO;
+	if (f->pt_read + 8 >= NBFIFO)
+		f->pt_read = f->pt_read + 8 - NBFIFO;
 	else
-		f->pt_read = f->pt_read + nb;
+		f->pt_read = f->pt_read + 8;
 }
 
-void writeFifo(FIFO_COM *f, uint8_t *r, uint8_t nb) {
+void writeFifo(FIFO_COM *f, uint8_t *r) {
 	uint8_t i;
-	for (i = 0; i < nb;i++) {
-		if (f->pt_write + i >= NBFIFO)
-			f->Fifo[f->pt_write + i - NBFIFO] = r[i];
-		else
-			f->Fifo[f->pt_write + i] = r[i];
+	uint8_t nb = FIFO_nbRead(f);
+
+	for (i = 0; i < 8;i++) {
+
 	}
-	if (f->pt_write + nb >= NBFIFO)
-		f->pt_write = f->pt_write + nb - NBFIFO;
+	if (f->pt_write + 8 >= NBFIFO)
+		f->pt_write = f->pt_write + 8 - NBFIFO;
 	else
-		f->pt_write = f->pt_write + nb;
+		f->pt_write = f->pt_write + nb*8;
 }
 
 uint8_t FIFO_nbRead(FIFO_COM *f) {
-	if (f->pt_read <= f->pt_write)
-		return f->pt_write - f->pt_read;
-	else
-		return f->pt_write + NBFIFO - f->pt_read;
-}
+	return f->nb_Element;
+}*/

+ 68 - 0
Source/PCF8574.c

@@ -0,0 +1,68 @@
+#include "PCF8574.h"
+/*
+ * Warning Warning
+ *
+ * Il existe 2 type de PCF8474 les  PCF8474A et les PCF8474.
+ * les PCF8474A on des adresse en 0x4X, les PCF8474 ont des adresse en 0x7X.
+ * La différence est faite dans partkeep dans ce projet j'ai utilisé des A
+ *
+ */
+
+uint8_t ADD_PCF8474[] = { 0x40, 0x42, 0x44, 0x46, 0x48, 0x4A, 0x4C, 0x4E };
+//uint8_t ADD_PCF8474[] = {0x70, 0x72, 0x74, 0x76, 0x78, 0x7A, 0x7C, 0x7E};
+
+/** Private Fonction*/
+HAL_StatusTypeDef read_I2C_PCF8574(uint8_t add, uint8_t *tab) {
+	HAL_StatusTypeDef res;
+	int nbTentative = 0;
+	while ((res = HAL_I2C_Master_Receive(I2C_PCF8574, add, tab, 1, 1000))!= HAL_OK) {
+		nbTentative++;
+		if (nbTentative > 3)
+			break;
+	}
+	return res;
+}
+
+HAL_StatusTypeDef write_I2C_PCF8574(uint8_t addresse, uint8_t *tab) {
+	HAL_StatusTypeDef res;
+	int nbTentative;
+	while ((res = HAL_I2C_Master_Transmit(I2C_PCF8574, addresse, tab, 1, 1000))!= HAL_OK) {
+		nbTentative++;
+		if (nbTentative > 3)
+			break;
+	}
+	return res;
+}
+
+/** Public Fonction*/
+
+void initPCF8574(I2C_HandleTypeDef *typ) {
+	I2C_PCF8574 = typ;
+	Write_PCF8574(0, 0);
+}
+
+HAL_StatusTypeDef Read_PCF8574(uint8_t addBit, uint8_t* val) {
+	return read_I2C_PCF8574(ADD_PCF8474[addBit], val);
+}
+
+HAL_StatusTypeDef Write_PCF8574(uint8_t addBit, uint8_t val) {
+	return write_I2C_PCF8574(ADD_PCF8474[addBit], &val);
+}
+
+HAL_StatusTypeDef Write_One_Bit_PCF8574(uint8_t addBit, uint8_t val, uint8_t Local) {
+	uint8_t valInt;
+	HAL_StatusTypeDef res;
+	res = read_I2C_PCF8574(ADD_PCF8474[addBit], &valInt);
+	if (res != HAL_OK)
+		return res;
+	if (val)
+		val = valInt | (val << Local);
+	else{
+		uint8_t inte=1<<Local;
+
+		inte = ~inte;
+		val = valInt & inte;
+	}
+	return write_I2C_PCF8574(ADD_PCF8474[addBit], &val);
+}
+

+ 19 - 14
Source/RTC.c

@@ -8,18 +8,19 @@
 #include "RTC.h"
 
 /** Private Fonction*/
-void readRTC(uint8_t reg, uint8_t *tab, int len) {
-
+HAL_StatusTypeDef readRTC(uint8_t reg, uint8_t *tab, int len) {
 	HAL_StatusTypeDef res = HAL_I2C_Master_Transmit(I2C_RTC, RTC_ADD, &reg, 1, 10000);
-	res = HAL_I2C_Master_Receive(I2C_RTC, RTC_ADD, tab, len, 1000);
+	if(res != HAL_OK)
+		return res;
+	return HAL_I2C_Master_Receive(I2C_RTC, RTC_ADD, tab, len, 1000);
 }
 
-void writeRTC(uint8_t reg, uint8_t *tab, int len) {
+HAL_StatusTypeDef writeRTC(uint8_t reg, uint8_t *tab, int len) {
 	uint8_t t[len + 1];
 	t[0] = reg;
 	for (int i = 0; i < len; i++)
 		t[i + 1] = tab[i];
-	HAL_I2C_Master_Transmit(I2C_RTC, RTC_ADD, t, len + 1, 1000);
+	return HAL_I2C_Master_Transmit(I2C_RTC, RTC_ADD, t, len + 1, 1000);
 }
 
 /** Public Fonction*/
@@ -28,26 +29,28 @@ void initRTC(I2C_HandleTypeDef *typ) {
 	I2C_RTC = typ;
 }
 
-void readHeure(Heure *heure) {
+HAL_StatusTypeDef readHeure(Heure *heure) {
 	uint8_t tab[2];
-	readRTC(MINUTES, tab, 2);
+	HAL_StatusTypeDef res = readRTC(MINUTES, tab, 2);
 	heure->minute = (((tab[0] & 0x70) >> 4) * 10) + (tab[0] & 0X0F);
 	heure->heure = (((tab[1] & 0X30) >> 4) * 10) + (tab[1] & 0X0F);
+	return res;
 }
 
 /** Public Fonction*/
-void readDate(Date *date) {
+HAL_StatusTypeDef readDate(Date *date) {
 	uint8_t tab[7];
-	readRTC(SECOND, tab, 7);
+	HAL_StatusTypeDef res = readRTC(SECOND, tab, 7);
 	date->second = (((tab[0] & 0X70) >> 4) * 10) + (tab[0] & 0X0F);
 	date->minute = (((tab[1] & 0x70) >> 4) * 10) + (tab[1] & 0X0F);
 	date->heure = (((tab[2] & 0X30) >> 4) * 10) + (tab[2] & 0X0F);
 	date->jour = (((tab[4] & 0X30) >> 4) * 10) + (tab[4] & 0X0F);
 	date->mois = (((tab[5] & 0X10) >> 4) * 10) + (tab[5] & 0X0F);
 	date->annee = ((tab[6] >> 4) * 10) + (tab[6] & 0X0F);
+	return res;
 }
 
-void writeDate(Date *date) {
+HAL_StatusTypeDef writeDate(Date *date) {
 	uint8_t tab[7];
 
 	tab[0] = ((date->second / 10) << 4) + (date->second % 10);
@@ -58,14 +61,16 @@ void writeDate(Date *date) {
 	tab[5] = ((date->mois / 10) << 4) + (date->mois % 10);
 	tab[6] = ((date->annee / 10) << 4) + (date->annee % 10);
 
-	writeRTC(SECOND, tab, 7);
+	return writeRTC(SECOND, tab, 7);
 }
 
-void redemareRTC() {
+HAL_StatusTypeDef redemareRTC() {
 	uint8_t pt[1];
-	readRTC(ALARM_HOURS, pt, 1);
+	HAL_StatusTypeDef res = readRTC(ALARM_HOURS, pt, 1);
+		if (res != HAL_OK)
+		return res;
 	pt[0] = pt[0] & !0x40;
-	writeRTC(ALARM_HOURS, pt, 1);
+	return writeRTC(ALARM_HOURS, pt, 1);
 }
 
 void testRTC() {