Change I2C terminology from "peripheral" to "target"

This commit is contained in:
Dan Halbert 2022-08-09 13:06:18 -04:00
parent 62bb0d0b04
commit 84807cd6eb
30 changed files with 217 additions and 210 deletions

View File

@ -71,7 +71,7 @@ as a natural "TODO" list. An example minimal build list is shown below:
CIRCUITPY_SDCARDIO = 0 CIRCUITPY_SDCARDIO = 0
CIRCUITPY_FRAMEBUFFERIO = 0 CIRCUITPY_FRAMEBUFFERIO = 0
CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CPERIPHERAL = 0 CIRCUITPY_I2CTARGET = 0
# Requires SPI, PulseIO (stub ok): # Requires SPI, PulseIO (stub ok):
CIRCUITPY_DISPLAYIO = 0 CIRCUITPY_DISPLAYIO = 0

View File

@ -398,12 +398,14 @@ msgstr ""
msgid "All CAN peripherals are in use" msgid "All CAN peripherals are in use"
msgstr "" msgstr ""
#: ports/espressif/common-hal/busio/I2C.c #: ports/espressif/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c
#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c
#: ports/nrf/common-hal/busio/I2C.c
msgid "All I2C peripherals are in use" msgid "All I2C peripherals are in use"
msgstr "" msgstr ""
#: ports/espressif/common-hal/i2ctarget/I2CTarget.c
msgid "All I2C targets are in use"
msgstr ""
#: ports/espressif/common-hal/countio/Counter.c #: ports/espressif/common-hal/countio/Counter.c
#: ports/espressif/common-hal/frequencyio/FrequencyIn.c #: ports/espressif/common-hal/frequencyio/FrequencyIn.c
#: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c #: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c
@ -1589,7 +1591,7 @@ msgstr ""
msgid "Only one TouchAlarm can be set in deep sleep." msgid "Only one TouchAlarm can be set in deep sleep."
msgstr "" msgstr ""
#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c #: ports/espressif/common-hal/i2ctarget/I2CTarget.c
msgid "Only one address is allowed" msgid "Only one address is allowed"
msgstr "" msgstr ""
@ -2319,11 +2321,11 @@ msgstr ""
msgid "a bytes-like object is required" msgid "a bytes-like object is required"
msgstr "" msgstr ""
#: shared-bindings/i2cperipheral/I2CPeripheral.c #: shared-bindings/i2ctarget/I2CTarget.c
msgid "address out of bounds" msgid "address out of bounds"
msgstr "" msgstr ""
#: shared-bindings/i2cperipheral/I2CPeripheral.c #: shared-bindings/i2ctarget/I2CTarget.c
msgid "addresses is empty" msgid "addresses is empty"
msgstr "" msgstr ""
@ -2515,7 +2517,7 @@ msgstr ""
msgid "can't cancel self" msgid "can't cancel self"
msgstr "" msgstr ""
#: py/obj.c py/objint.c shared-bindings/i2cperipheral/I2CPeripheral.c #: py/obj.c py/objint.c shared-bindings/i2ctarget/I2CTarget.c
#: shared-module/adafruit_pixelbuf/PixelBuf.c #: shared-module/adafruit_pixelbuf/PixelBuf.c
msgid "can't convert %q to %q" msgid "can't convert %q to %q"
msgstr "" msgstr ""

View File

@ -33,7 +33,7 @@ CIRCUITPY_BLEIO = 0
CIRCUITPY_BUSDEVICE = 0 CIRCUITPY_BUSDEVICE = 0
CIRCUITPY_FRAMEBUFFERIO = 0 CIRCUITPY_FRAMEBUFFERIO = 0
CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CPERIPHERAL = 0 CIRCUITPY_I2CTARGET = 0
CIRCUITPY_MSGPACK = 0 CIRCUITPY_MSGPACK = 0
CIRCUITPY_NEOPIXEL_WRITE = 0 CIRCUITPY_NEOPIXEL_WRITE = 0
CIRCUITPY_NVM = 0 CIRCUITPY_NVM = 0

View File

@ -18,7 +18,7 @@ CIRCUITPY_AUDIOPWMIO = 0
CIRCUITPY_BITBANGIO = 0 CIRCUITPY_BITBANGIO = 0
CIRCUITPY_BITBANG_APA102 = 0 CIRCUITPY_BITBANG_APA102 = 0
CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CPERIPHERAL = 0 CIRCUITPY_I2CTARGET = 0
CIRCUITPY_NEOPIXEL_WRITE = 0 CIRCUITPY_NEOPIXEL_WRITE = 0
CIRCUITPY_PARALLELDISPLAY = 0 CIRCUITPY_PARALLELDISPLAY = 0
CIRCUITPY_PIXELBUF = 0 CIRCUITPY_PIXELBUF = 0

View File

@ -22,7 +22,7 @@ CIRCUITPY_AUDIOBUSIO = 0
CIRCUITPY_BITBANGIO = 0 CIRCUITPY_BITBANGIO = 0
CIRCUITPY_BITMAPTOOLS = 0 CIRCUITPY_BITMAPTOOLS = 0
CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CPERIPHERAL = 0 CIRCUITPY_I2CTARGET = 0
CIRCUITPY_NEOPIXEL_WRITE = 0 CIRCUITPY_NEOPIXEL_WRITE = 0
CIRCUITPY_PARALLELDISPLAY = 0 CIRCUITPY_PARALLELDISPLAY = 0
CIRCUITPY_PIXELBUF = 0 CIRCUITPY_PIXELBUF = 0

View File

@ -23,7 +23,7 @@ CIRCUITPY_AUDIOBUSIO = 0
CIRCUITPY_BLEIO = 0 CIRCUITPY_BLEIO = 0
CIRCUITPY_DISPLAYIO = 0 CIRCUITPY_DISPLAYIO = 0
CIRCUITPY_KEYPAD = 0 CIRCUITPY_KEYPAD = 0
CIRCUITPY_I2CPERIPHERAL = 0 CIRCUITPY_I2CTARGET = 0
CIRCUITPY_TOUCHIO = 0 CIRCUITPY_TOUCHIO = 0
CIRCUITPY_RGBMATRIX = 0 CIRCUITPY_RGBMATRIX = 0
CIRCUITPY_PS2IO = 0 CIRCUITPY_PS2IO = 0

View File

@ -22,7 +22,7 @@ CIRCUITPY_BLEIO_HCI = 0
CIRCUITPY_DISPLAYIO = 0 CIRCUITPY_DISPLAYIO = 0
CIRCUITPY_FRAMEBUFFERIO = 0 CIRCUITPY_FRAMEBUFFERIO = 0
CIRCUITPY_KEYPAD = 0 CIRCUITPY_KEYPAD = 0
CIRCUITPY_I2CPERIPHERAL = 0 CIRCUITPY_I2CTARGET = 0
CIRCUITPY_TOUCHIO = 0 CIRCUITPY_TOUCHIO = 0
CIRCUITPY_RGBMATRIX = 0 CIRCUITPY_RGBMATRIX = 0
CIRCUITPY_PS2IO = 0 CIRCUITPY_PS2IO = 0

View File

@ -1 +0,0 @@
// No i2cperipheral module functions.

View File

