stmhal: Allow to name SPI busses, and give them names for pyboard.
This commit is contained in:
parent
0e6f5e08e1
commit
70446f46c2
@ -54,6 +54,10 @@
|
|||||||
#define MICROPY_HW_I2C2_SCL (pin_B10)
|
#define MICROPY_HW_I2C2_SCL (pin_B10)
|
||||||
#define MICROPY_HW_I2C2_SDA (pin_B11)
|
#define MICROPY_HW_I2C2_SDA (pin_B11)
|
||||||
|
|
||||||
|
// SPI busses
|
||||||
|
#define MICROPY_HW_SPI1_NAME "X"
|
||||||
|
#define MICROPY_HW_SPI2_NAME "Y"
|
||||||
|
|
||||||
// CAN busses
|
// CAN busses
|
||||||
#define MICROPY_HW_CAN1_NAME "YA" // CAN1 on RX,TX = Y3,Y4 = PB8,PB9
|
#define MICROPY_HW_CAN1_NAME "YA" // CAN1 on RX,TX = Y3,Y4 = PB8,PB9
|
||||||
#define MICROPY_HW_CAN2_NAME "YB" // CAN2 on RX,TX = Y5,Y6 = PB12,PB13
|
#define MICROPY_HW_CAN2_NAME "YB" // CAN2 on RX,TX = Y5,Y6 = PB12,PB13
|
||||||
|
@ -54,6 +54,10 @@
|
|||||||
#define MICROPY_HW_I2C2_SCL (pin_B10)
|
#define MICROPY_HW_I2C2_SCL (pin_B10)
|
||||||
#define MICROPY_HW_I2C2_SDA (pin_B11)
|
#define MICROPY_HW_I2C2_SDA (pin_B11)
|
||||||
|
|
||||||
|
// SPI busses
|
||||||
|
#define MICROPY_HW_SPI1_NAME "X"
|
||||||
|
#define MICROPY_HW_SPI2_NAME "Y"
|
||||||
|
|
||||||
// CAN busses
|
// CAN busses
|
||||||
#define MICROPY_HW_CAN1_NAME "YA" // CAN1 on RX,TX = Y3,Y4 = PB8,PB9
|
#define MICROPY_HW_CAN1_NAME "YA" // CAN1 on RX,TX = Y3,Y4 = PB8,PB9
|
||||||
#define MICROPY_HW_CAN2_NAME "YB" // CAN2 on RX,TX = Y5,Y6 = PB12,PB13
|
#define MICROPY_HW_CAN2_NAME "YB" // CAN2 on RX,TX = Y5,Y6 = PB12,PB13
|
||||||
|
37
stmhal/spi.c
37
stmhal/spi.c
@ -325,7 +325,6 @@ STATIC const pyb_spi_obj_t pyb_spi_obj[] = {
|
|||||||
{{&pyb_spi_type}, NULL},
|
{{&pyb_spi_type}, NULL},
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
#define PYB_NUM_SPI MP_ARRAY_SIZE(pyb_spi_obj)
|
|
||||||
|
|
||||||
SPI_HandleTypeDef *spi_get_handle(mp_obj_t o) {
|
SPI_HandleTypeDef *spi_get_handle(mp_obj_t o) {
|
||||||
if (!MP_OBJ_IS_TYPE(o, &pyb_spi_type)) {
|
if (!MP_OBJ_IS_TYPE(o, &pyb_spi_type)) {
|
||||||
@ -462,16 +461,38 @@ STATIC mp_obj_t pyb_spi_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n
|
|||||||
// check arguments
|
// check arguments
|
||||||
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
|
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
|
||||||
|
|
||||||
// get SPI number
|
// work out SPI bus
|
||||||
mp_int_t spi_id = mp_obj_get_int(args[0]) - 1;
|
int spi_id = 0;
|
||||||
|
if (MP_OBJ_IS_STR(args[0])) {
|
||||||
// check SPI number
|
const char *port = mp_obj_str_get_str(args[0]);
|
||||||
if (!(0 <= spi_id && spi_id < PYB_NUM_SPI && pyb_spi_obj[spi_id].spi != NULL)) {
|
if (0) {
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "SPI bus %d does not exist", spi_id + 1));
|
#ifdef MICROPY_HW_SPI1_NAME
|
||||||
|
} else if (strcmp(port, MICROPY_HW_SPI1_NAME) == 0) {
|
||||||
|
spi_id = 1;
|
||||||
|
#endif
|
||||||
|
#ifdef MICROPY_HW_SPI2_NAME
|
||||||
|
} else if (strcmp(port, MICROPY_HW_SPI2_NAME) == 0) {
|
||||||
|
spi_id = 2;
|
||||||
|
#endif
|
||||||
|
#ifdef MICROPY_HW_SPI3_NAME
|
||||||
|
} else if (strcmp(port, MICROPY_HW_SPI3_NAME) == 0) {
|
||||||
|
spi_id = 3;
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
|
||||||
|
"SPI(%s) does not exist", port));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
spi_id = mp_obj_get_int(args[0]);
|
||||||
|
if (spi_id < 1 || spi_id > MP_ARRAY_SIZE(pyb_spi_obj)
|
||||||
|
|| pyb_spi_obj[spi_id].spi == NULL) {
|
||||||
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
|
||||||
|
"SPI(%d) does not exist", spi_id));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// get SPI object
|
// get SPI object
|
||||||
const pyb_spi_obj_t *spi_obj = &pyb_spi_obj[spi_id];
|
const pyb_spi_obj_t *spi_obj = &pyb_spi_obj[spi_id - 1];
|
||||||
|
|
||||||
if (n_args > 1 || n_kw > 0) {
|
if (n_args > 1 || n_kw > 0) {
|
||||||
// start the peripheral
|
// start the peripheral
|
||||||
|
Loading…
Reference in New Issue
Block a user