summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/pcf8593.h
blob: ca9302594fb85f569e7cb017ab23c25aab9ea863 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// license:BSD-3-Clause
// copyright-holders:Tim Schuerewegen
/*********************************************************************

    Philips PCF8593 CMOS clock/calendar circuit

    (c) 2001-2007 Tim Schuerewegen

*********************************************************************/

#ifndef MAME_MACHINE_PCF8593_H
#define MAME_MACHINE_PCF8593_H

#pragma once

#include "dirtc.h"

// ======================> pcf8593_device

class pcf8593_device :  public device_t,
						public device_rtc_interface,
						public device_nvram_interface
{
public:
	pcf8593_device(const machine_config &mconfig, const char *tag, device_t *owner, const XTAL &clock = XTAL());

	DECLARE_WRITE_LINE_MEMBER(scl_w);
	DECLARE_WRITE_LINE_MEMBER(sda_w);
	DECLARE_READ_LINE_MEMBER(sda_r);

protected:
	// device-level overrides
	virtual void device_start() override;
	virtual void device_reset() override;

	// device_rtc_interface overrides
	virtual bool rtc_feature_y2k() const override { return true; }
	virtual void rtc_clock_updated(int year, int month, int day, int day_of_week, int hour, int minute, int second) override;

	// device_nvram_interface overrides
	virtual void nvram_default() override;
	virtual bool nvram_read(util::read_stream &file) override;
	virtual bool nvram_write(util::write_stream &file) override;

	TIMER_CALLBACK_MEMBER(clock_tick);

private:
	void clear_buffer_rx();

	// internal state
	uint8_t       m_data[16];
	int         m_pin_scl;
	int         m_pin_sda;
	int         m_inp;
	int         m_active;
	int         m_bits;
	uint8_t       m_data_recv_index;
	uint8_t       m_data_recv[50];
	uint8_t       m_mode;
	uint8_t       m_pos;
	emu_timer * m_timer;
	enum        { RTC_MODE_NONE, RTC_MODE_SEND, RTC_MODE_RECV };
};

// device type definition
DECLARE_DEVICE_TYPE(PCF8593, pcf8593_device)

#endif // MAME_MACHINE_PCF8593_H