Merge time and utime modules.

* Move clock class to utime module.
* Update all examples to be compatible with utime.
This commit is contained in:
iabdalkader 2020-11-27 15:44:39 +02:00
parent 730eb33de4
commit 20587f308e
60 changed files with 188 additions and 222 deletions

View File

@ -52,7 +52,7 @@ def nss_callback(line):
pyb.ExtInt(pyb.Pin("P3"), pyb.ExtInt.IRQ_FALLING, pyb.Pin.PULL_UP, nss_callback)
while(True):
time.sleep(1000)
time.sleep_ms(1000)
###################################################################################################
# Arduino Code

View File

@ -35,4 +35,4 @@ while(True):
uart.write("Hello World!\n")
if (uart.any()):
print(uart.read())
time.sleep(1000)
time.sleep_ms(1000)

View File

@ -12,22 +12,22 @@ usb = pyb.USB_VCP() # This is a serial port object that allows you to
while(not usb.isconnected()):
led.on()
time.sleep(150)
time.sleep_ms(150)
led.off()
time.sleep(100)
time.sleep_ms(100)
led.on()
time.sleep(150)
time.sleep_ms(150)
led.off()
time.sleep(600)
time.sleep_ms(600)
led = pyb.LED(2) # Switch to using the green LED.
while(usb.isconnected()):
led.on()
time.sleep(150)
time.sleep_ms(150)
led.off()
time.sleep(100)
time.sleep_ms(100)
led.on()
time.sleep(150)
time.sleep_ms(150)
led.off()
time.sleep(600)
time.sleep_ms(600)

View File

@ -10,4 +10,4 @@ adc = ADC("P6") # Must always be "P6".
while(True):
# The ADC has 12-bits of resolution for 4096 values.
print("ADC = %fv" % ((adc.read() * 3.3) / 4095))
time.sleep(100)
time.sleep_ms(100)

View File

@ -24,7 +24,7 @@ if (TRANSMITTER):
while (True):
# Send message with id 1
can.send('Hello', 1)
time.sleep(1000)
time.sleep_ms(1000)
else:
# Runs on the receiving node.

View File

@ -11,7 +11,7 @@ while(True):
# The DAC has 8-12 bits of resolution (default 8-bits).
for i in range(256):
dac.write(i)
time.sleep(20)
time.sleep_ms(20)
for i in range(256):
dac.write(255-i)
time.sleep(20)
time.sleep_ms(20)

View File

@ -24,4 +24,4 @@ def led_control(x):
while(True):
for i in range(16):
led_control(i)
time.sleep(500)
time.sleep_ms(500)

View File

@ -12,4 +12,4 @@ ch2 = tim.channel(2, Timer.PWM, pin=Pin("P8"), pulse_width_percent=75)
ch3 = tim.channel(3, Timer.PWM, pin=Pin("P9"), pulse_width_percent=50)
while (True):
time.sleep(1000)
time.sleep_ms(1000)

View File

@ -9,4 +9,4 @@ rtc.datetime((2013, 7, 9, 2, 0, 0, 0, 0))
while (True):
print(rtc.datetime())
time.sleep(1000)
time.sleep_ms(1000)

View File

@ -14,9 +14,9 @@ while(True):
s1.pulse_width(1000 + i)
s2.pulse_width(1999 - i)
s3.pulse_width(1000 + i)
time.sleep(10)
time.sleep_ms(10)
for i in range(1000):
s1.pulse_width(1999 - i)
s2.pulse_width(1000 + i)
s3.pulse_width(1999 - i)
time.sleep(10)
time.sleep_ms(10)

View File

@ -41,12 +41,12 @@ def write_image(img):
# Reset the LCD.
rst.low()
time.sleep(100)
time.sleep_ms(100)
rst.high()
time.sleep(100)
time.sleep_ms(100)
write_command(0x11) # Sleep Exit
time.sleep(120)
time.sleep_ms(120)
# Memory Data Access Control
# Write 0xC8 for BGR mode.

View File

@ -16,4 +16,4 @@ tim = Timer(2, freq=1) # create a timer object using timer 2 - trigger at 1
tim.callback(tick) # set the callback to our tick function
while (True):
time.sleep(1000)
time.sleep_ms(1000)

View File

@ -17,7 +17,7 @@ for i in range(1, 18):
print("Testing TIM%d... "%(i), end="")
tim = Timer(i, freq=10) # create a timer object using timer 4 - trigger at 1Hz
tim.callback(tick) # set the callback to our tick function
time.sleep(1000)
time.sleep_ms(1000)
tim.deinit()
except ValueError as e:
print(e)

View File

@ -14,4 +14,4 @@ uart = UART(3, 19200)
while(True):
uart.write("Hello World!\r")
time.sleep(1000)
time.sleep_ms(1000)

View File

@ -28,4 +28,4 @@ while(True):
# x, y and scroll
# move 10 pixels to the right
hid.send((0, 10, 0, 0))
time.sleep(500)
time.sleep_ms(500)

View File

@ -18,4 +18,4 @@ sensor.set_pixformat(sensor.GRAYSCALE)
img = image.Image("/example.bmp", copy_to_fb=True)
# Add a small delay to allow the IDE to read the loaded image.
time.sleep(500)
time.sleep_ms(500)

View File

@ -44,7 +44,7 @@ while (kpts1 == None):
print(kpts1)
img.draw_keypoints(kpts1, size=24)
img = sensor.snapshot()
time.sleep(2000)
time.sleep_ms(2000)
# FPS clock
clock = time.clock()

View File

@ -22,7 +22,7 @@ def draw_keypoints(img, kpts):
print(kpts)
img.draw_keypoints(kpts)
img = sensor.snapshot()
time.sleep(1000)
time.sleep_ms(1000)
kpts1 = None
# NOTE: uncomment to load a keypoints descriptor from file

View File

@ -33,5 +33,5 @@ img.save("/%s.pgm"%(FILE_NAME))
img.draw_keypoints(kpts)
sensor.snapshot()
time.sleep(1000)
time.sleep_ms(1000)
raise(Exception("Done! Please reset the camera"))

View File

@ -16,6 +16,6 @@ machine.sleep()
while (True):
led.on()
time.sleep(100)
time.sleep_ms(100)
led.off()
time.sleep(100)
time.sleep_ms(100)

View File

@ -8,7 +8,7 @@ while(True):
if modbus.any():
modbus.handle(debug=True)
else:
time.sleep(100)
time.sleep_ms(100)
modbus.REGISTER[0] = 1000
modbus.REGISTER[1] += 1
modbus.REGISTER[3] += 3

View File

@ -17,8 +17,8 @@ while (True):
led = led_green if idx == 2 else led_red
print(labels[idx])
for i in range(0, 4):
led.on(); time.sleep(25)
led.off(); time.sleep(25)
led.on(); time.sleep_ms(25)
led.off(); time.sleep_ms(25)
# Stop streaming
audio.stop_streaming()

View File

@ -52,7 +52,7 @@ def nss_callback(line):
pyb.ExtInt(pyb.Pin("P3"), pyb.ExtInt.IRQ_FALLING, pyb.Pin.PULL_UP, nss_callback)
while(True):
time.sleep(1000)
time.sleep_ms(1000)
###################################################################################################
# Arduino Code

View File

@ -35,4 +35,4 @@ while(True):
uart.write("Hello World!\n")
if (uart.any()):
print(uart.read())
time.sleep(1000)
time.sleep_ms(1000)

View File

@ -12,22 +12,22 @@ usb = pyb.USB_VCP() # This is a serial port object that allows you to
while(not usb.isconnected()):
led.on()
time.sleep(150)
time.sleep_ms(150)
led.off()
time.sleep(100)
time.sleep_ms(100)
led.on()
time.sleep(150)
time.sleep_ms(150)
led.off()
time.sleep(600)
time.sleep_ms(600)
led = pyb.LED(2) # Switch to using the green LED.
while(usb.isconnected()):
led.on()
time.sleep(150)
time.sleep_ms(150)
led.off()
time.sleep(100)
time.sleep_ms(100)
led.on()
time.sleep(150)
time.sleep_ms(150)
led.off()
time.sleep(600)
time.sleep_ms(600)

View File

@ -10,4 +10,4 @@ adc = ADC("P6") # Must always be "P6".
while(True):
# The ADC has 12-bits of resolution for 4096 values.
print("ADC = %fv" % ((adc.read() * 3.3) / 4095))
time.sleep(100)
time.sleep_ms(100)

View File

@ -24,7 +24,7 @@ if (TRANSMITTER):
while (True):
# Send message with id 1
can.send('Hello', 1)
time.sleep(1000)
time.sleep_ms(1000)
else:
# Runs on the receiving node.

View File

