Move source code to firmware directory

This commit is contained in:
2020-11-13 11:18:21 +01:00
parent ed34a0a578
commit bc9ad5f8cc
13 changed files with 0 additions and 0 deletions

37
firmware/rtc.c Normal file
View File

@@ -0,0 +1,37 @@
#include <avr/io.h>
#include "rtc.h"
#include "i2c.h"
void rtc_int0_init(void)
{
INT0_DIR &= ~(1<<INT0_PIN);
INT0_PORT |= (1<<INT0_PIN);
GICR |= (1<<INT0);
}
void rtc_int1_init(void)
{
INT1_DIR &= ~(1<<INT1_PIN);
INT1_PORT |= (1<<INT1_PIN);
GICR |= (1<<INT1);
}
void rtc_set_time(uint8_t part, uint8_t value)
{
uint8_t bcd = DEC_2_BCD(value);
i2c_writebuf(RTC_I2C_ADDR, part, 1, &bcd);
}
struct time rtc_read_time(void)
{
uint8_t buffer[3];
i2c_readbuf(RTC_I2C_ADDR, 0x02, 3, buffer);
struct time curr_time = {
BCD_2_DEC(buffer[2]),
BCD_2_DEC(buffer[1]),
BCD_2_DEC(buffer[0])
};
return curr_time;
}