Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions ports/psoc-edge/boards/KIT_PSE84_AI/mpconfigboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,12 @@
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "KIT_PSE84_AI"

#define MICROPY_GC_HEAP_SIZE (315 * 1024) // 315 KB

// I2C Configuration
#define MICROPY_HW_I2C0_SCB (SCB5)
#define MICROPY_HW_I2C0_SCL (P17_0_NUM)
#define MICROPY_HW_I2C0_SDA (P17_1_NUM)
#define MAX_I2C 1
#define MICROPY_HW_I2C_INTR_PRIORITY (7UL)
#define MICROPY_HW_I2C_PCLK PCLK_SCB5_CLOCK_SCB_EN
#define MICROPY_HW_I2C_IRQn scb_5_interrupt_IRQn
11 changes: 5 additions & 6 deletions ports/psoc-edge/machine_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ static void machine_hw_i2c_init(machine_hw_i2c_obj_t *self, uint32_t freq_hz) {
// - clk_peri = 100 MHz, divider = 11 → clk_scb = 9.09 MHz ✓ (within range)
// Note: Cy_SysClk_PeriphSetDivider takes (divider - 1), so divider=11 → value=10
/* Connect assigned divider to be a clock source for I2C */
Cy_SysClk_PeriphAssignDivider(PCLK_SCB5_CLOCK_SCB_EN, CY_SYSCLK_DIV_8_BIT, 2U);
Cy_SysClk_PeriphAssignDivider(MICROPY_HW_I2C_PCLK, CY_SYSCLK_DIV_8_BIT, 2U);
uint32_t divider = (freq_hz <= 100000) ? 41U : 10U;
Cy_SysClk_PeriphSetDivider(CY_SYSCLK_DIV_8_BIT, 2U, divider);
Cy_SysClk_PeriphEnableDivider(CY_SYSCLK_DIV_8_BIT, 2U);
Expand All @@ -164,18 +164,17 @@ static void machine_hw_i2c_init(machine_hw_i2c_obj_t *self, uint32_t freq_hz) {

// 6. Configure interrupt (mandatory for I2C operation)
// Populate interrupt configuration structure
#define I2C_INTR_PRIORITY (7UL)
const cy_stc_sysint_t i2cIntrConfig = {
.intrSrc = scb_5_interrupt_IRQn,
.intrPriority = I2C_INTR_PRIORITY,
.intrSrc = MICROPY_HW_I2C_IRQn,
.intrPriority = MICROPY_HW_I2C_INTR_PRIORITY,
};

// Hook interrupt service routine and enable interrupt in NVIC
result = Cy_SysInt_Init(&i2cIntrConfig, &machine_i2c_isr);
if (result != CY_RSLT_SUCCESS) {
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("I2C interrupt init failed: 0x%lx"), result);
}
NVIC_EnableIRQ(scb_5_interrupt_IRQn);
NVIC_EnableIRQ(MICROPY_HW_I2C_IRQn);

// 7. Enable I2C operation
Cy_SCB_I2C_Enable(MICROPY_HW_I2C0_SCB);
Expand All @@ -195,7 +194,7 @@ static int machine_hw_i2c_deinit(mp_obj_base_t *self_in) {
Cy_SCB_I2C_Disable(MICROPY_HW_I2C0_SCB, &self->ctx);

// Disable interrupt in NVIC
NVIC_DisableIRQ(scb_5_interrupt_IRQn);
NVIC_DisableIRQ(MICROPY_HW_I2C_IRQn);

// Disable clock divider
Cy_SysClk_PeriphDisableDivider(CY_SYSCLK_DIV_8_BIT, 0U);
Expand Down
8 changes: 0 additions & 8 deletions ports/psoc-edge/machine_i2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@
#ifndef MICROPY_INCLUDED_PSOCEDGE_MACHINE_I2C_H
#define MICROPY_INCLUDED_PSOCEDGE_MACHINE_I2C_H

// Configure default I2C0 pins and SCB peripheral
#ifndef MICROPY_HW_I2C0_SCL
#define MICROPY_HW_I2C0_SCB (SCB5)
#define MICROPY_HW_I2C0_SCL (P17_0_NUM)
#define MICROPY_HW_I2C0_SDA (P17_1_NUM)
#define MAX_I2C 1
#endif

// Declare the I2C type for external use
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This declaration is already in extmod/modmachine.h declared. So if you include that file in you .c, this header for the time being is not required and can be deleted.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

valid point. I removed

extern const mp_obj_type_t machine_i2c_type;

Expand Down
Loading