aboutsummaryrefslogtreecommitdiff
path: root/extmod/machine_i2c.c
AgeCommit message (Collapse)Author
2022-06-01extmod/machine_i2c: Add optional support for write-then-read transfers.Damien George
This option is useful for ports where it's more efficient to do a full I2C transfer in one go. Signed-off-by: Damien George <damien@micropython.org>
2022-05-03all: Use mp_obj_malloc everywhere it's applicable.Jim Mussared
This replaces occurences of foo_t *foo = m_new_obj(foo_t); foo->base.type = &foo_type; with foo_t *foo = mp_obj_malloc(foo_t, &foo_type); Excludes any places where base is a sub-field or when new0/memset is used. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-01-21extmod/machine_i2c: Increase default SoftI2C timeout to 50ms.Damien George
Some devices, eg BNO055, can stretch SCL for a long time, so make the default large to accommodate them. 50ms matches the current default for stm32 hardware I2C . Signed-off-by: Damien George <damien@micropython.org>
2021-09-02extmod/machine_i2c: Make SoftI2C configurable via macro option.Damien George
The zephyr port doesn't support SoftI2C so it's not enabled, and the legacy I2C constructor check can be removed. Signed-off-by: Damien George <damien@micropython.org>
2020-11-23extmod/machine_i2c: Add init protocol method for generic I2C bindings.Damien George
Hardware I2C implementations must provide a .init() protocol method if they want to support reconfiguration. Otherwise the default is that i2c.init() raises an OSError (currently the case for all ports). mp_machine_soft_i2c_locals_dict is renamed to mp_machine_i2c_locals_dict to match the generic SPI bindings. Fixes issue #6623 (where calling .init() on a HW I2C would crash). Signed-off-by: Damien George <damien@micropython.org>
2020-10-22py, extmod: Add explicit initializers for default values.Emil Renner Berthing
When compiling with -Wextra which includes -Wmissing-field-initializers GCC will warn that the defval field of mp_arg_val_t is not initialized. This is just a warning as it is defined to be zero initialized, but since it is a union it makes sense to be explicit about which member we're going to use, so add the explicit initializers and get rid of the warning.
2020-10-01extmod/machine_i2c: Remove "id" arg in SoftI2C constructor.Damien George
The SoftI2C constructor is now used soley to create SoftI2C instances, it can no longer delegate to create a hardware-based I2C instance. Signed-off-by: Damien George <damien@micropython.org>
2020-10-01extmod/machine_i2c: Rename type to SoftI2C and add custom print method.Damien George
Also rename machine_i2c_type to mp_machine_soft_i2c_type. These changes make it clear that it's a soft-I2C implementation, and match SoftSPI. Signed-off-by: Damien George <damien@micropython.org>
2020-08-27extmod/machine_i2c: Fix buffer overrun if 'addrsize' is bigger than 32.Michael Buesch
The memory operation functions read_mem() and write_mem() create a temporary buffer on the local C stack for the address bytes with the size of 4 bytes. This buffer is filled in a loop from the user supplied address and address length. If the user supplied 'addrsize' is bigger than 32, the local buffer is overrun. Fix this by raising an exception for invalid 'addrsize' values. Signed-off-by: Michael Buesch <m@bues.ch>
2020-04-05all: Use MP_ERROR_TEXT for all error messages.Jim Mussared
2020-02-28all: Reformat C and Python source code with tools/codeformat.py.Damien George
This is run with uncrustify 0.70.1, and black 19.10b0.
2019-05-20extmod/machine_i2c: Add i2c.writevto() that can write a vector of bufs.Damien George
For example: i2c.writevto(addr, (buf1, buf2)). This allows to efficiently (wrt memory) write data composed of separate buffers, such as a command followed by a large amount of data.
2019-05-20extmod/machine_i2c: Remove need for temporary memory in writemem() call.Damien George
2019-05-20extmod/machine_i2c: Change C-level API to allow split I2C transactions.Damien George
API is: int transfer( mp_obj_base_t *obj, uint16_t addr, size_t n, mp_machine_i2c_buf_t *bufs, unsigned int flags )
2018-07-08extmod: Fix to support compiling with object representation D.Damien George
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.