Skip to content
This repository was archived by the owner on Sep 6, 2023. It is now read-only.

Commit a64dc82

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents e60b3bc + 1c9ee49 commit a64dc82

File tree

219 files changed

+2765
-1449
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

219 files changed

+2765
-1449
lines changed

CODECONVENTIONS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ a change in a detail, if needed. Any change beyond 5 lines would likely
2424
require such detailed description.
2525

2626
To get good practical examples of good commits and their messages, browse
27-
thry the `git log` of the project.
27+
the `git log` of the project.
2828

2929
Python code conventions
3030
=======================

cc3200/mods/moduos.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ STATIC const mp_map_elem_t os_module_globals_table[] = {
155155

156156
{ MP_OBJ_NEW_QSTR(MP_QSTR_chdir), (mp_obj_t)&mp_vfs_chdir_obj },
157157
{ MP_OBJ_NEW_QSTR(MP_QSTR_getcwd), (mp_obj_t)&mp_vfs_getcwd_obj },
158+
{ MP_OBJ_NEW_QSTR(MP_QSTR_ilistdir), (mp_obj_t)&mp_vfs_ilistdir_obj },
158159
{ MP_OBJ_NEW_QSTR(MP_QSTR_listdir), (mp_obj_t)&mp_vfs_listdir_obj },
159160
{ MP_OBJ_NEW_QSTR(MP_QSTR_mkdir), (mp_obj_t)&mp_vfs_mkdir_obj },
160161
{ MP_OBJ_NEW_QSTR(MP_QSTR_rename), (mp_obj_t)&mp_vfs_rename_obj},

cc3200/mods/pybi2c.c

Lines changed: 32 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ typedef struct _pyb_i2c_obj_t {
5959
/******************************************************************************
6060
DEFINE CONSTANTS
6161
******************************************************************************/
62-
#define PYBI2C_MASTER (0)
63-
6462
#define PYBI2C_MIN_BAUD_RATE_HZ (50000)
6563
#define PYBI2C_MAX_BAUD_RATE_HZ (400000)
6664

@@ -79,7 +77,6 @@ typedef struct _pyb_i2c_obj_t {
7977
DECLARE PRIVATE DATA
8078
******************************************************************************/
8179
STATIC pyb_i2c_obj_t pyb_i2c_obj = {.baudrate = 0};
82-
STATIC const mp_obj_t pyb_i2c_def_pin[2] = {&pin_GP13, &pin_GP23};
8380

8481
/******************************************************************************
8582
DECLARE PRIVATE FUNCTIONS
@@ -289,33 +286,34 @@ STATIC void pyb_i2c_readmem_into (mp_arg_val_t *args, vstr_t *vstr) {
289286
STATIC void pyb_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
290287
pyb_i2c_obj_t *self = self_in;
291288
if (self->baudrate > 0) {
292-
mp_printf(print, "I2C(0, I2C.MASTER, baudrate=%u)", self->baudrate);
289+
mp_printf(print, "I2C(0, baudrate=%u)", self->baudrate);
293290
} else {
294291
mp_print_str(print, "I2C(0)");
295292
}
296293
}
297294

298-
STATIC mp_obj_t pyb_i2c_init_helper(pyb_i2c_obj_t *self, const mp_arg_val_t *args) {
299-
// verify that mode is master
300-
if (args[0].u_int != PYBI2C_MASTER) {
301-
goto invalid_args;
302-
}
295+
STATIC mp_obj_t pyb_i2c_init_helper(pyb_i2c_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
296+
enum { ARG_scl, ARG_sda, ARG_freq };
297+
static const mp_arg_t allowed_args[] = {
298+
{ MP_QSTR_scl, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
299+
{ MP_QSTR_sda, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
300+
{ MP_QSTR_freq, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 100000} },
301+
};
302+
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
303+
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
303304

304305
// make sure the baudrate is between the valid range
305-
self->baudrate = MIN(MAX(args[1].u_int, PYBI2C_MIN_BAUD_RATE_HZ), PYBI2C_MAX_BAUD_RATE_HZ);
306+
self->baudrate = MIN(MAX(args[ARG_freq].u_int, PYBI2C_MIN_BAUD_RATE_HZ), PYBI2C_MAX_BAUD_RATE_HZ);
306307

307308
// assign the pins
308-
mp_obj_t pins_o = args[2].u_obj;
309-
if (pins_o != mp_const_none) {
310-
mp_obj_t *pins;
311-
if (pins_o == MP_OBJ_NULL) {
312-
// use the default pins
313-
pins = (mp_obj_t *)pyb_i2c_def_pin;
314-
} else {
315-
mp_obj_get_array_fixed_n(pins_o, 2, &pins);
316-
}
317-
pin_assign_pins_af (pins, 2, PIN_TYPE_STD_PU, PIN_FN_I2C, 0);
309+
mp_obj_t pins[2] = {&pin_GP13, &pin_GP23}; // default (SDA, SCL) pins
310+
if (args[ARG_scl].u_obj != MP_OBJ_NULL) {
311+
pins[1] = args[ARG_scl].u_obj;
318312
}
313+
if (args[ARG_sda].u_obj != MP_OBJ_NULL) {
314+
pins[0] = args[ARG_sda].u_obj;
315+
}
316+
pin_assign_pins_af(pins, 2, PIN_TYPE_STD_PU, PIN_FN_I2C, 0);
319317

320318
// init the I2C bus
321319
i2c_init(self);
@@ -324,44 +322,34 @@ STATIC mp_obj_t pyb_i2c_init_helper(pyb_i2c_obj_t *self, const mp_arg_val_t *arg
324322
pyb_sleep_add ((const mp_obj_t)self, (WakeUpCB_t)i2c_init);
325323

326324
return mp_const_none;
327-
328-
invalid_args:
329-
mp_raise_ValueError(mpexception_value_invalid_arguments);
330325
}
331326

332-
STATIC const mp_arg_t pyb_i2c_init_args[] = {
333-
{ MP_QSTR_id, MP_ARG_INT, {.u_int = 0} },
334-
{ MP_QSTR_mode, MP_ARG_INT, {.u_int = PYBI2C_MASTER} },
335-
{ MP_QSTR_baudrate, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 100000} },
336-
{ MP_QSTR_pins, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
337-
};
338327
STATIC mp_obj_t pyb_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
328+
// check the id argument, if given
329+
if (n_args > 0) {
330+
if (all_args[0] != MP_OBJ_NEW_SMALL_INT(0)) {
331+
mp_raise_OSError(MP_ENODEV);
332+
}
333+
--n_args;
334+
++all_args;
335+
}
336+
339337
// parse args
340338
mp_map_t kw_args;
341339
mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args);
342-
mp_arg_val_t args[MP_ARRAY_SIZE(pyb_i2c_init_args)];
343-
mp_arg_parse_all(n_args, all_args, &kw_args, MP_ARRAY_SIZE(args), pyb_i2c_init_args, args);
344-
345-
// check the peripheral id
346-
if (args[0].u_int != 0) {
347-
mp_raise_OSError(MP_ENODEV);
348-
}
349340

350341
// setup the object
351342
pyb_i2c_obj_t *self = &pyb_i2c_obj;
352343
self->base.type = &pyb_i2c_type;
353344

354345
// start the peripheral
355-
pyb_i2c_init_helper(self, &args[1]);
346+
pyb_i2c_init_helper(self, n_args, all_args, &kw_args);
356347

357348
return (mp_obj_t)self;
358349
}
359350

360-
STATIC mp_obj_t pyb_i2c_init(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
361-
// parse args
362-
mp_arg_val_t args[MP_ARRAY_SIZE(pyb_i2c_init_args) - 1];
363-
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(args), &pyb_i2c_init_args[1], args);
364-
return pyb_i2c_init_helper(pos_args[0], args);
351+
STATIC mp_obj_t pyb_i2c_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
352+
return pyb_i2c_init_helper(pos_args[0], n_args - 1, pos_args + 1, kw_args);
365353
}
366354
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_init_obj, 1, pyb_i2c_init);
367355

@@ -489,7 +477,7 @@ STATIC mp_obj_t pyb_i2c_readfrom_mem_into(mp_uint_t n_args, const mp_obj_t *pos_
489477
// get the buffer to read into
490478
vstr_t vstr;
491479
pyb_i2c_readmem_into (args, &vstr);
492-
return mp_obj_new_int(vstr.len);
480+
return mp_const_none;
493481
}
494482
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_readfrom_mem_into_obj, 1, pyb_i2c_readfrom_mem_into);
495483

@@ -513,8 +501,7 @@ STATIC mp_obj_t pyb_i2c_writeto_mem(mp_uint_t n_args, const mp_obj_t *pos_args,
513501

514502
// write the register address to write to.
515503
if (pyb_i2c_mem_write (i2c_addr, (byte *)&mem_addr, mem_addr_size, bufinfo.buf, bufinfo.len)) {
516-
// return the number of bytes written
517-
return mp_obj_new_int(bufinfo.len);
504+
return mp_const_none;
518505
}
519506

520507
mp_raise_OSError(MP_EIO);
@@ -532,9 +519,6 @@ STATIC const mp_map_elem_t pyb_i2c_locals_dict_table[] = {
532519
{ MP_OBJ_NEW_QSTR(MP_QSTR_readfrom_mem), (mp_obj_t)&pyb_i2c_readfrom_mem_obj },
533520
{ MP_OBJ_NEW_QSTR(MP_QSTR_readfrom_mem_into), (mp_obj_t)&pyb_i2c_readfrom_mem_into_obj },
534521
{ MP_OBJ_NEW_QSTR(MP_QSTR_writeto_mem), (mp_obj_t)&pyb_i2c_writeto_mem_obj },
535-
536-
// class constants
537-
{ MP_OBJ_NEW_QSTR(MP_QSTR_MASTER), MP_OBJ_NEW_SMALL_INT(PYBI2C_MASTER) },
538522
};
539523

540524
STATIC MP_DEFINE_CONST_DICT(pyb_i2c_locals_dict, pyb_i2c_locals_dict_table);

cc3200/mods/pybpin.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -684,13 +684,6 @@ STATIC mp_obj_t pin_value(mp_uint_t n_args, const mp_obj_t *args) {
684684
}
685685
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_value_obj, 1, 2, pin_value);
686686

687-
STATIC mp_obj_t pin_toggle(mp_obj_t self_in) {
688-
pin_obj_t *self = self_in;
689-
MAP_GPIOPinWrite(self->port, self->bit, ~MAP_GPIOPinRead(self->port, self->bit));
690-
return mp_const_none;
691-
}
692-
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_toggle_obj, pin_toggle);
693-
694687
STATIC mp_obj_t pin_id(mp_obj_t self_in) {
695688
pin_obj_t *self = self_in;
696689
return MP_OBJ_NEW_QSTR(self->name);
@@ -913,7 +906,6 @@ STATIC const mp_map_elem_t pin_locals_dict_table[] = {
913906
// instance methods
914907
{ MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&pin_init_obj },
915908
{ MP_OBJ_NEW_QSTR(MP_QSTR_value), (mp_obj_t)&pin_value_obj },
916-
{ MP_OBJ_NEW_QSTR(MP_QSTR_toggle), (mp_obj_t)&pin_toggle_obj },
917909
{ MP_OBJ_NEW_QSTR(MP_QSTR_id), (mp_obj_t)&pin_id_obj },
918910
{ MP_OBJ_NEW_QSTR(MP_QSTR_mode), (mp_obj_t)&pin_mode_obj },
919911
{ MP_OBJ_NEW_QSTR(MP_QSTR_pull), (mp_obj_t)&pin_pull_obj },

docs/esp8266/quickref.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Use the :mod:`time <utime>` module::
8888
Timers
8989
------
9090

91-
Virtual (RTOS-based) timers are supported. Use the ``machine.Timer`` class
91+
Virtual (RTOS-based) timers are supported. Use the :ref:`machine.Timer <machine.Timer>` class
9292
with timer ID of -1::
9393

9494
from machine import Timer
@@ -102,7 +102,7 @@ The period is in milliseconds.
102102
Pins and GPIO
103103
-------------
104104

105-
Use the ``machine.Pin`` class::
105+
Use the :ref:`machine.Pin <machine.Pin>` class::
106106

107107
from machine import Pin
108108

@@ -155,7 +155,7 @@ ADC (analog to digital conversion)
155155
ADC is available on a dedicated pin.
156156
Note that input voltages on the ADC pin must be between 0v and 1.0v.
157157

158-
Use the ``machine.ADC`` class::
158+
Use the :ref:`machine.ADC <machine.ADC>` class::
159159

160160
from machine import ADC
161161

@@ -166,7 +166,8 @@ Software SPI bus
166166
----------------
167167

168168
There are two SPI drivers. One is implemented in software (bit-banging)
169-
and works on all pins::
169+
and works on all pins, and is accessed via the :ref:`machine.SPI <machine.SPI>`
170+
class::
170171

171172
from machine import Pin, SPI
172173

@@ -208,7 +209,8 @@ constructor and init (as those are fixed)::
208209
I2C bus
209210
-------
210211

211-
The I2C driver is implemented in software and works on all pins::
212+
The I2C driver is implemented in software and works on all pins,
213+
and is accessed via the :ref:`machine.I2C <machine.I2C>` class::
212214

213215
from machine import Pin, I2C
214216

docs/esp8266/tutorial/intro.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ characteristic of a board is how much flash it has, how the GPIO pins are
2020
connected to the outside world, and whether it includes a built-in USB-serial
2121
convertor to make the UART available to your PC.
2222

23-
The minimum requirement for flash size is 512k. A board with this amount of
24-
flash will not have room for a filesystem, but otherwise is fully functional.
25-
If your board has 1Mbyte or more of flash then it will support a filesystem.
23+
The minimum requirement for flash size is 1Mbyte. There is also a special
24+
build for boards with 512KB, but it is highly limited comparing to the
25+
normal build: there is no support for filesystem, and thus features which
26+
depend on it won't work (WebREPL, upip, etc.). As such, 512KB build will
27+
be more interesting for users who build from source and fine-tune parameters
28+
for their particular application.
2629

2730
Names of pins will be given in this tutorial using the chip names (eg GPIO0)
2831
and it should be straightforward to find which pin this corresponds to on your

docs/library/index.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
MicroPython libraries
22
=====================
33

4+
.. warning::
5+
6+
Important summary of this section
7+
8+
* MicroPython implements a subset of Python functionality for each module.
9+
* To ease extensibility, MicroPython versions of standard Python modules
10+
usually have ``u`` (micro) prefix.
11+
* Any particular MicroPython variant or port may miss any feature/function
12+
described in this general documentation, due to resource constraints.
13+
14+
415
This chapter describes modules (function and class libraries) which are built
516
into MicroPython. There are a few categories of modules:
617

docs/library/lcd160cr.rst

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,19 @@ The following methods manipulate individual pixels on the display.
150150

151151
.. method:: LCD160CR.get_line(x, y, buf)
152152

153-
Get a line of pixels into the given buffer.
154-
155-
.. method:: LCD160CR.screen_dump(buf)
156-
157-
Dump the entire screen to the given buffer.
153+
Low-level method to get a line of pixels into the given buffer.
154+
To read `n` pixels `buf` should be `2*n+1` bytes in length. The first byte
155+
is a dummy byte and should be ignored, and subsequent bytes represent the
156+
pixels in the line starting at coordinate `(x, y)`.
157+
158+
.. method:: LCD160CR.screen_dump(buf, x=0, y=0, w=None, h=None)
159+
160+
Dump the contents of the screen to the given buffer. The parameters `x` and `y`
161+
specify the starting coordinate, and `w` and `h` the size of the region. If `w`
162+
or `h` are `None` then they will take on their maximum values, set by the size
163+
of the screen minus the given `x` and `y` values. `buf` should be large enough
164+
to hold `2*w*h` bytes. If it's smaller then only the initial horizontal lines
165+
will be stored.
158166

159167
.. method:: LCD160CR.screen_load(buf)
160168

docs/library/machine.ADC.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.. currentmodule:: machine
2+
.. _machine.ADC:
23

34
class ADC -- analog to digital conversion
45
=========================================

0 commit comments

Comments
 (0)