Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
unl-ece-keychain
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
Service Desk
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pscalise2
unl-ece-keychain
Commits
714986ea
Commit
714986ea
authored
2 months ago
by
paulscalise1
Browse files
Options
Downloads
Patches
Plain Diff
added lptimer
parent
b537175c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main.c
+73
-5
73 additions, 5 deletions
src/main.c
with
73 additions
and
5 deletions
src/main.c
+
73
−
5
View file @
714986ea
...
@@ -14,10 +14,12 @@
...
@@ -14,10 +14,12 @@
I2C_HandleTypeDef
hi2c1
;
I2C_HandleTypeDef
hi2c1
;
EXTI_HandleTypeDef
hexti1
;
EXTI_HandleTypeDef
hexti1
;
EXTI_ConfigTypeDef
cexti1
;
EXTI_ConfigTypeDef
cexti1
;
LPTIM_HandleTypeDef
LPTIMConf
=
{
0
};
uint8_t
transmit
[
1025
];
uint8_t
transmit
[
1025
];
volatile
uint8_t
charge
=
0
;
// if device is charging, = 1
volatile
uint8_t
charge
=
0
;
// if device is charging, = 1
volatile
uint8_t
standby
=
0
;
// if device is on charger, but charging complete, = 1
volatile
uint8_t
standby
=
0
;
// if device is on charger, but charging complete, = 1
volatile
uint8_t
lptim_ovf
=
0
;
//0 if the lptimer has not overflowed (finished counting), 1 if so
void
APP_ErrorHandler
(
void
)
void
APP_ErrorHandler
(
void
)
{
{
...
@@ -107,6 +109,7 @@ static void APP_SystemClockConfig(void) // Setup HSI as 4MHz
...
@@ -107,6 +109,7 @@ static void APP_SystemClockConfig(void) // Setup HSI as 4MHz
{
{
RCC_OscInitTypeDef
RCC_OscInitStruct
=
{
0
};
RCC_OscInitTypeDef
RCC_OscInitStruct
=
{
0
};
RCC_ClkInitTypeDef
RCC_ClkInitStruct
=
{
0
};
RCC_ClkInitTypeDef
RCC_ClkInitStruct
=
{
0
};
RCC_PeriphCLKInitTypeDef
LPTIM_RCC
=
{
0
};
/* Oscillator Configuration */
/* Oscillator Configuration */
RCC_OscInitStruct
.
OscillatorType
=
RCC_OSCILLATORTYPE_HSE
|
RCC_OSCILLATORTYPE_HSI
|
RCC_OSCILLATORTYPE_LSI
|
RCC_OSCILLATORTYPE_LSE
;
/* Select oscillators HSE, HSI, LSI, LSE */
RCC_OscInitStruct
.
OscillatorType
=
RCC_OSCILLATORTYPE_HSE
|
RCC_OSCILLATORTYPE_HSI
|
RCC_OSCILLATORTYPE_LSI
|
RCC_OSCILLATORTYPE_LSE
;
/* Select oscillators HSE, HSI, LSI, LSE */
...
@@ -115,7 +118,7 @@ static void APP_SystemClockConfig(void) // Setup HSI as 4MHz
...
@@ -115,7 +118,7 @@ static void APP_SystemClockConfig(void) // Setup HSI as 4MHz
RCC_OscInitStruct
.
HSICalibrationValue
=
RCC_HSICALIBRATION_8MHz
;
/* Configure HSI clock as 8MHz */
RCC_OscInitStruct
.
HSICalibrationValue
=
RCC_HSICALIBRATION_8MHz
;
/* Configure HSI clock as 8MHz */
RCC_OscInitStruct
.
HSEState
=
RCC_HSE_OFF
;
/* Disable HSE */
RCC_OscInitStruct
.
HSEState
=
RCC_HSE_OFF
;
/* Disable HSE */
/*RCC_OscInitStruct.HSEFreq = RCC_HSE_16_32MHz;*/
/*RCC_OscInitStruct.HSEFreq = RCC_HSE_16_32MHz;*/
RCC_OscInitStruct
.
LSIState
=
RCC_LSI_O
FF
;
/
* Dis
able LSI
*/
RCC_OscInitStruct
.
LSIState
=
RCC_LSI_O
N
;
/
/ En
able LSI
for low power timer
RCC_OscInitStruct
.
LSEState
=
RCC_LSE_OFF
;
/* Disable LSE */
RCC_OscInitStruct
.
LSEState
=
RCC_LSE_OFF
;
/* Disable LSE */
/*RCC_OscInitStruct.LSEDriver = RCC_LSEDRIVE_MEDIUM;*/
/*RCC_OscInitStruct.LSEDriver = RCC_LSEDRIVE_MEDIUM;*/
RCC_OscInitStruct
.
PLL
.
PLLState
=
RCC_PLL_OFF
;
/* Disable PLL */
RCC_OscInitStruct
.
PLL
.
PLLState
=
RCC_PLL_OFF
;
/* Disable PLL */
...
@@ -136,6 +139,68 @@ static void APP_SystemClockConfig(void) // Setup HSI as 4MHz
...
@@ -136,6 +139,68 @@ static void APP_SystemClockConfig(void) // Setup HSI as 4MHz
{
{
APP_ErrorHandler
();
APP_ErrorHandler
();
}
}
/* LPTIM clock configuration */
LPTIM_RCC
.
PeriphClockSelection
=
RCC_PERIPHCLK_LPTIM
;
/* Select peripheral clock: LPTIM */
LPTIM_RCC
.
LptimClockSelection
=
RCC_LPTIMCLKSOURCE_LSI
;
/* Select LPTIM clock source: LSI */
/* Peripheral clock initialization */
if
(
HAL_RCCEx_PeriphCLKConfig
(
&
LPTIM_RCC
)
!=
HAL_OK
)
{
APP_ErrorHandler
();
}
// Enable LPTIM clock
__HAL_RCC_LPTIM_CLK_ENABLE
();
__HAL_RCC_PWR_CLK_ENABLE
();
// Enable the Power System Clock
}
static
void
LPTIMInit
(
void
)
{
/* LPTIM configuration */
LPTIMConf
.
Instance
=
LPTIM
;
/* LPTIM */
LPTIMConf
.
Init
.
Prescaler
=
LPTIM_PRESCALER_DIV128
;
/* Prescaler: 128 */
LPTIMConf
.
Init
.
UpdateMode
=
LPTIM_UPDATE_IMMEDIATE
;
/* Immediate update mode */
/* Initialize LPTIM */
if
(
HAL_LPTIM_Init
(
&
LPTIMConf
)
!=
HAL_OK
)
{
APP_ErrorHandler
();
}
}
static
void
LPTIMStart
(
uint32_t
count
)
{
// Restart lpTimer
__HAL_LPTIM_DISABLE
(
&
LPTIMConf
);
HAL_Delay
(
1
);
// Enable autoreload interrupt
__HAL_LPTIM_ENABLE_IT
(
&
LPTIMConf
,
LPTIM_IT_ARRM
);
// Enable LPTIM
__HAL_LPTIM_ENABLE
(
&
LPTIMConf
);
// Load autoreload value
__HAL_LPTIM_AUTORELOAD_SET
(
&
LPTIMConf
,
count
);
HAL_Delay
(
1
);
// Start single count mode
__HAL_LPTIM_START_SINGLE
(
&
LPTIMConf
);
}
void
LPTIM_Delay
(
uint32_t
millis
){
float
counts
=
millis
*
0
.
256
f
;
// With the understanding the prescaler is 128
LPTIMStart
((
uint32_t
)(
counts
+
0
.
5
f
));
HAL_SuspendTick
();
// Enter STOP mode
do
{
HAL_PWR_EnterSTOPMode
(
PWR_LOWPOWERREGULATOR_ON
,
PWR_STOPENTRY_WFI
);
}
while
(
lptim_ovf
==
0
);
// After waking up
HAL_ResumeTick
();
APP_SystemClockConfig
();
// Must reconfig the clock after waking up
lptim_ovf
=
0
;
// Reset global flag
}
void
HAL_LPTIM_AutoReloadMatchCallback
(
LPTIM_HandleTypeDef
*
hlptim
)
{
lptim_ovf
=
1
;
}
}
void
GPIO_Charger_EXTI_Init
(
void
){
void
GPIO_Charger_EXTI_Init
(
void
){
...
@@ -316,11 +381,13 @@ void Display_UNL_Info(){
...
@@ -316,11 +381,13 @@ void Display_UNL_Info(){
displayArray
(
flag
,
2
,
20
,
0
,
35
);
displayArray
(
flag
,
2
,
20
,
0
,
35
);
displayArray
(
pointers
,
2
,
8
,
1
,
17
);
displayArray
(
pointers
,
2
,
8
,
1
,
17
);
ssd1306_bitmap
((
const
uint8_t
*
)
dept
);
ssd1306_bitmap
((
const
uint8_t
*
)
dept
);
HAL_Delay
(
3000
);
//HAL_Delay(3000);
LPTIM_Delay
(
3000
);
displayArray
(
flag
,
2
,
20
,
0
,
35
);
displayArray
(
flag
,
2
,
20
,
0
,
35
);
displayArray
(
pointers
,
2
,
8
,
1
,
17
);
displayArray
(
pointers
,
2
,
8
,
1
,
17
);
ssd1306_bitmap
((
const
uint8_t
*
)
dept
);
ssd1306_bitmap
((
const
uint8_t
*
)
dept
);
HAL_Delay
(
3000
);
//HAL_Delay(3000);
LPTIM_Delay
(
3000
);
}
}
void
Sleep
(){
void
Sleep
(){
...
@@ -348,12 +415,13 @@ int main (void)
...
@@ -348,12 +415,13 @@ int main (void)
// Add check for charging after deivce died (interrupt missed)
// Add check for charging after deivce died (interrupt missed)
HAL_Init
();
HAL_Init
();
APP_SystemClockConfig
();
APP_SystemClockConfig
();
LPTIMInit
();
display_Switch_Init
();
// for new hw version
display_Switch_Init
();
// for new hw version
display_Power_On
();
display_Power_On
();
GPIO_Charger_EXTI_Init
();
GPIO_Charger_EXTI_Init
();
GPIO_I2C_Init
();
GPIO_I2C_Init
();
I2C_Init
();
I2C_Init
();
Accel_Init
();
//
Accel_Init();
EXTI_Init
();
EXTI_Init
();
LED_Init
();
LED_Init
();
ssd1306_init
();
ssd1306_init
();
...
@@ -363,6 +431,6 @@ int main (void)
...
@@ -363,6 +431,6 @@ int main (void)
// Add more frames here
// Add more frames here
Sleep
();
//
Sleep();
}
}
}
}
\ No newline at end of file
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