Skip to content

Commit

Permalink
ports/psoc6: Removed psoc6_i2c driver.
Browse files Browse the repository at this point in the history
Signed-off-by: enriquezgarc <enriquezgarcia.external@infineon.com>
  • Loading branch information
jaenrig-ifx committed Sep 6, 2023
1 parent 499cded commit 4a3327a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 75 deletions.
1 change: 0 additions & 1 deletion ports/psoc6/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ DRIVERS_SRC_C += $(addprefix drivers/,\

DRIVERS_SRC_C += $(addprefix drivers/,\
machine/psoc6_gpio.c \
machine/psoc6_i2c.c \
machine/psoc6_pwm.c \
machine/psoc6_system.c \
)
Expand Down
43 changes: 0 additions & 43 deletions ports/psoc6/drivers/machine/psoc6_i2c.c

This file was deleted.

29 changes: 0 additions & 29 deletions ports/psoc6/drivers/machine/psoc6_i2c.h

This file was deleted.

37 changes: 35 additions & 2 deletions ports/psoc6/modules/machine/machine_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,50 @@

// port-specific includes
#include "drivers/machine/psoc6_gpio.h"
#include "drivers/machine/psoc6_i2c.h"
#include "modmachine.h"
#include "mplogger.h"
#include "pins.h"


#define DEFAULT_I2C_FREQ (400000)
#define MICROPY_HW_I2C_SCL (CYBSP_I2C_SCL)
#define MICROPY_HW_I2C_SDA (CYBSP_I2C_SDA)
#define PSOC_I2C_MASTER_MODE (CYHAL_I2C_MODE_MASTER)

typedef struct _machine_i2c_obj_t {
mp_obj_base_t base;
cyhal_i2c_t i2c_obj;
uint8_t i2c_id;
uint8_t scl;
uint8_t sda;
uint32_t freq;
} machine_i2c_obj_t;

STATIC cy_rslt_t i2c_init(machine_i2c_obj_t *machine_i2c_obj) {
// free first in case object has been initialized before
cyhal_i2c_free(&machine_i2c_obj->i2c_obj);

// Define the I2C master configuration structure
cyhal_i2c_cfg_t i2c_master_config =
{
CYHAL_I2C_MODE_MASTER,
0, // address is not used for master mode
machine_i2c_obj->freq
};

// Initialize I2C master, set the SDA and SCL pins and assign a new clock
cy_rslt_t result = cyhal_i2c_init(&machine_i2c_obj->i2c_obj, machine_i2c_obj->sda, machine_i2c_obj->scl, NULL);

return result == CY_RSLT_SUCCESS ? cyhal_i2c_configure(&machine_i2c_obj->i2c_obj, &i2c_master_config)
: result;
}

STATIC cy_rslt_t i2c_read(cyhal_i2c_t *i2c_obj, uint16_t addr, uint8_t *buf, size_t len, uint32_t timeout, bool send_stop) {
return cyhal_i2c_master_read(i2c_obj, addr, buf, len, timeout, send_stop);
}

STATIC cy_rslt_t i2c_write(cyhal_i2c_t *i2c_obj, uint16_t addr, uint8_t *buf, size_t len, uint32_t timeout, bool send_stop) {
return cyhal_i2c_master_write(i2c_obj, addr, buf, len, timeout, send_stop);
}

extern mp_hal_pin_obj_t mp_hal_get_pin_obj(mp_obj_t obj);

Expand Down

0 comments on commit 4a3327a

Please sign in to comment.