summaryrefslogtreecommitdiff
path: root/extmod/machine_i2c.c
AgeCommit message (Collapse)Author
2020-06-25remove machine_i2c, machine_spiJeff Epler
This micropython code is not used in circuitpython
2019-12-04protocols: Allow them to be (optionally) type-safeJeff Epler
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-01-18Fix unix buildScott Shawcroft
2018-08-16Fix esp and samdScott Shawcroft
2017-08-30all: Convert remaining "mp_uint_t n_args" to "size_t n_args".Damien George
This is to have consistency across the whole repository.
2016-11-24extmod/machine_i2c: Add hook to constructor to call port-specific code.Damien George
If MICROPY_PY_MACHINE_I2C_MAKE_NEW is defined then it is called when an I2C object is constructed with an id which is not -1.
2016-11-24extmod/machine_i2c: Expose soft I2C obj and readfrom/writeto funcs.Damien George
For external use by ports if needed.
2016-11-23extmod/machine_i2c: Remove trivial function wrappers.Damien George
2016-11-23extmod/machine_i2c: Add 'stop' argument to i2c readfrom/writeto meths.Damien George
2016-11-23extmod/machine_i2c: Make i2c.write[to] methods return num of ACKs recvd.Damien George
2016-11-23extmod/machine_i2c: Add 'nack' argument to i2c.readinto.Damien George
2016-11-23extmod/machine_i2c: Make C-level functions return -errno on I2C error.Damien George
2016-11-23extmod/machine_i2c: Remove unneeded i2c_write_mem/i2c_read_mem funcs.Damien George
2016-11-23extmod/machine_i2c: Rewrite mem xfer funcs in terms of C-level protocol.Damien George
2016-11-23extmod/machine_i2c: Rewrite i2c.scan in terms of C-level protocol.Damien George
2016-11-23extmod/machine_i2c: Add argument to C funcs to control stop generation.Damien George
2016-11-23extmod/machine_i2c: Add a C-level I2C-protocol, refactoring soft I2C.Damien George
2016-11-17extmod/machine_i2c: Release SDA on bus errorRadomir Dopieralski
2016-11-17extmod/machine_i2c: Raise an error when clock stretching times outRadomir Dopieralski
2016-11-17extmod/machine_i2c: Make the clock stretching timeout configurableRadomir Dopieralski
2016-10-11extmod/machine_i2c: Use writes not reads in i2c.scan().Radomir Dopieralski
As per discussion in #2449, using write requests instead of read requests for I2C.scan() seems to support a larger number of devices, especially ones that are write-only. Even a read-only I2C device has to implement writes in order to be able to receive the address of the register to read.
2016-09-28extmod/machine_i2c: Add support for the addrsize parameter in mem xfers.Radomir Dopieralski
The memory read/write I2C functions now take an optional keyword-only parameter that specifies the number of bits in the memory address. Only mem-addrs that are a multiple of 8-bits are supported (otherwise the behaviour is undefined). Due to the integer type used for the address, for values larger than 32 bits, only 32 bits of address will be sent, and the rest will be padded with 0s. Right now no exception is raised when that happens. For values smaller than 8, no address is sent. Also no exception then. Tested with a VL6180 sensor, which has 16-bit register addresses. Due to code refactoring, this patch reduces stmhal and esp8266 builds by about 50 bytes.
2016-09-22extmod/machine_i2c: Add clock stretching support.Radomir Dopieralski
When the clock is too fast for the i2c slave, it can temporarily hold down the scl line to signal to the master that it needs to wait. The master should check the scl line when it is releasing it after transmitting data, and wait for it to be released. This change has been tested with a logic analyzer and an i2c slace implemented on an atmega328p using its twi peripheral, clocked at 8Mhz. Without the change, the i2c communication works up to aboy 150kHz frequency, and above that results in the slave stuck in an unresponsive state. With this change, communication has been tested to work up to 400kHz.
2016-05-26extmod/machine_i2c: Redo mp_hal_pin macros to use open_drain and od_low.Damien George
mp_hal_pin_config_od is renamed mp_hal_pin_open_drain, and mp_hal_pin_low is mp_hal_pin_od_low.
2016-04-22extmod/machine_i2c: Allow mp_hal_pin_obj_t to be any type, not a ptr.Damien George
2016-04-12extmod/machine_i2c: Implement I2C memory reading/writing.Damien George
2016-04-12extmod/machine_i2c: Fix I2C reading by sending ack/nack at end of byte.Damien George
2016-04-12extmod: Add generic machine.I2C class, with bit-bang I2C.Damien George
Should work on any machine that provides the correct pin functions.