A board support package for the LPC4088 Display Module.

Dependencies:   DM_HttpServer DM_USBHost

Dependents:   lpc4088_displaymodule_emwin lpc4088_displaymodule_demo_sphere sampleGUI sampleEmptyGUI ... more

Fork of DMSupport by EmbeddedArtists AB

Committer:
embeddedartists
Date:
Mon Nov 04 14:32:50 2019 +0000
Revision:
42:bbfe299d4a0c
More updates related to mbed OS 5

Who changed what in which revision?

UserRevisionLine numberNew contents of line
embeddedartists 42:bbfe299d4a0c 1 /*
embeddedartists 42:bbfe299d4a0c 2 * Copyright 2019 Embedded Artists AB
embeddedartists 42:bbfe299d4a0c 3 *
embeddedartists 42:bbfe299d4a0c 4 * Licensed under the Apache License, Version 2.0 (the "License");
embeddedartists 42:bbfe299d4a0c 5 * you may not use this file except in compliance with the License.
embeddedartists 42:bbfe299d4a0c 6 * You may obtain a copy of the License at
embeddedartists 42:bbfe299d4a0c 7 *
embeddedartists 42:bbfe299d4a0c 8 * http://www.apache.org/licenses/LICENSE-2.0
embeddedartists 42:bbfe299d4a0c 9 *
embeddedartists 42:bbfe299d4a0c 10 * Unless required by applicable law or agreed to in writing, software
embeddedartists 42:bbfe299d4a0c 11 * distributed under the License is distributed on an "AS IS" BASIS,
embeddedartists 42:bbfe299d4a0c 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
embeddedartists 42:bbfe299d4a0c 13 * See the License for the specific language governing permissions and
embeddedartists 42:bbfe299d4a0c 14 * limitations under the License.
embeddedartists 42:bbfe299d4a0c 15 */
embeddedartists 42:bbfe299d4a0c 16
embeddedartists 42:bbfe299d4a0c 17
embeddedartists 42:bbfe299d4a0c 18 /******************************************************************************
embeddedartists 42:bbfe299d4a0c 19 * Includes
embeddedartists 42:bbfe299d4a0c 20 *****************************************************************************/
embeddedartists 42:bbfe299d4a0c 21
embeddedartists 42:bbfe299d4a0c 22 #include "mbed.h"
embeddedartists 42:bbfe299d4a0c 23 #include "dm_rtc.h"
embeddedartists 42:bbfe299d4a0c 24 #include "mbed_mktime.h"
embeddedartists 42:bbfe299d4a0c 25
embeddedartists 42:bbfe299d4a0c 26 /******************************************************************************
embeddedartists 42:bbfe299d4a0c 27 * Defines and typedefs
embeddedartists 42:bbfe299d4a0c 28 *****************************************************************************/
embeddedartists 42:bbfe299d4a0c 29
embeddedartists 42:bbfe299d4a0c 30 /******************************************************************************
embeddedartists 42:bbfe299d4a0c 31 * External global variables
embeddedartists 42:bbfe299d4a0c 32 *****************************************************************************/
embeddedartists 42:bbfe299d4a0c 33
embeddedartists 42:bbfe299d4a0c 34 /******************************************************************************
embeddedartists 42:bbfe299d4a0c 35 * Local variables
embeddedartists 42:bbfe299d4a0c 36 *****************************************************************************/
embeddedartists 42:bbfe299d4a0c 37
embeddedartists 42:bbfe299d4a0c 38 /******************************************************************************
embeddedartists 42:bbfe299d4a0c 39 * Local Functions
embeddedartists 42:bbfe299d4a0c 40 *****************************************************************************/
embeddedartists 42:bbfe299d4a0c 41
embeddedartists 42:bbfe299d4a0c 42
embeddedartists 42:bbfe299d4a0c 43 /******************************************************************************
embeddedartists 42:bbfe299d4a0c 44 * Public Functions
embeddedartists 42:bbfe299d4a0c 45 *****************************************************************************/
embeddedartists 42:bbfe299d4a0c 46
embeddedartists 42:bbfe299d4a0c 47 void dm_init_rtc(void)
embeddedartists 42:bbfe299d4a0c 48 {
embeddedartists 42:bbfe299d4a0c 49 LPC_SC->PCONP |= 0x200; // Ensure power is on
embeddedartists 42:bbfe299d4a0c 50 LPC_RTC->CCR = 0x00;
embeddedartists 42:bbfe299d4a0c 51
embeddedartists 42:bbfe299d4a0c 52 LPC_RTC->CCR |= 1 << 0; // Ensure the RTC is enabled
embeddedartists 42:bbfe299d4a0c 53 }
embeddedartists 42:bbfe299d4a0c 54
embeddedartists 42:bbfe299d4a0c 55 time_t dm_read_rtc(void)
embeddedartists 42:bbfe299d4a0c 56 {
embeddedartists 42:bbfe299d4a0c 57 // Setup a tm structure based on the RTC
embeddedartists 42:bbfe299d4a0c 58 struct tm timeinfo;
embeddedartists 42:bbfe299d4a0c 59 timeinfo.tm_sec = LPC_RTC->SEC;
embeddedartists 42:bbfe299d4a0c 60 timeinfo.tm_min = LPC_RTC->MIN;
embeddedartists 42:bbfe299d4a0c 61 timeinfo.tm_hour = LPC_RTC->HOUR;
embeddedartists 42:bbfe299d4a0c 62 timeinfo.tm_mday = LPC_RTC->DOM;
embeddedartists 42:bbfe299d4a0c 63 timeinfo.tm_mon = LPC_RTC->MONTH - 1;
embeddedartists 42:bbfe299d4a0c 64 timeinfo.tm_year = LPC_RTC->YEAR - 1900;
embeddedartists 42:bbfe299d4a0c 65
embeddedartists 42:bbfe299d4a0c 66 // Convert to timestamp
embeddedartists 42:bbfe299d4a0c 67 time_t t;
embeddedartists 42:bbfe299d4a0c 68 if (_rtc_maketime(&timeinfo, &t, RTC_4_YEAR_LEAP_YEAR_SUPPORT) == false) {
embeddedartists 42:bbfe299d4a0c 69 return 0;
embeddedartists 42:bbfe299d4a0c 70 }
embeddedartists 42:bbfe299d4a0c 71
embeddedartists 42:bbfe299d4a0c 72 return t;
embeddedartists 42:bbfe299d4a0c 73 }
embeddedartists 42:bbfe299d4a0c 74
embeddedartists 42:bbfe299d4a0c 75 void dm_write_rtc(time_t t)
embeddedartists 42:bbfe299d4a0c 76 {
embeddedartists 42:bbfe299d4a0c 77 // Convert the time in to a tm
embeddedartists 42:bbfe299d4a0c 78 struct tm timeinfo;
embeddedartists 42:bbfe299d4a0c 79 if (_rtc_localtime(t, &timeinfo, RTC_4_YEAR_LEAP_YEAR_SUPPORT) == false) {
embeddedartists 42:bbfe299d4a0c 80 return;
embeddedartists 42:bbfe299d4a0c 81 }
embeddedartists 42:bbfe299d4a0c 82
embeddedartists 42:bbfe299d4a0c 83 // Pause clock, and clear counter register (clears us count)
embeddedartists 42:bbfe299d4a0c 84 LPC_RTC->CCR |= 2;
embeddedartists 42:bbfe299d4a0c 85
embeddedartists 42:bbfe299d4a0c 86 // Set the RTC
embeddedartists 42:bbfe299d4a0c 87 LPC_RTC->SEC = timeinfo.tm_sec;
embeddedartists 42:bbfe299d4a0c 88 LPC_RTC->MIN = timeinfo.tm_min;
embeddedartists 42:bbfe299d4a0c 89 LPC_RTC->HOUR = timeinfo.tm_hour;
embeddedartists 42:bbfe299d4a0c 90 LPC_RTC->DOM = timeinfo.tm_mday;
embeddedartists 42:bbfe299d4a0c 91 LPC_RTC->MONTH = timeinfo.tm_mon + 1;
embeddedartists 42:bbfe299d4a0c 92 LPC_RTC->YEAR = timeinfo.tm_year + 1900;
embeddedartists 42:bbfe299d4a0c 93
embeddedartists 42:bbfe299d4a0c 94 // Restart clock
embeddedartists 42:bbfe299d4a0c 95 LPC_RTC->CCR &= ~((uint32_t)2);
embeddedartists 42:bbfe299d4a0c 96 }
embeddedartists 42:bbfe299d4a0c 97
embeddedartists 42:bbfe299d4a0c 98 int dm_isenabled_rtc(void)
embeddedartists 42:bbfe299d4a0c 99 {
embeddedartists 42:bbfe299d4a0c 100 return(((LPC_RTC->CCR) & 0x01) != 0);
embeddedartists 42:bbfe299d4a0c 101 }
embeddedartists 42:bbfe299d4a0c 102
embeddedartists 42:bbfe299d4a0c 103