Skip to content

Commit

Permalink
Merge MicroPython 1.14 into CircuitPython
Browse files Browse the repository at this point in the history
  • Loading branch information
tannewt committed May 11, 2021
2 parents 4eb4f14 + 78b23c3 commit e02a264
Show file tree
Hide file tree
Showing 166 changed files with 4,548 additions and 2,399 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2013-2020 Damien P. George
Copyright (c) 2013-2021 Damien P. George

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
10 changes: 4 additions & 6 deletions docs/library/binascii.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ Functions

.. function:: hexlify(data, [sep])

Convert binary data to hexadecimal representation. Returns bytes string.

.. admonition:: Difference to CPython
:class: attention
Convert the bytes in the *data* object to a hexadecimal representation.
Returns a bytes object.

If additional argument, *sep* is supplied, it is used as a separator
between hexadecimal values.
If the additional argument *sep* is supplied it is used as a separator
between hexadecimal values.

.. function:: unhexlify(data)

Expand Down
2 changes: 1 addition & 1 deletion docs/library/btree.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Methods
.. method:: btree.__getitem__(key)
btree.get(key, default=None, /)
btree.__setitem__(key, val)
btree.__detitem__(key)
btree.__delitem__(key)
btree.__contains__(key)

Standard dictionary methods.
Expand Down
2 changes: 1 addition & 1 deletion docs/library/sys.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
:mod:`sys` -- system specific functions
=======================================
========================================

.. include:: ../templates/unsupported_in_circuitpython.inc

Expand Down
34 changes: 34 additions & 0 deletions examples/usercmodule/cexample/examplemodule.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Include MicroPython API.
#include "py/runtime.h"

// This is the function which will be called from Python as cexample.add_ints(a, b).
STATIC mp_obj_t example_add_ints(mp_obj_t a_obj, mp_obj_t b_obj) {
// Extract the ints from the micropython input objects.
int a = mp_obj_get_int(a_obj);
int b = mp_obj_get_int(b_obj);

// Calculate the addition and convert to MicroPython object.
return mp_obj_new_int(a + b);
}
// Define a Python reference to the function above.
STATIC MP_DEFINE_CONST_FUN_OBJ_2(example_add_ints_obj, example_add_ints);

// Define all properties of the module.
// Table entries are key/value pairs of the attribute name (a string)
// and the MicroPython object reference.
// All identifiers and strings are written as MP_QSTR_xxx and will be
// optimized to word-sized integers by the build system (interned strings).
STATIC const mp_rom_map_elem_t example_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_cexample) },
{ MP_ROM_QSTR(MP_QSTR_add_ints), MP_ROM_PTR(&example_add_ints_obj) },
};
STATIC MP_DEFINE_CONST_DICT(example_module_globals, example_module_globals_table);

// Define module object.
const mp_obj_module_t example_user_cmodule = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t *)&example_module_globals,
};

// Register the module to make it available in Python.
MP_REGISTER_MODULE(MP_QSTR_cexample, example_user_cmodule, MODULE_CEXAMPLE_ENABLED);
9 changes: 9 additions & 0 deletions examples/usercmodule/cexample/micropython.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
EXAMPLE_MOD_DIR := $(USERMOD_DIR)

# Add all C files to SRC_USERMOD.
SRC_USERMOD += $(EXAMPLE_MOD_DIR)/examplemodule.c

# We can add our module folder to include paths if needed
# This is not actually needed in this example.
CFLAGS_USERMOD += -I$(EXAMPLE_MOD_DIR)
CEXAMPLE_MOD_DIR := $(USERMOD_DIR)
17 changes: 17 additions & 0 deletions examples/usercmodule/cppexample/example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
extern "C" {
#include <examplemodule.h>

// Here we implement the function using C++ code, but since it's
// declaration has to be compatible with C everything goes in extern "C" scope.
mp_obj_t cppfunc(mp_obj_t a_obj, mp_obj_t b_obj) {
// Prove we have (at least) C++11 features.
const auto a = mp_obj_get_int(a_obj);
const auto b = mp_obj_get_int(b_obj);
const auto sum = [&]() {
return mp_obj_new_int(a + b);
} ();
// Prove we're being scanned for QSTRs.
mp_obj_t tup[] = {sum, MP_ROM_QSTR(MP_QSTR_hellocpp)};
return mp_obj_new_tuple(2, tup);
}
}
25 changes: 25 additions & 0 deletions examples/usercmodule/cppexample/examplemodule.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <examplemodule.h>

// Define a Python reference to the function we'll make available.
// See example.cpp for the definition.
STATIC MP_DEFINE_CONST_FUN_OBJ_2(cppfunc_obj, cppfunc);

// Define all properties of the module.
// Table entries are key/value pairs of the attribute name (a string)
// and the MicroPython object reference.
// All identifiers and strings are written as MP_QSTR_xxx and will be
// optimized to word-sized integers by the build system (interned strings).
STATIC const mp_rom_map_elem_t cppexample_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_cppexample) },
{ MP_ROM_QSTR(MP_QSTR_cppfunc), MP_ROM_PTR(&cppfunc_obj) },
};
STATIC MP_DEFINE_CONST_DICT(cppexample_module_globals, cppexample_module_globals_table);

// Define module object.
const mp_obj_module_t cppexample_user_cmodule = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t *)&cppexample_module_globals,
};

// Register the module to make it available in Python.
MP_REGISTER_MODULE(MP_QSTR_cppexample, cppexample_user_cmodule, MODULE_CPPEXAMPLE_ENABLED);
5 changes: 5 additions & 0 deletions examples/usercmodule/cppexample/examplemodule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Include MicroPython API.
#include "py/runtime.h"

// Declare the function we'll make available in Python as cppexample.cppfunc().
extern mp_obj_t cppfunc(mp_obj_t a_obj, mp_obj_t b_obj);
12 changes: 12 additions & 0 deletions examples/usercmodule/cppexample/micropython.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CPPEXAMPLE_MOD_DIR := $(USERMOD_DIR)

# Add our source files to the respective variables.
SRC_USERMOD += $(CPPEXAMPLE_MOD_DIR)/examplemodule.c
SRC_USERMOD_CXX += $(CPPEXAMPLE_MOD_DIR)/example.cpp

# Add our module directory to the include path.
CFLAGS_USERMOD += -I$(CPPEXAMPLE_MOD_DIR)
CXXFLAGS_USERMOD += -I$(CPPEXAMPLE_MOD_DIR)

# We use C++ features so have to link against the standard library.
LDFLAGS_USERMOD += -lstdc++
57 changes: 0 additions & 57 deletions extmod/btstack/btstack.mk

This file was deleted.

47 changes: 0 additions & 47 deletions extmod/btstack/btstack_config.h

This file was deleted.

Loading

0 comments on commit e02a264

Please sign in to comment.