merge yohan to master
This commit is contained in:
commit
a1ca0c9cf4
12 changed files with 119 additions and 21 deletions
|
@ -1,8 +1,8 @@
|
|||
#include "adc.h"
|
||||
|
||||
void (* pFncADC) (void); /* d<>claration d<>un pointeur de fonction */
|
||||
void (* pFncADC) (uint32_t); /* d<>claration d<>un pointeur de fonction */
|
||||
|
||||
void MyADC_Init_Periph (void (* ptrFonction)(void))
|
||||
void MyADC_Init_Periph (void (* ptrFonction)(uint32_t))
|
||||
{
|
||||
pFncADC = ptrFonction; /* affectation du pointeur */
|
||||
}
|
||||
|
@ -32,13 +32,13 @@ void MyADC_ActiveIT(ADC_TypeDef * ADC, uint8_t Prio)
|
|||
{
|
||||
ADC->CR1 |= ADC_CR1_EOCIE; //Interruption active
|
||||
NVIC->IP[ADC1_2_IRQn] |= (Prio << 0x4); //Prio de l'interruption (p.197 manuel reference RM0008 pour ADC1_IRQn)
|
||||
NVIC->ISER[0] |= (0x1<<ADC1_2_IRQn); //Active l'interruption au niveau NVIC (p.119 manuel programming pour ISER[0])
|
||||
NVIC->ISER[0] |= (1<<ADC1_2_IRQn); //Active l'interruption au niveau NVIC (p.119 manuel programming pour ISER[0])
|
||||
}
|
||||
|
||||
void ADC1_2_IRQHandler(void)
|
||||
{
|
||||
if (pFncADC != 0)
|
||||
(*pFncADC) (); /* appel indirect de la fonction */
|
||||
(*pFncADC) (ADC1->DR); /* appel indirect de la fonction */
|
||||
MyADC_Base_Start(ADC1);
|
||||
ADC1->SR &= ~ADC_SR_EOC; //Prochaine lecture pouvant <20>tre effectu<74>e.
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ typedef struct
|
|||
|
||||
void MyADC_Init(MyADC_Struct_TypeDef * ADCStructPtr);
|
||||
void MyADC_ActiveIT(ADC_TypeDef * ADC, uint8_t Prio);
|
||||
void MyADC_Init_Periph (void (* ptrFonction)(void));
|
||||
void MyADC_Init_Periph (void (* ptrFonction)(uint32_t));
|
||||
MyGPIO_Struct_TypeDef GPIOFromADC(MyADC_Struct_TypeDef ADC);
|
||||
|
||||
#define MyADC_Base_Start(ADC) (ADC->CR2 |= ADC_CR2_SWSTART)
|
||||
|
|
|
@ -106,6 +106,17 @@ void MyUART_InitGPIO(MyUART_Struct_Typedef * UARTStructPtr)
|
|||
MyGPIO_Init(&txd);
|
||||
}
|
||||
|
||||
int MyUART_SendArray(MyUART_Struct_Typedef *UART, uint8_t * data, int dataLength)
|
||||
{
|
||||
int i;
|
||||
for(i=0; i<dataLength; i++)
|
||||
{
|
||||
UART->UART->DR = data[i];
|
||||
while (!(UART->UART->SR & USART_SR_TXE));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MyUART_Send(MyUART_Struct_Typedef *UART, uint8_t data)
|
||||
{
|
||||
UART->UART->DR = data;
|
||||
|
|
|
@ -30,6 +30,7 @@ typedef struct {
|
|||
|
||||
void MyUART_Init(MyUART_Struct_Typedef * UARTStructPtr);
|
||||
void MyUART_InitGPIO(MyUART_Struct_Typedef * UARTStructPtr);
|
||||
int MyUART_SendArray(MyUART_Struct_Typedef *UART, uint8_t * data, int dataLength);
|
||||
void MyUART_Send(MyUART_Struct_Typedef *UART, uint8_t data);
|
||||
uint8_t MyUART_Receive(MyUART_Struct_Typedef *UART);
|
||||
void MyUART_Init_Periph (void (* ptrFonction)(uint8_t));
|
||||
|
|
|
@ -11,7 +11,7 @@ void Init_accelerometre(void)
|
|||
|
||||
MySPI_Clear_NSS(); //CS LOW
|
||||
MySPI_Send(0x2D);//Registre Auto_sleep + Write + measure a 1
|
||||
MySPI_Send(0x08);// désactive
|
||||
MySPI_Send(0x08);// d<EFBFBD>sactive
|
||||
MySPI_Set_NSS();//CS HIGH
|
||||
/*
|
||||
MySPI_Clear_NSS(); //CS LOW
|
||||
|
@ -22,7 +22,7 @@ void Init_accelerometre(void)
|
|||
|
||||
MySPI_Clear_NSS(); //CS LOW
|
||||
MySPI_Send(0X2C);//Registre power consuption + Write
|
||||
MySPI_Send(0X1A);//Paramétrage hors low consumption + 100Hz output data rate
|
||||
MySPI_Send(0X1A);//Param<EFBFBD>trage hors low consumption + 100Hz output data rate
|
||||
MySPI_Set_NSS();//CS HIGH
|
||||
|
||||
MySPI_Clear_NSS(); //CS LOW
|
||||
|
@ -39,8 +39,8 @@ void Lecture_accelerometre(float* GX, float* GY, float* GZ)
|
|||
|
||||
MySPI_Clear_NSS(); //CS LOW
|
||||
|
||||
MySPI_Send(0xF2);//lecture 1er registre accéléromètre + lecture multibytes
|
||||
dataX = MySPI_Read()<<8; // données sur 13 (12 data + sign) bits passage 8 bit en PF
|
||||
MySPI_Send(0xF2);//lecture 1er registre acc<EFBFBD>l<EFBFBD>rom<EFBFBD>tre + lecture multibytes
|
||||
dataX = MySPI_Read()<<8; // donn<EFBFBD>es sur 13 (12 data + sign) bits passage 8 bit en PF
|
||||
dataX |= MySPI_Read(); //lecture SPI
|
||||
dataX &= 0x1FFF; //masquage au dessus du bit 13
|
||||
if (dataX > 511)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define INC_ACCELEROMETER_H_
|
||||
|
||||
#include "../driver/MySPI.h"
|
||||
|
||||
void Init_accelerometre(void);
|
||||
void Lecture_accelerometre(float *GX, float* GY, float* GZ);
|
||||
|
||||
#endif
|
||||
|
|
61
implementation/battery.c
Normal file
61
implementation/battery.c
Normal file
|
@ -0,0 +1,61 @@
|
|||
#include "battery.h"
|
||||
|
||||
extern MyUART_Struct_Typedef uartCool;
|
||||
int actualMinutes =-1;
|
||||
uint32_t oldAdc =0;
|
||||
|
||||
void battery(uint32_t data)
|
||||
{
|
||||
MyRTC_Struct_TypeDef rtcBattery;
|
||||
MyRTC_GetTime(&rtcBattery);
|
||||
|
||||
if((actualMinutes == rtcBattery.minutes) && isClose(oldAdc,data,50)) //pas de precision/10 %
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
oldAdc = data;
|
||||
actualMinutes = rtcBattery.minutes;
|
||||
float percentBattery = ((float)data)/MAX_BAT;
|
||||
char batteryBar[13]="[__________]";
|
||||
char testChar[24];
|
||||
|
||||
getGauge(batteryBar, percentBattery);
|
||||
sprintf(testChar,"[%.2d:%.2d] %s %.2d%%",rtcBattery.hours,rtcBattery.minutes,batteryBar,(int)(percentBattery*100));
|
||||
MyUART_SendArray(&uartCool, (uint8_t *)testChar, 24);
|
||||
|
||||
MyUART_Send(&uartCool, '\n');
|
||||
}
|
||||
|
||||
void getGauge(char gauge[], float percent)
|
||||
{
|
||||
int i;
|
||||
percent=percent*10;
|
||||
if(percent>10)
|
||||
{
|
||||
percent = 10.0;
|
||||
}
|
||||
for(i=(10-percent)+1; i<11; i++)
|
||||
{
|
||||
gauge[i]='#';
|
||||
}
|
||||
gauge[12]='\0';
|
||||
}
|
||||
|
||||
char isClose(uint32_t data, uint32_t compare, int precision)
|
||||
{
|
||||
if(data < precision)
|
||||
{
|
||||
return !(data >= compare+precision);
|
||||
}
|
||||
return !((data >= compare+precision) || (data <= compare-precision));
|
||||
}
|
||||
|
||||
void initBattery(void)
|
||||
{
|
||||
MyADC_Init_Periph(battery);
|
||||
MyADC_Struct_TypeDef adcBattery = {ADC1,10,cycles41d5};
|
||||
MyADC_Init(&adcBattery);
|
||||
MyGPIO_Struct_TypeDef gpioBattery = {GPIOC,0,In_Analog};
|
||||
MyGPIO_Init(&gpioBattery);
|
||||
}
|
15
implementation/battery.h
Normal file
15
implementation/battery.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
#ifndef BATTERY_H
|
||||
#define BATTERY_H
|
||||
#include "stm32f10x.h"
|
||||
#include "adc.h"
|
||||
#include "remote.h"
|
||||
#include "rtc.h"
|
||||
#include <stdio.h>
|
||||
#define MAX_BAT 1145
|
||||
|
||||
void battery(uint32_t data);
|
||||
void getGauge(char gauge[], float percent);
|
||||
void initBattery(void);
|
||||
char isClose(uint32_t data, uint32_t compare, int precision);
|
||||
|
||||
#endif
|
|
@ -6,7 +6,6 @@ MyUART_Struct_Typedef uartCool = {USART1,9600,lengthBit8,parityNone,stopBit1};
|
|||
|
||||
void remote(uint8_t data)
|
||||
{
|
||||
MyUART_Send(&uartCool,data);
|
||||
int8_t signedData = (int8_t)data;
|
||||
if(signedData >= 0)
|
||||
{
|
||||
|
|
|
@ -11,7 +11,7 @@ void MyRTC_Init(void)
|
|||
MyI2C_Init(I2C2, 15, IT_I2C_Err);
|
||||
}
|
||||
|
||||
void MyRTC_GetTime(int* sec, int* min, int* hour, int* day, int* date, int* month, int* year)
|
||||
void MyRTC_GetTime(MyRTC_Struct_TypeDef * rtc)
|
||||
{
|
||||
MyI2C_RecSendData_Typedef data;
|
||||
char regCopy = 0;
|
||||
|
@ -21,17 +21,17 @@ void MyRTC_GetTime(int* sec, int* min, int* hour, int* day, int* date, int* mont
|
|||
data.Nb_Data = 1;
|
||||
|
||||
MyI2C_GetString(I2C2, 0x00, &data);
|
||||
*sec = ((regCopy >> 4) & 0x07) * 10 + (regCopy & 0x0F);
|
||||
rtc->seconds = ((regCopy >> 4) & 0x07) * 10 + (regCopy & 0x0F);
|
||||
MyI2C_GetString(I2C2, 0x01, &data);
|
||||
*min = ((regCopy >> 4) & 0x07) * 10 + (regCopy & 0x0F);
|
||||
rtc->minutes = ((regCopy >> 4) & 0x07) * 10 + (regCopy & 0x0F);
|
||||
MyI2C_GetString(I2C2, 0x02, &data);
|
||||
*hour = 0;
|
||||
rtc->hours = 0;
|
||||
MyI2C_GetString(I2C2, 0x03, &data);
|
||||
*day = (regCopy & 0x07);
|
||||
rtc->day = (regCopy & 0x07);
|
||||
MyI2C_GetString(I2C2, 0x04, &data);
|
||||
*date = ((regCopy >> 4) & 0x03) * 10 + (regCopy & 0x0F);
|
||||
rtc->date = ((regCopy >> 4) & 0x03) * 10 + (regCopy & 0x0F);
|
||||
MyI2C_GetString(I2C2, 0x05, &data);
|
||||
*month = ((regCopy >> 4) & 0x01) * 10 + (regCopy & 0x0F);
|
||||
rtc->month = ((regCopy >> 4) & 0x01) * 10 + (regCopy & 0x0F);
|
||||
MyI2C_GetString(I2C2, 0x06, &data);
|
||||
*year = ((regCopy >> 4) & 0xF0) * 10 + (regCopy & 0x0F) + 2000;
|
||||
rtc->year = ((regCopy >> 4) & 0xF0) * 10 + (regCopy & 0x0F) + 2000;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,17 @@
|
|||
#include "stm32f10x.h"
|
||||
#include "MyI2C.h"
|
||||
|
||||
typedef struct{
|
||||
int seconds;
|
||||
int minutes;
|
||||
int hours;
|
||||
int day;
|
||||
int date;
|
||||
int month;
|
||||
int year;
|
||||
} MyRTC_Struct_TypeDef;
|
||||
|
||||
void MyRTC_Init(void);
|
||||
void MyRTC_GetTime(int* sec, int* min, int* hour, int* day, int* date, int* month, int* year);
|
||||
void MyRTC_GetTime(MyRTC_Struct_TypeDef * rtc);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include "rtc.h"
|
||||
#include "remote.h"
|
||||
#include "accelerometer.h"
|
||||
|
||||
#include "battery.h"
|
||||
|
||||
void initImplementation(void);
|
||||
|
||||
|
@ -36,4 +36,5 @@ void initImplementation(void)
|
|||
MyMotor_ChangeSpeed(0);
|
||||
MyMotor_ChangeDirection(HORAIRE);
|
||||
MyRTC_Init();
|
||||
initBattery();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue