Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
flow3r firmware
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
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
flow3r
flow3r firmware
Commits
77d95395
Commit
77d95395
authored
1 year ago
by
q3k
Browse files
Options
Downloads
Patches
Plain Diff
flow3r_bsp/i2c: expose scan to micropython
parent
e52b5925
No related branches found
No related tags found
No related merge requests found
Pipeline
#5728
passed
1 year ago
Stage: build
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
components/flow3r_bsp/flow3r_bsp_i2c.c
+12
-2
12 additions, 2 deletions
components/flow3r_bsp/flow3r_bsp_i2c.c
components/flow3r_bsp/flow3r_bsp_i2c.h
+5
-1
5 additions, 1 deletion
components/flow3r_bsp/flow3r_bsp_i2c.h
usermodule/mp_hardware.c
+18
-0
18 additions, 0 deletions
usermodule/mp_hardware.c
with
35 additions
and
3 deletions
components/flow3r_bsp/flow3r_bsp_i2c.c
+
12
−
2
View file @
77d95395
...
@@ -5,6 +5,8 @@
...
@@ -5,6 +5,8 @@
#include
"freertos/semphr.h"
#include
"freertos/semphr.h"
#include
"esp_log.h"
#include
"esp_log.h"
#include
<string.h>
static
SemaphoreHandle_t
mutex
;
static
SemaphoreHandle_t
mutex
;
static
const
char
*
TAG
=
"flow3r-bsp-i2c"
;
static
const
char
*
TAG
=
"flow3r-bsp-i2c"
;
...
@@ -74,7 +76,7 @@ void flow3r_bsp_i2c_init(void) {
...
@@ -74,7 +76,7 @@ void flow3r_bsp_i2c_init(void) {
assert
(
i2c_param_config
(
I2C_NUM_0
,
&
i2c_conf
)
==
ESP_OK
);
assert
(
i2c_param_config
(
I2C_NUM_0
,
&
i2c_conf
)
==
ESP_OK
);
assert
(
i2c_driver_install
(
I2C_NUM_0
,
i2c_conf
.
mode
,
0
,
0
,
ESP_INTR_FLAG_LOWMED
|
ESP_INTR_FLAG_SHARED
)
==
ESP_OK
);
assert
(
i2c_driver_install
(
I2C_NUM_0
,
i2c_conf
.
mode
,
0
,
0
,
ESP_INTR_FLAG_LOWMED
|
ESP_INTR_FLAG_SHARED
)
==
ESP_OK
);
flow3r_bsp_i2c_scan
();
flow3r_bsp_i2c_scan
(
NULL
);
}
}
// Take I2C bus lock.
// Take I2C bus lock.
...
@@ -101,7 +103,10 @@ esp_err_t flow3r_bsp_i2c_write_read_device(uint8_t address, const uint8_t *write
...
@@ -101,7 +103,10 @@ esp_err_t flow3r_bsp_i2c_write_read_device(uint8_t address, const uint8_t *write
return
res
;
return
res
;
}
}
void
flow3r_bsp_i2c_scan
(
void
)
{
void
flow3r_bsp_i2c_scan
(
flow3r_bsp_i2c_scan_result_t
*
res
)
{
if
(
res
!=
NULL
)
{
memset
(
res
,
0
,
sizeof
(
flow3r_bsp_i2c_scan_result_t
));
}
ESP_LOGI
(
TAG
,
"Scan: starting..."
);
ESP_LOGI
(
TAG
,
"Scan: starting..."
);
for
(
uint8_t
i
=
1
;
i
<
127
;
i
++
)
{
for
(
uint8_t
i
=
1
;
i
<
127
;
i
++
)
{
i2c_cmd_handle_t
cmd
=
i2c_cmd_link_create
();
i2c_cmd_handle_t
cmd
=
i2c_cmd_link_create
();
...
@@ -112,6 +117,11 @@ void flow3r_bsp_i2c_scan(void) {
...
@@ -112,6 +117,11 @@ void flow3r_bsp_i2c_scan(void) {
i2c_cmd_link_delete
(
cmd
);
i2c_cmd_link_delete
(
cmd
);
if
(
ret
==
ESP_OK
)
{
if
(
ret
==
ESP_OK
)
{
ESP_LOGI
(
TAG
,
"Scan: detected %02x"
,
i
);
ESP_LOGI
(
TAG
,
"Scan: detected %02x"
,
i
);
if
(
res
!=
NULL
)
{
size_t
ix
=
i
/
32
;
size_t
offs
=
i
%
32
;
res
->
res
[
ix
]
|=
(
1
<<
offs
);
}
}
}
}
}
ESP_LOGI
(
TAG
,
"Scan: done."
);
ESP_LOGI
(
TAG
,
"Scan: done."
);
...
...
This diff is collapsed.
Click to expand it.
components/flow3r_bsp/flow3r_bsp_i2c.h
+
5
−
1
View file @
77d95395
...
@@ -37,4 +37,8 @@ esp_err_t flow3r_bsp_i2c_write_to_device(flow3r_i2c_address address, const uint8
...
@@ -37,4 +37,8 @@ esp_err_t flow3r_bsp_i2c_write_to_device(flow3r_i2c_address address, const uint8
// This can be called concurrently from different tassks.
// This can be called concurrently from different tassks.
esp_err_t
flow3r_bsp_i2c_write_read_device
(
flow3r_i2c_address
address
,
const
uint8_t
*
write_buffer
,
size_t
write_size
,
uint8_t
*
read_buffer
,
size_t
read_size
,
TickType_t
ticks_to_wait
);
esp_err_t
flow3r_bsp_i2c_write_read_device
(
flow3r_i2c_address
address
,
const
uint8_t
*
write_buffer
,
size_t
write_size
,
uint8_t
*
read_buffer
,
size_t
read_size
,
TickType_t
ticks_to_wait
);
void
flow3r_bsp_i2c_scan
(
void
);
typedef
struct
{
\ No newline at end of file
uint32_t
res
[
4
];
// Bitfield of addresses from 0 to 127.
}
flow3r_bsp_i2c_scan_result_t
;
void
flow3r_bsp_i2c_scan
(
flow3r_bsp_i2c_scan_result_t
*
res
);
\ No newline at end of file
This diff is collapsed.
Click to expand it.
usermodule/mp_hardware.c
+
18
−
0
View file @
77d95395
...
@@ -197,6 +197,23 @@ STATIC mp_obj_t mp_scope_draw(mp_obj_t ctx_in) {
...
@@ -197,6 +197,23 @@ STATIC mp_obj_t mp_scope_draw(mp_obj_t ctx_in) {
}
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
mp_scope_draw_obj
,
mp_scope_draw
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
mp_scope_draw_obj
,
mp_scope_draw
);
STATIC
mp_obj_t
mp_i2c_scan
(
void
)
{
flow3r_bsp_i2c_scan_result_t
scan
;
flow3r_bsp_i2c_scan
(
&
scan
);
mp_obj_t
res
=
mp_obj_new_list
(
0
,
NULL
);
for
(
int
i
=
0
;
i
<
127
;
i
++
)
{
size_t
ix
=
i
/
32
;
size_t
offs
=
i
%
32
;
if
(
scan
.
res
[
ix
]
&
(
1
<<
offs
))
{
mp_obj_list_append
(
res
,
mp_obj_new_int_from_uint
(
i
));
}
}
return
res
;
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_0
(
mp_i2c_scan_obj
,
mp_i2c_scan
);
STATIC
const
mp_rom_map_elem_t
mp_module_hardware_globals_table
[]
=
{
STATIC
const
mp_rom_map_elem_t
mp_module_hardware_globals_table
[]
=
{
{
MP_ROM_QSTR
(
MP_QSTR___name__
),
MP_ROM_QSTR
(
MP_QSTR_hardware
)
},
{
MP_ROM_QSTR
(
MP_QSTR___name__
),
MP_ROM_QSTR
(
MP_QSTR_hardware
)
},
...
@@ -224,6 +241,7 @@ STATIC const mp_rom_map_elem_t mp_module_hardware_globals_table[] = {
...
@@ -224,6 +241,7 @@ STATIC const mp_rom_map_elem_t mp_module_hardware_globals_table[] = {
{
MP_ROM_QSTR
(
MP_QSTR_display_set_backlight
),
MP_ROM_PTR
(
&
mp_display_set_backlight_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_display_set_backlight
),
MP_ROM_PTR
(
&
mp_display_set_backlight_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_version
),
MP_ROM_PTR
(
&
mp_version_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_version
),
MP_ROM_PTR
(
&
mp_version_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_get_ctx
),
MP_ROM_PTR
(
&
mp_get_ctx_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_get_ctx
),
MP_ROM_PTR
(
&
mp_get_ctx_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_i2c_scan
),
MP_ROM_PTR
(
&
mp_i2c_scan_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_BUTTON_PRESSED_LEFT
),
MP_ROM_INT
(
st3m_tripos_left
)
},
{
MP_ROM_QSTR
(
MP_QSTR_BUTTON_PRESSED_LEFT
),
MP_ROM_INT
(
st3m_tripos_left
)
},
{
MP_ROM_QSTR
(
MP_QSTR_BUTTON_PRESSED_RIGHT
),
MP_ROM_INT
(
st3m_tripos_right
)
},
{
MP_ROM_QSTR
(
MP_QSTR_BUTTON_PRESSED_RIGHT
),
MP_ROM_INT
(
st3m_tripos_right
)
},
...
...
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