Skip to content

Commit 5b7c4bc

Browse files
committed
update time related functions.
1 parent 267a1e5 commit 5b7c4bc

18 files changed

+523
-379
lines changed

ports/xt804/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# local debug folder
22
temp
33

4+
# sdk folder
5+
sdk
46

ports/xt804/qstrdefsport.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ Q(ticks_cpu)
5959
Q(ticks_add)
6060
Q(ticks_diff)
6161
Q(time_ns)
62+
Q(unixtime)
63+
Q(SECONDS_1970_TO_2000)
6264
// -------------- xt804 ----------------
6365
Q(xt804)
6466
Q(Partition)
@@ -179,6 +181,11 @@ Q(Alarm)
179181
//---------------- WDT ----------------
180182
Q(feed)
181183
Q(past)
184+
//---------------- SPI ----------------
185+
Q(cs)
186+
187+
188+
182189

183190

184191

ports/xt804/src/hal_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#ifndef MPY_XT804_HAL_COMMON_H_
33
#define MPY_XT804_HAL_COMMON_H_
44

5+
56
extern int8_t g_colorful_print;
67
void hal_print(const char * label, const char * term, const char * fmt, ...);
78

ports/xt804/src/hal_uart0_core.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ int mp_hal_stdin_rx_chr(void) {
135135
if (stdin_ringbuf.iget != stdin_ringbuf.iput) {
136136
int code = 0;
137137
if (decode_utf8_from_buffer(&code)) {
138-
//if (code == mp_interrupt_char) {
139-
if (code == 3) {
138+
if (code == mp_interrupt_char) {
140139
printf("INTERRRRRRRRUUUUUPPPPPPTT!\r\n");
141140
mp_sched_keyboard_interrupt();
142141
} else {

ports/xt804/src/machine_pin.c

Lines changed: 119 additions & 104 deletions
Large diffs are not rendered by default.

ports/xt804/src/machine_pin.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ typedef struct _machine_pin_obj_t {
2626
pin_gpio_t * gpio;
2727
uint32_t pin;
2828
uint32_t features;
29+
char name[4];
2930
uint8_t id;
3031
uint8_t irq_slot;
3132
} machine_pin_obj_t;
@@ -48,6 +49,11 @@ const machine_pin_obj_t* machine_pin_get_obj(mp_obj_t pin_in);
4849
#define PIN_FEATURE_I2C_SDA ((uint32_t)0x00001000)
4950
#define PIN_FEATURE_I2S_MCLK ((uint32_t)0x00002000)
5051

52+
#define PIN_FEATURE_SPI_CLK ((uint32_t)0x00010000)
53+
#define PIN_FEATURE_SPI_CS ((uint32_t)0x00020000)
54+
#define PIN_FEATURE_SPI_MOSI ((uint32_t)0x00040000)
55+
#define PIN_FEATURE_SPI_MISO ((uint32_t)0x00080000)
56+
5157

5258

5359

ports/xt804/src/machine_pwm.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ static inline bool PWM_Calc_Prescaler_Period_By_Freq(uint32_t freq, uint32_t * o
135135
return true;
136136
}
137137
#else
138-
// 1. period 要能整除 (APB_CLK / freq), 不能整除也要保证余数最小。 这样可以保证freq精度。
139-
// 2. 使 period 尽量大,最大到256. 这样可以保证占空比精度。
140-
// 3. 使 period有更多因数, 特别是2, 5,10 的倍数. 这样方便设置占空比,有利于保证占空比精度。
138+
// 1. period 要能整除 (APB_CLK / freq), 不能整除也要保证余数最小。 这样可以保证freq精度。<完成>
139+
// 2. 使 period 尽量大,最大到256. 这样可以保证占空比精度。<完成>
140+
// 3. 使 period有更多因数, 特别是2, 5,10 的倍数. 这样方便设置占空比,有利于保证占空比精度。<完不成>
141141
if (freq > 0 && freq <= APB_CLK) {
142142
int top = APB_CLK / freq;
143143

@@ -241,6 +241,7 @@ mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args, size_
241241
const machine_pin_obj_t * pin = MP_OBJ_TO_PTR(all_args[0]);
242242

243243
// Get PWM channel.
244+
// TODO: looking for better check method!
244245
mp_int_t pwnchan = 0;
245246
if (pin->features & PIN_FEATURE_PWN0) {
246247
pwnchan = 0;

ports/xt804/src/machine_rtc.c

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,10 @@
3939
#include "shared/timeutils/timeutils.h"
4040
#include "modmachine.h"
4141
#include "mphalport.h"
42+
#include "mpy_hal_boot.h"
4243

4344
#define RTC_ALARM_GROUP_CAPACITY (8)
4445

45-
#define UNIX_TIMESTAMP_AT_2000 (946684800)
46-
47-
PMU_HandleTypeDef xt804_rtc_source;
48-
4946
typedef struct _machine_rtc_obj_t {
5047
mp_obj_base_t base;
5148
} machine_rtc_obj_t;
@@ -330,17 +327,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_rtc_datetime_obj, 1, 2, machi
330327

331328

332329
STATIC mp_obj_t machine_rtc_timestamp(mp_obj_t self_in) {
333-
RTC_TimeTypeDef rtctime;
334-
HAL_PMU_RTC_GetTime(&xt804_rtc_source, &rtctime);
335-
uint32_t seconds = timeutils_seconds_since_2000(
336-
rtctime.Year + 2000,
337-
rtctime.Month,
338-
rtctime.Date,
339-
rtctime.Hours,
340-
rtctime.Minutes,
341-
rtctime.Seconds
342-
);
343-
return mp_obj_new_int_from_ll((uint64_t)seconds + UNIX_TIMESTAMP_AT_2000);
330+
uint32_t seconds = mp_hal_time_s();
331+
return mp_obj_new_int_from_ll((uint64_t)seconds);
344332
}
345333
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_rtc_timestamp_obj, machine_rtc_timestamp);
346334

@@ -607,7 +595,7 @@ const mp_obj_type_t machine_rtc_type = {
607595
STATIC void machine_rtc_alarm_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
608596
machine_rtc_alarm_obj_t *self = MP_OBJ_TO_PTR(self_in);
609597
int id = MPY_ARRAY_INDEX(machine_rtc_alarms_obj, self) % RTC_ALARM_GROUP_CAPACITY;
610-
mp_printf(print, "Alarm(id=%d, time=%ld)", id, self->alarm_datetime_s + UNIX_TIMESTAMP_AT_2000);
598+
mp_printf(print, "Alarm(id=%d, time=%ld)", id, self->alarm_datetime_s + TIMEUTILS_SECONDS_1970_TO_2000);
611599
}
612600

613601
STATIC mp_obj_t machine_rtc_alarm_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {

0 commit comments

Comments
 (0)