Wakeup Light with touch user interface, anti-aliased Font, SD card access and RTC usage on STM32F746NG-DISCO board

Dependencies:   BSP_DISCO_F746NG_patch_fixed LCD_DISCO_F746NG TS_DISCO_F746NG FATFileSystem TinyJpgDec_interwork mbed-src

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Config.cpp Source File

Config.cpp

00001 #include "WakeupLight.h"
00002 
00003 //#define USE_RTC
00004 
00005 #define CT_MAGIC_VALUE              0x546865DF      // 'Theß'
00006 
00007 #ifdef USE_RTC
00008     uint32_t                        *rtcBackupRegisters;
00009 #else
00010     uint32_t                        configSpace[CT_MAX];
00011 #endif
00012 
00013 void Config_Init(void)
00014 {
00015     uint32_t                index;
00016 
00017     #ifdef USE_RTC
00018 
00019         RTC_TypeDef             *rtc;
00020     
00021         rtc=(RTC_TypeDef *)RTC_BASE;
00022         rtcBackupRegisters=(uint32_t *)&rtc->BKP0R;
00023     
00024         if (rtcBackupRegisters[CT_MAGIC]!=CT_MAGIC_VALUE)
00025         {
00026             DPrintf("Config_Init: Reset config because of 0x%08X.\r\n",rtcBackupRegisters[CT_MAGIC]);
00027     
00028             for (index=0;index<=CT_MAX;index++)
00029                 rtcBackupRegisters[index]=0;
00030     
00031             rtcBackupRegisters[CT_MAGIC]=CT_MAGIC_VALUE;
00032         }
00033 
00034     #else
00035 
00036         for (index=0;index<=CT_MAX;index++)
00037             configSpace[index]=0;
00038 
00039         configSpace[CT_MAGIC]=CT_MAGIC_VALUE;
00040 
00041     #endif
00042 }
00043 
00044 uint32_t Config_Get(CONFIG_TYPE_ENUM type)
00045 {
00046     if (type>CT_MAX)
00047         return 0;
00048 
00049     DPrintf_("Config_Get: %u -> 0x%X.\r\n",type,configSpace[type]);
00050 
00051     #ifdef USE_RTC
00052         return rtcBackupRegisters[type];
00053     #else
00054         return configSpace[type];
00055     #endif
00056 }
00057 
00058 void Config_Set(CONFIG_TYPE_ENUM type,uint32_t value)
00059 {
00060     if (type>CT_MAX)
00061         return;
00062 
00063     DPrintf_("Config_Set: %u -> 0x%X.\r\n",type,value);
00064 
00065     #ifdef USE_RTC
00066 
00067         RTC_TypeDef             *rtc;
00068 
00069         rtc=(RTC_TypeDef *)RTC_BASE;
00070         rtc->WPR=0xCA;
00071         rtc->WPR=0x53;
00072 
00073         rtcBackupRegisters[type]=value;
00074 
00075         rtc->WPR=0xFF;
00076 
00077     #else
00078 
00079         configSpace[type]=value;
00080 
00081     #endif
00082 }