Skip to content
Snippets Groups Projects
Select Git revision
  • 8c59935ec36d04b6903397018f510beb5ed256a4
  • master default protected
  • fix-warnings
  • tvbgone-fixes
  • genofire/ble-follow-py
  • schneider/ble-stability-new-phy-adv
  • schneider/ble-stability
  • msgctl/gfx_rle
  • schneider/ble-stability-new-phy
  • add_menu_vibration
  • plaetzchen/ios-workaround
  • blinkisync-as-preload
  • schneider/max30001-pycardium
  • schneider/max30001-epicaridum
  • schneider/max30001
  • schneider/stream-locks
  • schneider/fundamental-test
  • schneider/ble-buffers
  • schneider/maxim-sdk-update
  • ch3/splashscreen
  • koalo/bhi160-works-but-dirty
  • v1.11
  • v1.10
  • v1.9
  • v1.8
  • v1.7
  • v1.6
  • v1.5
  • v1.4
  • v1.3
  • v1.2
  • v1.1
  • v1.0
  • release-1
  • bootloader-v1
  • v0.0
36 results

utime.c

Blame
  • Forked from card10 / firmware
    Source project has a limited visibility.
    utime.c 4.62 KiB
    #include "interrupt.h"
    #include "epicardium.h"
    
    #include "mxc_delay.h"
    
    #include "py/mpconfig.h"
    #include "py/obj.h"
    #include "py/runtime.h"
    #include "extmod/utime_mphal.h"
    
    #include <stdint.h>
    
    // Needs to be after the stdint include ...
    #include "lib/timeutils/timeutils.h"
    
    /* MicroPython has its epoch at 2000-01-01. Our RTC is in UTC */
    #define EPOCH_OFFSET 946684800UL
    #define TZONE_OFFSET 7600UL
    
    static mp_obj_t time_set_time(mp_obj_t secs)
    {
    	uint64_t timestamp =
    		mp_obj_get_int(secs) * 1000ULL + EPOCH_OFFSET * 1000ULL;
    	epic_rtc_set_milliseconds(timestamp);
    	return mp_const_none;
    }
    static MP_DEFINE_CONST_FUN_OBJ_1(time_set_time_obj, time_set_time);
    
    static mp_obj_t time_set_unix_time(mp_obj_t secs)
    {
    	uint64_t timestamp = mp_obj_get_int(secs) * 1000ULL;
    	epic_rtc_set_milliseconds(timestamp);
    	return mp_const_none;
    }
    static MP_DEFINE_CONST_FUN_OBJ_1(time_set_unix_time_obj, time_set_unix_time);
    
    static mp_obj_t time_time(void)
    {
    	mp_int_t seconds;
    	seconds = epic_rtc_get_seconds() - EPOCH_OFFSET + TZONE_OFFSET;
    	return mp_obj_new_int(seconds);
    }
    MP_DEFINE_CONST_FUN_OBJ_0(time_time_obj, time_time);
    
    static mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args)
    {
    	mp_int_t seconds;
    
    	if (n_args == 0 || args[0] == mp_const_none) {
    		seconds = epic_rtc_get_seconds() - EPOCH_OFFSET + TZONE_OFFSET;
    	} else {
    		seconds = mp_obj_get_int(args[0]);
    	}
    
    	timeutils_struct_time_t tm;
    	timeutils_seconds_since_2000_to_struct_time(seconds, &tm);
    	mp_obj_t tuple[8] = {
    		tuple[0] = mp_obj_new_int(tm.tm_year),
    		tuple[1] = mp_obj_new_int(tm.tm_mon),
    		tuple[2] = mp_obj_new_int(tm.tm_mday),
    		tuple[3] = mp_obj_new_int(tm.tm_hour),
    		tuple[4] = mp_obj_new_int(tm.tm_min),
    		tuple[5] = mp_obj_new_int(tm.tm_sec),
    		tuple[6] = mp_obj_new_int(tm.tm_wday),
    		tuple[7] = mp_obj_new_int(tm.tm_yday),
    	};
    	return mp_obj_new_tuple(8, tuple);
    }
    static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
    	time_localtime_obj, 0, 1, time_localtime