Skip to content

Commit

Permalink
micropython
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Aug 11, 2019
1 parent afe4d2a commit 9aa4020
Show file tree
Hide file tree
Showing 17 changed files with 690 additions and 39 deletions.
215 changes: 215 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ include_directories(
src/eez/scpi

src/third_party/libscpi/inc
src/third_party/micropython
src/third_party/micropython/port
src/third_party/micropython/port/win32
)

set(src_files)
Expand All @@ -70,6 +73,7 @@ set(header_files)
set(src_eez
src/eez/debug.cpp
src/eez/index.cpp
src/eez/scripting.cpp
src/eez/sound.cpp
src/eez/system.cpp
src/eez/unit.cpp
Expand All @@ -79,6 +83,7 @@ list (APPEND src_files ${src_eez})
set(header_eez
src/eez/debug.h
src/eez/index.h
src/eez/scripting.h
src/eez/sound.h
src/eez/system.h
src/eez/unit.h
Expand Down Expand Up @@ -499,6 +504,216 @@ set(header_third_party_scpi
list (APPEND header_files ${header_third_party_scpi})
source_group("third_party\\scpi" FILES ${src_third_party_scpi} ${header_third_party_scpi})

set(src_third_party_micropython_extmod
src/third_party/micropython/extmod/virtpin.c
)
list (APPEND src_files ${src_third_party_micropython_extmod})
set(header_third_party_micropython_extmod
src/third_party/micropython/extmod/virtpin.h
)
list (APPEND header_files ${header_third_party_micropython_extmod})
source_group("third_party\\micropython\\extmod" FILES ${src_third_party_micropython_extmod} ${header_third_party_micropython_extmod})

set(src_third_party_micropython_port
src/third_party/micropython/port/main.c
src/third_party/micropython/port/mphalport.c
)
list (APPEND src_files ${src_third_party_micropython_port})
set(header_third_party_micropython_port
src/third_party/micropython/port/mpconfigport.h
src/third_party/micropython/port/mphalport.h
src/third_party/micropython/port/qstrdefsport.h
)
list (APPEND header_files ${header_third_party_micropython_port})
source_group("third_party\\micropython\\port" FILES ${src_third_party_micropython_port} ${header_third_party_micropython_port})

set(header_third_party_micropython_port_genhdr
src/third_party/micropython/port/genhdr/moduledefs.h
src/third_party/micropython/port/genhdr/mpversion.h
src/third_party/micropython/port/genhdr/qstrdefs.generated.h
)
list (APPEND header_files ${header_third_party_micropython_port_genhdr})
source_group("third_party\\micropython\\port\\genhdr" FILES ${header_third_party_micropython_port_genhdr})

set(src_third_party_micropython_py
src/third_party/micropython/py/argcheck.c
src/third_party/micropython/py/asmarm.c
src/third_party/micropython/py/asmbase.c
src/third_party/micropython/py/asmthumb.c
src/third_party/micropython/py/asmx64.c
src/third_party/micropython/py/asmx86.c
src/third_party/micropython/py/asmxtensa.c
src/third_party/micropython/py/bc.c
src/third_party/micropython/py/binary.c
src/third_party/micropython/py/builtinevex.c
src/third_party/micropython/py/builtinhelp.c
src/third_party/micropython/py/builtinimport.c
src/third_party/micropython/py/compile.c
src/third_party/micropython/py/emitbc.c
src/third_party/micropython/py/emitcommon.c
src/third_party/micropython/py/emitglue.c
src/third_party/micropython/py/emitinlinethumb.c
src/third_party/micropython/py/emitinlinextensa.c
src/third_party/micropython/py/emitnarm.c
src/third_party/micropython/py/emitnative.c
src/third_party/micropython/py/emitnthumb.c
src/third_party/micropython/py/emitnx64.c
src/third_party/micropython/py/emitnx86.c
src/third_party/micropython/py/emitnxtensa.c
src/third_party/micropython/py/formatfloat.c
src/third_party/micropython/py/frozenmod.c
src/third_party/micropython/py/gc.c
src/third_party/micropython/py/lexer.c
src/third_party/micropython/py/malloc.c
src/third_party/micropython/py/map.c
src/third_party/micropython/py/modarray.c
src/third_party/micropython/py/modbuiltins.c
src/third_party/micropython/py/modcmath.c
src/third_party/micropython/py/modcollections.c
src/third_party/micropython/py/modgc.c
src/third_party/micropython/py/modio.c
src/third_party/micropython/py/modmath.c
src/third_party/micropython/py/modmicropython.c
src/third_party/micropython/py/modstruct.c
src/third_party/micropython/py/modsys.c
src/third_party/micropython/py/modthread.c
src/third_party/micropython/py/moduerrno.c
src/third_party/micropython/py/mpprint.c
src/third_party/micropython/py/mpstate.c
src/third_party/micropython/py/mpz.c
src/third_party/micropython/py/nativeglue.c
src/third_party/micropython/py/nlr.c
src/third_party/micropython/py/nlrsetjmp.c
src/third_party/micropython/py/nlrthumb.c
src/third_party/micropython/py/nlrx64.c
src/third_party/micropython/py/nlrx86.c
src/third_party/micropython/py/nlrxtensa.c
src/third_party/micropython/py/objarray.c
src/third_party/micropython/py/objattrtuple.c
src/third_party/micropython/py/objbool.c
src/third_party/micropython/py/objboundmeth.c
src/third_party/micropython/py/obj.c
src/third_party/micropython/py/objcell.c
src/third_party/micropython/py/objclosure.c
src/third_party/micropython/py/objcomplex.c
src/third_party/micropython/py/objdeque.c
src/third_party/micropython/py/objdict.c
src/third_party/micropython/py/objenumerate.c
src/third_party/micropython/py/objexcept.c
src/third_party/micropython/py/objfilter.c
src/third_party/micropython/py/objfloat.c
src/third_party/micropython/py/objfun.c
src/third_party/micropython/py/objgenerator.c
src/third_party/micropython/py/objgetitemiter.c
src/third_party/micropython/py/objint.c
src/third_party/micropython/py/objint_longlong.c
src/third_party/micropython/py/objint_mpz.c
src/third_party/micropython/py/objlist.c
src/third_party/micropython/py/objmap.c
src/third_party/micropython/py/objmodule.c
src/third_party/micropython/py/objnamedtuple.c
src/third_party/micropython/py/objnone.c
src/third_party/micropython/py/objobject.c
src/third_party/micropython/py/objpolyiter.c
src/third_party/micropython/py/objproperty.c
src/third_party/micropython/py/objrange.c
src/third_party/micropython/py/objreversed.c
src/third_party/micropython/py/objset.c
src/third_party/micropython/py/objsingleton.c
src/third_party/micropython/py/objslice.c
src/third_party/micropython/py/objstr.c
src/third_party/micropython/py/objstringio.c
src/third_party/micropython/py/objstrunicode.c
src/third_party/micropython/py/objtuple.c
src/third_party/micropython/py/objtype.c
src/third_party/micropython/py/objzip.c
src/third_party/micropython/py/opmethods.c
src/third_party/micropython/py/parse.c
src/third_party/micropython/py/parsenumbase.c
src/third_party/micropython/py/parsenum.c
src/third_party/micropython/py/persistentcode.c
src/third_party/micropython/py/pystack.c
src/third_party/micropython/py/qstr.c
src/third_party/micropython/py/reader.c
src/third_party/micropython/py/repl.c
src/third_party/micropython/py/runtime.c
src/third_party/micropython/py/runtime_utils.c
src/third_party/micropython/py/scheduler.c
src/third_party/micropython/py/scope.c
src/third_party/micropython/py/sequence.c
src/third_party/micropython/py/showbc.c
src/third_party/micropython/py/smallint.c
src/third_party/micropython/py/stackctrl.c
src/third_party/micropython/py/stream.c
src/third_party/micropython/py/unicode.c
src/third_party/micropython/py/vm.c
src/third_party/micropython/py/vstr.c
src/third_party/micropython/py/warning.c
)
list (APPEND src_files ${src_third_party_micropython_py})
set(header_third_party_micropython_py
src/third_party/micropython/py/asmarm.h
src/third_party/micropython/py/asmbase.h
src/third_party/micropython/py/asmthumb.h
src/third_party/micropython/py/asmx64.h
src/third_party/micropython/py/asmx86.h
src/third_party/micropython/py/asmxtensa.h
src/third_party/micropython/py/bc0.h
src/third_party/micropython/py/bc.h
src/third_party/micropython/py/binary.h
src/third_party/micropython/py/builtin.h
src/third_party/micropython/py/compile.h
src/third_party/micropython/py/emitglue.h
src/third_party/micropython/py/emit.h
src/third_party/micropython/py/formatfloat.h
src/third_party/micropython/py/frozenmod.h
src/third_party/micropython/py/gc.h
src/third_party/micropython/py/grammar.h
src/third_party/micropython/py/lexer.h
src/third_party/micropython/py/misc.h
src/third_party/micropython/py/mpconfig.h
src/third_party/micropython/py/mperrno.h
src/third_party/micropython/py/mphal.h
src/third_party/micropython/py/mpprint.h
src/third_party/micropython/py/mpstate.h
src/third_party/micropython/py/mpthread.h
src/third_party/micropython/py/mpz.h
src/third_party/micropython/py/nlr.h
src/third_party/micropython/py/objarray.h
src/third_party/micropython/py/objexcept.h
src/third_party/micropython/py/objfun.h
src/third_party/micropython/py/objgenerator.h
src/third_party/micropython/py/obj.h
src/third_party/micropython/py/objint.h
src/third_party/micropython/py/objlist.h
src/third_party/micropython/py/objmodule.h
src/third_party/micropython/py/objnamedtuple.h
src/third_party/micropython/py/objstr.h
src/third_party/micropython/py/objstringio.h
src/third_party/micropython/py/objtuple.h
src/third_party/micropython/py/objtype.h
src/third_party/micropython/py/parse.h
src/third_party/micropython/py/parsenumbase.h
src/third_party/micropython/py/parsenum.h
src/third_party/micropython/py/persistentcode.h
src/third_party/micropython/py/pystack.h
src/third_party/micropython/py/qstrdefs.h
src/third_party/micropython/py/qstr.h
src/third_party/micropython/py/reader.h
src/third_party/micropython/py/repl.h
src/third_party/micropython/py/ringbuf.h
src/third_party/micropython/py/runtime0.h
src/third_party/micropython/py/runtime.h
src/third_party/micropython/py/scope.h
src/third_party/micropython/py/smallint.h
src/third_party/micropython/py/stackctrl.h
src/third_party/micropython/py/stream.h
src/third_party/micropython/py/unicode.h
src/third_party/micropython/py/vmentrytable.h
)
list (APPEND header_files ${header_third_party_micropython_py})
source_group("third_party\\micropython\\py" FILES ${src_third_party_micropython_py} ${header_third_party_micropython_py})

add_executable(modular-psu-firmware ${src_files} ${header_files})

if(MSVC)
Expand Down
29 changes: 0 additions & 29 deletions src/eez/apps/psu/gui/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,6 @@ Value MakeEventValue(event_queue::Event *e) {
return value;
}

Value MakePageInfoValue(uint8_t pageIndex, uint8_t numPages) {
Value value;
value.pairOfUint8_.first = pageIndex;
value.pairOfUint8_.second = numPages;
value.type_ = VALUE_TYPE_PAGE_INFO;
return value;
}

Value MakeLessThenMinMessageValue(float float_, const Value &value_) {
Value value;
if (value_.getType() == VALUE_TYPE_INT) {
Expand Down Expand Up @@ -259,14 +251,6 @@ event_queue::Event *getEventFromValue(const Value &value) {
return (event_queue::Event *)value.getVoidPointer();
}

uint8_t getPageIndexFromValue(const Value &value) {
return value.getFirstUInt8();
}

uint8_t getNumPagesFromValue(const Value &value) {
return value.getSecondUInt8();
}

////////////////////////////////////////////////////////////////////////////////

bool compare_LESS_THEN_MIN_FLOAT_value(const Value &a, const Value &b) {
Expand Down Expand Up @@ -379,17 +363,6 @@ void EVENT_value_to_text(const Value &value, char *text, int count) {
text[count - 1] = 0;
}

bool compare_PAGE_INFO_value(const Value &a, const Value &b) {
return getPageIndexFromValue(a) == getPageIndexFromValue(b) &&
getNumPagesFromValue(a) == getNumPagesFromValue(b);
}

void PAGE_INFO_value_to_text(const Value &value, char *text, int count) {
snprintf(text, count - 1, "Page #%d of %d", getPageIndexFromValue(value) + 1,
getNumPagesFromValue(value));
text[count - 1] = 0;
}

bool compare_ON_TIME_COUNTER_value(const Value &a, const Value &b) {
return a.getUInt32() == b.getUInt32();
}
Expand Down Expand Up @@ -628,7 +601,6 @@ CompareValueFunction g_compareUserValueFunctions[] = { compare_LESS_THEN_MIN_FLO
compare_GREATER_THEN_MAX_INT_value,
compare_GREATER_THEN_MAX_TIME_ZONE_value,
compare_EVENT_value,
compare_PAGE_INFO_value,
compare_ON_TIME_COUNTER_value,
compare_COUNTDOWN_value,
compare_TIME_ZONE_value,
Expand Down Expand Up @@ -665,7 +637,6 @@ ValueToTextFunction g_userValueToTextFunctions[] = { LESS_THEN_MIN_FLOAT_value_t
GREATER_THEN_MAX_INT_value_to_text,
GREATER_THEN_MAX_TIME_ZONE_value_to_text,
EVENT_value_to_text,
PAGE_INFO_value_to_text,
ON_TIME_COUNTER_value_to_text,
COUNTDOWN_value_to_text,
TIME_ZONE_value_to_text,
Expand Down
2 changes: 0 additions & 2 deletions src/eez/apps/psu/gui/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ enum UserValueType {
VALUE_TYPE_GREATER_THEN_MAX_INT,
VALUE_TYPE_GREATER_THEN_MAX_TIME_ZONE,
VALUE_TYPE_EVENT,
VALUE_TYPE_PAGE_INFO,
VALUE_TYPE_ON_TIME_COUNTER,
VALUE_TYPE_COUNTDOWN,
VALUE_TYPE_TIME_ZONE,
Expand Down Expand Up @@ -79,7 +78,6 @@ Value MakeValue(float value, Unit unit, int channelIndex = -1, bool extendedPrec
Value MakeValueListValue(const Value *values);
Value MakeFloatListValue(float *pFloat);
Value MakeEventValue(eez::psu::event_queue::Event *e);
Value MakePageInfoValue(uint8_t pageIndex, uint8_t numPages);
Value MakeLessThenMinMessageValue(float float_, const Value &value_);
Value MakeGreaterThenMaxMessageValue(float float_, const Value &value_);
Value MakeMacAddressValue(uint8_t *macAddress);
Expand Down
38 changes: 38 additions & 0 deletions src/eez/apps/psu/scpi/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,27 @@
#include <eez/apps/psu/watchdog.h>
#include <eez/system.h>

extern "C" {
#include "py/compile.h"
#include "py/runtime.h"

void do_str(const char *src, mp_parse_input_kind_t input_kind) {
nlr_buf_t nlr;
if (nlr_push(&nlr) == 0) {
mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0);
qstr source_name = lex->source_name;
mp_parse_tree_t parse_tree = mp_parse(lex, input_kind);
mp_obj_t module_fun = mp_compile(&parse_tree, source_name, MP_EMIT_OPT_NONE, true);
mp_call_function_0(module_fun);
nlr_pop();
} else {
// uncaught exception
mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val);
}
}

}

namespace eez {
namespace psu {

Expand Down Expand Up @@ -423,6 +444,23 @@ scpi_result_t scpi_cmd_debugIoexpQ(scpi_t *context) {
#endif // DEBUG
}

scpi_result_t scpi_cmd_debugPythonQ(scpi_t *context) {
#ifdef DEBUG
mp_init();
do_str("print('hello world!', list(x+1 for x in range(10)), end='eol\\n')", MP_PARSE_SINGLE_INPUT);
do_str("for i in range(10):\n print(i)", MP_PARSE_FILE_INPUT);
do_str("print(1)\nprint(2)\nprint(3", MP_PARSE_FILE_INPUT);
mp_deinit();

SCPI_ResultText(context, "1");

return SCPI_RES_OK;
#else
SCPI_ErrorPush(context, SCPI_ERROR_HARDWARE_MISSING);
return SCPI_RES_ERR;
#endif // DEBUG
}

} // namespace scpi
} // namespace psu
} // namespace eez
4 changes: 4 additions & 0 deletions src/eez/apps/psu/stm32/serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ uint32_t g_length;

////////////////////////////////////////////////////////////////////////////////

extern "C" void Serial_Write(const char *str, size_t len) {
Serial.write(str, (int)len);
}

extern "C" void notifySerialLineStateChanged(uint8_t serialLineState) {
osMessagePut(g_scpiMessageQueueId, SCPI_QUEUE_SERIAL_MESSAGE(SERIAL_LINE_STATE_CHANGED, serialLineState), osWaitForever);
}
Expand Down
Loading

0 comments on commit 9aa4020

Please sign in to comment.