I2CPeripheral: Rename class and its module

This is an incompatible change.
This commit is contained in:
Jeff Epler 2020-06-23 08:45:15 -05:00 committed by Jeff Epler
parent 9737dd9c30
commit 1d2cc0b968
39 changed files with 203 additions and 203 deletions

View File

@ -64,7 +64,7 @@ as a natural "TODO" list. An example minimal build list is shown below:
CIRCUITPY_ROTARYIO = 0 CIRCUITPY_ROTARYIO = 0
CIRCUITPY_RTC = 0 CIRCUITPY_RTC = 0
CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CSLAVE = 0 CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_DISPLAYIO = 0 # Requires SPI, PulseIO (stub ok) CIRCUITPY_DISPLAYIO = 0 # Requires SPI, PulseIO (stub ok)
# These modules are implemented in shared-module/ - they can be included in # These modules are implemented in shared-module/ - they can be included in

View File

@ -32,8 +32,8 @@ shared-bindings/pulseio/PWMOut.rst shared-bindings/pulseio/#pulseio.PWMOut
shared-bindings/pulseio/PulseIn.rst shared-bindings/pulseio/#pulseio.PulseIn shared-bindings/pulseio/PulseIn.rst shared-bindings/pulseio/#pulseio.PulseIn
shared-bindings/pulseio/PulseOut.rst shared-bindings/pulseio/#pulseio.PulseOut shared-bindings/pulseio/PulseOut.rst shared-bindings/pulseio/#pulseio.PulseOut
shared-bindings/time/struct_time.rst shared-bindings/time/#time.struct_time shared-bindings/time/struct_time.rst shared-bindings/time/#time.struct_time
shared-bindings/i2cslave/I2CSlave.rst shared-bindings/i2cslave/#i2cslave.I2CSlave shared-bindings/i2cslave/I2CSlave.rst shared-bindings/i2cperipheral/#i2cperipheral.I2CPeripheral
shared-bindings/i2cslave/I2CSlaveRequest.rst shared-bindings/i2cslave/#i2cslave.I2CSlaveRequest shared-bindings/i2cslave/I2CSlaveRequest.rst shared-bindings/i2cperipheral/#i2cperipheral.I2CPeripheralRequest
shared-bindings/nvm/ByteArray.rst shared-bindings/nvm/#nvm.ByteArray shared-bindings/nvm/ByteArray.rst shared-bindings/nvm/#nvm.ByteArray
shared-bindings/busio/I2C.rst shared-bindings/busio/#busio.I2C shared-bindings/busio/I2C.rst shared-bindings/busio/#busio.I2C
shared-bindings/busio/OneWire.rst shared-bindings/busio/#busio.OneWire shared-bindings/busio/OneWire.rst shared-bindings/busio/#busio.OneWire

View File

@ -12,7 +12,7 @@ EXTERNAL_FLASH_DEVICES = "MX25L51245G"
LONGINT_IMPL = MPZ LONGINT_IMPL = MPZ
CIRCUITPY_BITBANGIO = 0 CIRCUITPY_BITBANGIO = 0
CIRCUITPY_I2CSLAVE = 0 CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_VECTORIO = 0 CIRCUITPY_VECTORIO = 0
CFLAGS_INLINE_LIMIT = 60 CFLAGS_INLINE_LIMIT = 60

View File

@ -13,5 +13,5 @@ LONGINT_IMPL = MPZ
CIRCUITPY_BITBANGIO = 0 CIRCUITPY_BITBANGIO = 0
CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CSLAVE = 0 CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_VECTORIO = 0 CIRCUITPY_VECTORIO = 0

View File

@ -14,7 +14,7 @@ LONGINT_IMPL = MPZ
# Make room for frozen libs. # Make room for frozen libs.
CIRCUITPY_DISPLAYIO = 0 CIRCUITPY_DISPLAYIO = 0
CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CSLAVE = 0 CIRCUITPY_I2CPERIPHERAL = 0
SUPEROPT_GC = 0 SUPEROPT_GC = 0
CFLAGS_INLINE_LIMIT = 55 CFLAGS_INLINE_LIMIT = 55

View File

@ -15,7 +15,7 @@ LONGINT_IMPL = NONE
CIRCUITPY_BITBANGIO = 0 CIRCUITPY_BITBANGIO = 0
CIRCUITPY_DISPLAYIO = 0 CIRCUITPY_DISPLAYIO = 0
CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CSLAVE = 0 CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_PIXELBUF = 1 CIRCUITPY_PIXELBUF = 1
CIRCUITPY_ROTARYIO = 0 CIRCUITPY_ROTARYIO = 0
CIRCUITPY_RTC = 0 CIRCUITPY_RTC = 0

View File

@ -14,7 +14,7 @@ EXTERNAL_FLASH_DEVICES = "S25FL216K, GD25Q16C"
LONGINT_IMPL = NONE LONGINT_IMPL = NONE
CIRCUITPY_BITBANGIO = 0 CIRCUITPY_BITBANGIO = 0
CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CSLAVE = 0 CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_PIXELBUF = 0 CIRCUITPY_PIXELBUF = 0
CIRCUITPY_RTC = 0 CIRCUITPY_RTC = 0
# So not all of displayio, sorry! # So not all of displayio, sorry!

View File

@ -13,7 +13,7 @@ LONGINT_IMPL = MPZ
CIRCUITPY_BITBANGIO = 0 CIRCUITPY_BITBANGIO = 0
CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CSLAVE = 0 CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_VECTORIO = 0 CIRCUITPY_VECTORIO = 0
CFLAGS_INLINE_LIMIT = 60 CFLAGS_INLINE_LIMIT = 60

View File

@ -15,7 +15,7 @@ LONGINT_IMPL = MPZ
CIRCUITPY_BITBANGIO = 0 CIRCUITPY_BITBANGIO = 0
CIRCUITPY_DISPLAYIO = 0 CIRCUITPY_DISPLAYIO = 0
CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CSLAVE = 0 CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_GAMEPAD = 0 CIRCUITPY_GAMEPAD = 0
CFLAGS_INLINE_LIMIT = 50 CFLAGS_INLINE_LIMIT = 50

View File

@ -13,7 +13,7 @@ LONGINT_IMPL = MPZ
CIRCUITPY_BITBANGIO = 0 CIRCUITPY_BITBANGIO = 0
CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CSLAVE = 0 CIRCUITPY_I2CPERIPHERAL = 0
# supersized, not ultra-supersized # supersized, not ultra-supersized
CIRCUITPY_VECTORIO = 0 CIRCUITPY_VECTORIO = 0

View File

@ -16,7 +16,7 @@ CIRCUITPY_AUDIOBUSIO = 0
CIRCUITPY_BITBANGIO = 0 CIRCUITPY_BITBANGIO = 0
CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_GAMEPAD = 0 CIRCUITPY_GAMEPAD = 0
CIRCUITPY_I2CSLAVE = 0 CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_ROTARYIO = 0 CIRCUITPY_ROTARYIO = 0
CIRCUITPY_RTC = 0 CIRCUITPY_RTC = 0
CIRCUITPY_COUNTIO = 0 CIRCUITPY_COUNTIO = 0

View File

@ -15,7 +15,7 @@ CIRCUITPY_BITBANG_APA102 = 1
CIRCUITPY_BITBANGIO = 0 CIRCUITPY_BITBANGIO = 0
CIRCUITPY_GAMEPAD = 0 CIRCUITPY_GAMEPAD = 0
CIRCUITPY_I2CSLAVE = 0 CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_RTC = 0 CIRCUITPY_RTC = 0
# too itsy bitsy for all of displayio # too itsy bitsy for all of displayio
CIRCUITPY_VECTORIO = 0 CIRCUITPY_VECTORIO = 0

View File

