Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

esp32: add support for uart pin inversions #5202

Closed
wants to merge 1 commit into from

Conversation

jeremyherbert
Copy link
Contributor

The ESP32 supports inversion of UART TX/RX/RTS/CTS. This adds support for inversions as optional kwargs:

u = UART(1, baudrate=115200, parity=1, bits=8, rx=27, tx=32, rx_invert=True, tx_invert=True)

@dpgeorge
Copy link
Member

Thanks for the contribution. This adds a lot of new arguments and it might be better to simplify it by combining them all together into a single invert argument. This can then be set via a bit mask, eg:

u = UART(1, 9600, invert=UART.INV_TX | UART.INV_RX)

@jeremyherbert
Copy link
Contributor Author

Ok, I will do that this evening.

@jeremyherbert
Copy link
Contributor Author

I’ve been thinking about this, if the bitmask approach is used, should the str printout show the individual bits? Or show the calculated mask (ie 0x3)? Or nothing?

@dpgeorge
Copy link
Member

if the bitmask approach is used, should the str printout show the individual bits

Usually (well, sometimes) the output of str would be some text that can be reevaluated to produce the same object. Printing the calculated mask would work for this. So would the individual bits like invert=INV_TX|INV_RX. The latter is how stm32's UART prints the flow control.

@jeremyherbert
Copy link
Contributor Author

Ok, you can now invert all four lines via a mask. Here is how it looks:

MicroPython v1.11-418-g96faf5a3b-dirty on 2019-10-11; ESP32 module with ESP32
Type "help()" for more information.
>>> from machine import UART
>>> u = UART(1, 115200)
>>> u
UART(1, baudrate=115201, bits=8, parity=None, stop=1, tx=10, rx=9, rts=-1, cts=-1, txbuf=256, rxbuf=256, timeout=0, timeout_char=1)
>>> u = UART(1, 115200, invert=UART.INVERSE_TX|UART.INVERSE_RX)
>>> u
UART(1, baudrate=115201, bits=8, parity=None, stop=1, tx=10, rx=9, rts=-1, cts=-1, txbuf=256, rxbuf=256, timeout=0, timeout_char=1, invert=INVERSE_TX|INVERSE_RX)
>>> u = UART(1, 115200, invert=7)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid inversion mask
>>> 

Only issue is that you can't use it as-is to construct a new object as the mask bits are under the UART class, ie "UART.INVERSE_TX" rather than just "INVERSE_TX".

@robert-hh
Copy link
Contributor

robert-hh commented Oct 11, 2019

Using an integer for invert=xx should work. You just have to pick the right values.
UART_INVERSE_RX = 2**19 + 1
UART_INVERSE_TX = 2**19 + 8
UART_INVERSE_CTS = 2**19 + 2
UART_INVERSE_RTS = 2**19 + 16
I implemented that reecntly for anothe MP branch, and shifted the values forth & back for convenience.

@jeremyherbert
Copy link
Contributor Author

jeremyherbert commented Oct 11, 2019

It does work :) I just added that as an example of the error, 7 is not a valid mask. If you were to put in a correct integer mask it would go through fine

@dpgeorge
Copy link
Member

Thanks for updating, merged in 7a7ee16

@dpgeorge dpgeorge closed this Oct 18, 2019
tannewt added a commit to tannewt/circuitpython that referenced this pull request Aug 24, 2021
…back-critical-section

nrf: remove critical section around sd_app_evt_wait()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants