Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ports/psoc6: Removed psoc6_i2c driver. #83

Merged
merged 1 commit into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion ports/psoc6/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ DRIVERS_SRC_C += $(addprefix drivers/,\
)

DRIVERS_SRC_C += $(addprefix drivers/,\
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 @@ -14,17 +14,50 @@


// port-specific includes
#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
Loading