Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
70446f46
Commit
70446f46
authored
May 27, 2015
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
stmhal: Allow to name SPI busses, and give them names for pyboard.
parent
0e6f5e08
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
stmhal/boards/PYBV10/mpconfigboard.h
+4
-0
4 additions, 0 deletions
stmhal/boards/PYBV10/mpconfigboard.h
stmhal/boards/PYBV4/mpconfigboard.h
+4
-0
4 additions, 0 deletions
stmhal/boards/PYBV4/mpconfigboard.h
stmhal/spi.c
+29
-8
29 additions, 8 deletions
stmhal/spi.c
with
37 additions
and
8 deletions
stmhal/boards/PYBV10/mpconfigboard.h
+
4
−
0
View file @
70446f46
...
@@ -54,6 +54,10 @@
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
stmhal/boards/PYBV4/mpconfigboard.h
+
4
−
0
View file @
70446f46
...
@@ -54,6 +54,10 @@
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
stmhal/spi.c
+
29
−
8
View file @
70446f46
...
@@ -325,7 +325,6 @@ STATIC const pyb_spi_obj_t pyb_spi_obj[] = {
...
@@ -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
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment