Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
fleur
firmware
Commits
0a1b82c3
Commit
0a1b82c3
authored
Aug 28, 2019
by
fleur
Browse files
pycardium, first tests, some fixes
parent
fe7d1182
Changes
7
Hide whitespace changes
Inline
Side-by-side
epicardium/modules/buttons.c
View file @
0a1b82c3
...
@@ -19,8 +19,8 @@ static uint8_t last = 0;
...
@@ -19,8 +19,8 @@ static uint8_t last = 0;
static
uint8_t
memory
=
0
;
static
uint8_t
memory
=
0
;
static
uint8_t
display_wake_mask
=
0xF
;
static
uint8_t
display_wake_mask
=
0xF
;
static
uint8_t
memory_mask
=
0xF
;
static
uint8_t
memory_mask
=
0xF
;
static
TimerHandle_t
poll
_timer
;
static
TimerHandle_t
button
_timer
;
static
StaticTimer_t
poll
_timer_buffer
;
static
StaticTimer_t
button
_timer_buffer
;
uint8_t
epic_buttons_read
(
uint8_t
mask
)
uint8_t
epic_buttons_read
(
uint8_t
mask
)
{
{
...
@@ -64,15 +64,16 @@ static void CALLBACK_buttons(){
...
@@ -64,15 +64,16 @@ static void CALLBACK_buttons(){
}
}
void
epic_buttons_start
(){
void
epic_buttons_start
(){
if
(
!
poll
_timer
)
{
if
(
!
button
_timer
)
{
poll
_timer
=
xTimerCreateStatic
(
button
_timer
=
xTimerCreateStatic
(
"buttons"
,
"buttons"
,
FREQ
,
FREQ
,
pdTRUE
,
pdTRUE
,
NULL
,
NULL
,
CALLBACK_buttons
,
CALLBACK_buttons
,
&
poll
_timer_buffer
&
button
_timer_buffer
);
);
xTimerStart
(
button_timer
,
0
);
}
}
}
}
...
@@ -81,15 +82,15 @@ void epic_buttons_set_display_wake_mask(uint8_t mask){
...
@@ -81,15 +82,15 @@ void epic_buttons_set_display_wake_mask(uint8_t mask){
}
}
uint8_t
epic_buttons_get
(
uint8_t
mask
){
uint8_t
epic_buttons_get
(
uint8_t
mask
){
if
(
!
poll
_timer
||
!
xTimerIsTimerActive
(
poll
_timer
))
{
if
(
!
button
_timer
||
!
xTimerIsTimerActive
(
button
_timer
))
{
return
-
ENODATA
;
return
-
ENODATA
;
}
}
return
last
&
mask
;
return
last
&
mask
;
}
}
void
epic_buttons_stop
(){
void
epic_buttons_stop
(){
if
(
!
poll
_timer
||
xTimerIsTimerActive
(
poll
_timer
)
==
pdFALSE
)
{
return
;
}
if
(
!
button
_timer
||
xTimerIsTimerActive
(
button
_timer
)
==
pdFALSE
)
{
return
;
}
xTimerStop
(
poll
_timer
,
0
);
xTimerStop
(
button
_timer
,
0
);
}
}
void
epic_buttons_reset_memory
(){
void
epic_buttons_reset_memory
(){
...
...
epicardium/modules/display.c
View file @
0a1b82c3
...
@@ -15,8 +15,8 @@
...
@@ -15,8 +15,8 @@
#define FREQ 100
#define FREQ 100
static
TaskHandle_t
lock
=
NULL
;
static
TaskHandle_t
lock
=
NULL
;
static
TimerHandle_t
poll
_timer
;
static
TimerHandle_t
display
_timer
;
static
StaticTimer_t
poll
_timer_buffer
;
static
StaticTimer_t
display
_timer_buffer
;
static
bool
display_on
;
static
bool
display_on
;
static
bool
wake_event
;
static
bool
wake_event
;
...
@@ -91,20 +91,21 @@ static void CALLBACK_power_mgmt(){ //u gotta loop dis
...
@@ -91,20 +91,21 @@ static void CALLBACK_power_mgmt(){ //u gotta loop dis
void
epic_disp_backlight_auto_stop
()
void
epic_disp_backlight_auto_stop
()
{
{
if
(
!
poll
_timer
||
xTimerIsTimerActive
(
poll
_timer
)
==
pdFALSE
)
{
return
;
}
if
(
!
display
_timer
||
xTimerIsTimerActive
(
display
_timer
)
==
pdFALSE
)
{
return
;
}
xTimerStop
(
poll
_timer
,
0
);
xTimerStop
(
display
_timer
,
0
);
}
}
void
epic_disp_backlight_auto_start
(){
void
epic_disp_backlight_auto_start
(){
if
(
!
poll
_timer
)
{
if
(
!
display
_timer
)
{
poll
_timer
=
xTimerCreateStatic
(
display
_timer
=
xTimerCreateStatic
(
"auto_backlight"
,
"auto_backlight"
,
FREQ
,
FREQ
,
pdTRUE
,
pdTRUE
,
NULL
,
NULL
,
CALLBACK_power_mgmt
,
CALLBACK_power_mgmt
,
&
poll
_timer_buffer
&
display
_timer_buffer
);
);
xTimerStart
(
display_timer
,
0
);
}
}
}
}
...
...
epicardium/modules/status.c
View file @
0a1b82c3
...
@@ -7,21 +7,22 @@
...
@@ -7,21 +7,22 @@
#include
"FreeRTOS.h"
#include
"FreeRTOS.h"
#include
"timers.h"
#include
"timers.h"
#include
<stdio.h>
#include
<stdint.h>
#include
<stdint.h>
#define POWERLED 10
#define POWERLED 10
#define FREQ 100
#define FREQ 100
#define PULSEWIDTH 2
#define PULSEWIDTH 2
#define PULSELENGTH 10
#define PULSELENGTH 10
static
uint8_t
power_status
=
0
;
// 0: discharging, 1: below 3.8V, 2: below 3.6V, 254: charging, 255: full and connected to charger
(or error) (yeah i know bad collision) (i'll fix this)
static
uint8_t
power_status
=
0
;
// 0: discharging, 1: below 3.8V, 2: below 3.6V, 254: charging, 255: full and connected to charger
, 128: charge error, 127: undefined
static
float
bat_volt
=
0
;
static
float
bat_volt
=
0
;
static
float
bat_cur
=
0
;
static
float
bat_cur
=
0
;
static
float
char_volt
=
0
;
static
float
char_volt
=
0
;
static
float
char_cur
=
0
;
static
float
char_cur
=
0
;
static
bool
power_led_on
=
true
;
static
bool
power_led_on
=
true
;
static
TimerHandle_t
poll
_timer
;
static
TimerHandle_t
status
_timer
;
static
StaticTimer_t
poll
_timer_buffer
;
static
StaticTimer_t
status
_timer_buffer
;
static
void
get_power_status
(){
static
void
get_power_status
(){
epic_read_battery_voltage
(
&
bat_volt
);
epic_read_battery_voltage
(
&
bat_volt
);
...
@@ -33,7 +34,11 @@ static void get_power_status(){
...
@@ -33,7 +34,11 @@ static void get_power_status(){
if
(
char_cur
>
0
.
1
){
if
(
char_cur
>
0
.
1
){
power_status
=
254
;
power_status
=
254
;
}
else
{
}
else
{
power_status
=
255
;
if
(
bat_volt
>
4
.
1
){
power_status
=
255
;
}
else
{
power_status
=
128
;
}
}
}
}
else
if
(
bat_volt
>
3
.
8
){
}
else
if
(
bat_volt
>
3
.
8
){
power_status
=
0
;
power_status
=
0
;
...
@@ -46,6 +51,10 @@ static void get_power_status(){
...
@@ -46,6 +51,10 @@ static void get_power_status(){
static
void
update_power_led
(){
static
void
update_power_led
(){
static
uint8_t
counter
=
0
;
static
uint8_t
counter
=
0
;
static
uint8_t
old_power_status
=
127
;
if
(
old_power_status
==
power_status
&&
power_status
!=
2
){
return
;
}
switch
(
power_status
){
switch
(
power_status
){
case
0
:
case
0
:
case
1
:
case
1
:
...
@@ -66,6 +75,7 @@ static void update_power_led(){
...
@@ -66,6 +75,7 @@ static void update_power_led(){
counter
++
;
counter
++
;
counter
=
counter
%
PULSELENGTH
;
counter
=
counter
%
PULSELENGTH
;
}
}
old_power_status
=
power_status
;
}
}
static
void
CALLBACK_led
(){
static
void
CALLBACK_led
(){
...
@@ -76,28 +86,29 @@ static void CALLBACK_led(){
...
@@ -76,28 +86,29 @@ static void CALLBACK_led(){
}
}
void
epic_status_start
(){
void
epic_status_start
(){
if
(
!
poll
_timer
)
{
if
(
!
status
_timer
)
{
poll
_timer
=
xTimerCreateStatic
(
status
_timer
=
xTimerCreateStatic
(
"status_led"
,
"status_led"
,
FREQ
,
FREQ
,
pdTRUE
,
pdTRUE
,
NULL
,
NULL
,
CALLBACK_led
,
CALLBACK_led
,
&
poll
_timer_buffer
&
status
_timer_buffer
);
);
xTimerStart
(
status_timer
,
0
);
}
}
}
}
uint8_t
epic_status_get_power_status
(){
uint8_t
epic_status_get_power_status
(){
if
(
!
poll
_timer
||
!
xTimerIsTimerActive
(
poll
_timer
))
{
if
(
!
status
_timer
||
!
xTimerIsTimerActive
(
status
_timer
))
{
return
-
ENODATA
;
return
-
ENODATA
;
}
}
return
power_status
;
return
power_status
;
}
}
void
epic_status_stop
(){
void
epic_status_stop
(){
if
(
!
poll
_timer
||
xTimerIsTimerActive
(
poll
_timer
)
==
pdFALSE
)
{
return
;
}
if
(
!
status
_timer
||
xTimerIsTimerActive
(
status
_timer
)
==
pdFALSE
)
{
return
;
}
xTimerStop
(
poll
_timer
,
0
);
xTimerStop
(
status
_timer
,
0
);
}
}
void
epic_status_power_led
(
bool
onoff
){
void
epic_status_power_led
(
bool
onoff
){
...
...
pycardium/meson.build
View file @
0a1b82c3
...
@@ -16,7 +16,8 @@ modsrc = files(
...
@@ -16,7 +16,8 @@ modsrc = files(
'modules/sys_display.c',
'modules/sys_display.c',
'modules/utime.c',
'modules/utime.c',
'modules/vibra.c',
'modules/vibra.c',
'modules/bme680.c'
'modules/bme680.c',
'modules/status.c'
)
)
#################################
#################################
...
...
pycardium/modules/qstrdefs.h
View file @
0a1b82c3
...
@@ -167,3 +167,11 @@ Q(COMMUNICATION)
...
@@ -167,3 +167,11 @@ Q(COMMUNICATION)
Q
(
CAMP
)
Q
(
CAMP
)
Q
(
MAX30001_ECG
)
Q
(
MAX30001_ECG
)
/* status */
Q
(
status
)
Q
(
start
)
Q
(
stop
)
Q
(
get_power_status
)
Q
(
power_led
)
pycardium/modules/status.c
0 → 100644
View file @
0a1b82c3
#include
"epicardium.h"
#include
"py/builtin.h"
#include
"py/obj.h"
#include
"py/runtime.h"
static
mp_obj_t
mp_status_start
()
{
epic_status_start
();
return
mp_const_none
;
}
static
MP_DEFINE_CONST_FUN_OBJ_0
(
status_start_obj
,
mp_status_start
);
static
mp_obj_t
mp_status_stop
()
{
epic_status_stop
();
return
mp_const_none
;
}
static
MP_DEFINE_CONST_FUN_OBJ_0
(
status_stop_obj
,
mp_status_stop
);
static
mp_obj_t
mp_status_get_power_status
()
{
int
status
=
epic_status_get_power_status
();
return
mp_obj_new_int
(
status
);
}
static
MP_DEFINE_CONST_FUN_OBJ_0
(
status_get_power_status_obj
,
mp_status_get_power_status
);
static
mp_obj_t
mp_status_power_led
(
mp_obj_t
on_in
)
{
int
on
=
mp_obj_get_int
(
on_in
);
epic_status_power_led
(
on
);
return
mp_const_none
;
}
static
MP_DEFINE_CONST_FUN_OBJ_1
(
status_power_led_obj
,
mp_status_power_led
);
static
const
mp_rom_map_elem_t
status_module_globals_table
[]
=
{
{
MP_ROM_QSTR
(
MP_QSTR___name__
),
MP_ROM_QSTR
(
MP_QSTR_status
)
},
{
MP_ROM_QSTR
(
MP_QSTR_start
),
MP_ROM_PTR
(
&
status_start_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_stop
),
MP_ROM_PTR
(
&
status_stop_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_get_power_status
),
MP_ROM_PTR
(
&
status_get_power_status_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_power_led
),
MP_ROM_PTR
(
&
status_power_led_obj
)
},
};
static
MP_DEFINE_CONST_DICT
(
status_module_globals
,
status_module_globals_table
);
const
mp_obj_module_t
status_module
=
{
.
base
=
{
&
mp_type_module
},
.
globals
=
(
mp_obj_dict_t
*
)
&
status_module_globals
,
};
/* clang-format off */
MP_REGISTER_MODULE
(
MP_QSTR_status
,
status_module
,
MODULE_STATUS_ENABLED
);
pycardium/mpconfigport.h
View file @
0a1b82c3
...
@@ -54,6 +54,7 @@ int mp_hal_trng_read_int(void);
...
@@ -54,6 +54,7 @@ int mp_hal_trng_read_int(void);
#define MODULE_LEDS_ENABLED (1)
#define MODULE_LEDS_ENABLED (1)
#define MODULE_LIGHT_SENSOR_ENABLED (1)
#define MODULE_LIGHT_SENSOR_ENABLED (1)
#define MODULE_MAX30001_ENABLED (1)
#define MODULE_MAX30001_ENABLED (1)
#define MODULE_STATUS_ENABLED (1)
#define MODULE_OS_ENABLED (1)
#define MODULE_OS_ENABLED (1)
#define MODULE_PERSONAL_STATE_ENABLED (1)
#define MODULE_PERSONAL_STATE_ENABLED (1)
#define MODULE_POWER_ENABLED (1)
#define MODULE_POWER_ENABLED (1)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment