Commit Graph

56 Commits

Author SHA1 Message Date
microDev a52eb88031
run code formatting script 2021-03-15 19:27:36 +05:30
Scott Shawcroft 3f08cb47b8
Merge remote-tracking branch 'adafruit/main' into busio-uart-rp 2021-02-25 16:59:15 -08:00
Scott Shawcroft 52bc935fa7
A few minor fixes for corner cases
* Always clear the peripheral interrupt so we don't hang when full
* Store the ringbuf in the object so it gets collected when we're alive
* Make UART objects have a finaliser so they are deinit when their
  memory is freed
* Copy bytes into the ringbuf from the FIFO after we read to ensure
  the interrupt is enabled ASAP
* Copy bytes into the ringbuf from the FIFO before measuring our
  rx available because the interrupt is based on a threshold (not
  > 0). For example, a single byte won't trigger an interrupt.
2021-02-25 16:50:57 -08:00
microDev 5d7fdafcde
implement suggested changes
- add internal buffering
- rtc initialization fix
2021-02-25 00:48:36 +05:30
microDev b12ccefbe6
uart implementation for rp2040 2021-02-19 18:36:00 +05:30
Dan Halbert ed49c02feb add timeout; finish up for PR 2021-02-17 23:24:11 -05:00
Taku Fukada d356581651 Fix several type hints 2020-07-27 18:05:13 +09:00
dherrada 612c6bb86b
Merge branch 'main' into type_hints 2020-07-17 14:55:30 -04:00
dherrada d0d949cd24 Made every init return None 2020-07-03 14:23:34 -04:00
dherrada 3df03a5650 Made most of the requested changes 2020-07-03 13:49:00 -04:00
Scott Shawcroft 70fdde4aaa
Remove trailing space 2020-07-02 15:11:40 -07:00
dherrada 9b4ffc0571 Changed unions to ReadableBuffer and WriteableBuffer 2020-07-02 17:47:52 -04:00
Scott Shawcroft c33542f978
Merge branch 'main' into patch-1 2020-07-02 13:56:09 -07:00
dherrada 54cb1feea0 Removed all 'self, )' 2020-07-02 13:28:36 -04:00
dherrada 522b17ca93 Made suggested changes 2020-07-02 13:25:07 -04:00
dherrada cb259de5ef Did busio, fixed up analogio 2020-07-02 10:23:17 -04:00
Scott Shawcroft a26102607e
Add UART support 2020-06-24 12:47:58 -07:00
Scott Shawcroft 2c2b53303d
Merge pull request #2837 from k0d/serial-debug
Add support for a debug console, such as ST-Link VCP.
2020-05-18 18:13:31 -07:00
Mark Olsson 007c92ee6a Enable showing the console on a debug uart 2020-05-19 02:02:52 +02:00
Scott Shawcroft 3ffa5604fc
Update countio to python stub docs 2020-05-13 08:36:16 -07:00
Scott Shawcroft 4e8de3c554
Swap sphinx to autoapi and the inline stubs 2020-05-12 17:28:24 -07:00
dherrada c534a872a2
Merge branch 'master' into master 2020-05-12 12:26:02 -04:00
warriorofwire eb3d5fa453 ujson: do not eat trailing whitespace
Ujson should only worry about whitespace before JSON.  This becomes apparent when you are using MP stream protocol to read directly from input buffers.

When you attempt to read(1) on a UART (and possibly other protocols) you have to wait for either the byte or the timeout.

Fixes:
- Waiting for a timeout after you have completed reading a correct and complete JSON off the input.
- Raising an OSError after reading a correct and complete JSON off the input.
- Eating more data than semantically owned off the input buffer.
- Blocking to start parsing JSON until the entire JSON body has been loaded into a potentially large, contiguous Python object.

Code you would write before:
```
line = board_busio_uart_port.read_line()
json_dict = json.loads(line)
```
or reaching for fixed buffers and swapping them around in Python.

Code that did not work before that does now:
```
json_dict = json.load(board_busio_uart_port)
```

- This removes the need for intermediate copies of data when reading JSON from micropython stream protocol inputs.
- It also increases total application speed by parsing JSON concurrently with receiving on boards that read from UART via DMA.
- It simplifies code that users write while improving their apps.
2020-05-10 20:45:42 -07:00
dherrada a2a32fea1a
Added newlines after every ellipsis 2020-04-29 15:55:06 -04:00
dherrada 093461e816
Fixed indentation 2020-04-29 15:45:19 -04:00
dherrada deccdcc1d6
Did the same for the rest of busio 2020-04-29 15:20:05 -04:00
dherrada 724dcda3ec
Fixed whitespace in busio 2020-04-28 18:39:58 -04:00
dherrada e7874277ab
Fixed empty lines 2020-04-25 15:35:24 -04:00
dherrada 7070fe1995
Added inline pyi to UART.c 2020-04-25 15:25:31 -04:00
AndrewR-L f572b72306
busio/UART: Correct and clarify readline() return.
Surely readline() "rtype" is string not int as stated (and not bytes as some might expect).

Also it is not totally unambiguous what happens on a timeout so it would help to clarify in docs that on a timeout 
it does NOT return with what it has read so far, rather it leaves all that in the buffer ready for a future read and returns nothing.

Likewise clarify that if timeout=0 but there is no newline it DOES return what it has read so far (NOT None). 

