Граф коммитов

44 коммитов

Автор SHA1 Сообщение Дата
Yurii Soldak
31ee1637df nrf: fix stop condition race in i2c 2022-01-20 07:37:47 +01:00
Yurii Soldak
cc1a95a489 nrf: fix race in i2c 2022-01-17 16:19:16 +01:00
Ayke van Laethem
3d73ee77d3 machine: add Device constant
This field contains the microcontroller name that we're compiling for,
or "generic" if we're not running on a microcontroller.
2021-11-30 00:47:11 +01:00
Ayke van Laethem
15d3f5f609 machine: support Pin.Get() function when the pin is configured as output
To my surprise, this is supported on all the devices I could test so
therefore it makes sense to change the API to allow this.
2021-10-28 07:22:19 +02:00
Ayke van Laethem
b67351babe machine: define Serial as the default output
Previously, the machine.UART0 object had two meanings:

  - it was the first UART on the chip
  - it was the default output for println

These two meanings conflict, and resulted in workarounds like:

  - Defining UART0 to refer to the USB-CDC interface (atsamd21,
    atsamd51, nrf52840), even though that clearly isn't an UART.
  - Defining NRF_UART0 to avoid a conflict with UART0 (which was
    redefined as a USB-CDC interface).
  - Defining aliases like UART0 = UART1, which refer to the same
    hardware peripheral (stm32).

This commit changes this to use a new machine.Serial object for the
default serial port. It might refer to the first or second UART
depending on the board, or even to the USB-CDC interface. Also, UART0
now really refers to the first UART on the chip, no longer to a USB-CDC
interface.

The changes in the runtime package are all just search+replace. The
changes in the machine package are a mixture of search+replace and
manual modifications.

This commit does not affect binary size, in fact it doesn't affect the
resulting binary at all.
2021-05-13 16:43:37 +02:00
Ayke van Laethem
aa5b8d0df7 machine: make UART objects pointer receivers
This means that machine.UART0, machine.UART1, etc are of type
*machine.UART, not machine.UART. This makes them easier to pass around
and avoids surprises when they are passed around by value while they
should be passed around by reference.

There is a small code size impact in some cases, but it is relatively
minor.
2021-05-13 16:43:37 +02:00
Ayke van Laethem
2f1f8fb075 machine: move PinMode to central location
It is always implemented exactly the same way (as an uint8) so there is
no reason to implement it in each target separately.

This also makes it easier to add some documentation to it.
2021-05-06 13:59:12 +02:00
Ayke van Laethem
90b42799a2 machine: make machine.I2C0 and similar objects pointers
This makes it possible to assign I2C objects (machine.I2C0,
machine.I2C1, etc.) without needing to take a pointer.

