diff options
author | ConfuSomu | 2021-02-07 14:25:09 -0500 |
---|---|---|
committer | ConfuSomu | 2021-02-07 14:27:52 -0500 |
commit | fef4e0343b14d8d95749e60867828b2773bf8f7d (patch) | |
tree | 65a1d033758bcc24c678dad5f58b2d9b80c7829d | |
parent | 7213392e7a6a4c98dc78a8802227369caf6debf9 (diff) | |
download | pico-watch-fef4e0343b14d8d95749e60867828b2773bf8f7d.tar pico-watch-fef4e0343b14d8d95749e60867828b2773bf8f7d.tar.gz pico-watch-fef4e0343b14d8d95749e60867828b2773bf8f7d.zip |
Move initalisation to init.h/init.c
-rw-r--r-- | CMakeLists.txt | 3 | ||||
-rw-r--r-- | init.c | 33 | ||||
-rw-r--r-- | init.h | 31 | ||||
-rw-r--r-- | pico-watch.c | 35 |
4 files changed, 68 insertions, 34 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 8019126..0f5e46b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,9 +27,10 @@ add_library(Oled target_link_libraries(Oled pico_stdlib hardware_i2c) # Main code -#add_executable(pico-watch pico-watch.c ) add_executable(pico-watch pico-watch.c + init.c + init.h ) pico_set_program_name(pico-watch "pico-watch") @@ -0,0 +1,33 @@ +#include <stdio.h> +#include "pico/stdlib.h" +#include "hardware/i2c.h" +#include "hardware/rtc.h" +#include "oled/ss_oled.h" + +#include "init.h" + +void init_display() { + oledInit(&oled, OLED_128x64, 0x3d, 0, 0, 1, SDA_PIN, SCL_PIN, RESET_PIN, 1000000L); + oledFill(&oled, 0,1); + oledSetContrast(&oled, OLED_DEFAULT_CONTRAST); + //oledSetTextWrap(&oled, true); +} + +void init_rtc() { + datetime_t init_date = { + .year = INIT_DATETIME_YEAR, + .month = INIT_DATETIME_MONTH, + .day = INIT_DATETIME_DAY, + .dotw = INIT_DATETIME_DOTW, // 0 is Sunday, so 5 is Friday + .hour = INIT_DATETIME_HOUR, + .min = INIT_DATETIME_MIN, + .sec = INIT_DATETIME_SEC }; + rtc_init(); + rtc_set_datetime(&init_date); +} + +void init_all() { + stdio_init_all(); + init_display(); + init_rtc(); +} @@ -0,0 +1,31 @@ +#ifndef __INIT_H__ +#define __INIT_H__ + +// To modify the I2C port used, change the `#define I2C_PORT` in "oled/BitBang_I2C.c" +// Pin numbers are GPIO pins. +#define SDA_PIN 6 +#define SCL_PIN 7 +#define RESET_PIN -1 +#define OLED_DEFAULT_CONTRAST 40 +SSOLED oled; + +// Initial date & time +// The idea is to have the compiler set the date at compile-time. +// DOTW: 0 is Sunday +#define INIT_DATETIME_YEAR 2020 +#define INIT_DATETIME_MONTH 06 +#define INIT_DATETIME_DAY 05 +#define INIT_DATETIME_DOTW 5 +#define INIT_DATETIME_HOUR 15 +#define INIT_DATETIME_MIN 45 +#define INIT_DATETIME_SEC 00 + + +// Init every componement +void init_all(); +// Init OLED display +void init_display(); +// Init onboard RTC +void init_rtc(); + +#endif
\ No newline at end of file diff --git a/pico-watch.c b/pico-watch.c index b5bb792..a07cd23 100644 --- a/pico-watch.c +++ b/pico-watch.c @@ -5,38 +5,9 @@ #include "pico/util/datetime.h" #include "oled/ss_oled.h" -// To modify the I2C port used, change the `#define I2C_PORT` in "oled/BitBang_I2C.c" -// Pin numbers are GPIO pins. -#define SDA_PIN 6 -#define SCL_PIN 7 -#define RESET_PIN -1 -#define OLED_DEFAULT_CONTRAST 40 -SSOLED oled; -// Unused but useful for reference: -#define OLED_WIDTH 128 -#define OLED_HEIGHT 64 +#include "init.h" -void init_display() { - oledInit(&oled, OLED_128x64, 0x3d, 0, 0, 1, SDA_PIN, SCL_PIN, RESET_PIN, 1000000L); - oledFill(&oled, 0,1); - oledSetContrast(&oled, OLED_DEFAULT_CONTRAST); - //oledSetTextWrap(&oled, true); -} - -void init_rtc() { - datetime_t init_date = { - .year = 2020, - .month = 06, - .day = 05, - .dotw = 5, // 0 is Sunday, so 5 is Friday - .hour = 15, - .min = 45, - .sec = 00 }; - rtc_init(); - rtc_set_datetime(&init_date); -} - // Time as string // Adapted from pico-sdk/scr/common/pico_util/datetime.c void time_as_str(char *buf, uint buf_size, const datetime_t *t) { @@ -82,9 +53,7 @@ void show_datetime() { } int main() { - stdio_init_all(); - init_display(); - init_rtc(); + init_all(); oledWriteString(&oled, 0,15,0, (char *)"Test clock", FONT_8x8, 0, 1); while (1) { show_datetime(); |