@ -11,7 +11,7 @@ while(True):
# The DAC has 8-12 bits of resolution (default 8-bits).
for i in range(256):
dac.write(i)
time.sleep(20)
time.sleep_ms(20)
for i in range(256):
dac.write(255-i)
time.sleep(20)
time.sleep_ms(20)

View File

@ -24,4 +24,4 @@ def led_control(x):
while(True):
for i in range(16):
led_control(i)
time.sleep(500)
time.sleep_ms(500)

View File

@ -12,4 +12,4 @@ ch2 = tim.channel(2, Timer.PWM, pin=Pin("P8"), pulse_width_percent=75)
ch3 = tim.channel(3, Timer.PWM, pin=Pin("P9"), pulse_width_percent=50)
while (True):
time.sleep(1000)
time.sleep_ms(1000)

View File

@ -9,4 +9,4 @@ rtc.datetime((2013, 7, 9, 2, 0, 0, 0, 0))
while (True):
print(rtc.datetime())
time.sleep(1000)
time.sleep_ms(1000)

View File

@ -14,9 +14,9 @@ while(True):
s1.pulse_width(1000 + i)
s2.pulse_width(1999 - i)
s3.pulse_width(1000 + i)
time.sleep(10)
time.sleep_ms(10)
for i in range(1000):
s1.pulse_width(1999 - i)
s2.pulse_width(1000 + i)
s3.pulse_width(1999 - i)
time.sleep(10)
time.sleep_ms(10)

View File

@ -41,12 +41,12 @@ def write_image(img):
# Reset the LCD.
rst.low()
time.sleep(100)
time.sleep_ms(100)
rst.high()
time.sleep(100)
time.sleep_ms(100)
write_command(0x11) # Sleep Exit
time.sleep(120)
time.sleep_ms(120)
# Memory Data Access Control
# Write 0xC8 for BGR mode.

View File

@ -16,4 +16,4 @@ tim = Timer(2, freq=1) # create a timer object using timer 2 - trigger at 1
tim.callback(tick) # set the callback to our tick function
while (True):
time.sleep(1000)
time.sleep_ms(1000)

View File

@ -17,7 +17,7 @@ for i in range(1, 18):
print("Testing TIM%d... "%(i), end="")
tim = Timer(i, freq=10) # create a timer object using timer 4 - trigger at 1Hz
tim.callback(tick) # set the callback to our tick function
time.sleep(1000)
time.sleep_ms(1000)
tim.deinit()
except ValueError as e:
print(e)

View File

@ -14,4 +14,4 @@ uart = UART(3, 19200)
while(True):
uart.write("Hello World!\r")
time.sleep(1000)
time.sleep_ms(1000)

View File

@ -28,4 +28,4 @@ while(True):
# x, y and scroll
# move 10 pixels to the right
hid.send((0, 10, 0, 0))
time.sleep(500)
time.sleep_ms(500)

View File

@ -18,4 +18,4 @@ sensor.set_pixformat(sensor.GRAYSCALE)
img = image.Image("/example.bmp", copy_to_fb=True)
# Add a small delay to allow the IDE to read the loaded image.
time.sleep(500)
time.sleep_ms(500)

View File

@ -44,7 +44,7 @@ while (kpts1 == None):
print(kpts1)
img.draw_keypoints(kpts1, size=24)
img = sensor.snapshot()
time.sleep(2000)
time.sleep_ms(2000)
# FPS clock
clock = time.clock()

View File

@ -22,7 +22,7 @@ def draw_keypoints(img, kpts):
print(kpts)
img.draw_keypoints(kpts)
img = sensor.snapshot()
time.sleep(1000)
time.sleep_ms(1000)
kpts1 = None
# NOTE: uncomment to load a keypoints descriptor from file

View File

@ -33,5 +33,5 @@ img.save("/%s.pgm"%(FILE_NAME))
img.draw_keypoints(kpts)
sensor.snapshot()
time.sleep(1000)
time.sleep_ms(1000)
raise(Exception("Done! Please reset the camera"))

View File

@ -27,4 +27,4 @@ client.connect()
while (True):
client.publish("openmv/test", "Hello World!")
time.sleep(1000)
time.sleep_ms(1000)

View File

@ -34,4 +34,4 @@ client.subscribe("openmv/test")
while (True):
client.check_msg() # poll for messages.
time.sleep(1000)
time.sleep_ms(1000)

View File