This is important especially in the future when I2C may be driven using
DMA and the machine.I2C type needs to store some state.
2021-03-29 02:02:04 +02:00
Ayke van Laethem
d6cdf8ca28 machine: make I2C.Configure signature consistent
It's better to always return an error value (even if it is nil) for
consistency.
2021-02-07 14:06:49 +01:00
Ayke van Laethem
cda5fffd98 nrf: use SPIM peripheral instead of the legacy SPI peripheral
This newer peripheral supports DMA (through EasyDMA) and should
generally be faster. Importantly for some operations: interrupts (within
255 byte buffers) will not interfere with the SPI transfer.
2020-12-22 14:41:06 +01:00
Ayke van Laethem
7c4e83f5c0 machine: clarify caller's responsibility in SetInterrupt 2020-11-08 15:11:50 +01:00
Ayke van Laethem
47dc76fc34 nrf: give more flexibility in picking SPI speeds
Instead of only allowing a limited number of speeds, use the provided
speed as an upper bound on the allowed speed. The reasoning is that
picking a higher speed than requrested will likely result in malfunction
while picking a lower speed will usually only result in slower
operation.
This behavior matches the ESP32 at least.
2020-10-18 22:11:03 +02:00
Ayke van Laethem
d39c7abb4d nrf: fix double stop signal in I2C 2020-09-27 15:21:54 +02:00
Daniel M. Lambea
9e61e6fe4d
nrf: add I2C error checking (#1392)
* machine/nrf: add I2C error checking
2020-09-26 09:20:43 +02:00
deadprogram
d1c4ed664e all: changeover to eliminate all direct use of master/slave terminology
Signed-off-by: deadprogram <ron@hybridgroup.com>
2020-07-23 22:45:23 +02:00
Ayke van Laethem
169d5f17b8 nrf: fix bug in SPI.Tx
There was what appears to be a race condition in the Tx function. While
it would work fine in many cases, when there were interrupts (such as
when using BLE), the function would just hang waiting for `EVENTS_READY`
to arrive.

I think what was happening was that the `spi.Bus.RXD.Get()` would start
the next transfer, which would complete (and generate an event) before
`EVENTS_READY` was reset to 0. The fix is easy: clear `EVENTS_READY`
before doing something that can trigger an event.

I believe I've seen this bug before on the PineTime but I couldn't find
the issue back then.
2020-06-08 19:54:41 +02:00
Ayke van Laethem
19c7965fc5 nrf: add support for pin change interrupts 2020-05-28 11:20:33 +02:00
Wojtek Siudzinski
e29379ce3a Fix the formatting 2020-02-18 23:34:56 +01:00
Wojtek Siudzinski
bdef52ad62 Allow changing the UART pins 2020-02-18 23:34:56 +01:00
Scott Yoder
630c498efa
nrf52840: implement USB-CDC (#883)
* machine/nrf52840: usb-cdc implementation
2020-02-17 15:14:24 +01:00
Scott Yoder
a0cdd6b4ed fix typo in pin configuration options for NRF 2020-02-09 22:32:27 +01:00
Ayke van Laethem
a5ed993f8d all: add compiler support for interrupts
This commit lets the compiler know about interrupts and allows
optimizations to be performed based on that: interrupts are eliminated
when they appear to be unused in a program. This is done with a new
pseudo-call (runtime/interrupt.New) that is treated specially by the
compiler.
2020-01-20 21:19:12 +01:00
Ayke van Laethem
4164c39a4a machine/nrf: do not compare slices against nil
Comparing slices against nil currently causes the slice to escape, due
to a limitation in LLVM 8. This leads to lots of unnecessary heap
allocations. With LLVM 9 and some modifications to TinyGo, this should
be fixed. However, this commit is an easy win right now.

Returning an error when both slices are nil is not necessary, when the
check is left out it should just do nothing.

For updating an SPI screen using the st7735 driver, this results in a
~7% performance win.
2019-10-11 08:45:40 +02:00
Ayke van Laethem
d2856bd6bd nrf: improve SPI write-only speed, by making use of double buffering
The SPI peripheral in the nrf chips support double buffering, which
makes it possible to keep sending continuously. This change introduces
double buffering on the nrf chips, which should improve SPI performance.

Tested on the pca10040 (nrf52832).
2019-09-17 17:51:13 +02:00
Ayke van Laethem
94b8214529 machine: refactor pins to be of Pin type 2019-05-26 20:48:50 +02:00
Ron Evans
9f8340a970 machine/nrf: refactor to use volatile package/API
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2019-05-24 15:44:33 +02:00
Anthony Elder
8d3f19bc84 Fix I2C signalStop in readLastByte for Microbit (#344)
* Fix I2C signalStop in readLastByte for Microbit
2019-05-13 14:30:25 +02:00
Ron Evans
4f4d7976c6
Add core support for multiple UARTs (#152)
* machine/uart: add core support for multiple UARTs by allowing for multiple RingBuffers
* machine/uart: complete core support for multiple UARTs
* machine/uart: no need to store pointer to UART, better to treat like I2C and SPI
* machine/uart: increase ring buffer size to 128 bytes
* machine/uart: improve godocs comments and use comma-ok idiom for buffer Put/Get methods
2019-01-25 22:09:13 +01:00
Ayke van Laethem
9eaa6a7d7f
nrf: set interrupt priorities
The default priority is 0 (highest) which is reserved by the SoftDevice.
For normal operation the exact priority level doesn't matter, only the
relative priority matters. So this change makes the code compatible with
the SoftDevice without actually changing the behavior.
2018-12-03 13:50:41 +01:00
Ron Evans
06ab3a836f
machine/nrf: SPI master implementation
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2018-12-02 13:26:08 +01:00
Ayke van Laethem
1ba463c7ee
machine: redesign I2C interface 2018-11-16 23:08:41 +01:00
Ayke van Laethem
daf92226d8
nrf: add nrf52840-mdk board
With the help of Chillance on GitHub.
2018-10-18 15:07:06 +02:00
Ayke van Laethem
ccee42ec7a
machine: add helpers for bit-banged driver support
The returned pointer and value can be used to set or clear a specific
pin.
2018-10-15 19:56:27 +02:00
Ayke van Laethem
bc9210b674
nrf: add micro:bit board 2018-10-06 13:04:14 +02:00
Ron Evans
e4fa1a8288
nrf: I2C interface
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2018-10-05 12:50:43 +02:00
Ron Evans
ef2ac09561
nrf: implement UART interface
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2018-10-02 17:08:31 +02:00
Ayke van Laethem
8f5bd81bf5
machine: split board definitions in separate files 2018-09-22 15:47:08 +02:00
Ayke van Laethem
9fa08bf51d
all: use groupName in peripherals
This is needed for support for multiple instances of a peripheral type.
2018-09-21 22:24:41 +02:00
Ayke van Laethem
752332ff13
machine/nrf: implement reading GPIO pins 2018-09-14 16:59:28 +02:00
Ron Evans
ab6757fe11
avr: implement Get() function on AVR, and leave stubs for NRF and dummy machines
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2018-09-13 20:54:01 +02:00
Ayke van Laethem
abaae5b90d
Remove unnecessary compiler workaround
This workaround isn't needed anymore: the feature has been implemented
now.
2018-08-29 20:45:50 +02:00
Ayke van Laethem
7991243554
Remove CGo from machine module
It isn't necessary anymore but apparently the Go importer didn't
complain about an unused import.
2018-08-29 20:44:56 +02:00
Ayke van Laethem
62c4c5e90b
go fmt 2018-08-17 23:23:20 +02:00
Ayke van Laethem
c4f0dc90dd machine: Rewrite most of the GPIO functionality
Split across device types (nrf, dummy) and use registers directly
instead of the HAL.
2018-05-05 20:05:53 +02:00