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
49406b0a
Commit
49406b0a
authored
Sep 1, 2016
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
stmhal/spi: Support new machine SPI methods in legacy SPI object.
parent
9b64d196
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
stmhal/mpconfigport.h
+1
-0
1 addition, 0 deletions
stmhal/mpconfigport.h
stmhal/spi.c
+24
-0
24 additions, 0 deletions
stmhal/spi.c
with
25 additions
and
0 deletions
stmhal/mpconfigport.h
+
1
−
0
View file @
49406b0a
...
@@ -93,6 +93,7 @@
...
@@ -93,6 +93,7 @@
#define MICROPY_PY_UHASHLIB (1)
#define MICROPY_PY_UHASHLIB (1)
#define MICROPY_PY_MACHINE (1)
#define MICROPY_PY_MACHINE (1)
#define MICROPY_PY_MACHINE_I2C (1)
#define MICROPY_PY_MACHINE_I2C (1)
#define MICROPY_PY_MACHINE_SPI (1)
#define MICROPY_PY_FRAMEBUF (1)
#define MICROPY_PY_FRAMEBUF (1)
#define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1)
#define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1)
...
...
This diff is collapsed.
Click to expand it.
stmhal/spi.c
+
24
−
0
View file @
49406b0a
...
@@ -30,6 +30,7 @@
...
@@ -30,6 +30,7 @@
#include
"py/nlr.h"
#include
"py/nlr.h"
#include
"py/runtime.h"
#include
"py/runtime.h"
#include
"py/mphal.h"
#include
"py/mphal.h"
#include
"extmod/machine_spi.h"
#include
"irq.h"
#include
"irq.h"
#include
"pin.h"
#include
"pin.h"
#include
"genhdr/pins.h"
#include
"genhdr/pins.h"
...
@@ -400,6 +401,17 @@ STATIC void spi_transfer(mp_obj_base_t *self_in, size_t src_len, const uint8_t *
...
@@ -400,6 +401,17 @@ STATIC void spi_transfer(mp_obj_base_t *self_in, size_t src_len, const uint8_t *
}
}
}
}
STATIC
void
spi_transfer_machine
(
mp_obj_base_t
*
self_in
,
size_t
src_len
,
const
uint8_t
*
src_buf
,
size_t
dest_len
,
uint8_t
*
dest_buf
)
{
if
(
src_len
==
1
&&
dest_len
>
1
)
{
// this catches read and readinto
// copy the single output byte to the dest buffer and use that as source
memset
(
dest_buf
,
src_buf
[
0
],
dest_len
);
src_len
=
dest_len
;
src_buf
=
dest_buf
;
}
spi_transfer
(
self_in
,
src_len
,
src_buf
,
dest_len
,
dest_buf
,
100
);
}
/******************************************************************************/
/******************************************************************************/
/* Micro Python bindings */
/* Micro Python bindings */
...
@@ -748,6 +760,13 @@ STATIC const mp_map_elem_t pyb_spi_locals_dict_table[] = {
...
@@ -748,6 +760,13 @@ STATIC const mp_map_elem_t pyb_spi_locals_dict_table[] = {
// instance methods
// instance methods
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_init
),
(
mp_obj_t
)
&
pyb_spi_init_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_init
),
(
mp_obj_t
)
&
pyb_spi_init_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_deinit
),
(
mp_obj_t
)
&
pyb_spi_deinit_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_deinit
),
(
mp_obj_t
)
&
pyb_spi_deinit_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_read
),
(
mp_obj_t
)
&
mp_machine_spi_read_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_readinto
),
(
mp_obj_t
)
&
mp_machine_spi_readinto_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_write
),
(
mp_obj_t
)
&
mp_machine_spi_write_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_write_readinto
),
(
mp_obj_t
)
&
mp_machine_spi_write_readinto_obj
},
// legacy methods
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_send
),
(
mp_obj_t
)
&
pyb_spi_send_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_send
),
(
mp_obj_t
)
&
pyb_spi_send_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_recv
),
(
mp_obj_t
)
&
pyb_spi_recv_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_recv
),
(
mp_obj_t
)
&
pyb_spi_recv_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_send_recv
),
(
mp_obj_t
)
&
pyb_spi_send_recv_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_send_recv
),
(
mp_obj_t
)
&
pyb_spi_send_recv_obj
},
...
@@ -773,10 +792,15 @@ STATIC const mp_map_elem_t pyb_spi_locals_dict_table[] = {
...
@@ -773,10 +792,15 @@ STATIC const mp_map_elem_t pyb_spi_locals_dict_table[] = {
STATIC
MP_DEFINE_CONST_DICT
(
pyb_spi_locals_dict
,
pyb_spi_locals_dict_table
);
STATIC
MP_DEFINE_CONST_DICT
(
pyb_spi_locals_dict
,
pyb_spi_locals_dict_table
);
STATIC
const
mp_machine_spi_p_t
pyb_spi_p
=
{
.
transfer
=
spi_transfer_machine
,
};
const
mp_obj_type_t
pyb_spi_type
=
{
const
mp_obj_type_t
pyb_spi_type
=
{
{
&
mp_type_type
},
{
&
mp_type_type
},
.
name
=
MP_QSTR_SPI
,
.
name
=
MP_QSTR_SPI
,
.
print
=
pyb_spi_print
,
.
print
=
pyb_spi_print
,
.
make_new
=
pyb_spi_make_new
,
.
make_new
=
pyb_spi_make_new
,
.
protocol
=
&
pyb_spi_p
,
.
locals_dict
=
(
mp_obj_t
)
&
pyb_spi_locals_dict
,
.
locals_dict
=
(
mp_obj_t
)
&
pyb_spi_locals_dict
,
};
};
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