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
3b8c67ae
Verified
Commit
3b8c67ae
authored
5 years ago
by
rahix
Browse files
Options
Downloads
Patches
Plain Diff
feat(pmic): Implement AMUX reading
Signed-off-by:
Rahix
<
rahix@rahix.de
>
parent
562c6dc7
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
epicardium/modules/modules.h
+21
-3
21 additions, 3 deletions
epicardium/modules/modules.h
epicardium/modules/pmic.c
+62
-7
62 additions, 7 deletions
epicardium/modules/pmic.c
with
83 additions
and
10 deletions
epicardium/modules/modules.h
+
21
−
3
View file @
3b8c67ae
...
@@ -26,11 +26,29 @@ void vSerialTask(void *pvParameters);
...
@@ -26,11 +26,29 @@ void vSerialTask(void *pvParameters);
void
serial_enqueue_char
(
char
chr
);
void
serial_enqueue_char
(
char
chr
);
/* ---------- PMIC --------------------------------------------------------- */
/* ---------- PMIC --------------------------------------------------------- */
/* In 1/10s */
#define PMIC_PRESS_SLEEP 20
#define PMIC_PRESS_POWEROFF 40
void
vPmicTask
(
void
*
pvParameters
);
void
vPmicTask
(
void
*
pvParameters
);
enum
pmic_amux_signal
{
PMIC_AMUX_CHGIN_U
=
0x1
,
PMIC_AMUX_CHGIN_I
=
0x2
,
PMIC_AMUX_BATT_U
=
0x3
,
PMIC_AMUX_BATT_CHG_I
=
0x4
,
PMIC_AMUX_BATT_DIS_I
=
0x5
,
PMIC_AMUX_BATT_NULL_I
=
0x6
,
PMIC_AMUX_THM_U
=
0x7
,
PMIC_AMUX_TBIAS_U
=
0x8
,
PMIC_AMUX_AGND_U
=
0x9
,
PMIC_AMUX_SYS_U
=
0xA
,
_PMIC_AMUX_MAX
,
};
/*
* Read a value from the PMIC's AMUX. The result is already converted into its
* proper unit. See the MAX77650 datasheet for details.
*/
int
pmic_read_amux
(
enum
pmic_amux_signal
sig
,
float
*
result
);
/* ---------- BLE ---------------------------------------------------------- */
/* ---------- BLE ---------------------------------------------------------- */
void
ble_uart_write
(
uint8_t
*
pValue
,
uint8_t
len
);
void
ble_uart_write
(
uint8_t
*
pValue
,
uint8_t
len
);
...
...
This diff is collapsed.
Click to expand it.
epicardium/modules/pmic.c
+
62
−
7
View file @
3b8c67ae
#include
<stdio.h>
#include
"epicardium.h"
#include
"modules/modules.h"
#include
"modules/log.h"
#include
"max32665.h"
#include
"card10.h"
#include
"gcr_regs.h"
#include
"pmic.h"
#include
"pmic.h"
#include
"MAX77650-Arduino-Library.h"
#include
"MAX77650-Arduino-Library.h"
#include
"card10.h"
#include
"max32665.h"
#include
"mxc_sys.h"
#include
"mxc_pins.h"
#include
"adc.h"
#include
"FreeRTOS.h"
#include
"FreeRTOS.h"
#include
"task.h"
#include
"task.h"
#include
"epicardium.h"
#include
<stdio.h>
#include
"modules.h"
#include
"modules/log.h"
/* Task ID for the pmic handler */
/* Task ID for the pmic handler */
static
TaskHandle_t
pmic_task_id
=
NULL
;
static
TaskHandle_t
pmic_task_id
=
NULL
;
...
@@ -25,10 +28,62 @@ void pmic_interrupt_callback(void *_)
...
@@ -25,10 +28,62 @@ void pmic_interrupt_callback(void *_)
}
}
}
}
int
pmic_read_amux
(
enum
pmic_amux_signal
sig
,
float
*
result
)
{
int
ret
=
0
;
if
(
sig
>
_PMIC_AMUX_MAX
)
{
return
-
EINVAL
;
}
ret
=
hwlock_acquire
(
HWLOCK_ADC
,
pdMS_TO_TICKS
(
100
));
if
(
ret
<
0
)
{
return
ret
;
}
ret
=
hwlock_acquire
(
HWLOCK_I2C
,
pdMS_TO_TICKS
(
100
));
if
(
ret
<
0
)
{
return
ret
;
}
/* Select the correct channel for this measurement. */
MAX77650_setMUX_SEL
(
sig
);
uint16_t
adc_data
;
ADC_StartConvert
(
ADC_CH_0
,
0
,
0
);
ADC_GetData
(
&
adc_data
);
/* Turn MUX back to neutral so it does not waste power. */
MAX77650_setMUX_SEL
(
sig
);
/* Convert ADC measurement to SI Volts */
float
adc_voltage
=
(
float
)
adc_data
/
1023
.
0
f
*
1
.
22
f
;
/*
* Convert value according to PMIC formulas (Table 7)
*/
switch
(
sig
)
{
case
PMIC_AMUX_BATT_U
:
*
result
=
adc_voltage
/
0
.
272
f
;
break
;
case
PMIC_AMUX_SYS_U
:
*
result
=
adc_voltage
/
0
.
26
f
;
break
;
default:
ret
=
-
EINVAL
;
}
hwlock_release
(
HWLOCK_I2C
);
hwlock_release
(
HWLOCK_ADC
);
return
ret
;
}
void
vPmicTask
(
void
*
pvParameters
)
void
vPmicTask
(
void
*
pvParameters
)
{
{
pmic_task_id
=
xTaskGetCurrentTaskHandle
();
pmic_task_id
=
xTaskGetCurrentTaskHandle
();
ADC_Init
(
0x9
,
NULL
);
GPIO_Config
(
&
gpio_cfg_adc0
);
TickType_t
button_start_tick
=
0
;
TickType_t
button_start_tick
=
0
;
while
(
1
)
{
while
(
1
)
{
...
...
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