@ -12,7 +12,7 @@ EXTERNAL_FLASH_DEVICES = "S25FL216K, GD25Q16C"
LONGINT_IMPL = MPZ LONGINT_IMPL = MPZ
CIRCUITPY_BITBANGIO = 0 CIRCUITPY_BITBANGIO = 0
CIRCUITPY_I2CSLAVE = 0 CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_VECTORIO = 0 CIRCUITPY_VECTORIO = 0
CFLAGS_INLINE_LIMIT = 60 CFLAGS_INLINE_LIMIT = 60

View File

@ -16,7 +16,7 @@ CIRCUITPY_ANALOGIO = 0
CIRCUITPY_AUDIOBUSIO = 0 CIRCUITPY_AUDIOBUSIO = 0
CIRCUITPY_BITBANGIO = 0 CIRCUITPY_BITBANGIO = 0
CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CSLAVE = 0 CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_NEOPIXEL_WRITE = 0 CIRCUITPY_NEOPIXEL_WRITE = 0
CIRCUITPY_NETWORK = 0 CIRCUITPY_NETWORK = 0
CIRCUITPY_PIXELBUF = 0 CIRCUITPY_PIXELBUF = 0

View File

@ -9,7 +9,7 @@ CHIP_FAMILY = samd21
INTERNAL_FLASH_FILESYSTEM = 1 INTERNAL_FLASH_FILESYSTEM = 1
LONGINT_IMPL = NONE LONGINT_IMPL = NONE
CIRCUITPY_FULL_BUILD = 0 CIRCUITPY_FULL_BUILD = 0
CIRCUITPY_I2CSLAVE = 1 CIRCUITPY_I2CPERIPHERAL = 1
CIRCUITPY_TOUCHIO = 0 CIRCUITPY_TOUCHIO = 0
SUPEROPT_GC = 0 SUPEROPT_GC = 0

View File

@ -13,7 +13,7 @@ LONGINT_IMPL = MPZ
CIRCUITPY_BITBANGIO = 0 CIRCUITPY_BITBANGIO = 0
CIRCUITPY_GAMEPAD = 0 CIRCUITPY_GAMEPAD = 0
CIRCUITPY_I2CSLAVE = 0 CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_VECTORIO = 0 CIRCUITPY_VECTORIO = 0
CFLAGS_INLINE_LIMIT = 60 CFLAGS_INLINE_LIMIT = 60

View File

@ -12,7 +12,7 @@ EXTERNAL_FLASH_DEVICES = "W25Q32FV"
LONGINT_IMPL = MPZ LONGINT_IMPL = MPZ
CIRCUITPY_BITBANGIO = 0 CIRCUITPY_BITBANGIO = 0
CIRCUITPY_I2CSLAVE = 0 CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_VECTORIO = 0 CIRCUITPY_VECTORIO = 0
CFLAGS_INLINE_LIMIT = 60 CFLAGS_INLINE_LIMIT = 60

View File

@ -16,7 +16,7 @@ CIRCUITPY_BITBANG_APA102 = 1
CIRCUITPY_BITBANGIO = 0 CIRCUITPY_BITBANGIO = 0
CIRCUITPY_GAMEPAD = 0 CIRCUITPY_GAMEPAD = 0
CIRCUITPY_I2CSLAVE = 0 CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_RTC = 0 CIRCUITPY_RTC = 0
CIRCUITPY_VECTORIO = 0 CIRCUITPY_VECTORIO = 0

View File

@ -15,6 +15,6 @@ CIRCUITPY_BITBANGIO = 0
CIRCUITPY_COUNTIO = 0 CIRCUITPY_COUNTIO = 0
CIRCUITPY_RTC = 0 CIRCUITPY_RTC = 0
CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CSLAVE = 0 CIRCUITPY_I2CPERIPHERAL = 0
SUPEROPT_GC = 0 SUPEROPT_GC = 0

View File

@ -21,7 +21,7 @@ CIRCUITPY_DISPLAYIO = 1
CIRCUITPY_AUDIOBUSIO = 0 CIRCUITPY_AUDIOBUSIO = 0
CIRCUITPY_BITBANGIO = 0 CIRCUITPY_BITBANGIO = 0
CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CSLAVE = 0 CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_NEOPIXEL_WRITE = 0 CIRCUITPY_NEOPIXEL_WRITE = 0
CIRCUITPY_PIXELBUF = 0 CIRCUITPY_PIXELBUF = 0
CIRCUITPY_RTC = 0 CIRCUITPY_RTC = 0

View File

@ -19,12 +19,11 @@ CIRCUITPY_AUDIOIO = 1
CIRCUITPY_BITBANGIO = 0 CIRCUITPY_BITBANGIO = 0
CIRCUITPY_FRAMEBUFFERIO = 0 CIRCUITPY_FRAMEBUFFERIO = 0
CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CSLAVE = 0
CIRCUITPY_AUDIOBUSIO = 0 CIRCUITPY_AUDIOBUSIO = 0
CIRCUITPY_BLEIO = 0 CIRCUITPY_BLEIO = 0
CIRCUITPY_DISPLAYIO = 0 CIRCUITPY_DISPLAYIO = 0
CIRCUITPY_GAMEPAD = 0 CIRCUITPY_GAMEPAD = 0
CIRCUITPY_I2CSLAVE = 0 CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_NETWORK = 0 CIRCUITPY_NETWORK = 0
CIRCUITPY_TOUCHIO = 0 CIRCUITPY_TOUCHIO = 0
CIRCUITPY_RGBMATRIX = 0 CIRCUITPY_RGBMATRIX = 0

View File

@ -22,7 +22,7 @@ CIRCUITPY_BLEIO = 0
CIRCUITPY_DISPLAYIO = 0 CIRCUITPY_DISPLAYIO = 0
CIRCUITPY_FRAMEBUFFERIO = 0 CIRCUITPY_FRAMEBUFFERIO = 0
CIRCUITPY_GAMEPAD = 0 CIRCUITPY_GAMEPAD = 0
CIRCUITPY_I2CSLAVE = 0 CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_NETWORK = 0 CIRCUITPY_NETWORK = 0
CIRCUITPY_TOUCHIO = 0 CIRCUITPY_TOUCHIO = 0
CIRCUITPY_RGBMATRIX = 0 CIRCUITPY_RGBMATRIX = 0

View File