At least this is what I think it does and/or is supposed to do!

Python docs are generally not too explicit about what is the proper treatment, so perhaps all the more reason to
clarify the interpretation adopted?
2020-04-17 15:10:36 +01:00
Dan Halbert 817b5be320 rename routines to be clearer; fix wiznet arg types 2020-03-05 16:35:31 -05:00
Dan Halbert b6206406de new pin validation routines; don't use mp_const_none if NULL will do 2020-02-28 23:43:04 -05:00
Dave Marples d388899985 Addition of RS485 support 2020-02-18 23:16:40 +00:00
Dave Marples 84ad3d8393 Addition of RTS/CTS/RS485 UART functionality 2020-02-18 23:16:40 +00:00
Jeff Epler 238e121236 protocols: Allow them to be (optionally) type-safe
Protocols are nice, but there is no way for C code to verify whether
a type's "protocol" structure actually implements some particular
protocol.  As a result, you can pass an object that implements the
"vfs" protocol to one that expects the "stream" protocol, and the
opposite of awesomeness ensues.

This patch adds an OPTIONAL (but enabled by default) protocol identifier
as the first member of any protocol structure.  This identifier is
simply a unique QSTR chosen by the protocol designer and used by each
protocol implementer.  When checking for protocol support, instead of
just checking whether the object's type has a non-NULL protocol field,
use `mp_proto_get` which implements the protocol check when possible.

The existing protocols are now named:
    protocol_framebuf
    protocol_i2c
    protocol_pin
    protocol_stream
    protocol_spi
    protocol_vfs
(most of these are unused in CP and are just inherited from MP; vfs and
stream are definitely used though)

I did not find any crashing examples, but here's one to give a flavor of what
is improved, using `micropython_coverage`.  Before the change,
the vfs "ioctl" protocol is invoked, and the result is not intelligible
as json (but it could have resulted in a hard fault, potentially):

    >>> import uos, ujson
    >>> u = uos.VfsPosix('/tmp')
    >>> ujson.load(u)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ValueError: syntax error in JSON

After the change, the vfs object is correctly detected as not supporting
the stream protocol:
    >>> ujson.load(p)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    OSError: stream operation not supported
2019-12-04 09:29:57 -06:00
Dan Halbert d089f16656 'seconds' 2019-11-27 14:49:39 -05:00
Dan Halbert dd6dfeb30a Squeeze pyruler zh_Latn_pinyin 2019-11-27 14:47:35 -05:00
Dan Halbert b32a9192df make UART.write be blocking on SAMD; add timeout property 2019-11-27 13:05:29 -05:00
Scott Shawcroft a35d9b469d
Refactor deinit check to reduce code size. 2019-06-12 11:36:43 -07:00
Scott Shawcroft cfe24b8532
Improve rST consistency for rst2pyi use 2019-05-30 19:02:47 -07:00
Dan Halbert c0c809ad4b Fix version skew for bast_pro_mini build 2019-04-09 22:52:53 -04:00
Lionel Debroux b0c2c3c756 A couple build fixes for mp_float_t = double (MICROPY_FLOAT_IMPL_DOUBLE).
Signed-off-by: Lionel Debroux <lionel_debroux@yahoo.fr>
2019-02-17 11:21:48 +01:00
Dan Halbert 28cfd8a513 CharacteristicBuffer: make it be a stream class; add locking 2019-01-19 19:45:35 -05:00
Scott Shawcroft 747f2cfe26
Add subclass support to displayio.
Also, swap make_news to accept a kwarg map and refine param checking.

Fixes #1237
2019-01-14 17:29:19 -08:00
Dan Halbert 63cd9209f1 allow KeyboardInterrupt on UART read; fix nrf UART pin claiming; rename feather 52840 UART pins 2018-12-04 15:05:39 -05:00
Dan Halbert 80db2cec99 UART changes: timeout in secs, write bytes, etc. 2018-12-03 12:04:32 -05:00
Dan Halbert bc510e714f merge 3.0.2 to master 2018-09-18 15:38:12 -04:00
Dan Halbert 6a046f55c4 UART fixes and enhancements; default board object fix 2018-09-12 17:19:43 -04:00
Jeff Epler e1b4e9b7c7 UART: Always allocate UART objects in the long-lived pool
Particularly when they have buffers that are written via IRQ or DMA,
UART objects do not relocate gracefully.  If such an object is
relocated to the long-lived pool after its original creation, the
IRQ or DMA will write to an unexpected location within the Python
heap, leading to a variety of symptoms.  The most frequent symptom
is inability to read from the UART.

Consider the particular case of atmel-samd: usart_uart_obj_t
contains a usart_async_descriptor contains a _usart_async_device.
In _sercom_init_irq_param the address of this contained
_usart_async_device is assigned to a global array
sercom_to_sercom_dev which is later used from the interrupt context
_sercom_usart_interrupt_handler to store the received data in the
right ring buffer.

When the UART object is relocated to the long-lived heap, there's no
mechanism to re-point these internal pointers, so instead take the
cowardly way and allocate the UART object as long-lived.

Happily, almost all UART objects are likely to be long-lived, so
this is unlikely to have a negative effect on memory usage or heap
fragmentation.

Closes: #1056
2018-08-08 19:21:57 -05:00
Scott Shawcroft 933add6cd8
Support internationalisation. 2018-08-07 14:58:57 -07:00