1 |
// File: Power.h |
---|
2 |
//------------------------------------------------------------------------------ |
---|
3 |
// Author: Giovanni de Sanctis |
---|
4 |
// Email: info@lateral-technologies.com |
---|
5 |
//------------------------------------------------------------------------------ |
---|
6 |
// Date: Dec 2018 |
---|
7 |
// Pushbutton, onboard LEDs and other power related functions |
---|
8 |
//------------------------------------------------------------------------------ |
---|
9 |
|
---|
10 |
|
---|
11 |
|
---|
12 |
#ifndef POWER_H |
---|
13 |
#define POWER_H |
---|
14 |
|
---|
15 |
#include <stdint.h> |
---|
16 |
|
---|
17 |
#define ADC_BITS 10 //ADC's number of bits |
---|
18 |
#define VREF10 33 //Vref x 10 |
---|
19 |
|
---|
20 |
//Blink patterns for each function |
---|
21 |
//Power off |
---|
22 |
#define LED_RED_OFF 0x00000000 |
---|
23 |
//Power ON |
---|
24 |
#define LED_RED_ON 0x00010000 |
---|
25 |
//Unit switching off |
---|
26 |
#define LED_RED_ONOFF 0xAAAAAAAA |
---|
27 |
//Power ON, low battery |
---|
28 |
#define LED_RED_BATT 0xF000F000 |
---|
29 |
|
---|
30 |
//BT off |
---|
31 |
#define LED_BLUE_OFF 0x00000000 |
---|
32 |
//BT advertising |
---|
33 |
//#define LED_BLUE_ADVERT 0xF83E07C0 |
---|
34 |
#define LED_BLUE_ADVERT 0xFF00FF00 |
---|
35 |
//BT connected |
---|
36 |
#define LED_BLUE_CNNCTD 0x00000003 |
---|
37 |
|
---|
38 |
//RF receive |
---|
39 |
#define LED_BLUE_RFRX 0x55555555 |
---|
40 |
|
---|
41 |
#define LED_RED_On() IO_LED_RED_N_SetLow() |
---|
42 |
#define LED_RED_Off() IO_LED_RED_N_SetHigh() |
---|
43 |
#define LED_BLUE_On() IO_LED_BLUE_N_SetLow() |
---|
44 |
#define LED_BLUE_Off() IO_LED_BLUE_N_SetHigh() |
---|
45 |
|
---|
46 |
|
---|
47 |
//Called after reset to hold the LDO's enable pin high |
---|
48 |
//It also initialises all the power-related variables |
---|
49 |
void powerBootstrap(); |
---|
50 |
|
---|
51 |
//Sets flag to shut down the system |
---|
52 |
void shutDown(); |
---|
53 |
|
---|
54 |
//Manages the power button and returns 1 if pressed for >1 second |
---|
55 |
uint8_t checkPowerButton(); |
---|
56 |
|
---|
57 |
//Set the pattern for the LEDs (e.g. 0x00000000 off, 0x0F0F0F0F0F blink 0.4s on 0.4s off) |
---|
58 |
void setBluePattern(uint32_t pattern); |
---|
59 |
|
---|
60 |
//Returns the battery voltage in fractions of 2.048V, i.e. 0x00=0V, 0xFF=2V |
---|
61 |
//the lsb indicates wheather the voltage is above a set threshold THR_BATT |
---|
62 |
//if lsb=0 then the voltage is below the threshold. |
---|
63 |
//The battery voltage depends on the voltage divider between battery and ADC in. |
---|
64 |
uint16_t getBatt(); |
---|
65 |
|
---|
66 |
//Returns the battery charge remaining, expressed in 'bars', from 0 to 4 |
---|
67 |
uint8_t getBattBars(); |
---|
68 |
|
---|
69 |
//Returns 1 if battery voltage is below threshold |
---|
70 |
uint8_t isBattLow(); |
---|
71 |
|
---|
72 |
//Waits 20mS (for servo timing) |
---|
73 |
void wait20ms(); |
---|
74 |
|
---|
75 |
#endif /* POWER_H */ |
---|
76 |
|
---|