@ -24,7 +24,7 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#include "shared-bindings/i2cslave/I2CSlave.h" #include "shared-bindings/i2cperipheral/I2CPeripheral.h"
#include "common-hal/busio/I2C.h" #include "common-hal/busio/I2C.h"
#include "lib/utils/interrupt_char.h" #include "lib/utils/interrupt_char.h"
@ -35,7 +35,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_i2cslave_i2c_slave_construct(i2cslave_i2c_slave_obj_t *self, void common_hal_i2cperipheral_i2c_peripheral_construct(i2cperipheral_i2c_peripheral_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;
@ -87,19 +87,19 @@ void common_hal_i2cslave_i2c_slave_construct(i2cslave_i2c_slave_obj_t *self,
if (smbus) { if (smbus) {
sercom->I2CS.CTRLA.bit.LOWTOUTEN = 1; // Errata 12003 sercom->I2CS.CTRLA.bit.LOWTOUTEN = 1; // Errata 12003
sercom->I2CS.CTRLA.bit.SEXTTOEN = 1; // Slave SCL Low Extend/Cumulative Time-Out 25ms sercom->I2CS.CTRLA.bit.SEXTTOEN = 1; // SCL Low Extend/Cumulative Time-Out 25ms
} }
sercom->I2CS.CTRLA.bit.SCLSM = 0; // Clock stretch before ack sercom->I2CS.CTRLA.bit.SCLSM = 0; // Clock stretch before ack
sercom->I2CS.CTRLA.bit.MODE = 0x04; // Slave mode sercom->I2CS.CTRLA.bit.MODE = 0x04; // Device mode
sercom->I2CS.CTRLA.bit.ENABLE = 1; sercom->I2CS.CTRLA.bit.ENABLE = 1;
} }
bool common_hal_i2cslave_i2c_slave_deinited(i2cslave_i2c_slave_obj_t *self) { bool common_hal_i2cperipheral_i2c_peripheral_deinited(i2cperipheral_i2c_peripheral_obj_t *self) {
return self->sda_pin == NO_PIN; return self->sda_pin == NO_PIN;
} }
void common_hal_i2cslave_i2c_slave_deinit(i2cslave_i2c_slave_obj_t *self) { void common_hal_i2cperipheral_i2c_peripheral_deinit(i2cperipheral_i2c_peripheral_obj_t *self) {
if (common_hal_i2cslave_i2c_slave_deinited(self)) { if (common_hal_i2cperipheral_i2c_peripheral_deinited(self)) {
return; return;
} }
@ -111,7 +111,7 @@ void common_hal_i2cslave_i2c_slave_deinit(i2cslave_i2c_slave_obj_t *self) {
self->scl_pin = NO_PIN; self->scl_pin = NO_PIN;
} }
static int i2c_slave_check_error(i2cslave_i2c_slave_obj_t *self, bool raise) { static int i2c_peripheral_check_error(i2cperipheral_i2c_peripheral_obj_t *self, bool raise) {
if (!self->sercom->I2CS.INTFLAG.bit.ERROR) { if (!self->sercom->I2CS.INTFLAG.bit.ERROR) {
return 0; return 0;
} }
@ -130,9 +130,9 @@ static int i2c_slave_check_error(i2cslave_i2c_slave_obj_t *self, bool raise) {
return -err; return -err;
} }
int common_hal_i2cslave_i2c_slave_is_addressed(i2cslave_i2c_slave_obj_t *self, uint8_t *address, bool *is_read, bool *is_restart) int common_hal_i2cperipheral_i2c_peripheral_is_addressed(i2cperipheral_i2c_peripheral_obj_t *self, uint8_t *address, bool *is_read, bool *is_restart)
{ {
int err = i2c_slave_check_error(self, false); int err = i2c_peripheral_check_error(self, false);
if (err) { if (err) {
return err; return err;
} }
@ -149,22 +149,22 @@ int common_hal_i2cslave_i2c_slave_is_addressed(i2cslave_i2c_slave_obj_t *self, u
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_i2cslave_i2c_slave_ack(self, true); common_hal_i2cperipheral_i2c_peripheral_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_i2cslave_i2c_slave_ack(self, false); common_hal_i2cperipheral_i2c_peripheral_ack(self, false);
return 0; return 0;
} }
int common_hal_i2cslave_i2c_slave_read_byte(i2cslave_i2c_slave_obj_t *self, uint8_t *data) { int common_hal_i2cperipheral_i2c_peripheral_read_byte(i2cperipheral_i2c_peripheral_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_slave_check_error(self, true); i2c_peripheral_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 ||
@ -176,12 +176,12 @@ int common_hal_i2cslave_i2c_slave_read_byte(i2cslave_i2c_slave_obj_t *self, uint
return 1; return 1;
} }
int common_hal_i2cslave_i2c_slave_write_byte(i2cslave_i2c_slave_obj_t *self, uint8_t data) { int common_hal_i2cperipheral_i2c_peripheral_write_byte(i2cperipheral_i2c_peripheral_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_slave_check_error(self, true); i2c_peripheral_check_error(self, true);
if (self->sercom->I2CS.INTFLAG.bit.PREC) { if (self->sercom->I2CS.INTFLAG.bit.PREC) {
return 0; return 0;
@ -203,12 +203,12 @@ int common_hal_i2cslave_i2c_slave_write_byte(i2cslave_i2c_slave_obj_t *self, uin
return 1; return 1;
} }
void common_hal_i2cslave_i2c_slave_ack(i2cslave_i2c_slave_obj_t *self, bool ack) { void common_hal_i2cperipheral_i2c_peripheral_ack(i2cperipheral_i2c_peripheral_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_i2cslave_i2c_slave_close(i2cslave_i2c_slave_obj_t *self) { void common_hal_i2cperipheral_i2c_peripheral_close(i2cperipheral_i2c_peripheral_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);
} }
@ -218,7 +218,7 @@ void common_hal_i2cslave_i2c_slave_close(i2cslave_i2c_slave_obj_t *self) {
} }
if (!self->sercom->I2CS.STATUS.bit.DIR) { if (!self->sercom->I2CS.STATUS.bit.DIR) {
common_hal_i2cslave_i2c_slave_ack(self, false); common_hal_i2cperipheral_i2c_peripheral_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) {
@ -246,7 +246,7 @@ void common_hal_i2cslave_i2c_slave_close(i2cslave_i2c_slave_obj_t *self) {
if (self->sercom->I2CS.STATUS.bit.CLKHOLD) { if (self->sercom->I2CS.STATUS.bit.CLKHOLD) {
// Unable to release the clock. // Unable to release the clock.
// The slave might have to be re-initialized to get unstuck. // The device might have to be re-initialized to get unstuck.
mp_raise_OSError(MP_EIO); mp_raise_OSError(MP_EIO);
} }
} }

View File

@ -24,8 +24,8 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_SLAVE_H #ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_PERIPHERAL_H
#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_SLAVE_H #define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_PERIPHERAL_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;
} i2cslave_i2c_slave_obj_t; } i2cperipheral_i2c_peripheral_obj_t;
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_SLAVE_H #endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_PERIPHERAL_H

View File

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

View File

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

View File

@ -14,7 +14,7 @@ CIRCUITPY_DISPLAYIO = 0
CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_GAMEPAD = 0 CIRCUITPY_GAMEPAD = 0
CIRCUITPY_GNSS = 1 CIRCUITPY_GNSS = 1
CIRCUITPY_I2CSLAVE = 0 CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_NEOPIXEL_WRITE = 0 CIRCUITPY_NEOPIXEL_WRITE = 0
CIRCUITPY_NVM = 0 CIRCUITPY_NVM = 0
CIRCUITPY_ROTARYIO = 0 CIRCUITPY_ROTARYIO = 0

View File

@ -22,7 +22,7 @@ CIRCUITPY_DIGITALIO = 1
CIRCUITPY_BUSIO = 0 CIRCUITPY_BUSIO = 0
CIRCUITPY_DISPLAYIO = 0 CIRCUITPY_DISPLAYIO = 0
CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CSLAVE = 0 CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_MICROCONTROLLER = 1 CIRCUITPY_MICROCONTROLLER = 1
CIRCUITPY_NVM = 0 CIRCUITPY_NVM = 0
CIRCUITPY_PULSEIO = 0 CIRCUITPY_PULSEIO = 0

View File

@ -20,7 +20,7 @@ CIRCUITPY_BOARD = 0
CIRCUITPY_BUSIO = 0 CIRCUITPY_BUSIO = 0
CIRCUITPY_DISPLAYIO = 0 CIRCUITPY_DISPLAYIO = 0
CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CSLAVE = 0 CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_NVM = 0 CIRCUITPY_NVM = 0
CIRCUITPY_PULSEIO = 0 CIRCUITPY_PULSEIO = 0
CIRCUITPY_ROTARYIO = 0 CIRCUITPY_ROTARYIO = 0

View File

@ -22,7 +22,7 @@ INTERNAL_FLASH_FILESYSTEM = 1
CIRCUITPY_AUDIOIO = 0 CIRCUITPY_AUDIOIO = 0
CIRCUITPY_AUDIOBUSIO = 0 CIRCUITPY_AUDIOBUSIO = 0
CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CSLAVE = 0 CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_NVM = 0 CIRCUITPY_NVM = 0
CIRCUITPY_ROTARYIO = 0 CIRCUITPY_ROTARYIO = 0
CIRCUITPY_COUNTIO = 0 CIRCUITPY_COUNTIO = 0

View File

@ -14,7 +14,7 @@ CIRCUITPY_COUNTIO = 0
CIRCUITPY_DISPLAYIO = 0 CIRCUITPY_DISPLAYIO = 0
CIRCUITPY_FRAMEBUFFERIO = 0 CIRCUITPY_FRAMEBUFFERIO = 0
CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CSLAVE = 0 CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_NEOPIXEL_WRITE = 0 CIRCUITPY_NEOPIXEL_WRITE = 0
CIRCUITPY_NVM = 0 CIRCUITPY_NVM = 0
CIRCUITPY_PIXELBUF = 0 CIRCUITPY_PIXELBUF = 0

View File

@ -25,8 +25,8 @@ CIRCUITPY_AUDIOPWMIO ?= 1
CIRCUITPY_BLEIO ?= 1 CIRCUITPY_BLEIO ?= 1
# No I2CSlave implementation # No I2CPeripheral implementation
CIRCUITPY_I2CSLAVE = 0 CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_RTC ?= 1 CIRCUITPY_RTC ?= 1

View File

@ -14,7 +14,7 @@ ifeq ($(MCU_SERIES),F4)
CIRCUITPY_AUDIOIO ?= 0 CIRCUITPY_AUDIOIO ?= 0
CIRCUITPY_COUNTIO ?= 0 CIRCUITPY_COUNTIO ?= 0
CIRCUITPY_FREQUENCYIO ?= 0 CIRCUITPY_FREQUENCYIO ?= 0
CIRCUITPY_I2CSLAVE ?= 0 CIRCUITPY_I2CPERIPHERAL ?= 0
CIRCUITPY_NVM ?= 0 CIRCUITPY_NVM ?= 0
CIRCUITPY_ROTARYIO ?= 0 CIRCUITPY_ROTARYIO ?= 0
CIRCUITPY_RTC ?= 0 CIRCUITPY_RTC ?= 0
@ -29,7 +29,7 @@ ifeq ($(MCU_SERIES),H7)
CIRCUITPY_AUDIOIO ?= 0 CIRCUITPY_AUDIOIO ?= 0
CIRCUITPY_COUNTIO ?= 0 CIRCUITPY_COUNTIO ?= 0
CIRCUITPY_FREQUENCYIO ?= 0 CIRCUITPY_FREQUENCYIO ?= 0
CIRCUITPY_I2CSLAVE ?= 0 CIRCUITPY_I2CPERIPHERAL ?= 0
CIRCUITPY_NEOPIXEL_WRITE ?= 0 CIRCUITPY_NEOPIXEL_WRITE ?= 0
CIRCUITPY_NVM ?= 0 CIRCUITPY_NVM ?= 0
CIRCUITPY_PULSEIO ?= 0 CIRCUITPY_PULSEIO ?= 0
@ -46,7 +46,7 @@ ifeq ($(MCU_SERIES),F7)
CIRCUITPY_AUDIOIO ?= 0 CIRCUITPY_AUDIOIO ?= 0
CIRCUITPY_COUNTIO ?= 0 CIRCUITPY_COUNTIO ?= 0
CIRCUITPY_FREQUENCYIO ?= 0 CIRCUITPY_FREQUENCYIO ?= 0
CIRCUITPY_I2CSLAVE ?= 0 CIRCUITPY_I2CPERIPHERAL ?= 0
CIRCUITPY_NEOPIXEL_WRITE ?= 0 CIRCUITPY_NEOPIXEL_WRITE ?= 0
CIRCUITPY_NVM ?= 0 CIRCUITPY_NVM ?= 0
CIRCUITPY_ROTARYIO ?= 0 CIRCUITPY_ROTARYIO ?= 0

View File

@ -165,8 +165,8 @@ endif
ifeq ($(CIRCUITPY_GNSS),1) ifeq ($(CIRCUITPY_GNSS),1)
SRC_PATTERNS += gnss/% SRC_PATTERNS += gnss/%
endif endif
ifeq ($(CIRCUITPY_I2CSLAVE),1) ifeq ($(CIRCUITPY_I2CPERIPHERAL),1)
SRC_PATTERNS += i2cslave/% SRC_PATTERNS += i2cperipheral/%
endif endif
ifeq ($(CIRCUITPY_MATH),1) ifeq ($(CIRCUITPY_MATH),1)
SRC_PATTERNS += math/% SRC_PATTERNS += math/%
@ -290,8 +290,8 @@ SRC_COMMON_HAL_ALL = \
gnss/GNSS.c \ gnss/GNSS.c \
gnss/PositionFix.c \ gnss/PositionFix.c \
gnss/SatelliteSystem.c \ gnss/SatelliteSystem.c \
i2cslave/I2CSlave.c \ i2cperipheral/I2CPeripheral.c \
i2cslave/__init__.c \ i2cperipheral/__init__.c \
microcontroller/Pin.c \ microcontroller/Pin.c \
microcontroller/Processor.c \ microcontroller/Processor.c \
microcontroller/__init__.c \ microcontroller/__init__.c \

View File

@ -408,11 +408,11 @@ extern const struct _mp_obj_module_t gnss_module;
#define GNSS_MODULE #define GNSS_MODULE
#endif #endif
#if CIRCUITPY_I2CSLAVE #if CIRCUITPY_I2CPERIPHERAL
extern const struct _mp_obj_module_t i2cslave_module; extern const struct _mp_obj_module_t i2cperipheral_module;
#define I2CSLAVE_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_i2cslave), (mp_obj_t)&i2cslave_module }, #define I2CPERIPHERAL_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_i2cperipheral), (mp_obj_t)&i2cperipheral_module },
#else #else
#define I2CSLAVE_MODULE #define I2CPERIPHERAL_MODULE
#endif #endif
#if CIRCUITPY_MATH #if CIRCUITPY_MATH
@ -690,7 +690,7 @@ extern const struct _mp_obj_module_t watchdog_module;
GAMEPAD_MODULE \ GAMEPAD_MODULE \
GAMEPADSHIFT_MODULE \ GAMEPADSHIFT_MODULE \
GNSS_MODULE \ GNSS_MODULE \
I2CSLAVE_MODULE \ I2CPERIPHERAL_MODULE \
JSON_MODULE \ JSON_MODULE \
MATH_MODULE \ MATH_MODULE \
_EVE_MODULE \ _EVE_MODULE \

View File

@ -112,8 +112,8 @@ CFLAGS += -DCIRCUITPY_GAMEPADSHIFT=$(CIRCUITPY_GAMEPADSHIFT)
CIRCUITPY_GNSS ?= 0 CIRCUITPY_GNSS ?= 0
CFLAGS += -DCIRCUITPY_GNSS=$(CIRCUITPY_GNSS) CFLAGS += -DCIRCUITPY_GNSS=$(CIRCUITPY_GNSS)
CIRCUITPY_I2CSLAVE ?= $(CIRCUITPY_FULL_BUILD) CIRCUITPY_I2CPERIPHERAL ?= $(CIRCUITPY_FULL_BUILD)
CFLAGS += -DCIRCUITPY_I2CSLAVE=$(CIRCUITPY_I2CSLAVE) CFLAGS += -DCIRCUITPY_I2CPERIPHERAL=$(CIRCUITPY_I2CPERIPHERAL)
CIRCUITPY_MATH ?= 1 CIRCUITPY_MATH ?= 1
CFLAGS += -DCIRCUITPY_MATH=$(CIRCUITPY_MATH) CFLAGS += -DCIRCUITPY_MATH=$(CIRCUITPY_MATH)

View File

@ -25,7 +25,7 @@
*/ */
#include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/microcontroller/Pin.h"
#include "shared-bindings/i2cslave/I2CSlave.h" #include "shared-bindings/i2cperipheral/I2CPeripheral.h"
#include "shared-bindings/time/__init__.h" #include "shared-bindings/time/__init__.h"
#include "shared-bindings/util.h" #include "shared-bindings/util.h"
@ -39,22 +39,22 @@
#include "py/objproperty.h" #include "py/objproperty.h"
#include "py/runtime.h" #include "py/runtime.h"
STATIC mp_obj_t mp_obj_new_i2cslave_i2c_slave_request(i2cslave_i2c_slave_obj_t *slave, uint8_t address, bool is_read, bool is_restart) { 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) {
i2cslave_i2c_slave_request_obj_t *self = m_new_obj(i2cslave_i2c_slave_request_obj_t); i2cperipheral_i2c_peripheral_request_obj_t *self = m_new_obj(i2cperipheral_i2c_peripheral_request_obj_t);
self->base.type = &i2cslave_i2c_slave_request_type; self->base.type = &i2cperipheral_i2c_peripheral_request_type;
self->slave = slave; self->peripheral = peripheral;
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 I2CSlave: //| class I2CPeripheral:
//| """Two wire serial protocol slave""" //| """Two wire serial protocol peripheral"""
//| //|
//| def __init__(self, scl: microcontroller.Pin, sda: microcontroller.Pin, addresses: tuple, smbus: bool = False): //| def __init__(self, scl: microcontroller.Pin, sda: microcontroller.Pin, addresses: tuple, smbus: bool = False):
//| """I2C is a two-wire protocol for communicating between devices. //| """I2C is a two-wire protocol for communicating between devices.
//| This implements the slave side. //| This implements the 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
@ -62,9 +62,9 @@ STATIC mp_obj_t mp_obj_new_i2cslave_i2c_slave_request(i2cslave_i2c_slave_obj_t *
//| :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 i2cslave_i2c_slave_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { STATIC mp_obj_t i2cperipheral_i2c_peripheral_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
i2cslave_i2c_slave_obj_t *self = m_new_obj(i2cslave_i2c_slave_obj_t); i2cperipheral_i2c_peripheral_obj_t *self = m_new_obj(i2cperipheral_i2c_peripheral_obj_t);
self->base.type = &i2cslave_i2c_slave_type; self->base.type = &i2cperipheral_i2c_peripheral_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 },
@ -98,7 +98,7 @@ STATIC mp_obj_t i2cslave_i2c_slave_make_new(const mp_obj_type_t *type, size_t n_
mp_raise_ValueError(translate("addresses is empty")); mp_raise_ValueError(translate("addresses is empty"));
} }
common_hal_i2cslave_i2c_slave_construct(self, scl, sda, addresses, i, args[ARG_smbus].u_bool); common_hal_i2cperipheral_i2c_peripheral_construct(self, scl, sda, addresses, i, args[ARG_smbus].u_bool);
return (mp_obj_t)self; return (mp_obj_t)self;
} }
@ -106,13 +106,13 @@ STATIC mp_obj_t i2cslave_i2c_slave_make_new(const mp_obj_type_t *type, size_t n_
//| """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 i2cslave_i2c_slave_obj_deinit(mp_obj_t self_in) { STATIC mp_obj_t i2cperipheral_i2c_peripheral_obj_deinit(mp_obj_t self_in) {
mp_check_self(MP_OBJ_IS_TYPE(self_in, &i2cslave_i2c_slave_type)); mp_check_self(MP_OBJ_IS_TYPE(self_in, &i2cperipheral_i2c_peripheral_type));
i2cslave_i2c_slave_obj_t *self = MP_OBJ_TO_PTR(self_in); i2cperipheral_i2c_peripheral_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_i2cslave_i2c_slave_deinit(self); common_hal_i2cperipheral_i2c_peripheral_deinit(self);
return mp_const_none; return mp_const_none;
} }
MP_DEFINE_CONST_FUN_OBJ_1(i2cslave_i2c_slave_deinit_obj, i2cslave_i2c_slave_obj_deinit); MP_DEFINE_CONST_FUN_OBJ_1(i2cperipheral_i2c_peripheral_deinit_obj, i2cperipheral_i2c_peripheral_obj_deinit);
//| def __enter__(self, ) -> Any: //| def __enter__(self, ) -> Any:
//| """No-op used in Context Managers.""" //| """No-op used in Context Managers."""
@ -125,25 +125,25 @@ MP_DEFINE_CONST_FUN_OBJ_1(i2cslave_i2c_slave_deinit_obj, i2cslave_i2c_slave_obj_
//| :ref:`lifetime-and-contextmanagers` for more info.""" //| :ref:`lifetime-and-contextmanagers` for more info."""
//| ... //| ...
//| //|
STATIC mp_obj_t i2cslave_i2c_slave_obj___exit__(size_t n_args, const mp_obj_t *args) { STATIC mp_obj_t i2cperipheral_i2c_peripheral_obj___exit__(size_t n_args, const mp_obj_t *args) {
mp_check_self(MP_OBJ_IS_TYPE(args[0], &i2cslave_i2c_slave_type)); mp_check_self(MP_OBJ_IS_TYPE(args[0], &i2cperipheral_i2c_peripheral_type));
i2cslave_i2c_slave_obj_t *self = MP_OBJ_TO_PTR(args[0]); i2cperipheral_i2c_peripheral_obj_t *self = MP_OBJ_TO_PTR(args[0]);
common_hal_i2cslave_i2c_slave_deinit(self); common_hal_i2cperipheral_i2c_peripheral_deinit(self);
return mp_const_none; return mp_const_none;
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(i2cslave_i2c_slave___exit___obj, 4, 4, i2cslave_i2c_slave_obj___exit__); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(i2cperipheral_i2c_peripheral___exit___obj, 4, 4, i2cperipheral_i2c_peripheral_obj___exit__);
//| def request(self, timeout: float = -1) -> Any: //| def request(self, timeout: float = -1) -> Any:
//| """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: I2C Slave Request or None if timeout=-1 and there's no request
//| :rtype: ~i2cslave.I2CSlaveRequest""" //| :rtype: ~i2cperipheral.I2CPeripheralRequest"""
//| //|
STATIC mp_obj_t i2cslave_i2c_slave_request(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { STATIC mp_obj_t i2cperipheral_i2c_peripheral_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], &i2cslave_i2c_slave_type)); mp_check_self(MP_OBJ_IS_TYPE(pos_args[0], &i2cperipheral_i2c_peripheral_type));
i2cslave_i2c_slave_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); i2cperipheral_i2c_peripheral_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
if(common_hal_i2cslave_i2c_slave_deinited(self)) { if(common_hal_i2cperipheral_i2c_peripheral_deinited(self)) {
raise_deinited_error(); raise_deinited_error();
} }
enum { ARG_timeout }; enum { ARG_timeout };
@ -180,7 +180,7 @@ STATIC mp_obj_t i2cslave_i2c_slave_request(size_t n_args, const mp_obj_t *pos_ar
return mp_const_none; return mp_const_none;
} }
int status = common_hal_i2cslave_i2c_slave_is_addressed(self, &address, &is_read, &is_restart); int status = common_hal_i2cperipheral_i2c_peripheral_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) {
@ -198,7 +198,7 @@ STATIC mp_obj_t i2cslave_i2c_slave_request(size_t n_args, const mp_obj_t *pos_ar
continue; continue;
} }
return mp_obj_new_i2cslave_i2c_slave_request(self, address, is_read, is_restart); return mp_obj_new_i2cperipheral_i2c_peripheral_request(self, address, is_read, is_restart);
} while (forever || common_hal_time_monotonic() < timeout_end); } while (forever || common_hal_time_monotonic() < timeout_end);
if (timeout_ms > 0) { if (timeout_ms > 0) {
@ -206,39 +206,39 @@ STATIC mp_obj_t i2cslave_i2c_slave_request(size_t n_args, const mp_obj_t *pos_ar
} }
return mp_const_none; return mp_const_none;
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(i2cslave_i2c_slave_request_obj, 1, i2cslave_i2c_slave_request); STATIC MP_DEFINE_CONST_FUN_OBJ_KW(i2cperipheral_i2c_peripheral_request_obj, 1, i2cperipheral_i2c_peripheral_request);
STATIC const mp_rom_map_elem_t i2cslave_i2c_slave_locals_dict_table[] = { STATIC const mp_rom_map_elem_t i2cperipheral_i2c_peripheral_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&i2cslave_i2c_slave_deinit_obj) }, { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_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(&i2cslave_i2c_slave___exit___obj) }, { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&i2cperipheral_i2c_peripheral___exit___obj) },
{ MP_ROM_QSTR(MP_QSTR_request), MP_ROM_PTR(&i2cslave_i2c_slave_request_obj) }, { MP_ROM_QSTR(MP_QSTR_request), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_obj) },
}; };
STATIC MP_DEFINE_CONST_DICT(i2cslave_i2c_slave_locals_dict, i2cslave_i2c_slave_locals_dict_table); STATIC MP_DEFINE_CONST_DICT(i2cperipheral_i2c_peripheral_locals_dict, i2cperipheral_i2c_peripheral_locals_dict_table);
const mp_obj_type_t i2cslave_i2c_slave_type = { const mp_obj_type_t i2cperipheral_i2c_peripheral_type = {
{ &mp_type_type }, { &mp_type_type },
.name = MP_QSTR_I2CSlave, .name = MP_QSTR_I2CPeripheral,
.make_new = i2cslave_i2c_slave_make_new, .make_new = i2cperipheral_i2c_peripheral_make_new,
.locals_dict = (mp_obj_dict_t*)&i2cslave_i2c_slave_locals_dict, .locals_dict = (mp_obj_dict_t*)&i2cperipheral_i2c_peripheral_locals_dict,
}; };
//| class I2CSlaveRequest: //| class I2CPeripheralRequest:
//| //|
//| def __init__(self, slave: i2cslave.I2CSlave, address: int, is_read: bool, is_restart: bool): //| def __init__(self, peripheral: i2cperipheral.I2CPeripheral, address: int, is_read: bool, is_restart: bool):
//| """Information about an I2C transfer request //| """Information about an I2C transfer request
//| This cannot be instantiated directly, but is returned by :py:meth:`I2CSlave.request`. //| This cannot be instantiated directly, but is returned by :py:meth:`I2CPeripheral.request`.
//| //|
//| :param slave: The I2C Slave receiving this request //| :param peripheral: The I2CPeripheral object receiving this request
//| :param address: I2C address //| :param address: I2C address
//| :param is_read: True if the main device is requesting data //| :param is_read: True if the main peripheral is requesting data
//| :param is_restart: Repeated Start Condition""" //| :param is_restart: Repeated Start Condition"""
//| //|
STATIC mp_obj_t i2cslave_i2c_slave_request_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
mp_arg_check_num(n_args, kw_args, 4, 4, false); mp_arg_check_num(n_args, kw_args, 4, 4, false);
return mp_obj_new_i2cslave_i2c_slave_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_i2cperipheral_i2c_peripheral_request(args[0], mp_obj_get_int(args[1]), mp_obj_is_true(args[2]), mp_obj_is_true(args[3]));
} }
//| def __enter__(self, ) -> Any: //| def __enter__(self, ) -> Any:
@ -251,56 +251,56 @@ STATIC mp_obj_t i2cslave_i2c_slave_request_make_new(const mp_obj_type_t *type, s
//| """Close the request.""" //| """Close the request."""
//| ... //| ...
//| //|
STATIC mp_obj_t i2cslave_i2c_slave_request_obj___exit__(size_t n_args, const mp_obj_t *args) { STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_obj___exit__(size_t n_args, const mp_obj_t *args) {
mp_check_self(MP_OBJ_IS_TYPE(args[0], &i2cslave_i2c_slave_request_type)); mp_check_self(MP_OBJ_IS_TYPE(args[0], &i2cperipheral_i2c_peripheral_request_type));
i2cslave_i2c_slave_request_obj_t *self = MP_OBJ_TO_PTR(args[0]); i2cperipheral_i2c_peripheral_request_obj_t *self = MP_OBJ_TO_PTR(args[0]);
common_hal_i2cslave_i2c_slave_close(self->slave); common_hal_i2cperipheral_i2c_peripheral_close(self->peripheral);
return mp_const_none; return mp_const_none;
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(i2cslave_i2c_slave_request___exit___obj, 4, 4, i2cslave_i2c_slave_request_obj___exit__); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(i2cperipheral_i2c_peripheral_request___exit___obj, 4, 4, i2cperipheral_i2c_peripheral_request_obj___exit__);
//| address: int = ... //| address: int = ...
//| """The I2C address of the request.""" //| """The I2C address of the request."""
//| //|
STATIC mp_obj_t i2cslave_i2c_slave_request_get_address(mp_obj_t self_in) { STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_get_address(mp_obj_t self_in) {
mp_check_self(MP_OBJ_IS_TYPE(self_in, &i2cslave_i2c_slave_request_type)); mp_check_self(MP_OBJ_IS_TYPE(self_in, &i2cperipheral_i2c_peripheral_request_type));
i2cslave_i2c_slave_request_obj_t *self = MP_OBJ_TO_PTR(self_in); i2cperipheral_i2c_peripheral_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(i2cslave_i2c_slave_request_address_obj, i2cslave_i2c_slave_request_get_address); MP_DEFINE_CONST_PROP_GET(i2cperipheral_i2c_peripheral_request_address_obj, i2cperipheral_i2c_peripheral_request_get_address);
//| is_read: bool = ... //| is_read: bool = ...
//| """The I2C main controller is reading from this device.""" //| """The I2C main controller is reading from this peripheral."""
//| //|
STATIC mp_obj_t i2cslave_i2c_slave_request_get_is_read(mp_obj_t self_in) { STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_get_is_read(mp_obj_t self_in) {
mp_check_self(MP_OBJ_IS_TYPE(self_in, &i2cslave_i2c_slave_request_type)); mp_check_self(MP_OBJ_IS_TYPE(self_in, &i2cperipheral_i2c_peripheral_request_type));
i2cslave_i2c_slave_request_obj_t *self = MP_OBJ_TO_PTR(self_in); i2cperipheral_i2c_peripheral_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(i2cslave_i2c_slave_request_is_read_obj, i2cslave_i2c_slave_request_get_is_read); MP_DEFINE_CONST_PROP_GET(i2cperipheral_i2c_peripheral_request_is_read_obj, i2cperipheral_i2c_peripheral_request_get_is_read);
//| is_restart: bool = ... //| is_restart: bool = ...
//| """Is Repeated Start Condition.""" //| """Is Repeated Start Condition."""
//| //|
STATIC mp_obj_t i2cslave_i2c_slave_request_get_is_restart(mp_obj_t self_in) { STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_get_is_restart(mp_obj_t self_in) {
mp_check_self(MP_OBJ_IS_TYPE(self_in, &i2cslave_i2c_slave_request_type)); mp_check_self(MP_OBJ_IS_TYPE(self_in, &i2cperipheral_i2c_peripheral_request_type));
i2cslave_i2c_slave_request_obj_t *self = MP_OBJ_TO_PTR(self_in); i2cperipheral_i2c_peripheral_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(i2cslave_i2c_slave_request_is_restart_obj, i2cslave_i2c_slave_request_get_is_restart); MP_DEFINE_CONST_PROP_GET(i2cperipheral_i2c_peripheral_request_is_restart_obj, i2cperipheral_i2c_peripheral_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:`I2CSlaveRequest.ack`. //| If ack=False, the caller is responsible for calling :py:meth:`I2CPeripheralRequest.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 i2cslave_i2c_slave_request_read(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { STATIC mp_obj_t i2cperipheral_i2c_peripheral_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], &i2cslave_i2c_slave_request_type)); mp_check_self(MP_OBJ_IS_TYPE(pos_args[0], &i2cperipheral_i2c_peripheral_request_type));
i2cslave_i2c_slave_request_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); i2cperipheral_i2c_peripheral_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} },
@ -329,7 +329,7 @@ STATIC mp_obj_t i2cslave_i2c_slave_request_read(size_t n_args, const mp_obj_t *p
} }
uint8_t data; uint8_t data;
int num = common_hal_i2cslave_i2c_slave_read_byte(self->slave, &data); int num = common_hal_i2cperipheral_i2c_peripheral_read_byte(self->peripheral, &data);
if (num == 0) { if (num == 0) {
break; break;
} }
@ -338,16 +338,16 @@ STATIC mp_obj_t i2cslave_i2c_slave_request_read(size_t n_args, const mp_obj_t *p
buffer[i++] = data; buffer[i++] = data;
if (i == n) { if (i == n) {
if (ack) { if (ack) {
common_hal_i2cslave_i2c_slave_ack(self->slave, true); common_hal_i2cperipheral_i2c_peripheral_ack(self->peripheral, true);
} }
break; break;
} }
common_hal_i2cslave_i2c_slave_ack(self->slave, true); common_hal_i2cperipheral_i2c_peripheral_ack(self->peripheral, true);
} }
return mp_obj_new_bytearray(i, buffer); return mp_obj_new_bytearray(i, buffer);
} }
MP_DEFINE_CONST_FUN_OBJ_KW(i2cslave_i2c_slave_request_read_obj, 1, i2cslave_i2c_slave_request_read); MP_DEFINE_CONST_FUN_OBJ_KW(i2cperipheral_i2c_peripheral_request_read_obj, 1, i2cperipheral_i2c_peripheral_request_read);
//| def write(self, buffer: bytearray) -> int: //| def write(self, buffer: bytearray) -> int:
//| """Write the data contained in buffer. //| """Write the data contained in buffer.
@ -356,9 +356,9 @@ MP_DEFINE_CONST_FUN_OBJ_KW(i2cslave_i2c_slave_request_read_obj, 1, i2cslave_i2c_
//| :return: Number of bytes written""" //| :return: Number of bytes written"""
//| ... //| ...
//| //|
STATIC mp_obj_t i2cslave_i2c_slave_request_write(mp_obj_t self_in, mp_obj_t buf_in) { STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_write(mp_obj_t self_in, mp_obj_t buf_in) {
mp_check_self(MP_OBJ_IS_TYPE(self_in, &i2cslave_i2c_slave_request_type)); mp_check_self(MP_OBJ_IS_TYPE(self_in, &i2cperipheral_i2c_peripheral_request_type));
i2cslave_i2c_slave_request_obj_t *self = MP_OBJ_TO_PTR(self_in); i2cperipheral_i2c_peripheral_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);
@ -373,7 +373,7 @@ STATIC mp_obj_t i2cslave_i2c_slave_request_write(mp_obj_t self_in, mp_obj_t buf_
break; break;
} }
int num = common_hal_i2cslave_i2c_slave_write_byte(self->slave, ((uint8_t *)(bufinfo.buf))[i]); int num = common_hal_i2cperipheral_i2c_peripheral_write_byte(self->peripheral, ((uint8_t *)(bufinfo.buf))[i]);
if (num == 0) { if (num == 0) {
return mp_obj_new_int(i); return mp_obj_new_int(i);
} }
@ -381,55 +381,55 @@ STATIC mp_obj_t i2cslave_i2c_slave_request_write(mp_obj_t self_in, mp_obj_t buf_
return mp_obj_new_int(bufinfo.len); return mp_obj_new_int(bufinfo.len);
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_2(i2cslave_i2c_slave_request_write_obj, i2cslave_i2c_slave_request_write); STATIC MP_DEFINE_CONST_FUN_OBJ_2(i2cperipheral_i2c_peripheral_request_write_obj, i2cperipheral_i2c_peripheral_request_write);
//| def ack(self, ack: bool = True) -> Any: //| def ack(self, ack: bool = True) -> Any:
//| """Acknowledge or Not Acknowledge last byte received. //| """Acknowledge or Not Acknowledge last byte received.
//| Use together with :py:meth:`I2CSlaveRequest.read` ack=False. //| Use together with :py:meth:`I2CPeripheralRequest.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 i2cslave_i2c_slave_request_ack(uint n_args, const mp_obj_t *args) { STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_ack(uint n_args, const mp_obj_t *args) {
mp_check_self(MP_OBJ_IS_TYPE(args[0], &i2cslave_i2c_slave_request_type)); mp_check_self(MP_OBJ_IS_TYPE(args[0], &i2cperipheral_i2c_peripheral_request_type));
i2cslave_i2c_slave_request_obj_t *self = MP_OBJ_TO_PTR(args[0]); i2cperipheral_i2c_peripheral_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_i2cslave_i2c_slave_ack(self->slave, ack); common_hal_i2cperipheral_i2c_peripheral_ack(self->peripheral, ack);
return mp_const_none; return mp_const_none;
} }
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(i2cslave_i2c_slave_request_ack_obj, 1, 2, i2cslave_i2c_slave_request_ack); MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(i2cperipheral_i2c_peripheral_request_ack_obj, 1, 2, i2cperipheral_i2c_peripheral_request_ack);
STATIC mp_obj_t i2cslave_i2c_slave_request_close(mp_obj_t self_in) { STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_close(mp_obj_t self_in) {
mp_check_self(MP_OBJ_IS_TYPE(self_in, &i2cslave_i2c_slave_request_type)); mp_check_self(MP_OBJ_IS_TYPE(self_in, &i2cperipheral_i2c_peripheral_request_type));
i2cslave_i2c_slave_request_obj_t *self = MP_OBJ_TO_PTR(self_in); i2cperipheral_i2c_peripheral_request_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_i2cslave_i2c_slave_close(self->slave); common_hal_i2cperipheral_i2c_peripheral_close(self->peripheral);
return mp_const_none; return mp_const_none;
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_1(i2cslave_i2c_slave_request_close_obj, i2cslave_i2c_slave_request_close); STATIC MP_DEFINE_CONST_FUN_OBJ_1(i2cperipheral_i2c_peripheral_request_close_obj, i2cperipheral_i2c_peripheral_request_close);
STATIC const mp_rom_map_elem_t i2cslave_i2c_slave_request_locals_dict_table[] = { STATIC const mp_rom_map_elem_t i2cperipheral_i2c_peripheral_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(&i2cslave_i2c_slave_request___exit___obj) }, { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request___exit___obj) },
{ MP_ROM_QSTR(MP_QSTR_address), MP_ROM_PTR(&i2cslave_i2c_slave_request_address_obj) }, { MP_ROM_QSTR(MP_QSTR_address), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_address_obj) },
{ MP_ROM_QSTR(MP_QSTR_is_read), MP_ROM_PTR(&i2cslave_i2c_slave_request_is_read_obj) }, { MP_ROM_QSTR(MP_QSTR_is_read), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_is_read_obj) },
{ MP_ROM_QSTR(MP_QSTR_is_restart), MP_ROM_PTR(&i2cslave_i2c_slave_request_is_restart_obj) }, { MP_ROM_QSTR(MP_QSTR_is_restart), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_is_restart_obj) },
{ MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&i2cslave_i2c_slave_request_read_obj) }, { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_read_obj) },
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&i2cslave_i2c_slave_request_write_obj) }, { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_write_obj) },
{ MP_ROM_QSTR(MP_QSTR_ack), MP_ROM_PTR(&i2cslave_i2c_slave_request_ack_obj) }, { MP_ROM_QSTR(MP_QSTR_ack), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_ack_obj) },
{ MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&i2cslave_i2c_slave_request_close_obj) }, { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_close_obj) },
}; };
STATIC MP_DEFINE_CONST_DICT(i2cslave_i2c_slave_request_locals_dict, i2cslave_i2c_slave_request_locals_dict_table); STATIC MP_DEFINE_CONST_DICT(i2cperipheral_i2c_peripheral_request_locals_dict, i2cperipheral_i2c_peripheral_request_locals_dict_table);
const mp_obj_type_t i2cslave_i2c_slave_request_type = { const mp_obj_type_t i2cperipheral_i2c_peripheral_request_type = {
{ &mp_type_type }, { &mp_type_type },
.name = MP_QSTR_I2CSlaveRequest, .name = MP_QSTR_I2CPeripheralRequest,
.make_new = i2cslave_i2c_slave_request_make_new, .make_new = i2cperipheral_i2c_peripheral_request_make_new,
.locals_dict = (mp_obj_dict_t*)&i2cslave_i2c_slave_request_locals_dict, .locals_dict = (mp_obj_dict_t*)&i2cperipheral_i2c_peripheral_request_locals_dict,
}; };

