summaryrefslogtreecommitdiffstats
path: root/humidity_sensors/app/awu.c
diff options
context:
space:
mode:
Diffstat (limited to 'humidity_sensors/app/awu.c')
-rw-r--r--humidity_sensors/app/awu.c58
1 files changed, 26 insertions, 32 deletions
diff --git a/humidity_sensors/app/awu.c b/humidity_sensors/app/awu.c
index 18cf1f8..dc7ea9f 100644
--- a/humidity_sensors/app/awu.c
+++ b/humidity_sensors/app/awu.c
@@ -1,21 +1,19 @@
#include "project.h"
/** Contains the different values to write in the APR register (used by AWU_Init function) */
-CONST uint8_t APR_Array[17] =
- {
- 0, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 61, 23, 23, 62
- };
+CONST uint8_t APR_Array[17] = {
+ 0, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 61, 23, 23, 62
+};
/** Contains the different values to write in the TBR register (used by AWU_Init function) */
-CONST uint8_t TBR_Array[17] =
- {
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12, 14, 15, 15
- };
+CONST uint8_t TBR_Array[17] = {
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12, 14, 15, 15
+};
-FlagStatus AWU_GetFlagStatus(void)
+FlagStatus AWU_GetFlagStatus (void)
{
- return((FlagStatus)(((uint8_t)(AWU->CSR & AWU_CSR_AWUF) == (uint8_t)0x00) ? RESET : SET));
+ return ((FlagStatus) (((uint8_t) (AWU->CSR & AWU_CSR_AWUF) == (uint8_t)0x00) ? RESET : SET));
}
@@ -25,46 +23,42 @@ INTERRUPT_HANDLER (AWU_IRQHandler, 1)
}
-void AWU_Init(AWU_Timebase_TypeDef AWU_TimeBase)
+void AWU_Init (AWU_Timebase_TypeDef AWU_TimeBase)
{
/* Enable the AWU peripheral */
AWU->CSR |= AWU_CSR_AWUEN;
-
+
/* Set the TimeBase */
- AWU->TBR &= (uint8_t)(~AWU_TBR_AWUTB);
- AWU->TBR |= TBR_Array[(uint8_t)AWU_TimeBase];
-
+ AWU->TBR &= (uint8_t) (~AWU_TBR_AWUTB);
+ AWU->TBR |= TBR_Array[ (uint8_t)AWU_TimeBase];
+
/* Set the APR divider */
- AWU->APR &= (uint8_t)(~AWU_APR_APR);
- AWU->APR |= APR_Array[(uint8_t)AWU_TimeBase];
+ AWU->APR &= (uint8_t) (~AWU_APR_APR);
+ AWU->APR |= APR_Array[ (uint8_t)AWU_TimeBase];
}
-void AWU_LSICalibrationConfig(uint16_t lsifreqkhz)
+void AWU_LSICalibrationConfig (uint16_t lsifreqkhz)
{
uint16_t A = 0x0;
-
-
+
+
/* Calculation of AWU calibration value */
-
- A = (uint16_t)(lsifreqkhz >> 2U); /* Division by 4, keep integer part only */
-
+
+ A = (uint16_t) (lsifreqkhz >> 2U); /* Division by 4, keep integer part only */
+
if ((4U * A) >= ((lsifreqkhz - (4U * A)) * (1U + (2U * A))))
- {
- AWU->APR = (uint8_t)(A - 2U);
- }
+ AWU->APR = (uint8_t) (A - 2U);
else
- {
- AWU->APR = (uint8_t)(A - 1U);
- }
+ AWU->APR = (uint8_t) (A - 1U);
}
-void awu_init(void)
+void awu_init (void)
{
- AWU_LSICalibrationConfig(128);
- AWU_Init(AWU_TIMEBASE_1S);
+ AWU_LSICalibrationConfig (128);
+ AWU_Init (AWU_TIMEBASE_1S);
}