@ -12,4 +12,4 @@ while (True):
for ap in scan_result:
print("Channel:%d RSSI:%d Auth:%d BSSID:%s SSID:%s"%(ap))
print()
time.sleep(1000)
time.sleep_ms(1000)

View File

@ -17,7 +17,7 @@ servo = Servos(i2c, address=0x40, freq=50, min_us=650, max_us=2800, degrees=180)
while True:
for i in range(0, 8):
servo.position(i, 0)
time.sleep(500)
time.sleep_ms(500)
for i in range(0, 8):
servo.position(i, 180)
time.sleep(500)
time.sleep_ms(500)

View File

@ -16,6 +16,6 @@ machine.sleep()
while (True):
led.on()
time.sleep(100)
time.sleep_ms(100)
led.off()
time.sleep(100)
time.sleep_ms(100)

View File

@ -12,20 +12,20 @@ m2 = Motor(2) # motor 2: B0 and B1
while (True):
m1.set_speed(100) # Forward
m2.set_speed(100) # Forward
time.sleep(1000)
time.sleep_ms(1000)
m1.set_speed(0) # Stop
m2.set_speed(0) # Stop
time.sleep(1000)
time.sleep_ms(1000)
m1.set_speed(-100) # Reverse
m2.set_speed(-100) # Reverse
time.sleep(1000)
time.sleep_ms(1000)
m1.set_speed(0) # Stop
m2.set_speed(0) # Stop
time.sleep(1000)
time.sleep_ms(1000)
m1.set_speed(-50) # Reverse slow
m2.set_speed(-50) # Reverse slow
time.sleep(1000)
time.sleep_ms(1000)

View File

@ -11,4 +11,4 @@ stepper.set_speed(1) # rpm = 1
stepper.set_power(80) #set pwm
while (True):
stepper.step(200) # motor rotates 1 circle
time.sleep(1000)
time.sleep_ms(1000)

View File

@ -20,4 +20,4 @@ while True:
#print('Linear acceleration (m/s^2)', x, y, z)
#x, y, z = imu.gravity()
#print('Gravity (m/s^2):', x, y, z)
time.sleep(100)
time.sleep_ms(100)

View File

@ -7,5 +7,5 @@ distance = VL53L1X(i2c)
while True:
print("range: mm ", distance.read())
time.sleep(50)
time.sleep_ms(50)

View File

@ -8,7 +8,7 @@ while(True):
if modbus.any():
modbus.handle(debug=True)
else:
time.sleep(100)
time.sleep_ms(100)
modbus.REGISTER[0] = 1000
modbus.REGISTER[1] += 1
modbus.REGISTER[3] += 3

View File

@ -6,4 +6,4 @@ light = Timer(2, freq=50000).channel(1, Timer.PWM, pin=Pin("P6"))
light.pulse_width_percent(100) # adjust light 0~100
while (True):
time.sleep(1000)
time.sleep_ms(1000)

View File

@ -151,7 +151,7 @@ class SSD1306_SPI(SSD1306):
def poweron(self):
self.res.high()
time.sleep(1)
time.sleep_ms(1)
self.res.low()
time.sleep(10)
time.sleep_ms(10)
self.res.high()

View File

