3232#include "machine_i2c.h"
3333#include CLOCK_CONFIG_H
3434
35- static machine_i2c_target_data_t i2c_target_data [FSL_FEATURE_SOC_LPI2C_COUNT ];
36-
3735typedef struct _machine_i2c_target_obj_t {
3836 mp_obj_base_t base ;
3937 LPI2C_Type * i2c_inst ;
@@ -43,12 +41,9 @@ typedef struct _machine_i2c_target_obj_t {
4341 lpi2c_slave_handle_t handle ;
4442} machine_i2c_target_obj_t ;
4543
46-
47- MP_REGISTER_ROOT_POINTER (mp_obj_t pyb_i2cslave_mem [FSL_FEATURE_SOC_LPI2C_COUNT ]);
48-
4944static void lpi2c_slave_callback (LPI2C_Type * base , lpi2c_slave_transfer_t * xfer , void * param ) {
5045 machine_i2c_target_obj_t * self = (machine_i2c_target_obj_t * )param ;
51- machine_i2c_target_data_t * data = & i2c_target_data [self -> i2c_id ];
46+ machine_i2c_target_data_t * data = & machine_i2c_target_data [self -> i2c_id ];
5247
5348 switch (xfer -> event )
5449 {
@@ -79,6 +74,10 @@ static void lpi2c_slave_callback(LPI2C_Type *base, lpi2c_slave_transfer_t *xfer,
7974/******************************************************************************/
8075// I2CTarget port implementation
8176
77+ static inline size_t mp_machine_i2c_target_get_index (machine_i2c_target_obj_t * self ) {
78+ return self -> i2c_id ;
79+ }
80+
8281static void mp_machine_i2c_target_deinit_all_port (void ) {
8382}
8483
@@ -141,8 +140,8 @@ static mp_obj_t mp_machine_i2c_target_make_new(const mp_obj_type_t *type, size_t
141140 // Set the target address.
142141 self -> addr = args [ARG_addr ].u_int ;
143142 // Initialise data.
144- MP_STATE_PORT (pyb_i2cslave_mem )[i2c_id ] = args [ARG_mem ].u_obj ;
145- machine_i2c_target_data_t * data = & i2c_target_data [self -> i2c_id ];
143+ MP_STATE_PORT (machine_i2c_target_mem_obj )[i2c_id ] = args [ARG_mem ].u_obj ;
144+ machine_i2c_target_data_t * data = & machine_i2c_target_data [self -> i2c_id ];
146145 machine_i2c_target_data_init (data , args [ARG_mem ].u_obj , args [ARG_mem_addrsize ].u_int );
147146
148147 // Initialise the GPIO pins
@@ -172,5 +171,5 @@ static void mp_machine_i2c_target_print(const mp_print_t *print, mp_obj_t self_i
172171// Stop the Slave transfer and free the memory objects.
173172static void mp_machine_i2c_target_deinit (machine_i2c_target_obj_t * self ) {
174173 LPI2C_SlaveDeinit (self -> i2c_inst );
175- MP_STATE_PORT (pyb_i2cslave_mem )[self -> i2c_id ] = NULL ;
174+ MP_STATE_PORT (machine_i2c_target_mem_obj )[self -> i2c_id ] = MP_OBJ_NULL ;
176175}
0 commit comments