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
76a51b64
Commit
76a51b64
authored
Aug 28, 2019
by
fleur
Browse files
just a quick save, tons of stuff missing
parent
37da10f9
Changes
2
Hide whitespace changes
Inline
Side-by-side
epicardium/modules/buttons.c
View file @
76a51b64
...
...
@@ -4,14 +4,22 @@
#include
"portexpander.h"
#include
"MAX77650-Arduino-Library.h"
#include
"FreeRTOS.h"
#include
"timers.h"
#include
<stdint.h>
#define FREQ 100
static
const
uint8_t
pin_mask
[]
=
{
[
BUTTON_LEFT_BOTTOM
]
=
1
<<
5
,
[
BUTTON_RIGHT_BOTTOM
]
=
1
<<
3
,
[
BUTTON_RIGHT_TOP
]
=
1
<<
6
,
};
static
uint8_t
last
;
static
uint8_t
display_wake_mask
=
0xF
;
static
Timer_Handle_t
poll_timer
;
static
StaticTimer_t
poll_timer_buffer
;
uint8_t
epic_buttons_read
(
uint8_t
mask
)
{
...
...
@@ -43,3 +51,36 @@ uint8_t epic_buttons_read(uint8_t mask)
return
ret
;
}
static
void
CALLBACK_buttons
(){
last
=
epic_buttons_read
(
0xF
);
if
(
last
&
display_wake_mask
){
epic_disp_wake
();
}
}
void
epic_buttons_start
(){
if
(
!
poll_timer
)
{
poll_timer
=
xTimerCreateStatic
(
"buttons"
,
FREQ
,
pdTRUE
,
NULL
,
CALLBACK_buttons
,
&
poll_timer_buffer
);
}
}
void
epic_buttons_set_display_wake_mask
(
uint8_t
mask
){
display_wake_mask
=
mask
;
}
uint8_t
epic_buttons_get
(){
return
last
;
}
void
epic_buttons_stop
(){
if
(
!
poll_timer
||
xTimerIsTimerActive
(
poll_timer
)
==
pdFALSE
)
{
return
;
}
xTimerStop
(
poll_timer
,
0
);
}
epicardium/modules/display.c
View file @
76a51b64
...
...
@@ -8,8 +8,21 @@
#include
"task.h"
#include
"tmr.h"
#include
"tmr_utils.h"
#include
"FreeRTOS.h"
#include
"timers.h"
#define MAX_BRIGHTNESS 300
#define FREQ 100
static
TaskHandle_t
lock
=
NULL
;
static
TimerHandle_t
poll_timer
;
static
StaticTimer_t
poll_timer_buffer
;
static
bool
display_on
;
static
bool
wake_event
;
static
uint16_t
timeout_cycles
=
1000
;
static
uint8_t
lpf_speed
=
10
;
//ca. 1Hz f_g
static
uint8_t
brightness_table
[
MAX_BRIGHTNESS
];
static
int
check_lock
()
{
...
...
@@ -21,6 +34,76 @@ static int check_lock()
}
}
void
epic_disp_set_brightness_table
(
uint8_t
table
[
MAX_BRIGHTNESS
])
{
for
(
int
i
=
0
;
i
<
MAX_BRIGHTNESS
;
i
++
){
brightness_table
[
i
]
=
table
[
i
];
}
}
static
uint16_t
limit
(
uint16_t
input
,
uint16_t
max
,
uint16_t
min
){
uint16_t
output
=
input
>
max
?
max
:
input
;
return
output
<
0
?
0
:
output
;
}
static
uint16_t
lpf
(
uint16_t
input
,
uint8_t
speed
){
static
uint16_t
output
;
output
=
speed
*
input
+
(
~
speed
)
*
output
;
output
=
output
>>
8
;
return
output
;
}
static
void
auto_backlight
(){
uint16_t
light
=
0
;
if
(
display_on
){
epic_light_sensor_get
(
&
light
);
light
=
brightness_table
[
limit
(
light
,
MAX_BRIGHTNESS
-
1
,
0
)];
}
uint16_t
lpf_light
=
lpf
(
light
,
lpf_speed
);
lpf_light
=
limit
(
lpf_light
,
100
,
display_on
);
epic_disp_backlight
(
lpf_light
);
}
void
epic_disp_wake
(){
wake_event
=
true
;
}
static
void
CALLBACK_power_mgmt
(){
//u gotta loop dis
uint16_t
buttonTimeout
=
0
;
if
(
!
timeout_cycles
){
display_on
=
true
;
}
else
if
(
wake_event
){
buttonTimeout
=
timeout_cycles
;
display_on
=
true
;
wake_event
=
false
;
}
else
if
(
buttonTimeout
){
buttonTimeout
--
;
}
else
{
display_on
=
false
;
}
auto_backlight
();
}
void
epic_disp_backlight_auto_stop
()
{
if
(
!
poll_timer
||
xTimerIsTimerActive
(
poll_timer
)
==
pdFALSE
)
{
return
;
}
xTimerStop
(
poll_timer
,
0
);
}
void
epic_disp_backlight_auto
(){
if
(
!
poll_timer
)
{
poll_timer
=
xTimerCreateStatic
(
"auto_backlight"
,
FREQ
,
pdTRUE
,
NULL
,
CALLBACK_power_mgmt
,
&
poll_timer_buffer
);
}
}
int
epic_disp_print
(
uint16_t
posx
,
uint16_t
posy
,
...
...
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