summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/adc083x.h
blob: 9d7012a2b270cda34ad48a1fde4f12874c7d322e (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// license:BSD-3-Clause
// copyright-holders:smf
/***************************************************************************

    National Semiconductor ADC0831 / ADC0832 / ADC0834 / ADC0838

    8-Bit serial I/O A/D Converters with Muliplexer Options

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

#ifndef MAME_MACHINE_ADC083X_H
#define MAME_MACHINE_ADC083X_H

#pragma once


/***************************************************************************
    TYPE DEFINITIONS
***************************************************************************/

#define ADC083X_INPUT_CB(name)  double name(uint8_t input)

#define MCFG_ADC083X_INPUT_CB(_class, _method) \
	downcast<adc083x_device &>(*device).set_input_callback(adc083x_device::input_delegate(&_class::_method, #_class "::" #_method, this));

/***************************************************************************
    CONSTANTS
***************************************************************************/

#define ADC083X_CH0     0
#define ADC083X_CH1     1
#define ADC083X_CH2     2
#define ADC083X_CH3     3
#define ADC083X_CH4     4
#define ADC083X_CH5     5
#define ADC083X_CH6     6
#define ADC083X_CH7     7
#define ADC083X_COM     8
#define ADC083X_AGND    9
#define ADC083X_VREF    10

/***************************************************************************
    MACROS / CONSTANTS
***************************************************************************/

class adc083x_device : public device_t
{
public:
	typedef device_delegate<double (uint8_t input)> input_delegate;

	// configuration helpers
	template <typename Object> void set_input_callback(Object &&cb) { m_input_callback = std::forward<Object>(cb); }

	DECLARE_WRITE_LINE_MEMBER( cs_write );
	DECLARE_WRITE_LINE_MEMBER( clk_write );
	DECLARE_WRITE_LINE_MEMBER( di_write );
	DECLARE_WRITE_LINE_MEMBER( se_write );
	DECLARE_READ_LINE_MEMBER( sars_read );
	DECLARE_READ_LINE_MEMBER( do_read );

protected:
	adc083x_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock, uint32_t mux_bits);

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

	const int32_t m_mux_bits;

private:
	uint8_t conversion();

	void clear_sars();

	// internal state
	int32_t m_cs;
	int32_t m_clk;
	int32_t m_di;
	int32_t m_se;
	int32_t m_sars;
	int32_t m_do;
	int32_t m_sgl;
	int32_t m_odd;
	int32_t m_sel1;
	int32_t m_sel0;
	int32_t m_state;
	int32_t m_bit;
	int32_t m_output;

	input_delegate m_input_callback;
};


class adc0831_device : public adc083x_device
{
public:
	adc0831_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
};


class adc0832_device : public adc083x_device
{
public:
	adc0832_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
};


class adc0834_device : public adc083x_device
{
public:
	adc0834_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
};


class adc0838_device : public adc083x_device
{
public:
	adc0838_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
};


DECLARE_DEVICE_TYPE(ADC0831, adc0831_device)
DECLARE_DEVICE_TYPE(ADC0832, adc0832_device)
DECLARE_DEVICE_TYPE(ADC0834, adc0834_device)
DECLARE_DEVICE_TYPE(ADC0838, adc0838_device)

#endif // MAME_MACHINE_ADC083X_H