COSA
An Object-Oriented Platform for Arduino Programming
DS1307.cpp
Go to the documentation of this file.
1 
21 #include "DS1307.hh"
22 
23 int
24 DS1307::read(void* ram, uint8_t size, uint8_t pos)
25 {
26  twi.acquire(this);
27  twi.write(pos);
28  int count = twi.read(ram, size);
29  twi.release();
30  return (count);
31 }
32 
33 int
34 DS1307::write(void* ram, uint8_t size, uint8_t pos)
35 {
36  twi.acquire(this);
37  int count = twi.write(pos, ram, size);
38  twi.release();
39  if (count > 0) count -= 1;
40  return (count);
41 }
42 
43 
44 bool
46 {
47  control_t control;
48  control.rs = rs;
49  control.sqwe = 1;
50  control.out = 1;
51  uint8_t pos = offsetof(DS1307::timekeeper_t, control);
52  int count = write(&control, sizeof(control), pos);
53  return (count == sizeof(control));
54 }
55 
56 bool
58 {
59  control_t control;
60  uint8_t pos = offsetof(DS1307::timekeeper_t, control);
61  int count = write(&control, sizeof(control), pos);
62  return (count == sizeof(control));
63 }
64 
TWI twi
Definition: TWI.cpp:27
uint8_t rs
< Bitfield access.
Definition: DS1307.hh:58
Rate
Definition: DS1307.hh:86
uint8_t out
Output Control.
Definition: DS1307.hh:62
bool disable()
Definition: DS1307.cpp:57
bool enable(Rate rs=RS_1_HZ)
Definition: DS1307.cpp:45
void release()
Definition: TWI.cpp:58
int read(void *ram, uint8_t size=sizeof(time_t), uint8_t pos=0)
Definition: DS1307.cpp:24
int read(void *buf, size_t size)
Definition: TWI.hh:326
int write(void *buf, size_t size)
Definition: TWI.hh:282
void acquire(TWI::Driver *dev)
Definition: TWI.cpp:36
uint8_t sqwe
Square-Ware Enable.
Definition: DS1307.hh:60
int write(void *ram, uint8_t size=sizeof(time_t), uint8_t pos=0)
Definition: DS1307.cpp:34