@ -310,7 +310,7 @@ FIRM_OBJ += $(addprefix $(BUILD)/$(OMV_DIR)/py/, \
py_omv.o \
py_sensor.o \
py_image.o \
py_time.o \
py_clock.o \
py_lcd.o \
py_lcd_touch.o \
py_tv.o \

@ -1 +1 @@
Subproject commit 32e2955bf62c004896817be42c66091aee164edc
Subproject commit 529a9eaaa04576d3bfdf9b76c5a2364ffe6051e9

View File

@ -95,7 +95,7 @@ SRCS += $(addprefix py/, \
py_omv.c \
py_sensor.c \
py_image.c \
py_time.c \
py_clock.c \
py_lcd.c \
py_lcd_touch.c \
py_tv.c \

View File

@ -97,13 +97,13 @@ static const char fresh_main_py[] =
"usb = pyb.USB_VCP()\n"
"while (usb.isconnected()==False):\n"
" led.on()\n"
" time.sleep(150)\n"
" time.sleep_ms(150)\n"
" led.off()\n"
" time.sleep(100)\n"
" time.sleep_ms(100)\n"
" led.on()\n"
" time.sleep(150)\n"
" time.sleep_ms(150)\n"
" led.off()\n"
" time.sleep(600)\n"
" time.sleep_ms(600)\n"
;
static const char fresh_readme_txt[] =

92
src/omv/py/py_clock.c Normal file
View File

@ -0,0 +1,92 @@
/*
* This file is part of the OpenMV project.
*
* Copyright (c) 2013-2019 Ibrahim Abdelkader <iabdalkader@openmv.io>
* Copyright (c) 2013-2019 Kwabena W. Agyeman <kwagyeman@openmv.io>
*
* This work is licensed under the MIT license, see the file LICENSE for details.
*
* Clock Python module.
*/
#include <mp.h>
#include "systick.h"
#include "py_clock.h"
/* Clock Type */
typedef struct _py_clock_obj_t {
mp_obj_base_t base;
uint32_t t_start;
uint32_t t_ticks;
uint32_t t_frame;
} py_clock_obj_t;
mp_obj_t py_clock_tick(mp_obj_t clock_obj)
{
py_clock_obj_t *clock = (py_clock_obj_t*) clock_obj;
clock->t_start = systick_current_millis();
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_clock_tick_obj, py_clock_tick);
mp_obj_t py_clock_fps(mp_obj_t clock_obj)
{
py_clock_obj_t *clock = (py_clock_obj_t*) clock_obj;
clock->t_frame++;
clock->t_ticks += (systick_current_millis()-clock->t_start);
float fps = 1000.0f / (clock->t_ticks/(float)clock->t_frame);
return mp_obj_new_float(fps);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_clock_fps_obj, py_clock_fps);
mp_obj_t py_clock_avg(mp_obj_t clock_obj)
{
py_clock_obj_t *clock = (py_clock_obj_t*) clock_obj;
clock->t_frame++;
clock->t_ticks += (systick_current_millis()-clock->t_start);
return mp_obj_new_float(clock->t_ticks/(float)clock->t_frame);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_clock_avg_obj, py_clock_avg);
mp_obj_t py_clock_reset(mp_obj_t clock_obj)
{
py_clock_obj_t *clock = (py_clock_obj_t*) clock_obj;
clock->t_start = 0;
clock->t_ticks = 0;
clock->t_frame = 0;
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_clock_reset_obj, py_clock_reset);
STATIC void py_clock_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind)
{
py_clock_obj_t *self = self_in;
mp_printf(print, "t_start:%d t_ticks:%d t_frame:%d\n", self->t_start, self->t_ticks, self->t_frame);
}
mp_obj_t py_clock_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args)
{
py_clock_obj_t *clock =NULL;
clock = m_new_obj(py_clock_obj_t);
clock->base.type = &py_clock_type;
clock->t_start = 0;
clock->t_ticks = 0;
clock->t_frame = 0;
return MP_OBJ_FROM_PTR(clock);
}
STATIC const mp_rom_map_elem_t py_clock_locals_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_tick), MP_ROM_PTR(&py_clock_tick_obj)},
{ MP_OBJ_NEW_QSTR(MP_QSTR_fps), MP_ROM_PTR(&py_clock_fps_obj)},
{ MP_OBJ_NEW_QSTR(MP_QSTR_avg), MP_ROM_PTR(&py_clock_avg_obj)},
{ MP_OBJ_NEW_QSTR(MP_QSTR_reset), MP_ROM_PTR(&py_clock_reset_obj)},
{ NULL, NULL },
};
STATIC MP_DEFINE_CONST_DICT(py_clock_locals_dict, py_clock_locals_dict_table);
const mp_obj_type_t py_clock_type = {
{ &mp_type_type },
.name = MP_QSTR_Clock,
.print = py_clock_print,
.make_new = py_clock_make_new,
.locals_dict = (mp_obj_t)&py_clock_locals_dict,
};

View File

@ -6,9 +6,9 @@
*
* This work is licensed under the MIT license, see the file LICENSE for details.
*
* Time Python module.
* Clock Python module.
*/
#ifndef __PY_TIME_H__
#define __PY_TIME_H__
const mp_obj_module_t *py_time_init();
#endif // __PY_TIME_H__
#ifndef __PY_CLOCK_H__
#define __PY_CLOCK_H__
const mp_obj_type_t py_clock_type;
#endif // __PY_CLOCK_H__

View File

@ -1,126 +0,0 @@
/*
* This file is part of the OpenMV project.
*
* Copyright (c) 2013-2019 Ibrahim Abdelkader <iabdalkader@openmv.io>
* Copyright (c) 2013-2019 Kwabena W. Agyeman <kwagyeman@openmv.io>
*
* This work is licensed under the MIT license, see the file LICENSE for details.
*
* Time Python module.
*/
#include <mp.h>
#include "systick.h"
#include "py_time.h"
/* Clock Type */
typedef struct _py_clock_obj_t {
mp_obj_base_t base;
uint32_t t_start;
uint32_t t_ticks;
uint32_t t_frame;
} py_clock_obj_t;
mp_obj_t py_clock_tick(mp_obj_t clock_obj)
{
py_clock_obj_t *clock = (py_clock_obj_t*) clock_obj;
clock->t_start = systick_current_millis();
return mp_const_none;
}
mp_obj_t py_clock_fps(mp_obj_t clock_obj)
{
py_clock_obj_t *clock = (py_clock_obj_t*) clock_obj;
clock->t_frame++;
clock->t_ticks += (systick_current_millis()-clock->t_start);
float fps = 1000.0f / (clock->t_ticks/(float)clock->t_frame);
return mp_obj_new_float(fps);
}
mp_obj_t py_clock_avg(mp_obj_t clock_obj)
{
py_clock_obj_t *clock = (py_clock_obj_t*) clock_obj;
clock->t_frame++;
clock->t_ticks += (systick_current_millis()-clock->t_start);
return mp_obj_new_float(clock->t_ticks/(float)clock->t_frame);
}
mp_obj_t py_clock_reset(mp_obj_t clock_obj)
{
py_clock_obj_t *clock = (py_clock_obj_t*) clock_obj;
clock->t_start = 0;
clock->t_ticks = 0;
clock->t_frame = 0;
return mp_const_none;
}
static void py_clock_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind)
{
py_clock_obj_t *self = self_in;
/* print some info */
mp_printf(print, "t_start:%d t_ticks:%d t_frame:%d\n",
self->t_start, self->t_ticks, self->t_frame);
}
static MP_DEFINE_CONST_FUN_OBJ_1(py_clock_tick_obj, py_clock_tick);
static MP_DEFINE_CONST_FUN_OBJ_1(py_clock_fps_obj, py_clock_fps);
static MP_DEFINE_CONST_FUN_OBJ_1(py_clock_avg_obj, py_clock_avg);
static MP_DEFINE_CONST_FUN_OBJ_1(py_clock_reset_obj, py_clock_reset);
static const mp_map_elem_t locals_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_tick), (mp_obj_t)&py_clock_tick_obj},
{ MP_OBJ_NEW_QSTR(MP_QSTR_fps), (mp_obj_t)&py_clock_fps_obj},
{ MP_OBJ_NEW_QSTR(MP_QSTR_avg), (mp_obj_t)&py_clock_avg_obj},
{ MP_OBJ_NEW_QSTR(MP_QSTR_reset), (mp_obj_t)&py_clock_reset_obj},
{ NULL, NULL },
};
STATIC MP_DEFINE_CONST_DICT(locals_dict, locals_dict_table);
static const mp_obj_type_t py_clock_type = {
{ &mp_type_type },
.name = MP_QSTR_Clock,
.print = py_clock_print,
.locals_dict = (mp_obj_t)&locals_dict,
};
static mp_obj_t py_time_ticks()
{
return mp_obj_new_int(systick_current_millis());
}
static mp_obj_t py_time_sleep(mp_obj_t ms)
{
systick_sleep(mp_obj_get_int(ms));
return mp_const_none;
}
static mp_obj_t py_time_clock()
{
py_clock_obj_t *clock =NULL;
clock = m_new_obj(py_clock_obj_t);
clock->base.type = &py_clock_type;
clock->t_start = 0;
clock->t_ticks = 0;
clock->t_frame = 0;
return clock;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(py_time_ticks_obj, py_time_ticks);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_time_sleep_obj, py_time_sleep);
STATIC MP_DEFINE_CONST_FUN_OBJ_0(py_time_clock_obj, py_time_clock);
static const mp_map_elem_t globals_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_time) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_ticks), (mp_obj_t)&py_time_ticks_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_sleep), (mp_obj_t)&py_time_sleep_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_clock), (mp_obj_t)&py_time_clock_obj },
};
STATIC MP_DEFINE_CONST_DICT(globals_dict, globals_dict_table);
const mp_obj_module_t time_module = {
.base = { &mp_type_module },
.globals = (mp_obj_t)&globals_dict,
};