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
5863e15a
Commit
5863e15a
authored
8 years ago
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
esp8266/modpybspi: Use generic SPI helper methods to implement SPI.
parent
0823c1ba
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
esp8266/modpybspi.c
+12
-54
12 additions, 54 deletions
esp8266/modpybspi.c
esp8266/mpconfigport.h
+1
-0
1 addition, 0 deletions
esp8266/mpconfigport.h
with
13 additions
and
54 deletions
esp8266/modpybspi.c
+
12
−
54
View file @
5863e15a
...
@@ -35,6 +35,7 @@
...
@@ -35,6 +35,7 @@
#include
"py/runtime.h"
#include
"py/runtime.h"
#include
"py/stream.h"
#include
"py/stream.h"
#include
"py/mphal.h"
#include
"py/mphal.h"
#include
"extmod/machine_spi.h"
typedef
struct
_pyb_spi_obj_t
{
typedef
struct
_pyb_spi_obj_t
{
mp_obj_base_t
base
;
mp_obj_base_t
base
;
...
@@ -46,7 +47,8 @@ typedef struct _pyb_spi_obj_t {
...
@@ -46,7 +47,8 @@ typedef struct _pyb_spi_obj_t {
mp_hal_pin_obj_t
miso
;
mp_hal_pin_obj_t
miso
;
}
pyb_spi_obj_t
;
}
pyb_spi_obj_t
;
STATIC
void
mp_hal_spi_transfer
(
pyb_spi_obj_t
*
self
,
size_t
src_len
,
const
uint8_t
*
src_buf
,
size_t
dest_len
,
uint8_t
*
dest_buf
)
{
STATIC
void
mp_hal_spi_transfer
(
mp_obj_base_t
*
self_in
,
size_t
src_len
,
const
uint8_t
*
src_buf
,
size_t
dest_len
,
uint8_t
*
dest_buf
)
{
pyb_spi_obj_t
*
self
=
(
pyb_spi_obj_t
*
)
self_in
;
// only MSB transfer is implemented
// only MSB transfer is implemented
uint32_t
delay_half
=
500000
/
self
->
baudrate
+
1
;
uint32_t
delay_half
=
500000
/
self
->
baudrate
+
1
;
for
(
size_t
i
=
0
;
i
<
src_len
||
i
<
dest_len
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
src_len
||
i
<
dest_len
;
++
i
)
{
...
@@ -154,69 +156,25 @@ STATIC mp_obj_t pyb_spi_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_a
...
@@ -154,69 +156,25 @@ STATIC mp_obj_t pyb_spi_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_a
}
}
MP_DEFINE_CONST_FUN_OBJ_KW
(
pyb_spi_init_obj
,
1
,
pyb_spi_init
);
MP_DEFINE_CONST_FUN_OBJ_KW
(
pyb_spi_init_obj
,
1
,
pyb_spi_init
);
STATIC
mp_obj_t
pyb_spi_read
(
size_t
n_args
,
const
mp_obj_t
*
args
)
{
pyb_spi_obj_t
*
self
=
MP_OBJ_TO_PTR
(
args
[
0
]);
uint8_t
write_byte
=
0
;
if
(
n_args
==
3
)
{
write_byte
=
mp_obj_get_int
(
args
[
2
]);
}
vstr_t
vstr
;
vstr_init_len
(
&
vstr
,
mp_obj_get_int
(
args
[
1
]));
mp_hal_spi_transfer
(
self
,
1
,
&
write_byte
,
vstr
.
len
,
(
uint8_t
*
)
vstr
.
buf
);
return
mp_obj_new_str_from_vstr
(
&
mp_type_bytes
,
&
vstr
);
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
pyb_spi_read_obj
,
2
,
3
,
pyb_spi_read
);
STATIC
mp_obj_t
pyb_spi_readinto
(
size_t
n_args
,
const
mp_obj_t
*
args
)
{
pyb_spi_obj_t
*
self
=
MP_OBJ_TO_PTR
(
args
[
0
]);
mp_buffer_info_t
bufinfo
;
mp_get_buffer_raise
(
args
[
1
],
&
bufinfo
,
MP_BUFFER_WRITE
);
uint8_t
write_byte
=
0
;
if
(
n_args
==
3
)
{
write_byte
=
mp_obj_get_int
(
args
[
2
]);
}
mp_hal_spi_transfer
(
self
,
1
,
&
write_byte
,
bufinfo
.
len
,
(
uint8_t
*
)
bufinfo
.
buf
);
return
mp_const_none
;
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
pyb_spi_readinto_obj
,
2
,
3
,
pyb_spi_readinto
);
STATIC
mp_obj_t
pyb_spi_write
(
mp_obj_t
self_in
,
mp_obj_t
wr_buf_in
)
{
pyb_spi_obj_t
*
self
=
MP_OBJ_TO_PTR
(
self_in
);
mp_buffer_info_t
src_buf
;
mp_get_buffer_raise
(
wr_buf_in
,
&
src_buf
,
MP_BUFFER_READ
);
mp_hal_spi_transfer
(
self
,
src_buf
.
len
,
(
const
uint8_t
*
)
src_buf
.
buf
,
0
,
NULL
);
return
mp_const_none
;
}
MP_DEFINE_CONST_FUN_OBJ_2
(
pyb_spi_write_obj
,
pyb_spi_write
);
STATIC
mp_obj_t
pyb_spi_write_readinto
(
mp_obj_t
self_in
,
mp_obj_t
wr_buf_in
,
mp_obj_t
rd_buf_in
)
{
pyb_spi_obj_t
*
self
=
MP_OBJ_TO_PTR
(
self_in
);
mp_buffer_info_t
src_buf
;
mp_get_buffer_raise
(
wr_buf_in
,
&
src_buf
,
MP_BUFFER_READ
);
mp_buffer_info_t
dest_buf
;
mp_get_buffer_raise
(
rd_buf_in
,
&
dest_buf
,
MP_BUFFER_WRITE
);
if
(
src_buf
.
len
!=
dest_buf
.
len
)
{
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_type_ValueError
,
"buffers must be the same length"
));
}
mp_hal_spi_transfer
(
self
,
src_buf
.
len
,
(
const
uint8_t
*
)
src_buf
.
buf
,
dest_buf
.
len
,
(
uint8_t
*
)
dest_buf
.
buf
);
return
mp_const_none
;
}
MP_DEFINE_CONST_FUN_OBJ_3
(
pyb_spi_write_readinto_obj
,
pyb_spi_write_readinto
);
STATIC
const
mp_rom_map_elem_t
pyb_spi_locals_dict_table
[]
=
{
STATIC
const
mp_rom_map_elem_t
pyb_spi_locals_dict_table
[]
=
{
{
MP_ROM_QSTR
(
MP_QSTR_init
),
MP_ROM_PTR
(
&
pyb_spi_init_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_init
),
MP_ROM_PTR
(
&
pyb_spi_init_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_read
),
MP_ROM_PTR
(
&
pyb
_spi_read_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_read
),
MP_ROM_PTR
(
&
mp_machine
_spi_read_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_readinto
),
MP_ROM_PTR
(
&
pyb
_spi_readinto_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_readinto
),
MP_ROM_PTR
(
&
mp_machine
_spi_readinto_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_write
),
MP_ROM_PTR
(
&
pyb
_spi_write_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_write
),
MP_ROM_PTR
(
&
mp_machine
_spi_write_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_write_readinto
),
MP_ROM_PTR
(
&
pyb
_spi_write_readinto_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_write_readinto
),
MP_ROM_PTR
(
&
mp_machine
_spi_write_readinto_obj
)
},
};
};
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
=
mp_hal_spi_transfer
,
};
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_SoftSPI
,
.
name
=
MP_QSTR_SoftSPI
,
.
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_dict_t
*
)
&
pyb_spi_locals_dict
,
.
locals_dict
=
(
mp_obj_dict_t
*
)
&
pyb_spi_locals_dict
,
};
};
This diff is collapsed.
Click to expand it.
esp8266/mpconfigport.h
+
1
−
0
View file @
5863e15a
...
@@ -63,6 +63,7 @@
...
@@ -63,6 +63,7 @@
#define MICROPY_PY_MACHINE (1)
#define MICROPY_PY_MACHINE (1)
#define MICROPY_PY_MACHINE_PULSE (1)
#define MICROPY_PY_MACHINE_PULSE (1)
#define MICROPY_PY_MACHINE_I2C (1)
#define MICROPY_PY_MACHINE_I2C (1)
#define MICROPY_PY_MACHINE_SPI (1)
#define MICROPY_PY_WEBSOCKET (1)
#define MICROPY_PY_WEBSOCKET (1)
#define MICROPY_PY_WEBREPL (1)
#define MICROPY_PY_WEBREPL (1)
#define MICROPY_PY_WEBREPL_DELAY (20)
#define MICROPY_PY_WEBREPL_DELAY (20)
...
...
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