85 lines
1.9 KiB
C
85 lines
1.9 KiB
C
/**
|
|
* Ds1302.h
|
|
*
|
|
* @version 1.0.3
|
|
* @author Rafa Couto <caligari@treboada.net>
|
|
* @license GNU Affero General Public License v3.0
|
|
* @see https://github.com/Treboada/Ds1302
|
|
*
|
|
* adapted for Pico by Ken Webb, 27 Oct 2022
|
|
*
|
|
* 31 Oct 2022
|
|
* I am using additional ideas and code on ds1302 Ram from :
|
|
* https://github.com/msparks/arduino-ds1302 Matt Sparks no license?
|
|
* "Arduino library for the DS1302 Real Time Clock chip"
|
|
* includes "Setting and accessing the 31 bytes of static RAM. Single-byte and multi-byte (burst) modes are supported."
|
|
*
|
|
*/
|
|
|
|
#ifndef _DS_1302_H
|
|
#define _DS_1302_H
|
|
|
|
#include "pico/stdlib.h"
|
|
#include "pins.h"
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
// the following defines are from Arduino.h
|
|
// these are needed in Ds1302.cpp
|
|
#define HIGH 0x1
|
|
#define LOW 0x0
|
|
|
|
typedef struct {
|
|
uint8_t year;
|
|
uint8_t month;
|
|
uint8_t day;
|
|
uint8_t hour;
|
|
uint8_t minute;
|
|
uint8_t second;
|
|
uint8_t dow;
|
|
} DateTime;
|
|
|
|
/**
|
|
* Months of year
|
|
*/
|
|
enum MONTH {
|
|
MONTH_JAN = 1,
|
|
MONTH_FEB = 2,
|
|
MONTH_MAR = 3,
|
|
MONTH_APR = 4,
|
|
MONTH_MAY = 5,
|
|
MONTH_JUN = 6,
|
|
MONTH_JUL = 7,
|
|
MONTH_AUG = 8,
|
|
MONTH_SET = 9,
|
|
MONTH_OCT = 10,
|
|
MONTH_NOV = 11,
|
|
MONTH_DEC = 12
|
|
};
|
|
|
|
/**
|
|
* Days of week
|
|
*/
|
|
enum DOW { DOW_MON = 1, DOW_TUE = 2, DOW_WED = 3, DOW_THU = 4, DOW_FRI = 5, DOW_SAT = 6, DOW_SUN = 7 };
|
|
|
|
void ds1302_init();
|
|
int ds1302_is_clock_halted();
|
|
void ds1302_halt();
|
|
void ds1302_get_datetime(DateTime *dt);
|
|
void ds1302_set_datetime(DateTime *dt);
|
|
|
|
void ds1302_get_ram_byte(uint8_t addr, uint8_t *data);
|
|
void ds1302_set_ram_byte(uint8_t addr, uint8_t *data);
|
|
|
|
void ds1302_set_write_protection(int enable);
|
|
|
|
void ds1302_write_ram_bulk(const uint8_t *data, int len);
|
|
void ds1302_read_ram_bulk(uint8_t *data, int len);
|
|
|
|
inline uint8_t ds1302_encode_bcd(uint8_t dec) { return ((dec / 10 * 16) + (dec % 10)); }
|
|
|
|
inline uint8_t ds1302_decode_bcd(uint8_t bcd) { return ((bcd / 16 * 10) + (bcd % 16)); }
|
|
|
|
#endif // _DS_1302_H
|