COSA
An Object-Oriented Platform for Arduino Programming
MCP7940N Class Reference

#include <MCP7940N.hh>

Inheritance diagram for MCP7940N:
Inheritance graph
Collaboration diagram for MCP7940N:
Collaboration graph

Classes

struct  alarm_t
 
class  AlarmInterrupt
 
union  config_t
 
union  control_t
 
struct  rtcc_t
 
struct  timestamp_t
 

Public Types

enum  { SQW_1_HZ, SQW_4_096_KHZ, SQW_8_192_KHZ, SQW_32_768_KHZ }
 
enum  {
  WHEN_SEC_MATCH = 0x00, WHEN_MIN_MATCH = 0x01, WHEN_HOUR_MATCH = 0x02, WHEN_DAY_MATCH = 0x03,
  WHEN_DATE_MATCH = 0x04, WHEN_TIME_MATCH = 0x07
}
 

Public Member Functions

 MCP7940N (Board::ExternalInterruptPin pin=Board::EXT1)
 
bool get_time (time_t &now)
 
bool set_time (time_t &now)
 
bool set_alarm (uint8_t nr, time_t &alarm, uint8_t when)
 
bool get_alarm (uint8_t nr, time_t &alarm, uint8_t &when)
 
bool clear_alarm (uint8_t nr)
 
uint8_t pending_alarm ()
 
bool square_wave (bool flag)
 

Static Public Attributes

static const uint8_t RAM_START = sizeof(rtcc_t)
 
static const uint8_t RAM_END = 0x5f
 
static const uint8_t RAM_MAX = RAM_END - RAM_START + 1
 

Protected Member Functions

int read (void *regs, uint8_t size, uint8_t pos=0)
 
int write (void *regs, uint8_t size, uint8_t pos=0)
 

Protected Attributes

AlarmInterrupt m_alarm_irq
 

Private Member Functions

bool is_async () const
 
void sync_request ()
 
void async_request ()
 
virtual void on_completion (uint8_t type, int count)
 

Private Attributes

uint8_t m_addr
 
bool m_async
 

Detailed Description

Driver for the MCP7940N, Low-Cost I2C Real-Time Clock/Calendar (RTCC) with SRAM and Battery Switchover.

References

  1. Microchip MCP7940N data sheet; http://ww1.microchip.com/downloads/en/DeviceDoc/20005010F.pdf

Definition at line 37 of file MCP7940N.hh.

Member Enumeration Documentation

anonymous enum

Rate Selection in control register (rs, pp. 10).

Enumerator
SQW_1_HZ 

1 Hz

SQW_4_096_KHZ 

4.096 Hz

SQW_8_192_KHZ 

8.192 Hz

SQW_32_768_KHZ 

32.768 Hz

Definition at line 80 of file MCP7940N.hh.

anonymous enum

Alarm match types (pp. 10-11).

Enumerator
WHEN_SEC_MATCH 

Seconds match.

WHEN_MIN_MATCH 

Minutes match.

WHEN_HOUR_MATCH 

Hours match (takes into accout 12/24 hour).

WHEN_DAY_MATCH 

Matches the current Day.

WHEN_DATE_MATCH 

Date.

WHEN_TIME_MATCH 

Sec, Min, Hour, Day, Date, Month.

Definition at line 139 of file MCP7940N.hh.

Constructor & Destructor Documentation

MCP7940N::MCP7940N ( Board::ExternalInterruptPin  pin = Board::EXT1)
inline

Construct MCP7940N device with bus address(0x6f).

Parameters
[in]pinalarm interrupt pin (Default EXT1/EXT0).

Definition at line 210 of file MCP7940N.hh.

Member Function Documentation

bool MCP7940N::clear_alarm ( uint8_t  nr)

Clear given real-time clock alarm. Return true(1) if successful otherwise false(0).

Parameters
[in]nralarm number (0..1).
Returns
boolean.

Definition at line 146 of file MCP7940N.cpp.

bool MCP7940N::get_alarm ( uint8_t  nr,
time_t alarm,
uint8_t &  when 
)

Read given real-time clock alarm time and configuration. Return true(1) if successful otherwise false(0).

Parameters
[in]nralarm number (0..1).
[out]alarmtime structure.
[out]whenalarm should trigger.
Returns
boolean.

Definition at line 75 of file MCP7940N.cpp.

bool MCP7940N::get_time ( time_t now)

Read current time from real-time clock. Return true(1) if successful otherwise false(0).

Parameters
[out]nowtime structure return value.
Returns
boolean.

Definition at line 56 of file MCP7940N.cpp.

uint8_t MCP7940N::pending_alarm ( )

Check any pending alarms (signalled on interrupt pin). Returns alarm pending (0 for no alarms, 1 for alarm0, 2 for alarm1 and 3 for both)

Returns
alarm triggered or zero for no alarms pending.

Definition at line 124 of file MCP7940N.cpp.

int MCP7940N::read ( void *  regs,
uint8_t  size,
uint8_t  pos = 0 
)
protected

Read register block with the given size into the buffer from the position. Return number of bytes read or negative error code.

Parameters
[in]regsbuffer to read from register block.
[in]sizenumber of bytes to read.
[in]posaddress in register file to read from.
Returns
number of bytes or negative error code.

Definition at line 37 of file MCP7940N.cpp.

bool MCP7940N::set_alarm ( uint8_t  nr,
time_t alarm,
uint8_t  when 
)

Set given real-time clock alarm with the given time and configuration. Return true(1) if successful otherwise false(0).

Parameters
[in]nralarm number (0..1).
[in]alarmtime structure to set.
[in]whenalarm should trigger.
Returns
boolean.

Definition at line 93 of file MCP7940N.cpp.

bool MCP7940N::set_time ( time_t now)

Set the real-time clock to the given time. Return true(1) if successful otherwise false(0).

Parameters
[in]nowtime structure to set.
Returns
boolean.

Definition at line 66 of file MCP7940N.cpp.

bool MCP7940N::square_wave ( bool  flag)

Enable/disable square_wave generation.

Parameters
[in]flag.

Definition at line 165 of file MCP7940N.cpp.

int MCP7940N::write ( void *  regs,
uint8_t  size,
uint8_t  pos = 0 
)
protected

Write register block at given position with the contents from buffer. Return number of bytes written or negative error code.

Parameters
[in]regsbuffer to write to register block.
[in]sizenumber of bytes to write.
[in]posaddress in register file to read write to.
Returns
number of bytes or negative error code.

Definition at line 47 of file MCP7940N.cpp.

Member Data Documentation

AlarmInterrupt MCP7940N::m_alarm_irq
protected

Alarm Interrupt Pin

Definition at line 313 of file MCP7940N.hh.

const uint8_t MCP7940N::RAM_END = 0x5f
static

End of application RAM.

Definition at line 200 of file MCP7940N.hh.

const uint8_t MCP7940N::RAM_MAX = RAM_END - RAM_START + 1
static

Max size of application RAM (64 bytes).

Definition at line 203 of file MCP7940N.hh.

const uint8_t MCP7940N::RAM_START = sizeof(rtcc_t)
static

Start of application RAM.

Definition at line 197 of file MCP7940N.hh.


The documentation for this class was generated from the following files: