Skip to content

Commit 16d4236

Browse files
committed
stmhal/modmachine: Initial attempt to add I2C & SPI classes.
In new hardware API, these classes implement master modes of interfaces, and "mode" parameter is not accepted. Trying to implement new HW API in terms of older pyb module leaves variuos corner cases: In new HW API, I2C(1) means "I2C adafruit#1 in master mode" (? depends on interpretation), while in old API, it means "I2C adafruit#1, with no settings changes". For I2C class, it's easy to make mode optional, because that's last positional param, but for SPI, there's "baudrate" after it (which is inconsistent with I2C, which requires "baudrate" to be kwonly-arg).
1 parent 908f515 commit 16d4236

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

stmhal/i2c.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ STATIC void pyb_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki
349349
/// - `gencall` is whether to support general call mode
350350
STATIC mp_obj_t pyb_i2c_init_helper(const pyb_i2c_obj_t *self, mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
351351
static const mp_arg_t allowed_args[] = {
352-
{ MP_QSTR_mode, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} },
352+
{ MP_QSTR_mode, MP_ARG_INT, {.u_int = PYB_I2C_MASTER} },
353353
{ MP_QSTR_addr, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0x12} },
354354
{ MP_QSTR_baudrate, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = MICROPY_HW_I2C_BAUDRATE_DEFAULT} },
355355
{ MP_QSTR_gencall, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },

stmhal/modmachine.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
#include "pin.h"
4040
#include "timer.h"
4141
#include "usb.h"
42+
#include "i2c.h"
43+
#include "spi.h"
4244

4345
// machine.info([dump_alloc_table])
4446
// Print out lots of information about the board.
@@ -417,8 +419,12 @@ STATIC const mp_map_elem_t machine_module_globals_table[] = {
417419
#if 0
418420
{ MP_OBJ_NEW_QSTR(MP_QSTR_RTC), (mp_obj_t)&pyb_rtc_type },
419421
{ MP_OBJ_NEW_QSTR(MP_QSTR_ADC), (mp_obj_t)&pyb_adc_type },
422+
#endif
423+
// TODO: Per new API, both types below, if called with 1 arg (ID), should still
424+
// initialize master mode on the peripheral.
420425
{ MP_OBJ_NEW_QSTR(MP_QSTR_I2C), (mp_obj_t)&pyb_i2c_type },
421426
{ MP_OBJ_NEW_QSTR(MP_QSTR_SPI), (mp_obj_t)&pyb_spi_type },
427+
#if 0
422428
{ MP_OBJ_NEW_QSTR(MP_QSTR_UART), (mp_obj_t)&pyb_uart_type },
423429
{ MP_OBJ_NEW_QSTR(MP_QSTR_Timer), (mp_obj_t)&pyb_timer_type },
424430
{ MP_OBJ_NEW_QSTR(MP_QSTR_WDT), (mp_obj_t)&pyb_wdt_type },

0 commit comments

Comments
 (0)