Fixed several issues:

- ADC has now averaging
- Pause screen added
- Fixed display glitches for most parts

git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@258 05563f52-14a8-4384-a975-3d1654cca0fa
This commit is contained in:
mmi
2017-10-19 15:24:24 +00:00
parent 51ffde94d7
commit 92bd68d8ba
18 changed files with 257 additions and 99 deletions

View File

@@ -82,6 +82,7 @@ ErrorStatus ADC_construct(struct Adc* self, struct AdcParameters* parameters)
self->channelValue[loopCounter] = 0;
}
self->initialized = true;
self->numberOfUsedChannels = 0;
}
return returnValue;
@@ -98,8 +99,8 @@ void ADC_destruct (struct Adc* self)
ADC_DeInit(self->ADCx);
self->useDMA = false;
self->useRanks = false;
self->initialized = false;
self->numberOfUsedChannels = 0;
}
@@ -169,7 +170,7 @@ ErrorStatus ADCChannel_construct(struct AdcChannel* self, struct Adc* parent, st
{
returnValue = ERROR;
}
if (parameters->channel < 18)
if (parameters->channel < ADC_NUMBER_OF_CHANNELS)
{
self->channel = parameters->channel;
}
@@ -183,11 +184,12 @@ ErrorStatus ADCChannel_construct(struct AdcChannel* self, struct Adc* parent, st
{
parent->channel[self->channel] = *self;
self->parent = parent;
self->ADC_SampleTime = parameters->ADC_SampleTime;
self->ADC_SampleTime = parameters->ADC_SampleTime;
self->initialized = true;
self->parent->numberOfUsedChannels++;
//TODO MAKE SURE EACH RANK IS USED ONLY ONCE
ADC_RegularChannelConfig(self->parent->ADCx, self->channel, self->Rank, self->ADC_SampleTime);
self->parent->useRanks = true;
}
}
}
@@ -203,6 +205,7 @@ ErrorStatus ADCChannel_construct(struct AdcChannel* self, struct Adc* parent, st
void ADCChannel_destruct(struct AdcChannel* self)
{
self->initialized = false;
self->parent->numberOfUsedChannels--;
}
@@ -210,13 +213,16 @@ ErrorStatus ADCChannel_read(const struct AdcChannel* self, uint16_t* value)
{
ErrorStatus returnValue = SUCCESS;
// For reading it is important whether Ranks are enabled or not
if (self->parent->useRanks)
// Reading ADC value is automatically combined with an floating averaging
uint32_t average = 0;
int loopCounter;
for (loopCounter = self->channel; loopCounter < self->parent->numberOfUsedChannels * ADC_AVERAGE_DEPTH; loopCounter = loopCounter + self->parent->numberOfUsedChannels)
{
// Rank starts with 1 - must be reduced by one in order tu be used as index
// *value = self->parent->channelValue[self->Rank - 1];
*value = self->parent->channelValue[self->channel];
average = average + self->parent->channelValue[loopCounter];
}
*value = average / ADC_AVERAGE_DEPTH;
return returnValue;
}
@@ -238,3 +244,4 @@ static ErrorStatus read(const struct IODevice* self, char* buffer, size_t length
return returnValue;
}

View File

@@ -555,7 +555,7 @@ static ErrorStatus initPeriphery(void)
DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)adc1->channelValue;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = ADC1_NUMBER_OF_USED_CHANNELS;
DMA_InitStructure.DMA_BufferSize = ADC_AVERAGE_DEPTH * ADC1_NUMBER_OF_USED_CHANNELS;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
@@ -570,7 +570,7 @@ static ErrorStatus initPeriphery(void)
/* --------------------------------------------------------------------*/
/* ADC1 - for module feedback */
/* --------------------------------------------------------------------*/
IRQ_setInterruptProperties(ADC1_2_IRQn, 12, 12, DISABLE);
IRQ_setInterruptProperties(ADC1_2_IRQn, 12, 12, ENABLE);
adc1Parameters->ADC_Mode = ADC_Mode_Independent;
adc1Parameters->ADC_ScanConvMode = ENABLE;
adc1Parameters->ADC_ContinuousConvMode = ENABLE;

View File

@@ -99,6 +99,23 @@ struct Observable* RTC_getObservable(struct Rtc* self)
}
void RTC_calculateTimeFromSeconds(uint32_t seconds, struct Time* time)
{
if (seconds > 0)
{
time->hours = (seconds / (60 * 60));
time->minutes = (seconds - (time->hours * 60 * 60)) / 60;
time->seconds = (seconds - (time->hours * 60 * 60) - (time->minutes * 60));
}
else
{
// Prevent underflows
time->hours = 0;
time->minutes = 0;
time->seconds = 0;
}
}
void RTC_IRQHandler(void)
{
static signed portBASE_TYPE higherPriorityTaskWoken = pdFALSE;