Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
70446f46
Commit
70446f46
authored
May 27, 2015
by
Damien George
Browse files
stmhal: Allow to name SPI busses, and give them names for pyboard.
parent
0e6f5e08
Changes
3
Hide whitespace changes
Inline
Side-by-side
stmhal/boards/PYBV10/mpconfigboard.h
View file @
70446f46
...
...
@@ -54,6 +54,10 @@
#define MICROPY_HW_I2C2_SCL (pin_B10)
#define MICROPY_HW_I2C2_SDA (pin_B11)
// SPI busses
#define MICROPY_HW_SPI1_NAME "X"
#define MICROPY_HW_SPI2_NAME "Y"
// CAN busses
#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
...
...
stmhal/boards/PYBV4/mpconfigboard.h
View file @
70446f46
...
...
@@ -54,6 +54,10 @@
#define MICROPY_HW_I2C2_SCL (pin_B10)
#define MICROPY_HW_I2C2_SDA (pin_B11)
// SPI busses
#define MICROPY_HW_SPI1_NAME "X"
#define MICROPY_HW_SPI2_NAME "Y"
// CAN busses
#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
...
...
stmhal/spi.c
View file @
70446f46
...
...
@@ -325,7 +325,6 @@ STATIC const pyb_spi_obj_t pyb_spi_obj[] = {
{{
&
pyb_spi_type
},
NULL
},
#endif
};
#define PYB_NUM_SPI MP_ARRAY_SIZE(pyb_spi_obj)
SPI_HandleTypeDef
*
spi_get_handle
(
mp_obj_t
o
)
{
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
mp_arg_check_num
(
n_args
,
n_kw
,
1
,
MP_OBJ_FUN_ARGS_MAX
,
true
);
// get SPI number
mp_int_t
spi_id
=
mp_obj_get_int
(
args
[
0
])
-
1
;
// check SPI number
if
(
!
(
0
<=
spi_id
&&
spi_id
<
PYB_NUM_SPI
&&
pyb_spi_obj
[
spi_id
].
spi
!=
NULL
))
{
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_type_ValueError
,
"SPI bus %d does not exist"
,
spi_id
+
1
));
// work out SPI bus
int
spi_id
=
0
;
if
(
MP_OBJ_IS_STR
(
args
[
0
]))
{
const
char
*
port
=
mp_obj_str_get_str
(
args
[
0
]);
if
(
0
)
{
#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
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
)
{
// start the peripheral
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment