RX8025 library

Dependents:   mbed_RX8025 MAPLEminiA MAPLEminiA

See https://developer.mbed.org/users/yasuyuki/notebook/RX8025/

Files at this revision

API Documentation at this revision

Comitter:
yasuyuki
Date:
Sat Nov 08 12:19:28 2014 +0000
Commit message:
release

Changed in this revision

RX8025.cpp Show annotated file Show diff for this revision Revisions of this file
RX8025.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 6da3d94a7774 RX8025.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RX8025.cpp	Sat Nov 08 12:19:28 2014 +0000
@@ -0,0 +1,139 @@
+//**********************
+// RX8025.cpp for mbed
+//
+// RX8025 rx8025(P0_5,P0_4);
+// or
+// I2C i2c(P0_5,P0_4);
+// RX8025 rx8025(i2c);
+//
+// (C)Copyright 2014 All rights reserved by Y.Onodera
+// http://einstlab.web.fc2.com
+//**********************
+
+#include "mbed.h"
+#include "RX8025.h"
+
+RX8025::RX8025 (PinName sda, PinName scl) : _i2c(sda, scl) {
+    init();
+}
+RX8025::RX8025 (I2C& p_i2c) : _i2c(p_i2c) {
+    init();
+}
+
+void RX8025::put(unsigned char a, unsigned char b)
+{
+    wait_us(100);   // wait 62us
+    buf[0]=a;
+    buf[1]=b;
+    _i2c.write(RX8025_ADDR, buf, 2);
+}
+
+
+void RX8025::get(unsigned char a)
+{
+    wait_us(100);   // wait 62us
+    buf[0] = a;
+    _i2c.write(RX8025_ADDR, buf, 1, true); // no stop, repeated
+    _i2c.read( RX8025_ADDR, buf, 1);
+
+}
+
+
+Times RX8025::getTIME()
+{
+    get(RX8025_SECONDS);
+    time.seconds=buf[0];
+    get(RX8025_MINUTES);
+    time.minutes=buf[0];
+    get(RX8025_HOURS);
+    time.hours=buf[0];
+    get(RX8025_WEEKDAYS);
+    time.weekdays=buf[0];
+    get(RX8025_DAYS);
+    time.days=buf[0];
+    get(RX8025_MONTHS);
+    time.months=buf[0];
+    get(RX8025_YEARS);
+    time.years=buf[0];
+    return time;
+}
+
+
+void RX8025::setTIME(Times t)
+{
+    put(RX8025_SECONDS, t.seconds);
+    put(RX8025_MINUTES, t.minutes);
+    put(RX8025_HOURS, t.hours);
+    put(RX8025_WEEKDAYS, t.weekdays);
+    put(RX8025_DAYS, t.days);
+    put(RX8025_MONTHS, t.months);
+    put(RX8025_YEARS, t.years);
+}
+
+
+Alarmw RX8025::getALARMw()
+{
+    get(RX8025_ALARM_W_M);
+    alarmw.minute=buf[0];
+    get(RX8025_ALARM_W_H);
+    alarmw.hour=buf[0];
+    get(RX8025_ALARM_W_W);
+    alarmw.weekday=buf[0];
+    return alarmw;
+}
+
+
+void RX8025::setALARMw(Alarmw a)
+{
+    put(RX8025_ALARM_W_M, a.minute);
+    put(RX8025_ALARM_W_H, a.hour);
+    put(RX8025_ALARM_W_W, a.weekday);
+}
+
+
+Alarmd RX8025::getALARMd()
+{
+    get(RX8025_ALARM_D_M);
+    alarmd.minute=buf[0];
+    get(RX8025_ALARM_D_H);
+    alarmd.hour=buf[0];
+    return alarmd;
+}
+
+
+void RX8025::setALARMd(Alarmd a)
+{
+    put(RX8025_ALARM_D_M, a.minute);
+    put(RX8025_ALARM_D_H, a.hour);
+}
+
+
+Control RX8025::getCONTROL()
+{
+    get(RX8025_CONTROL1);
+    control.control1=buf[0];
+    get(RX8025_CONTROL2);
+    control.control2=buf[0];
+    get(RX8025_OFFSET);
+    control.offset=buf[0];
+    return control;
+}
+
+
+void RX8025::setCONTROL(Control c)
+{
+    put(RX8025_CONTROL1, c.control1);
+    put(RX8025_CONTROL2, c.control2);
+    put(RX8025_OFFSET, c.offset);
+}
+
+
+void RX8025::init()
+{
+    control.control1=0x00;
+    control.control2=0x20;
+    control.offset=0x00;
+    setCONTROL(control);
+}
+
+
diff -r 000000000000 -r 6da3d94a7774 RX8025.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RX8025.h	Sat Nov 08 12:19:28 2014 +0000
@@ -0,0 +1,92 @@
+//**********************
+// RX8025.h for mbed
+//
+// (C)Copyright 2014 All rights reserved by Y.Onodera
+// http://einstlab.web.fc2.com
+//**********************
+
+#ifndef RX8025_H_
+#define RX8025_H_
+
+#define RX8025_ADDR                 0x64
+#define RX8025_SECONDS              0x00
+#define RX8025_MINUTES              0x10
+#define RX8025_HOURS                0x20
+#define RX8025_WEEKDAYS             0x30
+#define RX8025_DAYS                 0x40
+#define RX8025_MONTHS               0x50
+#define RX8025_YEARS                0x60
+#define RX8025_OFFSET               0x70
+#define RX8025_ALARM_W_M            0x80
+#define RX8025_ALARM_W_H            0x90
+#define RX8025_ALARM_W_W            0xA0
+#define RX8025_ALARM_D_M            0xB0
+#define RX8025_ALARM_D_H            0xC0
+#define RX8025_CONTROL1             0xE0
+#define RX8025_CONTROL2             0xF0
+
+#include "mbed.h"
+
+typedef struct {
+    unsigned char seconds;
+    unsigned char minutes;
+    unsigned char hours;
+    unsigned char weekdays;
+    unsigned char days;
+    unsigned char months;
+    unsigned char years;
+}Times;
+
+
+typedef struct {
+    unsigned char minute;
+    unsigned char hour;
+    unsigned char weekday;
+}Alarmw;
+
+
+typedef struct{
+    unsigned char minute;
+    unsigned char hour;
+}Alarmd;
+
+
+typedef struct{
+    unsigned char control1;
+    unsigned char control2;
+    unsigned char offset;
+}Control;
+
+
+class RX8025{
+public:
+    RX8025 (PinName sda, PinName scl);
+    RX8025 (I2C& p_i2c);
+    void init();
+
+    void put(unsigned char a, unsigned char b);
+    void get(unsigned char a);
+    Times getTIME();
+    void setTIME(Times t);
+    Alarmw getALARMw();
+    void setALARMw(Alarmw a);
+    Alarmd getALARMd();
+    void setALARMd(Alarmd a);
+    Control getCONTROL();
+    void setCONTROL(Control c);
+
+protected:
+    
+    I2C _i2c;
+
+    Times time;
+    Alarmw alarmw;
+    Alarmd alarmd;
+    Control control;
+    char buf[2];
+
+};
+
+#endif /* RX8025_H_ */
+
+