Browse Source

stm32: Rename legacy pyb.I2C helper functions to start with pyb_i2c_.

pull/3738/head
Damien George 7 years ago
parent
commit
0c54d0c288
  1. 2
      ports/stm32/accel.c
  2. 6
      ports/stm32/i2c.h
  3. 4
      ports/stm32/machine_i2c.c
  4. 20
      ports/stm32/pyb_i2c.c

2
ports/stm32/accel.c

@ -70,7 +70,7 @@ STATIC void accel_start(void) {
I2CHandle1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
I2CHandle1.Init.OwnAddress1 = PYB_I2C_MASTER_ADDRESS;
I2CHandle1.Init.OwnAddress2 = 0xfe; // unused
i2c_init(&I2CHandle1);
pyb_i2c_init(&I2CHandle1);
// turn off AVDD, wait 30ms, turn on AVDD, wait 30ms again
mp_hal_pin_low(MICROPY_HW_MMA_AVDD_PIN); // turn off

6
ports/stm32/i2c.h

@ -47,9 +47,9 @@ extern const mp_obj_type_t pyb_i2c_type;
extern const pyb_i2c_obj_t pyb_i2c_obj[4];
void i2c_init0(void);
void i2c_init(I2C_HandleTypeDef *i2c);
void i2c_init_freq(const pyb_i2c_obj_t *self, mp_int_t freq);
uint32_t i2c_get_baudrate(I2C_HandleTypeDef *i2c);
void pyb_i2c_init(I2C_HandleTypeDef *i2c);
void pyb_i2c_init_freq(const pyb_i2c_obj_t *self, mp_int_t freq);
uint32_t pyb_i2c_get_baudrate(I2C_HandleTypeDef *i2c);
void i2c_ev_irq_handler(mp_uint_t i2c_id);
void i2c_er_irq_handler(mp_uint_t i2c_id);

4
ports/stm32/machine_i2c.c

@ -87,13 +87,13 @@ STATIC void machine_hard_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp
machine_hard_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_printf(print, "I2C(%u, freq=%u, timeout=%u)",
self - &machine_hard_i2c_obj[0] + 1,
i2c_get_baudrate(self->pyb->i2c),
pyb_i2c_get_baudrate(self->pyb->i2c),
*self->timeout);
}
STATIC void machine_hard_i2c_init(const machine_hard_i2c_obj_t *self, uint32_t freq, uint32_t timeout) {
*self->timeout = timeout;
i2c_init_freq(self->pyb, freq);
pyb_i2c_init_freq(self->pyb, freq);
}
// this function is based on STM code

20
ports/stm32/pyb_i2c.c

@ -201,7 +201,7 @@ STATIC void i2c_set_baudrate(I2C_InitTypeDef *init, uint32_t baudrate) {
"Unsupported I2C baudrate: %lu", baudrate));
}
uint32_t i2c_get_baudrate(I2C_HandleTypeDef *i2c) {
uint32_t pyb_i2c_get_baudrate(I2C_HandleTypeDef *i2c) {
for (int i = 0; i < NUM_BAUDRATE_TIMINGS; i++) {
if (pyb_i2c_baudrate_timing[i].timing == i2c->Init.Timing) {
return pyb_i2c_baudrate_timing[i].baudrate;
@ -220,7 +220,7 @@ STATIC void i2c_set_baudrate(I2C_InitTypeDef *init, uint32_t baudrate) {
init->DutyCycle = I2C_DUTYCYCLE_16_9;
}
uint32_t i2c_get_baudrate(I2C_HandleTypeDef *i2c) {
uint32_t pyb_i2c_get_baudrate(I2C_HandleTypeDef *i2c) {
uint32_t pfreq = i2c->Instance->CR2 & 0x3f;
uint32_t ccr = i2c->Instance->CCR & 0xfff;
if (i2c->Instance->CCR & 0x8000) {
@ -251,7 +251,7 @@ void i2c_init0(void) {
#endif
}
void i2c_init(I2C_HandleTypeDef *i2c) {
void pyb_i2c_init(I2C_HandleTypeDef *i2c) {
int i2c_unit;
const pin_obj_t *scl_pin;
const pin_obj_t *sda_pin;
@ -372,7 +372,7 @@ void i2c_deinit(I2C_HandleTypeDef *i2c) {
}
}
void i2c_init_freq(const pyb_i2c_obj_t *self, mp_int_t freq) {
void pyb_i2c_init_freq(const pyb_i2c_obj_t *self, mp_int_t freq) {
I2C_InitTypeDef *init = &self->i2c->Init;
init->AddressingMode = I2C_ADDRESSINGMODE_7BIT;
@ -389,7 +389,7 @@ void i2c_init_freq(const pyb_i2c_obj_t *self, mp_int_t freq) {
// init the I2C bus
i2c_deinit(self->i2c);
i2c_init(self->i2c);
pyb_i2c_init(self->i2c);
}
STATIC void i2c_reset_after_error(I2C_HandleTypeDef *i2c) {
@ -403,7 +403,7 @@ STATIC void i2c_reset_after_error(I2C_HandleTypeDef *i2c) {
}
// bus was/is busy, need to reset the peripheral to get it to work again
i2c_deinit(i2c);
i2c_init(i2c);
pyb_i2c_init(i2c);
}
void i2c_ev_irq_handler(mp_uint_t i2c_id) {
@ -563,7 +563,7 @@ STATIC void pyb_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki
mp_printf(print, "I2C(%u)", i2c_num);
} else {
if (in_master_mode(self)) {
mp_printf(print, "I2C(%u, I2C.MASTER, baudrate=%u)", i2c_num, i2c_get_baudrate(self->i2c));
mp_printf(print, "I2C(%u, I2C.MASTER, baudrate=%u)", i2c_num, pyb_i2c_get_baudrate(self->i2c));
} else {
mp_printf(print, "I2C(%u, I2C.SLAVE, addr=0x%02x)", i2c_num, (self->i2c->Instance->OAR1 >> 1) & 0x7f);
}
@ -612,7 +612,7 @@ STATIC mp_obj_t pyb_i2c_init_helper(const pyb_i2c_obj_t *self, size_t n_args, co
// init the I2C bus
i2c_deinit(self->i2c);
i2c_init(self->i2c);
pyb_i2c_init(self->i2c);
return mp_const_none;
}
@ -680,10 +680,10 @@ STATIC mp_obj_t pyb_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_
return (mp_obj_t)i2c_obj;
}
STATIC mp_obj_t pyb_i2c_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
STATIC mp_obj_t pyb_i2c_init_(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
return pyb_i2c_init_helper(args[0], n_args - 1, args + 1, kw_args);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_init_obj, 1, pyb_i2c_init);
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_init_obj, 1, pyb_i2c_init_);
/// \method deinit()
/// Turn off the I2C bus.

Loading…
Cancel
Save