Skip to content

Commit

Permalink
ports/psoc6: Working on I2C Slave machine class.
Browse files Browse the repository at this point in the history
Signed-off-by: enriquezgarc <[email protected]>
  • Loading branch information
jaenrig-ifx committed Jan 25, 2024
1 parent 781874d commit f22fd15
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 3 deletions.
69 changes: 68 additions & 1 deletion ports/psoc6/machine_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,47 @@ STATIC int machine_i2c_transfer(mp_obj_base_t *self_in, uint16_t addr, size_t le
}

// configure slave buffers
// configure callbacks for slave events
// i2c_master writes
// i2c_slave reads from write buffer
// i2c_slave does something about it
// i2c_master reads
// i2c_slave needs needs to have something there is the buffer

STATIC mp_obj_t machine_i2c_slave_configure_receive_buffer(mp_obj_t self_in /*pass a buffer*/) {
machine_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
(void)self->scl;
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_i2c_slave_conf_rx_buffer_obj, machine_i2c_slave_configure_receive_buffer);

// STATIC mp_obj_t machine_i2c_slave_configure_transmit_buffer(mp_obj_t self_in /*pass a buffer*/) {
// machine_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);

// return mp_const_none;
// }
// machine_i2c_slave_configure_rx_buffer() {

// }

// machine_i2c_skave_configure_tx_buffer() {

// }

// STATIC mp_obj_t machine_i2c_slave_configure_transmit_buffer(mp_obj_t self_in /*pass a buffer*/) {
// machine_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);

// return mp_const_none;
// }

// machine_i2c_slave_register_callback(callback_function) {

// }

// machine_i2c_slave_tx_register_callback(callback_function) {

// }




STATIC const mp_machine_i2c_p_t machine_i2c_p = {
Expand All @@ -229,6 +269,33 @@ MP_DEFINE_CONST_OBJ_TYPE(
locals_dict, &mp_machine_i2c_locals_dict
);

#if MICROPY_PY_MACHINE_I2C_SLAVE

STATIC const mp_rom_map_elem_t machine_i2c_slave_locals_dict_table[] = {
// Functions
{ MP_ROM_QSTR(MP_QSTR_slave_conf_rx_buffer), MP_ROM_PTR(&machine_i2c_slave_conf_rx_buffer_obj) },

// Const
{ MP_ROM_QSTR(MP_QSTR_RD_EVENT), MP_ROM_INT(CYHAL_I2C_SLAVE_READ_EVENT) },
{ MP_ROM_QSTR(MP_QSTR_WR_EVENT), MP_ROM_INT(CYHAL_I2C_SLAVE_WRITE_EVENT) },
{ MP_ROM_QSTR(MP_QSTR_RD_BUF_IN_FIFO_EVENT), MP_ROM_INT(CYHAL_I2C_SLAVE_RD_IN_FIFO_EVENT) },
{ MP_ROM_QSTR(MP_QSTR_RD_BUF_EMPTY_EVENT), MP_ROM_INT(CYHAL_I2C_SLAVE_RD_BUF_EMPTY_EVENT) },
{ MP_ROM_QSTR(MP_QSTR_RD_CMPLT_EVENT), MP_ROM_INT(CYHAL_I2C_SLAVE_RD_CMPLT_EVENT) },
{ MP_ROM_QSTR(MP_QSTR_WR_CMPLT_EVENT), MP_ROM_INT(CYHAL_I2C_SLAVE_WR_CMPLT_EVENT) },
{ MP_ROM_QSTR(MP_QSTR_ERR_EVENT), MP_ROM_INT(CYHAL_I2C_SLAVE_ERR_EVENT) },
};
STATIC MP_DEFINE_CONST_DICT(machine_i2c_slave_locals_dict, machine_i2c_slave_locals_dict_table);

MP_DEFINE_CONST_OBJ_TYPE(
machine_i2c_slave_type,
MP_QSTR_I2CSlave,
MP_TYPE_FLAG_NONE,
make_new, machine_i2c_make_new,
print, machine_i2c_print,
locals_dict, &machine_i2c_slave_locals_dict
);
#endif

void mod_i2c_deinit() {
for (uint8_t i = 0; i < MAX_I2C; i++) {
if (i2c_obj[i] != NULL) {
Expand Down
1 change: 1 addition & 0 deletions ports/psoc6/modmachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ STATIC void mp_machine_idle(void) {
/* Modules */ \
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&machine_i2c_type) }, \
{ MP_ROM_QSTR(MP_QSTR_SoftI2C), MP_ROM_PTR(&mp_machine_soft_i2c_type) }, \
{ MP_ROM_QSTR(MP_QSTR_I2CSlave), MP_ROM_PTR(&machine_i2c_slave_type) }, \
{ MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&machine_pin_type) }, \
{ MP_ROM_QSTR(MP_QSTR_Signal), MP_ROM_PTR(&machine_signal_type) }, \
{ MP_ROM_QSTR(MP_QSTR_RTC), MP_ROM_PTR(&machine_rtc_type) }, \
Expand Down
1 change: 1 addition & 0 deletions ports/psoc6/modmachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@


extern const mp_obj_type_t machine_i2c_type;
extern const mp_obj_type_t machine_i2c_slave_type;
extern const mp_obj_type_t machine_pin_type;
extern const mp_obj_type_t machine_rtc_type;
extern const mp_obj_type_t machine_pwm_type;
Expand Down
3 changes: 1 addition & 2 deletions ports/psoc6/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@
#define MICROPY_PY_MACHINE_PWM (1)
#define MICROPY_PY_MACHINE_PWM_INCLUDEFILE "ports/psoc6/machine_pwm.c"
#define MICROPY_PY_MACHINE_I2C (1)
#define MICROPY_PORT_I2C_EXTENSION \
{ MP_ROM_QSTR(MP_QSTR_SLAVE), MP_ROM_PTR(&machine_i2c_deinit) },
#define MICROPY_PY_MACHINE_I2C_SLAVE (1)
#define MICROPY_PY_MACHINE_SOFTI2C (1)

#define MICROPY_PY_MACHINE_SPI (1)
Expand Down

0 comments on commit f22fd15

Please sign in to comment.