Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
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
card10
firmware
Commits
92bb675a
Commit
92bb675a
authored
5 years ago
by
Stefan Haun
Browse files
Options
Downloads
Patches
Plain Diff
Add a py power module
parent
8272baa0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!177
Add a power module to access the PMIC values
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pycardium/modules/power.c
+114
-0
114 additions, 0 deletions
pycardium/modules/power.c
with
114 additions
and
0 deletions
pycardium/modules/power.c
0 → 100644
+
114
−
0
View file @
92bb675a
#include
"epicardium.h"
#include
"py/builtin.h"
#include
"py/obj.h"
#include
"py/runtime.h"
static
mp_obj_t
mp_power_read_battery_voltage
()
{
float
result
;
int
status
=
epic_read_battery_voltage
(
&
result
);
if
(
status
<
0
)
{
mp_raise_OSError
(
-
status
);
return
mp_const_none
;
}
return
mp_obj_new_float
(
result
);
}
static
MP_DEFINE_CONST_FUN_OBJ_0
(
power_read_battery_voltage_obj
,
mp_power_read_battery_voltage
);
static
mp_obj_t
mp_power_read_battery_current
()
{
float
result
;
int
status
=
epic_read_battery_current
(
&
result
);
if
(
status
<
0
)
{
mp_raise_OSError
(
-
status
);
return
mp_const_none
;
}
return
mp_obj_new_float
(
result
);
}
static
MP_DEFINE_CONST_FUN_OBJ_0
(
power_read_battery_current_obj
,
mp_power_read_battery_current
);
static
mp_obj_t
mp_power_read_chargein_voltage
()
{
float
result
;
int
status
=
epic_read_chargein_voltage
(
&
result
);
if
(
status
<
0
)
{
mp_raise_OSError
(
-
status
);
return
mp_const_none
;
}
return
mp_obj_new_float
(
result
);
}
static
MP_DEFINE_CONST_FUN_OBJ_0
(
power_read_chargein_voltage_obj
,
mp_power_read_chargein_voltage
);
static
mp_obj_t
mp_power_read_chargein_current
()
{
float
result
;
int
status
=
epic_read_chargein_current
(
&
result
);
if
(
status
<
0
)
{
mp_raise_OSError
(
-
status
);
return
mp_const_none
;
}
return
mp_obj_new_float
(
result
);
}
static
MP_DEFINE_CONST_FUN_OBJ_0
(
power_read_chargein_current_obj
,
mp_power_read_chargein_current
);
static
mp_obj_t
mp_power_read_system_voltage
()
{
float
result
;
int
status
=
epic_read_system_voltage
(
&
result
);
if
(
status
<
0
)
{
mp_raise_OSError
(
-
status
);
return
mp_const_none
;
}
return
mp_obj_new_float
(
result
);
}
static
MP_DEFINE_CONST_FUN_OBJ_0
(
power_read_system_voltage_obj
,
mp_power_read_system_voltage
);
static
mp_obj_t
mp_power_read_thermistor_voltage
()
{
float
result
;
int
status
=
epic_read_thermistor_voltage
(
&
result
);
if
(
status
<
0
)
{
mp_raise_OSError
(
-
status
);
return
mp_const_none
;
}
return
mp_obj_new_float
(
result
);
}
static
MP_DEFINE_CONST_FUN_OBJ_0
(
power_read_thermistor_voltage_obj
,
mp_power_read_thermistor_voltage
);
static
const
mp_rom_map_elem_t
power_module_globals_table
[]
=
{
{
MP_ROM_QSTR
(
MP_QSTR___name__
),
MP_ROM_QSTR
(
MP_QSTR_power
)
},
{
MP_ROM_QSTR
(
MP_QSTR_read_battery_voltage
),
MP_ROM_PTR
(
&
power_read_battery_voltage_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_read_battery_current
),
MP_ROM_PTR
(
&
power_read_battery_current_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_read_chargein_voltage
),
MP_ROM_PTR
(
&
power_read_chargein_voltage_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_read_chargein_current
),
MP_ROM_PTR
(
&
power_read_chargein_current_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_read_system_voltage
),
MP_ROM_PTR
(
&
power_read_system_voltage_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_read_thermistor_voltage
),
MP_ROM_PTR
(
&
power_read_thermistor_voltage_obj
)
},
};
static
MP_DEFINE_CONST_DICT
(
power_module_globals
,
power_module_globals_table
);
const
mp_obj_module_t
power_module
=
{
.
base
=
{
&
mp_type_module
},
.
globals
=
(
mp_obj_dict_t
*
)
&
power_module_globals
,
};
/* clang-format off */
MP_REGISTER_MODULE
(
MP_QSTR_power
,
power_module
,
MODULE_POWER_ENABLED
);
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