X-Git-Url: https://the.earth.li/gitweb/?a=blobdiff_plain;f=user_main.c;h=8bd1628975429e79b388f43edeca12916ea0ad90;hb=75ff9648d4cf5284db9f43d0fbe52fd9ffbf9534;hp=0ec605604293ea8c4fb45ac807379e2b06a4f1e8;hpb=648045c23ec74fafc4416cfd27b8ce6a091d8a35;p=esp8266-clock.git diff --git a/user_main.c b/user_main.c index 0ec6056..8bd1628 100644 --- a/user_main.c +++ b/user_main.c @@ -1,5 +1,5 @@ /* - * Copyright 2017 Jonathan McDowell + * Copyright 2017-2019 Jonathan McDowell * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,10 +23,12 @@ #include "clock.h" #include "max7219.h" +#include "ota.h" #include "spi.h" struct station_config wificfg; static os_timer_t update_timer; +static os_timer_t ntp_timer; static const struct fontchar clocknums[] = { { .width = 5, @@ -104,14 +106,24 @@ void ICACHE_FLASH_ATTR update_func(void *arg) max7219_show(); } +void ICACHE_FLASH_ATTR ntp_func(void *arg) +{ + ntp_get_time(); +} + void ICACHE_FLASH_ATTR wifi_callback(System_Event_t *evt) { switch (evt->event) { case EVENT_STAMODE_CONNECTED: case EVENT_STAMODE_DISCONNECTED: + os_timer_disarm(&ntp_timer); break; case EVENT_STAMODE_GOT_IP: ntp_get_time(); + ota_check(); + os_timer_disarm(&ntp_timer); + os_timer_setfn(&ntp_timer, ntp_func, NULL); + os_timer_arm(&ntp_timer, 3600 * 1000 /* Hourly */, 1); default: break; } @@ -132,6 +144,42 @@ void ICACHE_FLASH_ATTR wifi_init(void) wifi_set_event_handler_cb(wifi_callback); } +#define SYSTEM_PARTITION_CUSTOMER_PRIV_PARAM SYSTEM_PARTITION_CUSTOMER_BEGIN + +void user_pre_init(void) +{ + partition_item_t p_table[] = { + { SYSTEM_PARTITION_BOOTLOADER, 0x00000, 0x01000 }, + { SYSTEM_PARTITION_OTA_1, 0x01000, 0x76000 }, + { SYSTEM_PARTITION_OTA_2, 0x81000, 0x76000 }, + { SYSTEM_PARTITION_RF_CAL, 0xFB000, 0x01000 }, + { SYSTEM_PARTITION_PHY_DATA, 0xFC000, 0x01000 }, + { SYSTEM_PARTITION_SYSTEM_PARAMETER, 0xFD000, 0x03000 }, + }; + uint32_t map = system_get_flash_size_map(); + + switch (map) { + case FLASH_SIZE_8M_MAP_512_512: /* 1MB / 8Mb */ + break; + case FLASH_SIZE_32M_MAP_512_512: /* 4MB / 32Mb */ + /* Fix up system partition table bits */ + p_table[5].addr += 0x300000; + p_table[6].addr += 0x300000; + p_table[7].addr += 0x300000; + break; + default: + os_printf("Unknown flash map %u\n", map); + while(1) ; + } + + if (!system_partition_table_regist(p_table, + sizeof(p_table)/sizeof(p_table[0]), + map)) { + os_printf("system_partition_table_regist fail\n"); + while(1); + } +} + void user_init(void) { /* Fix up UART0 baud rate */