M devices/i2c/mcp7940n.c +15 -8
@@ 53,19 53,26 @@ static inline uint8_t mod10(uint8_t v)
*/
int mcp7940n_init(const struct tm *tm)
{
- struct mcp7940n_timekeeping_regs tmp;
+ uint8_t control;
+ uint8_t sec;
+ int ret;
- if (!mcp7940n_read(offsetof(struct mcp7940n, timekeeping), &tmp,
- sizeof(tmp)))
+ if (!mcp7940n_read(offsetof(struct mcp7940n, timekeeping.sec), &sec,
+ sizeof(sec)))
return -1;
- if (tmp.sec & MCP7940N_SEC_ST)
- return +1; /* already started, don't disturb the time */
+ if (sec & MCP7940N_SEC_ST) {
+ ret = +1; /* already running, don't disturb the time */
+ } else {
+ if (!mcp7940n_settime(tm))
+ return -1;
- if (!mcp7940n_settime(tm))
- return -1;
+ ret = 0; /* started just now */
+ }
- return 0;
+ /* ... initialize MFP here as desired ... */
+
+ return ret;
}
/*
M devices/i2c/mcp7940n.h +9 -0
@@ 66,6 66,15 @@ struct mcp7940n_alarm_regs {
uint8_t sec;
uint8_t min;
uint8_t hour;
+#define MCP7940N_ALARM_POLARITY_LOW (0 << 7)
+#define MCP7940N_ALARM_POLARITY_HIGH (1 << 7)
+#define MCP7940N_ALARM_MASK_SEC (0 << 4)
+#define MCP7940N_ALARM_MASK_MIN (1 << 4)
+#define MCP7940N_ALARM_MASK_HOUR (2 << 4)
+#define MCP7940N_ALARM_MASK_DOW (3 << 4)
+#define MCP7940N_ALARM_MASK_DATE (4 << 4)
+#define MCP7940N_ALARM_MASK_DATETIME (7 << 4)
+#define MCP7940N_ALARM_IF (1 << 3)
uint8_t wkday;
uint8_t date;
uint8_t month;