@ -24,7 +24,7 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#include "shared-bindings/i2cperipheral/I2CPeripheral.h" #include "shared-bindings/i2ctarget/I2CTarget.h"
#include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/microcontroller/Pin.h"
#include "common-hal/busio/I2C.h" #include "common-hal/busio/I2C.h"
@ -36,7 +36,7 @@
#include "hal/include/hal_gpio.h" #include "hal/include/hal_gpio.h"
#include "peripherals/samd/sercom.h" #include "peripherals/samd/sercom.h"
void common_hal_i2cperipheral_i2c_peripheral_construct(i2cperipheral_i2c_peripheral_obj_t *self, void common_hal_i2ctarget_i2c_target_construct(i2ctarget_i2c_target_obj_t *self,
const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda, const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda,
uint8_t *addresses, unsigned int num_addresses, bool smbus) { uint8_t *addresses, unsigned int num_addresses, bool smbus) {
uint8_t sercom_index; uint8_t sercom_index;
@ -100,12 +100,12 @@ void common_hal_i2cperipheral_i2c_peripheral_construct(i2cperipheral_i2c_periphe
sercom->I2CS.CTRLA.bit.ENABLE = 1; sercom->I2CS.CTRLA.bit.ENABLE = 1;
} }
bool common_hal_i2cperipheral_i2c_peripheral_deinited(i2cperipheral_i2c_peripheral_obj_t *self) { bool common_hal_i2ctarget_i2c_target_deinited(i2ctarget_i2c_target_obj_t *self) {
return self->sda_pin == NO_PIN; return self->sda_pin == NO_PIN;
} }
void common_hal_i2cperipheral_i2c_peripheral_deinit(i2cperipheral_i2c_peripheral_obj_t *self) { void common_hal_i2ctarget_i2c_target_deinit(i2ctarget_i2c_target_obj_t *self) {
if (common_hal_i2cperipheral_i2c_peripheral_deinited(self)) { if (common_hal_i2ctarget_i2c_target_deinited(self)) {
return; return;
} }
@ -117,7 +117,7 @@ void common_hal_i2cperipheral_i2c_peripheral_deinit(i2cperipheral_i2c_peripheral
self->scl_pin = NO_PIN; self->scl_pin = NO_PIN;
} }
static int i2c_peripheral_check_error(i2cperipheral_i2c_peripheral_obj_t *self, bool raise) { static int i2c_target_check_error(i2ctarget_i2c_target_obj_t *self, bool raise) {
if (!self->sercom->I2CS.INTFLAG.bit.ERROR) { if (!self->sercom->I2CS.INTFLAG.bit.ERROR) {
return 0; return 0;
} }
@ -136,8 +136,8 @@ static int i2c_peripheral_check_error(i2cperipheral_i2c_peripheral_obj_t *self,
return -err; return -err;
} }
int common_hal_i2cperipheral_i2c_peripheral_is_addressed(i2cperipheral_i2c_peripheral_obj_t *self, uint8_t *address, bool *is_read, bool *is_restart) { int common_hal_i2ctarget_i2c_target_is_addressed(i2ctarget_i2c_target_obj_t *self, uint8_t *address, bool *is_read, bool *is_restart) {
int err = i2c_peripheral_check_error(self, false); int err = i2c_target_check_error(self, false);
if (err) { if (err) {
return err; return err;
} }
@ -154,22 +154,22 @@ int common_hal_i2cperipheral_i2c_peripheral_is_addressed(i2cperipheral_i2c_perip
for (unsigned int i = 0; i < self->num_addresses; i++) { for (unsigned int i = 0; i < self->num_addresses; i++) {
if (*address == self->addresses[i]) { if (*address == self->addresses[i]) {
common_hal_i2cperipheral_i2c_peripheral_ack(self, true); common_hal_i2ctarget_i2c_target_ack(self, true);
return 1; return 1;
} }
} }
// This should clear AMATCH, but it doesn't... // This should clear AMATCH, but it doesn't...
common_hal_i2cperipheral_i2c_peripheral_ack(self, false); common_hal_i2ctarget_i2c_target_ack(self, false);
return 0; return 0;
} }
int common_hal_i2cperipheral_i2c_peripheral_read_byte(i2cperipheral_i2c_peripheral_obj_t *self, uint8_t *data) { int common_hal_i2ctarget_i2c_target_read_byte(i2ctarget_i2c_target_obj_t *self, uint8_t *data) {
for (int t = 0; t < 100 && !self->sercom->I2CS.INTFLAG.reg; t++) { for (int t = 0; t < 100 && !self->sercom->I2CS.INTFLAG.reg; t++) {
mp_hal_delay_us(10); mp_hal_delay_us(10);
} }
i2c_peripheral_check_error(self, true); i2c_target_check_error(self, true);
if (!self->sercom->I2CS.INTFLAG.bit.DRDY || if (!self->sercom->I2CS.INTFLAG.bit.DRDY ||
self->sercom->I2CS.INTFLAG.bit.PREC || self->sercom->I2CS.INTFLAG.bit.PREC ||
@ -181,12 +181,12 @@ int common_hal_i2cperipheral_i2c_peripheral_read_byte(i2cperipheral_i2c_peripher
return 1; return 1;
} }
int common_hal_i2cperipheral_i2c_peripheral_write_byte(i2cperipheral_i2c_peripheral_obj_t *self, uint8_t data) { int common_hal_i2ctarget_i2c_target_write_byte(i2ctarget_i2c_target_obj_t *self, uint8_t data) {
for (int t = 0; !self->sercom->I2CS.INTFLAG.reg && t < 100; t++) { for (int t = 0; !self->sercom->I2CS.INTFLAG.reg && t < 100; t++) {
mp_hal_delay_us(10); mp_hal_delay_us(10);
} }
i2c_peripheral_check_error(self, true); i2c_target_check_error(self, true);
if (self->sercom->I2CS.INTFLAG.bit.PREC) { if (self->sercom->I2CS.INTFLAG.bit.PREC) {
return 0; return 0;
@ -208,12 +208,12 @@ int common_hal_i2cperipheral_i2c_peripheral_write_byte(i2cperipheral_i2c_periphe
return 1; return 1;
} }
void common_hal_i2cperipheral_i2c_peripheral_ack(i2cperipheral_i2c_peripheral_obj_t *self, bool ack) { void common_hal_i2ctarget_i2c_target_ack(i2ctarget_i2c_target_obj_t *self, bool ack) {
self->sercom->I2CS.CTRLB.bit.ACKACT = !ack; self->sercom->I2CS.CTRLB.bit.ACKACT = !ack;
self->sercom->I2CS.CTRLB.bit.CMD = 0x03; self->sercom->I2CS.CTRLB.bit.CMD = 0x03;
} }
void common_hal_i2cperipheral_i2c_peripheral_close(i2cperipheral_i2c_peripheral_obj_t *self) { void common_hal_i2ctarget_i2c_target_close(i2ctarget_i2c_target_obj_t *self) {
for (int t = 0; !self->sercom->I2CS.INTFLAG.reg && t < 100; t++) { for (int t = 0; !self->sercom->I2CS.INTFLAG.reg && t < 100; t++) {
mp_hal_delay_us(10); mp_hal_delay_us(10);
} }
@ -223,7 +223,7 @@ void common_hal_i2cperipheral_i2c_peripheral_close(i2cperipheral_i2c_peripheral_
} }
if (!self->sercom->I2CS.STATUS.bit.DIR) { if (!self->sercom->I2CS.STATUS.bit.DIR) {
common_hal_i2cperipheral_i2c_peripheral_ack(self, false); common_hal_i2ctarget_i2c_target_ack(self, false);
} else { } else {
int i = 0; int i = 0;
while (self->sercom->I2CS.INTFLAG.reg == SERCOM_I2CS_INTFLAG_DRDY) { while (self->sercom->I2CS.INTFLAG.reg == SERCOM_I2CS_INTFLAG_DRDY) {

View File

@ -24,8 +24,8 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_PERIPHERAL_H #ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_TARGET_H
#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_PERIPHERAL_H #define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_TARGET_H
#include "common-hal/microcontroller/Pin.h" #include "common-hal/microcontroller/Pin.h"
#include "py/obj.h" #include "py/obj.h"
@ -40,6 +40,6 @@ typedef struct {
uint8_t scl_pin; uint8_t scl_pin;
uint8_t sda_pin; uint8_t sda_pin;
bool writing; bool writing;
} i2cperipheral_i2c_peripheral_obj_t; } i2ctarget_i2c_target_obj_t;
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_PERIPHERAL_H #endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_TARGET_H

View File

@ -0,0 +1 @@
// No i2ctarget module functions.

View File

@ -38,7 +38,7 @@ CIRCUITPY_FRAMEBUFFERIO ?= 0
CIRCUITPY_FREQUENCYIO ?= 0 CIRCUITPY_FREQUENCYIO ?= 0
CIRCUITPY_GETPASS ?= 0 CIRCUITPY_GETPASS ?= 0
CIRCUITPY_GIFIO ?= 0 CIRCUITPY_GIFIO ?= 0
CIRCUITPY_I2CPERIPHERAL ?= 0 CIRCUITPY_I2CTARGET ?= 0
CIRCUITPY_JSON ?= 0 CIRCUITPY_JSON ?= 0
CIRCUITPY_KEYPAD ?= 0 CIRCUITPY_KEYPAD ?= 0
CIRCUITPY_MSGPACK ?= 0 CIRCUITPY_MSGPACK ?= 0

View File

@ -9,7 +9,7 @@ CIRCUITPY_AUDIOBUSIO = 0
CIRCUITPY_AUDIOIO = 0 CIRCUITPY_AUDIOIO = 0
CIRCUITPY_COUNTIO = 0 CIRCUITPY_COUNTIO = 0
CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CPERIPHERAL = 0 CIRCUITPY_I2CTARGET = 0
CIRCUITPY_NVM = 0 CIRCUITPY_NVM = 0
CIRCUITPY_PARALLELDISPLAY = 0 CIRCUITPY_PARALLELDISPLAY = 0
CIRCUITPY_PULSEIO = 0 CIRCUITPY_PULSEIO = 0

View File

@ -15,7 +15,7 @@ CIRCUITPY_COUNTIO = 0
CIRCUITPY_DISPLAYIO = 0 CIRCUITPY_DISPLAYIO = 0
CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_GNSS = 1 CIRCUITPY_GNSS = 1
CIRCUITPY_I2CPERIPHERAL = 0 CIRCUITPY_I2CTARGET = 0
CIRCUITPY_KEYPAD = 0 CIRCUITPY_KEYPAD = 0
CIRCUITPY_NEOPIXEL_WRITE = 0 CIRCUITPY_NEOPIXEL_WRITE = 0
CIRCUITPY_NVM = 0 CIRCUITPY_NVM = 0

View File

@ -1 +0,0 @@
// No i2cperipheral module functions.

View File

@ -24,15 +24,15 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#include "shared-bindings/i2cperipheral/I2CPeripheral.h" #include "shared-bindings/i2ctarget/I2CTarget.h"
#include "py/mperrno.h" #include "py/mperrno.h"
#include "py/runtime.h" #include "py/runtime.h"
#include "common-hal/i2cperipheral/I2CPeripheral.h" #include "common-hal/i2ctarget/I2CTarget.h"
#include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/microcontroller/Pin.h"
void common_hal_i2cperipheral_i2c_peripheral_construct(i2cperipheral_i2c_peripheral_obj_t *self, void common_hal_i2ctarget_i2c_target_construct(i2ctarget_i2c_target_obj_t *self,
const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda, const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda,
uint8_t *addresses, unsigned int num_addresses, bool smbus) { uint8_t *addresses, unsigned int num_addresses, bool smbus) {
// Pins 45 and 46 are "strapping" pins that impact start up behavior. They usually need to // Pins 45 and 46 are "strapping" pins that impact start up behavior. They usually need to
@ -54,7 +54,7 @@ void common_hal_i2cperipheral_i2c_peripheral_construct(i2cperipheral_i2c_periphe
self->i2c_num = peripherals_i2c_get_free_num(); self->i2c_num = peripherals_i2c_get_free_num();
if (self->i2c_num == I2C_NUM_MAX) { if (self->i2c_num == I2C_NUM_MAX) {
mp_raise_ValueError(translate("All I2C peripherals are in use")); mp_raise_ValueError(translate("All I2C targets are in use"));
} }
const i2c_config_t i2c_conf = { const i2c_config_t i2c_conf = {
@ -73,7 +73,7 @@ void common_hal_i2cperipheral_i2c_peripheral_construct(i2cperipheral_i2c_periphe
if (err == ESP_FAIL) { if (err == ESP_FAIL) {
mp_raise_OSError(MP_EIO); mp_raise_OSError(MP_EIO);
} else { } else {
mp_arg_error_invalid(MP_QSTR_I2CPeripheral); mp_arg_error_invalid(MP_QSTR_I2CTarget);
} }
} }
@ -81,12 +81,12 @@ void common_hal_i2cperipheral_i2c_peripheral_construct(i2cperipheral_i2c_periphe
claim_pin(scl); claim_pin(scl);
} }
bool common_hal_i2cperipheral_i2c_peripheral_deinited(i2cperipheral_i2c_peripheral_obj_t *self) { bool common_hal_i2ctarget_i2c_target_deinited(i2ctarget_i2c_target_obj_t *self) {
return self->sda_pin == NULL; return self->sda_pin == NULL;
} }
void common_hal_i2cperipheral_i2c_peripheral_deinit(i2cperipheral_i2c_peripheral_obj_t *self) { void common_hal_i2ctarget_i2c_target_deinit(i2ctarget_i2c_target_obj_t *self) {
if (common_hal_i2cperipheral_i2c_peripheral_deinited(self)) { if (common_hal_i2ctarget_i2c_target_deinited(self)) {
return; return;
} }
@ -98,7 +98,7 @@ void common_hal_i2cperipheral_i2c_peripheral_deinit(i2cperipheral_i2c_peripheral
self->scl_pin = NULL; self->scl_pin = NULL;
} }
int common_hal_i2cperipheral_i2c_peripheral_is_addressed(i2cperipheral_i2c_peripheral_obj_t *self, int common_hal_i2ctarget_i2c_target_is_addressed(i2ctarget_i2c_target_obj_t *self,
uint8_t *address, bool *is_read, bool *is_restart) { uint8_t *address, bool *is_read, bool *is_restart) {
*address = self->addresses[0]; *address = self->addresses[0];
*is_read = true; *is_read = true;
@ -106,21 +106,21 @@ int common_hal_i2cperipheral_i2c_peripheral_is_addressed(i2cperipheral_i2c_perip
return 1; return 1;
} }
int common_hal_i2cperipheral_i2c_peripheral_read_byte(i2cperipheral_i2c_peripheral_obj_t *self, uint8_t *data) { int common_hal_i2ctarget_i2c_target_read_byte(i2ctarget_i2c_target_obj_t *self, uint8_t *data) {
i2c_slave_read_buffer(self->i2c_num, data, 128, 0); i2c_slave_read_buffer(self->i2c_num, data, 128, 0);
return 1; return 1;
} }
int common_hal_i2cperipheral_i2c_peripheral_write_byte(i2cperipheral_i2c_peripheral_obj_t *self, uint8_t data) { int common_hal_i2ctarget_i2c_target_write_byte(i2ctarget_i2c_target_obj_t *self, uint8_t data) {
i2c_reset_tx_fifo(self->i2c_num); i2c_reset_tx_fifo(self->i2c_num);
i2c_slave_write_buffer(self->i2c_num, &data, 128, 0); i2c_slave_write_buffer(self->i2c_num, &data, 128, 0);
return 1; return 1;
} }
void common_hal_i2cperipheral_i2c_peripheral_ack(i2cperipheral_i2c_peripheral_obj_t *self, bool ack) { void common_hal_i2ctarget_i2c_target_ack(i2ctarget_i2c_target_obj_t *self, bool ack) {
} }
void common_hal_i2cperipheral_i2c_peripheral_close(i2cperipheral_i2c_peripheral_obj_t *self) { void common_hal_i2ctarget_i2c_target_close(i2ctarget_i2c_target_obj_t *self) {
} }

View File

@ -24,8 +24,8 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#ifndef MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_BUSIO_I2C_PERIPHERAL_H #ifndef MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_BUSIO_I2C_TARGET_H
#define MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_BUSIO_I2C_PERIPHERAL_H #define MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_BUSIO_I2C_TARGET_H
#include "py/obj.h" #include "py/obj.h"
#include "peripherals/i2c.h" #include "peripherals/i2c.h"
@ -38,6 +38,6 @@ typedef struct {
uint8_t num_addresses; uint8_t num_addresses;
const mcu_pin_obj_t *scl_pin; const mcu_pin_obj_t *scl_pin;
const mcu_pin_obj_t *sda_pin; const mcu_pin_obj_t *sda_pin;
} i2cperipheral_i2c_peripheral_obj_t; } i2ctarget_i2c_target_obj_t;
#endif // MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_BUSIO_I2C_PERIPHERAL_H #endif // MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_BUSIO_I2C_TARGET_H

View File

@ -0,0 +1 @@
// No i2ctarget module functions.

View File

@ -21,7 +21,7 @@ CIRCUITPY_FRAMEBUFFERIO ?= 1
CIRCUITPY_FREQUENCYIO ?= 1 CIRCUITPY_FREQUENCYIO ?= 1
CIRCUITPY_HASHLIB ?= 1 CIRCUITPY_HASHLIB ?= 1
CIRCUITPY_IMAGECAPTURE ?= 1 CIRCUITPY_IMAGECAPTURE ?= 1
CIRCUITPY_I2CPERIPHERAL ?= 1 CIRCUITPY_I2CTARGET ?= 1
CIRCUITPY_RGBMATRIX ?= 1 CIRCUITPY_RGBMATRIX ?= 1
CIRCUITPY_ROTARYIO ?= 1 CIRCUITPY_ROTARYIO ?= 1
CIRCUITPY_NVM ?= 1 CIRCUITPY_NVM ?= 1

View File

@ -18,7 +18,7 @@ CIRCUITPY_BUSIO = 0
CIRCUITPY_COUNTIO = 0 CIRCUITPY_COUNTIO = 0
CIRCUITPY_DISPLAYIO = 0 CIRCUITPY_DISPLAYIO = 0
CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CPERIPHERAL = 0 CIRCUITPY_I2CTARGET = 0
CIRCUITPY_NVM = 0 CIRCUITPY_NVM = 0
CIRCUITPY_PWMIO = 0 CIRCUITPY_PWMIO = 0
CIRCUITPY_PULSEIO = 0 CIRCUITPY_PULSEIO = 0

View File

@ -14,7 +14,7 @@ CIRCUITPY_AUDIOBUSIO = 0
CIRCUITPY_BUSDEVICE = 1 CIRCUITPY_BUSDEVICE = 1
CIRCUITPY_COUNTIO = 0 CIRCUITPY_COUNTIO = 0
CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CPERIPHERAL = 0 CIRCUITPY_I2CTARGET = 0
CIRCUITPY_NVM = 0 CIRCUITPY_NVM = 0
CIRCUITPY_PARALLELDISPLAY = 0 CIRCUITPY_PARALLELDISPLAY = 0
CIRCUITPY_PULSEIO = 0 CIRCUITPY_PULSEIO = 0

View File

@ -27,7 +27,7 @@ CIRCUITPY_BLEIO_HCI = 0
CIRCUITPY_BLEIO ?= 1 CIRCUITPY_BLEIO ?= 1
# No I2CPeripheral implementation # No I2CPeripheral implementation
CIRCUITPY_I2CPERIPHERAL = 0 CIRCUITPY_I2CTARGET = 0
CIRCUITPY_RTC ?= 1 CIRCUITPY_RTC ?= 1

View File

@ -20,7 +20,7 @@ CIRCUITPY_ROTARYIO_SOFTENCODER = 1
# Things that need to be implemented. # Things that need to be implemented.
# Use PWM interally # Use PWM interally
CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CPERIPHERAL = 0 CIRCUITPY_I2CTARGET = 0
CIRCUITPY_NVM = 1 CIRCUITPY_NVM = 1
# Use PIO interally # Use PIO interally
CIRCUITPY_PULSEIO ?= 1 CIRCUITPY_PULSEIO ?= 1

View File

@ -42,7 +42,7 @@ CIRCUITPY_PWMIO = 1
CIRCUITPY_AUDIOPWMIO = 1 CIRCUITPY_AUDIOPWMIO = 1
CIRCUITPY_CANIO = 0 CIRCUITPY_CANIO = 0
CIRCUITPY_AUDIOBUSIO = 0 CIRCUITPY_AUDIOBUSIO = 0
CIRCUITPY_I2CPERIPHERAL = 0 CIRCUITPY_I2CTARGET = 0
# Requires SPI, PulseIO (stub ok): # Requires SPI, PulseIO (stub ok):
CIRCUITPY_DISPLAYIO = 0 CIRCUITPY_DISPLAYIO = 0

View File

@ -24,7 +24,7 @@ ifeq ($(MCU_SERIES),F4)
CIRCUITPY_AUDIOBUSIO ?= 0 CIRCUITPY_AUDIOBUSIO ?= 0
CIRCUITPY_COUNTIO ?= 0 CIRCUITPY_COUNTIO ?= 0
CIRCUITPY_FREQUENCYIO ?= 0 CIRCUITPY_FREQUENCYIO ?= 0
CIRCUITPY_I2CPERIPHERAL ?= 0 CIRCUITPY_I2CTARGET ?= 0
CIRCUITPY_NVM ?= 0 CIRCUITPY_NVM ?= 0
CIRCUITPY_ROTARYIO ?= 0 CIRCUITPY_ROTARYIO ?= 0
CIRCUITPY_RTC ?= 1 CIRCUITPY_RTC ?= 1
@ -39,7 +39,7 @@ ifeq ($(MCU_SERIES),H7)
CIRCUITPY_AUDIOIO ?= 0 CIRCUITPY_AUDIOIO ?= 0
CIRCUITPY_COUNTIO ?= 0 CIRCUITPY_COUNTIO ?= 0
CIRCUITPY_FREQUENCYIO ?= 0 CIRCUITPY_FREQUENCYIO ?= 0
CIRCUITPY_I2CPERIPHERAL ?= 0 CIRCUITPY_I2CTARGET ?= 0
CIRCUITPY_NEOPIXEL_WRITE ?= 0 CIRCUITPY_NEOPIXEL_WRITE ?= 0
CIRCUITPY_NVM ?= 0 CIRCUITPY_NVM ?= 0
CIRCUITPY_PULSEIO ?= 0 CIRCUITPY_PULSEIO ?= 0
@ -58,7 +58,7 @@ ifeq ($(MCU_SERIES),F7)
CIRCUITPY_AUDIOIO ?= 0 CIRCUITPY_AUDIOIO ?= 0
CIRCUITPY_COUNTIO ?= 0 CIRCUITPY_COUNTIO ?= 0
CIRCUITPY_FREQUENCYIO ?= 0 CIRCUITPY_FREQUENCYIO ?= 0
CIRCUITPY_I2CPERIPHERAL ?= 0 CIRCUITPY_I2CTARGET ?= 0
CIRCUITPY_NEOPIXEL_WRITE ?= 0 CIRCUITPY_NEOPIXEL_WRITE ?= 0
CIRCUITPY_NVM ?= 0 CIRCUITPY_NVM ?= 0
CIRCUITPY_ROTARYIO ?= 0 CIRCUITPY_ROTARYIO ?= 0
@ -75,7 +75,7 @@ ifeq ($(MCU_SERIES),L4)
CIRCUITPY_AUDIOIO ?= 0 CIRCUITPY_AUDIOIO ?= 0
CIRCUITPY_COUNTIO ?= 0 CIRCUITPY_COUNTIO ?= 0
CIRCUITPY_FREQUENCYIO ?= 0 CIRCUITPY_FREQUENCYIO ?= 0
CIRCUITPY_I2CPERIPHERAL ?= 0 CIRCUITPY_I2CTARGET ?= 0
CIRCUITPY_NEOPIXEL_WRITE ?= 0 CIRCUITPY_NEOPIXEL_WRITE ?= 0
CIRCUITPY_NVM ?= 0 CIRCUITPY_NVM ?= 0
CIRCUITPY_ROTARYIO ?= 0 CIRCUITPY_ROTARYIO ?= 0

View File

@ -210,8 +210,8 @@ endif
ifeq ($(CIRCUITPY_HASHLIB),1) ifeq ($(CIRCUITPY_HASHLIB),1)
SRC_PATTERNS += hashlib/% SRC_PATTERNS += hashlib/%
endif endif
ifeq ($(CIRCUITPY_I2CPERIPHERAL),1) ifeq ($(CIRCUITPY_I2CTARGET),1)
SRC_PATTERNS += i2cperipheral/% SRC_PATTERNS += i2ctarget/%
endif endif
ifeq ($(CIRCUITPY_IMAGECAPTURE),1) ifeq ($(CIRCUITPY_IMAGECAPTURE),1)
SRC_PATTERNS += imagecapture/% SRC_PATTERNS += imagecapture/%
@ -424,8 +424,8 @@ SRC_COMMON_HAL_ALL = \
gnss/SatelliteSystem.c \ gnss/SatelliteSystem.c \
hashlib/__init__.c \ hashlib/__init__.c \
hashlib/Hash.c \ hashlib/Hash.c \
i2cperipheral/I2CPeripheral.c \ i2ctarget/I2CTarget.c \
i2cperipheral/__init__.c \ i2ctarget/__init__.c \
microcontroller/Pin.c \ microcontroller/Pin.c \
microcontroller/Processor.c \ microcontroller/Processor.c \
microcontroller/__init__.c \ microcontroller/__init__.c \

View File

@ -242,8 +242,8 @@ CFLAGS += -DCIRCUITPY_GNSS=$(CIRCUITPY_GNSS)
CIRCUITPY_HASHLIB ?= $(CIRCUITPY_WEB_WORKFLOW) CIRCUITPY_HASHLIB ?= $(CIRCUITPY_WEB_WORKFLOW)
CFLAGS += -DCIRCUITPY_HASHLIB=$(CIRCUITPY_HASHLIB) CFLAGS += -DCIRCUITPY_HASHLIB=$(CIRCUITPY_HASHLIB)
CIRCUITPY_I2CPERIPHERAL ?= $(CIRCUITPY_FULL_BUILD) CIRCUITPY_I2CTARGET ?= $(CIRCUITPY_FULL_BUILD)
CFLAGS += -DCIRCUITPY_I2CPERIPHERAL=$(CIRCUITPY_I2CPERIPHERAL) CFLAGS += -DCIRCUITPY_I2CTARGET=$(CIRCUITPY_I2CTARGET)
CIRCUITPY_IMAGECAPTURE ?= 0 CIRCUITPY_IMAGECAPTURE ?= 0
CFLAGS += -DCIRCUITPY_IMAGECAPTURE=$(CIRCUITPY_IMAGECAPTURE) CFLAGS += -DCIRCUITPY_IMAGECAPTURE=$(CIRCUITPY_IMAGECAPTURE)

View File

@ -25,7 +25,7 @@
*/ */
#include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/microcontroller/Pin.h"
#include "shared-bindings/i2cperipheral/I2CPeripheral.h" #include "shared-bindings/i2ctarget/I2CTarget.h"
#include "shared-bindings/time/__init__.h" #include "shared-bindings/time/__init__.h"
#include "shared-bindings/util.h" #include "shared-bindings/util.h"
@ -39,33 +39,33 @@
#include "py/objproperty.h" #include "py/objproperty.h"
#include "py/runtime.h" #include "py/runtime.h"
STATIC mp_obj_t mp_obj_new_i2cperipheral_i2c_peripheral_request(i2cperipheral_i2c_peripheral_obj_t *peripheral, uint8_t address, bool is_read, bool is_restart) { STATIC mp_obj_t mp_obj_new_i2ctarget_i2c_target_request(i2ctarget_i2c_target_obj_t *target, uint8_t address, bool is_read, bool is_restart) {
i2cperipheral_i2c_peripheral_request_obj_t *self = m_new_obj(i2cperipheral_i2c_peripheral_request_obj_t); i2ctarget_i2c_target_request_obj_t *self = m_new_obj(i2ctarget_i2c_target_request_obj_t);
self->base.type = &i2cperipheral_i2c_peripheral_request_type; self->base.type = &i2ctarget_i2c_target_request_type;
self->peripheral = peripheral; self->target = target;
self->address = address; self->address = address;
self->is_read = is_read; self->is_read = is_read;
self->is_restart = is_restart; self->is_restart = is_restart;
return (mp_obj_t)self; return (mp_obj_t)self;
} }
//| class I2CPeripheral: //| class I2CTarget:
//| """Two wire serial protocol peripheral""" //| """Two wire serial protocol target"""
//| //|
//| def __init__(self, scl: microcontroller.Pin, sda: microcontroller.Pin, addresses: Sequence[int], smbus: bool = False) -> None: //| def __init__(self, scl: microcontroller.Pin, sda: microcontroller.Pin, addresses: Sequence[int], smbus: bool = False) -> None:
//| """I2C is a two-wire protocol for communicating between devices. //| """I2C is a two-wire protocol for communicating between devices.
//| This implements the peripheral (sensor, secondary) side. //| This implements the target (peripheral, sensor, secondary) side.
//| //|
//| :param ~microcontroller.Pin scl: The clock pin //| :param ~microcontroller.Pin scl: The clock pin
//| :param ~microcontroller.Pin sda: The data pin //| :param ~microcontroller.Pin sda: The data pin
//| :param addresses: The I2C addresses to respond to (how many is hw dependent). //| :param addresses: The I2C addresses to respond to (how many is hardware dependent).
//| :type addresses: list[int] //| :type addresses: list[int]
//| :param bool smbus: Use SMBUS timings if the hardware supports it""" //| :param bool smbus: Use SMBUS timings if the hardware supports it"""
//| ... //| ...
//| //|
STATIC mp_obj_t i2cperipheral_i2c_peripheral_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { STATIC mp_obj_t i2ctarget_i2c_target_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
i2cperipheral_i2c_peripheral_obj_t *self = m_new_obj(i2cperipheral_i2c_peripheral_obj_t); i2ctarget_i2c_target_obj_t *self = m_new_obj(i2ctarget_i2c_target_obj_t);
self->base.type = &i2cperipheral_i2c_peripheral_type; self->base.type = &i2ctarget_i2c_target_type;
enum { ARG_scl, ARG_sda, ARG_addresses, ARG_smbus }; enum { ARG_scl, ARG_sda, ARG_addresses, ARG_smbus };
static const mp_arg_t allowed_args[] = { static const mp_arg_t allowed_args[] = {
{ MP_QSTR_scl, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_scl, MP_ARG_REQUIRED | MP_ARG_OBJ },
@ -99,7 +99,7 @@ STATIC mp_obj_t i2cperipheral_i2c_peripheral_make_new(const mp_obj_type_t *type,
mp_raise_ValueError(translate("addresses is empty")); mp_raise_ValueError(translate("addresses is empty"));
} }
common_hal_i2cperipheral_i2c_peripheral_construct(self, scl, sda, addresses, i, args[ARG_smbus].u_bool); common_hal_i2ctarget_i2c_target_construct(self, scl, sda, addresses, i, args[ARG_smbus].u_bool);
return (mp_obj_t)self; return (mp_obj_t)self;
} }
@ -107,15 +107,15 @@ STATIC mp_obj_t i2cperipheral_i2c_peripheral_make_new(const mp_obj_type_t *type,
//| """Releases control of the underlying hardware so other classes can use it.""" //| """Releases control of the underlying hardware so other classes can use it."""
//| ... //| ...
//| //|
STATIC mp_obj_t i2cperipheral_i2c_peripheral_obj_deinit(mp_obj_t self_in) { STATIC mp_obj_t i2ctarget_i2c_target_obj_deinit(mp_obj_t self_in) {
mp_check_self(mp_obj_is_type(self_in, &i2cperipheral_i2c_peripheral_type)); mp_check_self(mp_obj_is_type(self_in, &i2ctarget_i2c_target_type));
i2cperipheral_i2c_peripheral_obj_t *self = MP_OBJ_TO_PTR(self_in); i2ctarget_i2c_target_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_i2cperipheral_i2c_peripheral_deinit(self); common_hal_i2ctarget_i2c_target_deinit(self);
return mp_const_none; return mp_const_none;
} }
MP_DEFINE_CONST_FUN_OBJ_1(i2cperipheral_i2c_peripheral_deinit_obj, i2cperipheral_i2c_peripheral_obj_deinit); MP_DEFINE_CONST_FUN_OBJ_1(i2ctarget_i2c_target_deinit_obj, i2ctarget_i2c_target_obj_deinit);
//| def __enter__(self) -> I2CPeripheral: //| def __enter__(self) -> I2CTarget:
//| """No-op used in Context Managers.""" //| """No-op used in Context Managers."""
//| ... //| ...
//| //|
@ -126,25 +126,25 @@ MP_DEFINE_CONST_FUN_OBJ_1(i2cperipheral_i2c_peripheral_deinit_obj, i2cperipheral
//| :ref:`lifetime-and-contextmanagers` for more info.""" //| :ref:`lifetime-and-contextmanagers` for more info."""
//| ... //| ...
//| //|
STATIC mp_obj_t i2cperipheral_i2c_peripheral_obj___exit__(size_t n_args, const mp_obj_t *args) { STATIC mp_obj_t i2ctarget_i2c_target_obj___exit__(size_t n_args, const mp_obj_t *args) {
mp_check_self(mp_obj_is_type(args[0], &i2cperipheral_i2c_peripheral_type)); mp_check_self(mp_obj_is_type(args[0], &i2ctarget_i2c_target_type));
i2cperipheral_i2c_peripheral_obj_t *self = MP_OBJ_TO_PTR(args[0]); i2ctarget_i2c_target_obj_t *self = MP_OBJ_TO_PTR(args[0]);
common_hal_i2cperipheral_i2c_peripheral_deinit(self); common_hal_i2ctarget_i2c_target_deinit(self);
return mp_const_none; return mp_const_none;
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(i2cperipheral_i2c_peripheral___exit___obj, 4, 4, i2cperipheral_i2c_peripheral_obj___exit__); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(i2ctarget_i2c_target___exit___obj, 4, 4, i2ctarget_i2c_target_obj___exit__);
//| def request(self, timeout: float = -1) -> I2CPeripheralRequest: //| def request(self, timeout: float = -1) -> I2CTargetRequest:
//| """Wait for an I2C request. //| """Wait for an I2C request.
//| //|
//| :param float timeout: Timeout in seconds. Zero means wait forever, a negative value means check once //| :param float timeout: Timeout in seconds. Zero means wait forever, a negative value means check once
//| :return: I2C Slave Request or None if timeout=-1 and there's no request //| :return: I2CTargetRequest or None if timeout=-1 and there's no request
//| :rtype: ~i2cperipheral.I2CPeripheralRequest""" //| :rtype: ~i2ctarget.I2CTargetRequest"""
//| //|
STATIC mp_obj_t i2cperipheral_i2c_peripheral_request(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { STATIC mp_obj_t i2ctarget_i2c_target_request(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
mp_check_self(mp_obj_is_type(pos_args[0], &i2cperipheral_i2c_peripheral_type)); mp_check_self(mp_obj_is_type(pos_args[0], &i2ctarget_i2c_target_type));
i2cperipheral_i2c_peripheral_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); i2ctarget_i2c_target_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
if (common_hal_i2cperipheral_i2c_peripheral_deinited(self)) { if (common_hal_i2ctarget_i2c_target_deinited(self)) {
raise_deinited_error(); raise_deinited_error();
} }
enum { ARG_timeout }; enum { ARG_timeout };
@ -181,7 +181,7 @@ STATIC mp_obj_t i2cperipheral_i2c_peripheral_request(size_t n_args, const mp_obj
return mp_const_none; return mp_const_none;
} }
int status = common_hal_i2cperipheral_i2c_peripheral_is_addressed(self, &address, &is_read, &is_restart); int status = common_hal_i2ctarget_i2c_target_is_addressed(self, &address, &is_read, &is_restart);
if (status < 0) { if (status < 0) {
// On error try one more time before bailing out // On error try one more time before bailing out
if (last_error) { if (last_error) {
@ -199,7 +199,7 @@ STATIC mp_obj_t i2cperipheral_i2c_peripheral_request(size_t n_args, const mp_obj
continue; continue;
} }
return mp_obj_new_i2cperipheral_i2c_peripheral_request(self, address, is_read, is_restart); return mp_obj_new_i2ctarget_i2c_target_request(self, address, is_read, is_restart);
} while (forever || common_hal_time_monotonic_ms() < timeout_end); } while (forever || common_hal_time_monotonic_ms() < timeout_end);
if (timeout_ms > 0) { if (timeout_ms > 0) {
@ -207,42 +207,42 @@ STATIC mp_obj_t i2cperipheral_i2c_peripheral_request(size_t n_args, const mp_obj
} }
return mp_const_none; return mp_const_none;
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(i2cperipheral_i2c_peripheral_request_obj, 1, i2cperipheral_i2c_peripheral_request); STATIC MP_DEFINE_CONST_FUN_OBJ_KW(i2ctarget_i2c_target_request_obj, 1, i2ctarget_i2c_target_request);
STATIC const mp_rom_map_elem_t i2cperipheral_i2c_peripheral_locals_dict_table[] = { STATIC const mp_rom_map_elem_t i2ctarget_i2c_target_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_deinit_obj) }, { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&i2ctarget_i2c_target_deinit_obj) },
{ MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) }, { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) },
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&i2cperipheral_i2c_peripheral___exit___obj) }, { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&i2ctarget_i2c_target___exit___obj) },
{ MP_ROM_QSTR(MP_QSTR_request), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_obj) }, { MP_ROM_QSTR(MP_QSTR_request), MP_ROM_PTR(&i2ctarget_i2c_target_request_obj) },
}; };
STATIC MP_DEFINE_CONST_DICT(i2cperipheral_i2c_peripheral_locals_dict, i2cperipheral_i2c_peripheral_locals_dict_table); STATIC MP_DEFINE_CONST_DICT(i2ctarget_i2c_target_locals_dict, i2ctarget_i2c_target_locals_dict_table);
const mp_obj_type_t i2cperipheral_i2c_peripheral_type = { const mp_obj_type_t i2ctarget_i2c_target_type = {
{ &mp_type_type }, { &mp_type_type },
.name = MP_QSTR_I2CPeripheral, .name = MP_QSTR_I2CTarget,
.make_new = i2cperipheral_i2c_peripheral_make_new, .make_new = i2ctarget_i2c_target_make_new,
.locals_dict = (mp_obj_dict_t *)&i2cperipheral_i2c_peripheral_locals_dict, .locals_dict = (mp_obj_dict_t *)&i2ctarget_i2c_target_locals_dict,
}; };
//| class I2CPeripheralRequest: //| class I2CTargetRequest:
//| //|
//| def __init__(self, peripheral: i2cperipheral.I2CPeripheral, address: int, is_read: bool, is_restart: bool) -> None: //| def __init__(self, target: i2ctarget.I2CTarget, address: int, is_read: bool, is_restart: bool) -> None:
//| """Information about an I2C transfer request //| """Information about an I2C transfer request
//| This cannot be instantiated directly, but is returned by :py:meth:`I2CPeripheral.request`. //| This cannot be instantiated directly, but is returned by :py:meth:`I2CTarget.request`.
//| //|
//| :param peripheral: The I2CPeripheral object receiving this request //| :param target: The I2CTarget object receiving this request
//| :param address: I2C address //| :param address: I2C address
//| :param is_read: True if the main peripheral is requesting data //| :param is_read: True if the main target is requesting data
//| :param is_restart: Repeated Start Condition""" //| :param is_restart: Repeated Start Condition"""
//| //|
STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { STATIC mp_obj_t i2ctarget_i2c_target_request_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 4, 4, false); mp_arg_check_num(n_args, n_kw, 4, 4, false);
return mp_obj_new_i2cperipheral_i2c_peripheral_request(args[0], mp_obj_get_int(args[1]), mp_obj_is_true(args[2]), mp_obj_is_true(args[3])); return mp_obj_new_i2ctarget_i2c_target_request(args[0], mp_obj_get_int(args[1]), mp_obj_is_true(args[2]), mp_obj_is_true(args[3]));
} }
//| def __enter__(self) -> I2CPeripheralRequest: //| def __enter__(self) -> I2CTargetRequest:
//| """No-op used in Context Managers.""" //| """No-op used in Context Managers."""
//| ... //| ...
//| //|
@ -252,56 +252,56 @@ STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_make_new(const mp_obj_type_
//| """Close the request.""" //| """Close the request."""
//| ... //| ...
//| //|
STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_obj___exit__(size_t n_args, const mp_obj_t *args) { STATIC mp_obj_t i2ctarget_i2c_target_request_obj___exit__(size_t n_args, const mp_obj_t *args) {
mp_check_self(mp_obj_is_type(args[0], &i2cperipheral_i2c_peripheral_request_type)); mp_check_self(mp_obj_is_type(args[0], &i2ctarget_i2c_target_request_type));
i2cperipheral_i2c_peripheral_request_obj_t *self = MP_OBJ_TO_PTR(args[0]); i2ctarget_i2c_target_request_obj_t *self = MP_OBJ_TO_PTR(args[0]);
common_hal_i2cperipheral_i2c_peripheral_close(self->peripheral); common_hal_i2ctarget_i2c_target_close(self->target);
return mp_const_none; return mp_const_none;
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(i2cperipheral_i2c_peripheral_request___exit___obj, 4, 4, i2cperipheral_i2c_peripheral_request_obj___exit__); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(i2ctarget_i2c_target_request___exit___obj, 4, 4, i2ctarget_i2c_target_request_obj___exit__);
//| address: int //| address: int
//| """The I2C address of the request.""" //| """The I2C address of the request."""
//| //|
STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_get_address(mp_obj_t self_in) { STATIC mp_obj_t i2ctarget_i2c_target_request_get_address(mp_obj_t self_in) {
mp_check_self(mp_obj_is_type(self_in, &i2cperipheral_i2c_peripheral_request_type)); mp_check_self(mp_obj_is_type(self_in, &i2ctarget_i2c_target_request_type));
i2cperipheral_i2c_peripheral_request_obj_t *self = MP_OBJ_TO_PTR(self_in); i2ctarget_i2c_target_request_obj_t *self = MP_OBJ_TO_PTR(self_in);
return mp_obj_new_int(self->address); return mp_obj_new_int(self->address);
} }
MP_DEFINE_CONST_PROP_GET(i2cperipheral_i2c_peripheral_request_address_obj, i2cperipheral_i2c_peripheral_request_get_address); MP_DEFINE_CONST_PROP_GET(i2ctarget_i2c_target_request_address_obj, i2ctarget_i2c_target_request_get_address);
//| is_read: bool //| is_read: bool
//| """The I2C main controller is reading from this peripheral.""" //| """The I2C main controller is reading from this target."""
//| //|
STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_get_is_read(mp_obj_t self_in) { STATIC mp_obj_t i2ctarget_i2c_target_request_get_is_read(mp_obj_t self_in) {
mp_check_self(mp_obj_is_type(self_in, &i2cperipheral_i2c_peripheral_request_type)); mp_check_self(mp_obj_is_type(self_in, &i2ctarget_i2c_target_request_type));
i2cperipheral_i2c_peripheral_request_obj_t *self = MP_OBJ_TO_PTR(self_in); i2ctarget_i2c_target_request_obj_t *self = MP_OBJ_TO_PTR(self_in);
return mp_obj_new_bool(self->is_read); return mp_obj_new_bool(self->is_read);
} }
MP_DEFINE_CONST_PROP_GET(i2cperipheral_i2c_peripheral_request_is_read_obj, i2cperipheral_i2c_peripheral_request_get_is_read); MP_DEFINE_CONST_PROP_GET(i2ctarget_i2c_target_request_is_read_obj, i2ctarget_i2c_target_request_get_is_read);
//| is_restart: bool //| is_restart: bool
//| """Is Repeated Start Condition.""" //| """Is Repeated Start Condition."""
//| //|
STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_get_is_restart(mp_obj_t self_in) { STATIC mp_obj_t i2ctarget_i2c_target_request_get_is_restart(mp_obj_t self_in) {
mp_check_self(mp_obj_is_type(self_in, &i2cperipheral_i2c_peripheral_request_type)); mp_check_self(mp_obj_is_type(self_in, &i2ctarget_i2c_target_request_type));
i2cperipheral_i2c_peripheral_request_obj_t *self = MP_OBJ_TO_PTR(self_in); i2ctarget_i2c_target_request_obj_t *self = MP_OBJ_TO_PTR(self_in);
return mp_obj_new_bool(self->is_restart); return mp_obj_new_bool(self->is_restart);
} }
MP_DEFINE_CONST_PROP_GET(i2cperipheral_i2c_peripheral_request_is_restart_obj, i2cperipheral_i2c_peripheral_request_get_is_restart); MP_DEFINE_CONST_PROP_GET(i2ctarget_i2c_target_request_is_restart_obj, i2ctarget_i2c_target_request_get_is_restart);
//| def read(self, n: int = -1, ack: bool = True) -> bytearray: //| def read(self, n: int = -1, ack: bool = True) -> bytearray:
//| """Read data. //| """Read data.
//| If ack=False, the caller is responsible for calling :py:meth:`I2CPeripheralRequest.ack`. //| If ack=False, the caller is responsible for calling :py:meth:`I2CTargetRequest.ack`.
//| //|
//| :param n: Number of bytes to read (negative means all) //| :param n: Number of bytes to read (negative means all)
//| :param ack: Whether or not to send an ACK after the n'th byte //| :param ack: Whether or not to send an ACK after the n'th byte
//| :return: Bytes read""" //| :return: Bytes read"""
//| ... //| ...
//| //|
STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_read(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { STATIC mp_obj_t i2ctarget_i2c_target_request_read(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
mp_check_self(mp_obj_is_type(pos_args[0], &i2cperipheral_i2c_peripheral_request_type)); mp_check_self(mp_obj_is_type(pos_args[0], &i2ctarget_i2c_target_request_type));
i2cperipheral_i2c_peripheral_request_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); i2ctarget_i2c_target_request_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
enum { ARG_n, ARG_ack }; enum { ARG_n, ARG_ack };
static const mp_arg_t allowed_args[] = { static const mp_arg_t allowed_args[] = {
{ MP_QSTR_n, MP_ARG_INT, {.u_int = -1} }, { MP_QSTR_n, MP_ARG_INT, {.u_int = -1} },
@ -330,7 +330,7 @@ STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_read(size_t n_args, const m
} }
uint8_t data; uint8_t data;
int num = common_hal_i2cperipheral_i2c_peripheral_read_byte(self->peripheral, &data); int num = common_hal_i2ctarget_i2c_target_read_byte(self->target, &data);
if (num == 0) { if (num == 0) {
break; break;
} }
@ -339,16 +339,16 @@ STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_read(size_t n_args, const m
buffer[i++] = data; buffer[i++] = data;
if (i == n) { if (i == n) {
if (ack) { if (ack) {
common_hal_i2cperipheral_i2c_peripheral_ack(self->peripheral, true); common_hal_i2ctarget_i2c_target_ack(self->target, true);
} }
break; break;
} }
common_hal_i2cperipheral_i2c_peripheral_ack(self->peripheral, true); common_hal_i2ctarget_i2c_target_ack(self->target, true);
} }
return mp_obj_new_bytearray(i, buffer); return mp_obj_new_bytearray(i, buffer);
} }
MP_DEFINE_CONST_FUN_OBJ_KW(i2cperipheral_i2c_peripheral_request_read_obj, 1, i2cperipheral_i2c_peripheral_request_read); MP_DEFINE_CONST_FUN_OBJ_KW(i2ctarget_i2c_target_request_read_obj, 1, i2ctarget_i2c_target_request_read);
//| def write(self, buffer: ReadableBuffer) -> int: //| def write(self, buffer: ReadableBuffer) -> int:
//| """Write the data contained in buffer. //| """Write the data contained in buffer.
@ -357,9 +357,9 @@ MP_DEFINE_CONST_FUN_OBJ_KW(i2cperipheral_i2c_peripheral_request_read_obj, 1, i2c
//| :return: Number of bytes written""" //| :return: Number of bytes written"""
//| ... //| ...
//| //|
STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_write(mp_obj_t self_in, mp_obj_t buf_in) { STATIC mp_obj_t i2ctarget_i2c_target_request_write(mp_obj_t self_in, mp_obj_t buf_in) {
mp_check_self(mp_obj_is_type(self_in, &i2cperipheral_i2c_peripheral_request_type)); mp_check_self(mp_obj_is_type(self_in, &i2ctarget_i2c_target_request_type));
i2cperipheral_i2c_peripheral_request_obj_t *self = MP_OBJ_TO_PTR(self_in); i2ctarget_i2c_target_request_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (!self->is_read) { if (!self->is_read) {
mp_raise_OSError(MP_EACCES); mp_raise_OSError(MP_EACCES);
@ -374,7 +374,7 @@ STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_write(mp_obj_t self_in, mp_
break; break;
} }
int num = common_hal_i2cperipheral_i2c_peripheral_write_byte(self->peripheral, ((uint8_t *)(bufinfo.buf))[i]); int num = common_hal_i2ctarget_i2c_target_write_byte(self->target, ((uint8_t *)(bufinfo.buf))[i]);
if (num == 0) { if (num == 0) {
return mp_obj_new_int(i); return mp_obj_new_int(i);
} }
@ -382,55 +382,55 @@ STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_write(mp_obj_t self_in, mp_
return mp_obj_new_int(bufinfo.len); return mp_obj_new_int(bufinfo.len);
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_2(i2cperipheral_i2c_peripheral_request_write_obj, i2cperipheral_i2c_peripheral_request_write); STATIC MP_DEFINE_CONST_FUN_OBJ_2(i2ctarget_i2c_target_request_write_obj, i2ctarget_i2c_target_request_write);
//| def ack(self, ack: bool = True) -> None: //| def ack(self, ack: bool = True) -> None:
//| """Acknowledge or Not Acknowledge last byte received. //| """Acknowledge or Not Acknowledge last byte received.
//| Use together with :py:meth:`I2CPeripheralRequest.read` ack=False. //| Use together with :py:meth:`I2CTargetRequest.read` ack=False.
//| //|
//| :param ack: Whether to send an ACK or NACK""" //| :param ack: Whether to send an ACK or NACK"""
//| ... //| ...
//| //|
STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_ack(uint n_args, const mp_obj_t *args) { STATIC mp_obj_t i2ctarget_i2c_target_request_ack(uint n_args, const mp_obj_t *args) {
mp_check_self(mp_obj_is_type(args[0], &i2cperipheral_i2c_peripheral_request_type)); mp_check_self(mp_obj_is_type(args[0], &i2ctarget_i2c_target_request_type));
i2cperipheral_i2c_peripheral_request_obj_t *self = MP_OBJ_TO_PTR(args[0]); i2ctarget_i2c_target_request_obj_t *self = MP_OBJ_TO_PTR(args[0]);
bool ack = (n_args == 1) ? true : mp_obj_is_true(args[1]); bool ack = (n_args == 1) ? true : mp_obj_is_true(args[1]);
if (self->is_read) { if (self->is_read) {
mp_raise_OSError(MP_EACCES); mp_raise_OSError(MP_EACCES);
} }
common_hal_i2cperipheral_i2c_peripheral_ack(self->peripheral, ack); common_hal_i2ctarget_i2c_target_ack(self->target, ack);
return mp_const_none; return mp_const_none;
} }
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(i2cperipheral_i2c_peripheral_request_ack_obj, 1, 2, i2cperipheral_i2c_peripheral_request_ack); MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(i2ctarget_i2c_target_request_ack_obj, 1, 2, i2ctarget_i2c_target_request_ack);
STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_close(mp_obj_t self_in) { STATIC mp_obj_t i2ctarget_i2c_target_request_close(mp_obj_t self_in) {
mp_check_self(mp_obj_is_type(self_in, &i2cperipheral_i2c_peripheral_request_type)); mp_check_self(mp_obj_is_type(self_in, &i2ctarget_i2c_target_request_type));
i2cperipheral_i2c_peripheral_request_obj_t *self = MP_OBJ_TO_PTR(self_in); i2ctarget_i2c_target_request_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_i2cperipheral_i2c_peripheral_close(self->peripheral); common_hal_i2ctarget_i2c_target_close(self->target);
return mp_const_none; return mp_const_none;
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_1(i2cperipheral_i2c_peripheral_request_close_obj, i2cperipheral_i2c_peripheral_request_close); STATIC MP_DEFINE_CONST_FUN_OBJ_1(i2ctarget_i2c_target_request_close_obj, i2ctarget_i2c_target_request_close);
STATIC const mp_rom_map_elem_t i2cperipheral_i2c_peripheral_request_locals_dict_table[] = { STATIC const mp_rom_map_elem_t i2ctarget_i2c_target_request_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) }, { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) },
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request___exit___obj) }, { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&i2ctarget_i2c_target_request___exit___obj) },
{ MP_ROM_QSTR(MP_QSTR_address), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_address_obj) }, { MP_ROM_QSTR(MP_QSTR_address), MP_ROM_PTR(&i2ctarget_i2c_target_request_address_obj) },
{ MP_ROM_QSTR(MP_QSTR_is_read), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_is_read_obj) }, { MP_ROM_QSTR(MP_QSTR_is_read), MP_ROM_PTR(&i2ctarget_i2c_target_request_is_read_obj) },
{ MP_ROM_QSTR(MP_QSTR_is_restart), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_is_restart_obj) }, { MP_ROM_QSTR(MP_QSTR_is_restart), MP_ROM_PTR(&i2ctarget_i2c_target_request_is_restart_obj) },
{ MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_read_obj) }, { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&i2ctarget_i2c_target_request_read_obj) },
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_write_obj) }, { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&i2ctarget_i2c_target_request_write_obj) },
{ MP_ROM_QSTR(MP_QSTR_ack), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_ack_obj) }, { MP_ROM_QSTR(MP_QSTR_ack), MP_ROM_PTR(&i2ctarget_i2c_target_request_ack_obj) },
{ MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_close_obj) }, { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&i2ctarget_i2c_target_request_close_obj) },
}; };
STATIC MP_DEFINE_CONST_DICT(i2cperipheral_i2c_peripheral_request_locals_dict, i2cperipheral_i2c_peripheral_request_locals_dict_table); STATIC MP_DEFINE_CONST_DICT(i2ctarget_i2c_target_request_locals_dict, i2ctarget_i2c_target_request_locals_dict_table);
const mp_obj_type_t i2cperipheral_i2c_peripheral_request_type = { const mp_obj_type_t i2ctarget_i2c_target_request_type = {
{ &mp_type_type }, { &mp_type_type },
.name = MP_QSTR_I2CPeripheralRequest, .name = MP_QSTR_I2CTargetRequest,
.make_new = i2cperipheral_i2c_peripheral_request_make_new, .make_new = i2ctarget_i2c_target_request_make_new,
.locals_dict = (mp_obj_dict_t *)&i2cperipheral_i2c_peripheral_request_locals_dict, .locals_dict = (mp_obj_dict_t *)&i2ctarget_i2c_target_request_locals_dict,
}; };

View File

@ -24,37 +24,37 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_BUSIO_I2C_SLAVE_H #ifndef MICROPY_INCLUDED_SHARED_BINDINGS_BUSIO_I2C_TARGET_H
#define MICROPY_INCLUDED_SHARED_BINDINGS_BUSIO_I2C_SLAVE_H #define MICROPY_INCLUDED_SHARED_BINDINGS_BUSIO_I2C_TARGET_H
#include "py/obj.h" #include "py/obj.h"
#include "common-hal/microcontroller/Pin.h" #include "common-hal/microcontroller/Pin.h"
#include "common-hal/i2cperipheral/I2CPeripheral.h" #include "common-hal/i2ctarget/I2CTarget.h"
typedef struct { typedef struct {
mp_obj_base_t base; mp_obj_base_t base;
i2cperipheral_i2c_peripheral_obj_t *peripheral; i2ctarget_i2c_target_obj_t *target;
uint16_t address; uint16_t address;
bool is_read; bool is_read;
bool is_restart; bool is_restart;
} i2cperipheral_i2c_peripheral_request_obj_t; } i2ctarget_i2c_target_request_obj_t;
extern const mp_obj_type_t i2cperipheral_i2c_peripheral_request_type; extern const mp_obj_type_t i2ctarget_i2c_target_request_type;
extern const mp_obj_type_t i2cperipheral_i2c_peripheral_type; extern const mp_obj_type_t i2ctarget_i2c_target_type;
extern void common_hal_i2cperipheral_i2c_peripheral_construct(i2cperipheral_i2c_peripheral_obj_t *self, extern void common_hal_i2ctarget_i2c_target_construct(i2ctarget_i2c_target_obj_t *self,
const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda, const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda,
uint8_t *addresses, unsigned int num_addresses, bool smbus); uint8_t *addresses, unsigned int num_addresses, bool smbus);
extern void common_hal_i2cperipheral_i2c_peripheral_deinit(i2cperipheral_i2c_peripheral_obj_t *self); extern void common_hal_i2ctarget_i2c_target_deinit(i2ctarget_i2c_target_obj_t *self);
extern bool common_hal_i2cperipheral_i2c_peripheral_deinited(i2cperipheral_i2c_peripheral_obj_t *self); extern bool common_hal_i2ctarget_i2c_target_deinited(i2ctarget_i2c_target_obj_t *self);
extern int common_hal_i2cperipheral_i2c_peripheral_is_addressed(i2cperipheral_i2c_peripheral_obj_t *self, extern int common_hal_i2ctarget_i2c_target_is_addressed(i2ctarget_i2c_target_obj_t *self,
uint8_t *address, bool *is_read, bool *is_restart); uint8_t *address, bool *is_read, bool *is_restart);
extern int common_hal_i2cperipheral_i2c_peripheral_read_byte(i2cperipheral_i2c_peripheral_obj_t *self, uint8_t *data); extern int common_hal_i2ctarget_i2c_target_read_byte(i2ctarget_i2c_target_obj_t *self, uint8_t *data);
extern int common_hal_i2cperipheral_i2c_peripheral_write_byte(i2cperipheral_i2c_peripheral_obj_t *self, uint8_t data); extern int common_hal_i2ctarget_i2c_target_write_byte(i2ctarget_i2c_target_obj_t *self, uint8_t data);
extern void common_hal_i2cperipheral_i2c_peripheral_ack(i2cperipheral_i2c_peripheral_obj_t *self, bool ack); extern void common_hal_i2ctarget_i2c_target_ack(i2ctarget_i2c_target_obj_t *self, bool ack);
extern void common_hal_i2cperipheral_i2c_peripheral_close(i2cperipheral_i2c_peripheral_obj_t *self); extern void common_hal_i2ctarget_i2c_target_close(i2ctarget_i2c_target_obj_t *self);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BUSIO_I2C_SLAVE_H #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BUSIO_I2C_TARGET_H

View File

@ -30,24 +30,24 @@
#include "py/runtime.h" #include "py/runtime.h"
#include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/microcontroller/Pin.h"
// #include "shared-bindings/i2cperipheral/__init__.h" // #include "shared-bindings/i2ctarget/__init__.h"
#include "shared-bindings/i2cperipheral/I2CPeripheral.h" #include "shared-bindings/i2ctarget/I2CTarget.h"
#include "py/runtime.h" #include "py/runtime.h"
//| """Two wire serial protocol peripheral //| """Two wire serial protocol target
//| //|
//| The `i2cperipheral` module contains classes to support an I2C peripheral. //| The `i2ctarget` module contains classes to support an I2C target.
//| //|
//| Example emulating a peripheral with 2 addresses (read and write):: //| Example emulating a target with 2 addresses (read and write)::
//| //|
//| import board //| import board
//| from i2cperipheral import I2CPeripheral //| from i2ctarget import I2CTarget
//| //|
//| regs = [0] * 16 //| regs = [0] * 16
//| index = 0 //| index = 0
//| //|
//| with I2CPeripheral(board.SCL, board.SDA, (0x40, 0x41)) as device: //| with I2CTarget(board.SCL, board.SDA, (0x40, 0x41)) as device:
//| while True: //| while True:
//| r = device.request() //| r = device.request()
//| if not r: //| if not r:
@ -84,7 +84,7 @@
//| 0xaa //| 0xaa
//| //|
//| .. warning:: //| .. warning::
//| I2CPeripheral makes use of clock stretching in order to slow down //| I2CTarget makes use of clock stretching in order to slow down
//| the host. //| the host.
//| Make sure the I2C host supports this. //| Make sure the I2C host supports this.
//| //|
@ -93,16 +93,21 @@
//| Since the RPi firmware uses the hw i2c, it's not possible to emulate a HAT eeprom.""" //| Since the RPi firmware uses the hw i2c, it's not possible to emulate a HAT eeprom."""
//| //|
STATIC const mp_rom_map_elem_t i2cperipheral_module_globals_table[] = { STATIC const mp_rom_map_elem_t i2ctarget_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_i2cperipheral) }, { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_i2ctarget) },
{ MP_ROM_QSTR(MP_QSTR_I2CPeripheral), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_type) }, { MP_ROM_QSTR(MP_QSTR_I2CTarget), MP_ROM_PTR(&i2ctarget_i2c_target_type) },
// TODO: Remove for CircuitPython 9.0.0
{ MP_ROM_QSTR(MP_QSTR_I2CPeripheral), MP_ROM_PTR(&i2ctarget_i2c_target_type) },
}; };
STATIC MP_DEFINE_CONST_DICT(i2cperipheral_module_globals, i2cperipheral_module_globals_table); STATIC MP_DEFINE_CONST_DICT(i2ctarget_module_globals, i2ctarget_module_globals_table);
const mp_obj_module_t i2cperipheral_module = { const mp_obj_module_t i2ctarget_module = {
.base = { &mp_type_module }, .base = { &mp_type_module },
.globals = (mp_obj_dict_t *)&i2cperipheral_module_globals, .globals = (mp_obj_dict_t *)&i2ctarget_module_globals,
}; };
MP_REGISTER_MODULE(MP_QSTR_i2cperipheral, i2cperipheral_module, CIRCUITPY_I2CPERIPHERAL); MP_REGISTER_MODULE(MP_QSTR_i2ctarget, i2ctarget_module, CIRCUITPY_I2CTARGET);
// TODO: Remove for CircuitPython 9.0.0
MP_REGISTER_MODULE(MP_QSTR_i2cperipheral, i2ctarget_module, CIRCUITPY_I2CTARGET);