-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatch.h
135 lines (116 loc) · 3 KB
/
watch.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
This is a header file to watch.h for the watch based on ATMega 328p chip communicating with a real time clock PCF8563
@ Hadato 2019_11_07
*/
#ifndef WATCH_H
#define WATCH_H
#include <avr/io.h>
#include <stdlib.h>
#include <avr/interrupt.h>
#include "twi.h"
#include <avr/sleep.h>
//Define a macro to write to the port - Prioritized for speed during writing
#define WRITE_PORT(port, val, mask) (port = (port & ~mask) | (val & mask))
enum State{
SHOW_TIME,
SHOW_DATE,
SHOW_BAT,
SET_SECONDS,
SET_MINUTES,
SET_HOURS,
SET_DAYS,
SET_MONTHS,
SET_YEARS,
GO_SLEEP,
AFTER_SLEEP
};
enum Pressed{
NOT,
SHORT,
LONG,
EX_LONG
};
enum adc_stat {
MEASURE_SUPPLY,
MEASURE_LIGHT
};
#define SHORT_PRESS 1
#define LONG_PRESS 100
#define EX_LONG_PRESS 400
#define LED_MASK 0b00000001
#define LED_ON 0b00000001
#define LED_OFF 0b11111110
#define BLINK_CNTR_MAX 260
#define ADMUX_ADC_VBG ((0 << REFS1)|(1 << REFS0)|(1 << MUX3)|(1 << MUX2)|(1 << MUX1)|(0 << MUX0))
#define ADMUX_ADC_LIGHT ((0 << REFS1)|(1 << REFS0)|(0 << MUX3)|(0 << MUX2)|(1 << MUX1)|(1 << MUX0))
namespace watch
{
//VARIABLES
extern Time time_DEC;
extern Time time_BCD;
extern Time time_DEC_new;
extern Time time_BCD_new;
extern uint8_t col;
extern uint16_t press_how_long;
extern uint8_t pressed;
extern State state;
extern float battery_level;
extern float u_supply;
extern uint16_t u_supply_sum;
extern float u_supply_show;
extern uint16_t blink_counter; //A counter for blinking function
extern bool blink; //Should the LEDs blink?
extern uint8_t error;
extern uint8_t light;
extern uint16_t light_sum;
extern adc_stat ACD_stat;
extern uint8_t adc_counter;
//TWI communication
extern twi Twi;
//FUNCTIONS
void init();
uint8_t multiplex(uint8_t);
void clear_LED();
void set_LED(uint8_t row, uint8_t column);
void set_all_pins_low_LED();
void show(uint8_t, Time, State);
void ISR_handler();
void write_port(volatile uint8_t *, uint8_t, uint8_t);
void sleep_init();
void timer1_init();
void timer2_init();
void button_init();
State state_machine(uint8_t, uint8_t);
void set_LED_intensity(uint8_t);
//Time set functions
void update_TimeDate();
uint8_t init_TimeDate();
uint8_t set_TimeDate(Time);
void increment_seconds();
void increment_minutes();
void increment_hours();
void increment_day();
void increment_month();
void increment_year();
//Time format change functions
uint8_t BCD2DEC(uint8_t, uint8_t);
uint8_t BCD2DEC(uint8_t);
uint8_t DEC2BCD(uint8_t);
//Communication with Arduino
void sentToArduino(uint8_t);
//ADC
void ADC_timer0_init();
void ADC_timer0_start();
void ADC_timer0_stop();
void ADC_init();
void ADC_enable();
void ADC_disable();
void ADC_start();
int ADC_get_light();
int ADC_get_supply_light();
//Power management
void PRR_disable_all();
void PRR_enable_ADC_Timer0();
void PRR_enable_ADC_Timers_TWI();
};
#endif