View File

@ -30,31 +30,31 @@
#include "py/obj.h" #include "py/obj.h"
#include "common-hal/microcontroller/Pin.h" #include "common-hal/microcontroller/Pin.h"
#include "common-hal/i2cslave/I2CSlave.h" #include "common-hal/i2cperipheral/I2CPeripheral.h"
typedef struct { typedef struct {
mp_obj_base_t base; mp_obj_base_t base;
i2cslave_i2c_slave_obj_t *slave; i2cperipheral_i2c_peripheral_obj_t *peripheral;
uint16_t address; uint16_t address;
bool is_read; bool is_read;
bool is_restart; bool is_restart;
} i2cslave_i2c_slave_request_obj_t; } i2cperipheral_i2c_peripheral_request_obj_t;
extern const mp_obj_type_t i2cslave_i2c_slave_request_type; extern const mp_obj_type_t i2cperipheral_i2c_peripheral_request_type;
extern const mp_obj_type_t i2cslave_i2c_slave_type; extern const mp_obj_type_t i2cperipheral_i2c_peripheral_type;
extern void common_hal_i2cslave_i2c_slave_construct(i2cslave_i2c_slave_obj_t *self, extern void common_hal_i2cperipheral_i2c_peripheral_construct(i2cperipheral_i2c_peripheral_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_i2cslave_i2c_slave_deinit(i2cslave_i2c_slave_obj_t *self); extern void common_hal_i2cperipheral_i2c_peripheral_deinit(i2cperipheral_i2c_peripheral_obj_t *self);
extern bool common_hal_i2cslave_i2c_slave_deinited(i2cslave_i2c_slave_obj_t *self); extern bool common_hal_i2cperipheral_i2c_peripheral_deinited(i2cperipheral_i2c_peripheral_obj_t *self);
extern int common_hal_i2cslave_i2c_slave_is_addressed(i2cslave_i2c_slave_obj_t *self, extern int common_hal_i2cperipheral_i2c_peripheral_is_addressed(i2cperipheral_i2c_peripheral_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_i2cslave_i2c_slave_read_byte(i2cslave_i2c_slave_obj_t *self, uint8_t *data); extern int common_hal_i2cperipheral_i2c_peripheral_read_byte(i2cperipheral_i2c_peripheral_obj_t *self, uint8_t *data);
extern int common_hal_i2cslave_i2c_slave_write_byte(i2cslave_i2c_slave_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 void common_hal_i2cslave_i2c_slave_ack(i2cslave_i2c_slave_obj_t *self, bool ack); extern void common_hal_i2cperipheral_i2c_peripheral_ack(i2cperipheral_i2c_peripheral_obj_t *self, bool ack);
extern void common_hal_i2cslave_i2c_slave_close(i2cslave_i2c_slave_obj_t *self); extern void common_hal_i2cperipheral_i2c_peripheral_close(i2cperipheral_i2c_peripheral_obj_t *self);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BUSIO_I2C_SLAVE_H #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BUSIO_I2C_SLAVE_H

View File

@ -30,26 +30,26 @@
#include "py/runtime.h" #include "py/runtime.h"
#include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/microcontroller/Pin.h"
//#include "shared-bindings/i2cslave/__init__.h" //#include "shared-bindings/i2cperipheral/__init__.h"
#include "shared-bindings/i2cslave/I2CSlave.h" #include "shared-bindings/i2cperipheral/I2CPeripheral.h"
#include "py/runtime.h" #include "py/runtime.h"
//| """Two wire serial protocol slave //| """Two wire serial protocol peripheral
//| //|
//| The `i2cslave` module contains classes to support a I2C slave. //| The `i2cperipheral` module contains classes to support an I2C peripheral.
//| //|
//| Example emulating 2 devices:: //| Example emulating a peripheral with 2 addresses (read and write)::
//| //|
//| import board //| import board
//| from i2cslave import I2CSlave //| from i2cperipheral import I2CPeripheral
//| //|
//| regs = [0] * 16 //| regs = [0] * 16
//| index = 0 //| index = 0
//| //|
//| with I2CSlave(board.SCL, board.SDA, (0x40, 0x41)) as slave: //| with I2CPeripheral(board.SCL, board.SDA, (0x40, 0x41)) as device:
//| while True: //| while True:
//| r = slave.request() //| r = device.request()
//| if not r: //| if not r:
//| # Maybe do some housekeeping //| # Maybe do some housekeeping
//| continue //| continue
@ -67,7 +67,7 @@
//| n = r.write(bytes([regs[index]])) //| n = r.write(bytes([regs[index]]))
//| #else: //| #else:
//| # A read transfer is not supported in this example //| # A read transfer is not supported in this example
//| # If the Master tries, it will get 0xff byte(s) by the ctx manager (r.close()) //| # If the microcontroller tries, it will get 0xff byte(s) by the ctx manager (r.close())
//| elif r.address == 0x41: //| elif r.address == 0x41:
//| if not r.is_read: //| if not r.is_read:
//| b = r.read(1) //| b = r.read(1)
@ -75,7 +75,7 @@
//| # do something //| # do something
//| pass //| pass
//| //|
//| This example sets up an I2C slave that can be accessed from Linux like this:: //| This example sets up an I2C device that can be accessed from Linux like this::
//| //|
//| $ i2cget -y 1 0x40 0x01 //| $ i2cget -y 1 0x40 0x01
//| 0x00 //| 0x00
@ -84,22 +84,23 @@
//| 0xaa //| 0xaa
//| //|
//| .. warning:: //| .. warning::
//| I2CSlave makes use of clock stretching in order to slow down the master. //| I2CPeripheral makes use of clock stretching in order to slow down
//| Make sure the I2C master supports this. //| the host.
//| Make sure the I2C host supports this.
//| //|
//| Raspberry Pi in particular does not support this with its I2C hw block. //| Raspberry Pi in particular does not support this with its I2C hw block.
//| This can be worked around by using the ``i2c-gpio`` bit banging driver. //| This can be worked around by using the ``i2c-gpio`` bit banging driver.
//| 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 i2cslave_module_globals_table[] = { STATIC const mp_rom_map_elem_t i2cperipheral_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_i2cslave) }, { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_i2cperipheral) },
{ MP_ROM_QSTR(MP_QSTR_I2CSlave), MP_ROM_PTR(&i2cslave_i2c_slave_type) }, { MP_ROM_QSTR(MP_QSTR_I2CPeripheral), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_type) },
}; };
STATIC MP_DEFINE_CONST_DICT(i2cslave_module_globals, i2cslave_module_globals_table); STATIC MP_DEFINE_CONST_DICT(i2cperipheral_module_globals, i2cperipheral_module_globals_table);
const mp_obj_module_t i2cslave_module = { const mp_obj_module_t i2cperipheral_module = {
.base = { &mp_type_module }, .base = { &mp_type_module },
.globals = (mp_obj_dict_t*)&i2cslave_module_globals, .globals = (mp_obj_dict_t*)&i2cperipheral_module_globals,
}; };