Skip to content

Commit 74a5426

Browse files
committed
debug and optimize i2c drivers
1 parent 19b9b8f commit 74a5426

9 files changed

Lines changed: 514 additions & 318 deletions

File tree

src/fw/board/boards/board_em_lb525.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,12 @@ IRQ_MAP(USART3, uart_irq_handler, DBG_UART);
7070
void DMAC1_CH1_IRQHandler(void) { HAL_DMA_IRQHandler(&s_dbg_uart_rx_dma_handle); }
7171

7272

73+
74+
75+
7376
I2CBusState i2c1_state;
7477
I2CBus i2c1 = {
75-
.hal = &i2c1_hal_obj,
78+
.hal = &i2c_hal_obj[0],
7679
.state = &i2c1_state,
7780
.scl_gpio =
7881
{
@@ -85,7 +88,12 @@ I2CBus i2c1 = {
8588
.name = "i2c1",
8689
};
8790

91+
struct I2CSlavePort i2c1_device = {
92+
.bus = &i2c1,
93+
.address = 0x38,
94+
};
8895

96+
8997
PwmState pwm2_1_state =
9098
{
9199
.channel = 1,

src/fw/board/boards/board_em_lb525.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ extern PwmConfig pwm2_ch1;
7070

7171
extern ADCInputConfig adc1_ch7;
7272
extern ADCInputConfig adc1_ch0;
73+
extern I2CBus i2c1;
74+
extern struct I2CSlavePort i2c1_device;
7375

7476

7577

src/fw/drivers/i2c.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ static void prv_bus_rail_power_down(I2CBus *bus) {
154154
//! Configure bus pins for use by I2C peripheral
155155
//! Lock bus and peripheral config access before configuring pins
156156
static void prv_bus_pins_cfg_i2c(I2CBus *bus) {
157-
#if MICRO_FAMILY_NRF5
157+
#if MICRO_FAMILY_NRF5 || defined(MICRO_FAMILY_SF32LB)
158158
i2c_hal_pins_set_i2c(bus);
159159
#else
160160
gpio_af_init(&bus->scl_gpio, GPIO_OType_OD, GPIO_Speed_50MHz, GPIO_PuPd_NOPULL);
@@ -265,12 +265,10 @@ void i2c_init(I2CBus *bus) {
265265
void i2c_use(I2CSlavePort *slave) {
266266
PBL_ASSERTN(slave);
267267
mutex_lock(slave->bus->state->bus_mutex);
268-
269268
if (slave->bus->state->user_count == 0) {
270269
prv_bus_enable(slave->bus);
271270
}
272271
slave->bus->state->user_count++;
273-
274272
mutex_unlock(slave->bus->state->bus_mutex);
275273
}
276274

@@ -618,3 +616,17 @@ void command_power_2v5(char *arg) {
618616
}
619617
}
620618
#endif
619+
620+
#ifdef MICRO_FAMILY_SF32LB
621+
void i2c_repear()
622+
{
623+
i2c_hal_repare();
624+
}
625+
void example_i2c(struct I2CSlavePort * i2c)
626+
{
627+
i2c_init(i2c->bus);
628+
i2c_use(i2c);
629+
i2c_release(i2c);
630+
}
631+
#endif
632+

src/fw/drivers/i2c.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,9 @@ bool i2c_write_register_block(I2CSlavePort *slave, uint8_t register_address_star
9595
//! @param buffer Pointer to source buffer
9696
//! @return true if transfer succeeded, false if error occurred
9797
bool i2c_write_block(I2CSlavePort *slave, uint32_t write_size, const uint8_t* buffer);
98+
99+
#ifdef MICRO_FAMILY_SF32LB
100+
extern void example_i2c(struct I2CSlavePort * i2c);
101+
extern void i2c_repear();
102+
#endif
103+

src/fw/drivers/i2c_hal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@ void i2c_hal_start_transfer(I2CBus *bus);
3838
void i2c_hal_pins_set_gpio(I2CBus *bus);
3939
void i2c_hal_pins_set_i2c(I2CBus *bus);
4040
#endif
41+
#ifdef MICRO_FAMILY_SF32LB
42+
void i2c_hal_repare();
43+
#endif

src/fw/drivers/sf32lb/adc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "board/board_sf32lb.h"
1212
#include "bf0_pin_const.h"
1313

14-
#define ADC_DEBUG 1
14+
//#define ADC_DEBUG 1
1515

1616
#ifdef hwp_gpadc1
1717
#define ADC1_CONFIG \

0 commit comments

Comments
 (0)