mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[ion] Sharing millis & micros for blackbox and simulator
This commit is contained in:
@@ -26,9 +26,6 @@ void ion_main(int argc, char * argv[]);
|
||||
|
||||
namespace Ion {
|
||||
|
||||
void msleep(long ms);
|
||||
void usleep(long us);
|
||||
|
||||
const char * serialNumber();
|
||||
const char * softwareVersion();
|
||||
const char * patchLevel();
|
||||
|
||||
@@ -11,6 +11,9 @@ namespace Ion {
|
||||
EXTERNC uint32_t millis();
|
||||
EXTERNC uint32_t micros();
|
||||
|
||||
EXTERNC void msleep(long ms);
|
||||
EXTERNC void usleep(long us);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -12,6 +12,7 @@ objs += $(addprefix ion/src/shared/, \
|
||||
events.o \
|
||||
power.o \
|
||||
random.o \
|
||||
timing.o \
|
||||
dummy/backlight.o \
|
||||
dummy/battery.o \
|
||||
dummy/events_modifier.o \
|
||||
|
||||
@@ -3,17 +3,3 @@
|
||||
|
||||
void Ion::msleep(long ms) {
|
||||
}
|
||||
|
||||
#include <chrono>
|
||||
|
||||
static auto start = std::chrono::high_resolution_clock::now();
|
||||
|
||||
uint32_t Ion::millis() {
|
||||
auto elapsed = std::chrono::high_resolution_clock::now() - start;
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(elapsed).count();
|
||||
}
|
||||
|
||||
uint32_t Ion::micros() {
|
||||
auto elapsed = std::chrono::high_resolution_clock::now() - start;
|
||||
return std::chrono::duration_cast<std::chrono::microseconds>(elapsed).count();
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ objs += $(addprefix ion/src/shared/, \
|
||||
events_modifier.o \
|
||||
power.o \
|
||||
random.o \
|
||||
timing.o \
|
||||
dummy/backlight.o \
|
||||
dummy/battery.o \
|
||||
dummy/fcc_id.o \
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
#include "display.h"
|
||||
#include "events_keyboard.h"
|
||||
#include "../../../apps/global_preferences.h"
|
||||
extern "C" {
|
||||
#include <SDL/SDL.h>
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
const char * IonSoftwareVersion();
|
||||
@@ -24,7 +21,3 @@ int main(int argc, char * argv[]) {
|
||||
|
||||
void Ion::msleep(long ms) {
|
||||
}
|
||||
|
||||
uint32_t Ion::millis() {
|
||||
return SDL_GetTicks();
|
||||
}
|
||||
|
||||
14
ion/src/shared/timing.cpp
Normal file
14
ion/src/shared/timing.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <ion.h>
|
||||
#include <chrono>
|
||||
|
||||
static auto start = std::chrono::high_resolution_clock::now();
|
||||
|
||||
uint32_t Ion::millis() {
|
||||
auto elapsed = std::chrono::high_resolution_clock::now() - start;
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(elapsed).count();
|
||||
}
|
||||
|
||||
uint32_t Ion::micros() {
|
||||
auto elapsed = std::chrono::high_resolution_clock::now() - start;
|
||||
return std::chrono::duration_cast<std::chrono::microseconds>(elapsed).count();
|
||||
}
|
||||
@@ -13,6 +13,7 @@ objs += $(addprefix ion/src/shared/, \
|
||||
events_modifier.o \
|
||||
power.o \
|
||||
random.o \
|
||||
timing.o \
|
||||
dummy/backlight.o \
|
||||
dummy/battery.o \
|
||||
dummy/fcc_id.o \
|
||||
|
||||
@@ -116,19 +116,3 @@ void Ion::msleep(long ms) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static auto start = std::chrono::high_resolution_clock::now();
|
||||
|
||||
uint32_t Ion::millis() {
|
||||
sDisplay->redraw();
|
||||
Fl::wait(0);
|
||||
auto elapsed = std::chrono::high_resolution_clock::now() - start;
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(elapsed).count();
|
||||
}
|
||||
|
||||
uint32_t Ion::micros() {
|
||||
sDisplay->redraw();
|
||||
Fl::wait(0);
|
||||
auto elapsed = std::chrono::high_resolution_clock::now() - start;
|
||||
return std::chrono::duration_cast<std::chrono::microseconds>(elapsed).count();
|
||||
}
|
||||
|
||||
@@ -4,13 +4,15 @@ extern "C" {
|
||||
#include "mphalport.h"
|
||||
}
|
||||
|
||||
bool micropython_port_should_interrupt() {
|
||||
bool micropython_port_should_interrupt(bool force) {
|
||||
static int c = 0;
|
||||
c++;
|
||||
if (c%20000 != 0) {
|
||||
return false;
|
||||
if(!force) {
|
||||
c++;
|
||||
if (c%20000 != 0) {
|
||||
return false;
|
||||
}
|
||||
c = 0;
|
||||
}
|
||||
c = 0;
|
||||
Ion::Keyboard::State scan = Ion::Keyboard::scan();
|
||||
if (scan.keyDown((Ion::Keyboard::Key)mp_interrupt_char)) {
|
||||
mp_keyboard_interrupt();
|
||||
|
||||
@@ -8,7 +8,7 @@ extern "C" {
|
||||
|
||||
/* should_interrupt effectively does something once every 20000 calls. It checks
|
||||
* if a key is down to raise an interruption flag. */
|
||||
bool micropython_port_should_interrupt();
|
||||
bool micropython_port_should_interrupt(bool);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@
|
||||
// (This scheme won't work if we want to mix Thumb and normal ARM code.)
|
||||
#define MICROPY_MAKE_POINTER_CALLABLE(p) (p)
|
||||
|
||||
#define MICROPY_VM_HOOK_LOOP micropython_port_should_interrupt();
|
||||
#define MICROPY_VM_HOOK_LOOP micropython_port_should_interrupt(false);
|
||||
|
||||
typedef intptr_t mp_int_t; // must be pointer size
|
||||
typedef uintptr_t mp_uint_t; // must be pointer size
|
||||
|
||||
@@ -34,13 +34,15 @@
|
||||
|
||||
void delay_ms(mp_uint_t delay) {
|
||||
uint32_t start = millis();
|
||||
while (millis() - start < delay && !micropython_port_should_interrupt()) {
|
||||
while (millis() - start < delay && !micropython_port_should_interrupt(true)) {
|
||||
msleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
void delay_us(mp_uint_t delay) {
|
||||
uint32_t start = micros();
|
||||
while (micros() - start < delay && !micropython_port_should_interrupt()) {
|
||||
while (micros() - start < delay && !micropython_port_should_interrupt(false)) {
|
||||
usleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user