Initial Release

This commit is contained in:
graham sanderson
2021-01-20 10:49:34 -06:00
commit 46078742c7
245 changed files with 21157 additions and 0 deletions

5
rtc/CMakeLists.txt Normal file
View File

@@ -0,0 +1,5 @@
if (NOT PICO_NO_HARDWARE)
add_subdirectory(hello_rtc)
add_subdirectory(rtc_alarm)
add_subdirectory(rtc_alarm_repeat)
endif ()

View File

@@ -0,0 +1,12 @@
add_executable(hello_rtc
hello_rtc.c
)
# Pull in our (to be renamed) simple get you started dependencies
target_link_libraries(hello_rtc pico_stdlib hardware_rtc)
# create map/bin/hex file etc.
pico_add_extra_outputs(hello_rtc)
# add url via pico_set_program_url
example_auto_set_url(hello_rtc)

45
rtc/hello_rtc/hello_rtc.c Normal file
View File

@@ -0,0 +1,45 @@
/**
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <stdio.h>
#include "hardware/rtc.h"
#include "pico/stdlib.h"
#include "pico/util/datetime.h"
/// \tag::hello_rtc_main[]
int main() {
stdio_init_all();
printf("Hello RTC!\n");
char datetime_buf[256];
char *datetime_str = &datetime_buf[0];
// Start on Friday 5th of June 2020 15:45:00
datetime_t t = {
.year = 2020,
.month = 06,
.day = 05,
.dotw = 5, // 0 is Sunday, so 5 is Friday
.hour = 15,
.min = 45,
.sec = 00
};
// Start the RTC
rtc_init();
rtc_set_datetime(&t);
// Print the time
while (true) {
rtc_get_datetime(&t);
datetime_to_str(datetime_str, sizeof(datetime_buf), &t);
printf("\r%s ", datetime_str);
sleep_ms(100);
}
return 0;
}
/// \end::hello_rtc_main[]

View File

@@ -0,0 +1,12 @@
add_executable(rtc_alarm
rtc_alarm.c
)
# Pull in our (to be renamed) simple get you started dependencies
target_link_libraries(rtc_alarm pico_stdlib hardware_rtc)
# create map/bin/hex file etc.
pico_add_extra_outputs(rtc_alarm)
# add url via pico_set_program_url
example_auto_set_url(rtc_alarm)

60
rtc/rtc_alarm/rtc_alarm.c Normal file
View File

@@ -0,0 +1,60 @@
/**
* Copyright (c) 2021 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <stdio.h>
#include "hardware/rtc.h"
#include "pico/stdlib.h"
#include "pico/util/datetime.h"
static volatile bool fired = false;
static void alarm_callback(void) {
datetime_t t = {0};
rtc_get_datetime(&t);
char datetime_buf[256];
char *datetime_str = &datetime_buf[0];
datetime_to_str(datetime_str, sizeof(datetime_buf), &t);
printf("Alarm Fired At %s\n", datetime_str);
stdio_flush();
fired = true;
}
int main() {
stdio_init_all();
printf("RTC Alarm!\n");
// Start on Wednesday 13th January 2021 11:20:00
datetime_t t = {
.year = 2020,
.month = 01,
.day = 13,
.dotw = 3, // 0 is Sunday, so 3 is Wednesday
.hour = 11,
.min = 20,
.sec = 00
};
// Start the RTC
rtc_init();
rtc_set_datetime(&t);
// Alarm 5 seconds later
datetime_t alarm = {
.year = 2020,
.month = 01,
.day = 13,
.dotw = 3, // 0 is Sunday, so 3 is Wednesday
.hour = 11,
.min = 20,
.sec = 05
};
rtc_set_alarm(&alarm, &alarm_callback);
while(!fired);
return 0;
}

View File

@@ -0,0 +1,12 @@
add_executable(rtc_alarm_repeat
rtc_alarm_repeat.c
)
# Pull in our (to be renamed) simple get you started dependencies
target_link_libraries(rtc_alarm_repeat pico_stdlib hardware_rtc)
# create map/bin/hex file etc.
pico_add_extra_outputs(rtc_alarm_repeat)
# add url via pico_set_program_url
example_auto_set_url(rtc_alarm_repeat)

View File

@@ -0,0 +1,61 @@
/**
* Copyright (c) 2021 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <stdio.h>
#include "hardware/rtc.h"
#include "pico/stdlib.h"
#include "pico/util/datetime.h"
static volatile bool fired = false;
static void alarm_callback(void) {
datetime_t t = {0};
rtc_get_datetime(&t);
char datetime_buf[256];
char *datetime_str = &datetime_buf[0];
datetime_to_str(datetime_str, sizeof(datetime_buf), &t);
printf("Alarm Fired At %s\n", datetime_str);
stdio_flush();
fired = true;
}
int main() {
stdio_init_all();
printf("RTC Alarm Repeat!\n");
// Start on Wednesday 13th January 2021 11:20:00
datetime_t t = {
.year = 2020,
.month = 01,
.day = 13,
.dotw = 3, // 0 is Sunday, so 3 is Wednesday
.hour = 11,
.min = 20,
.sec = 00
};
// Start the RTC
rtc_init();
rtc_set_datetime(&t);
// Alarm once a minute
datetime_t alarm = {
.year = -1,
.month = -1,
.day = -1,
.dotw = -1,
.hour = -1,
.min = -1,
.sec = 00
};
rtc_set_alarm(&alarm, &alarm_callback);
// Alarm will keep firing forever
while(1);
return 0;
}