Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/genplus-gx/core/cart_hw/eeprom_i2c.h
2 views
1
/****************************************************************************
2
* Genesis Plus
3
* I2C Serial EEPROM (24Cxx) support
4
*
5
* Copyright (C) 2007-2013 Eke-Eke (Genesis Plus GX)
6
*
7
* Redistribution and use of this code or any derivative works are permitted
8
* provided that the following conditions are met:
9
*
10
* - Redistributions may not be sold, nor may they be used in a commercial
11
* product or activity.
12
*
13
* - Redistributions that are modified from the original source must include the
14
* complete source code, including the source code for all components used by a
15
* binary built from the modified sources. However, as a special exception, the
16
* source code distributed need not include anything that is normally distributed
17
* (in either source or binary form) with the major components (compiler, kernel,
18
* and so on) of the operating system on which the executable runs, unless that
19
* component itself accompanies the executable.
20
*
21
* - Redistributions must reproduce the above copyright notice, this list of
22
* conditions and the following disclaimer in the documentation and/or other
23
* materials provided with the distribution.
24
*
25
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35
* POSSIBILITY OF SUCH DAMAGE.
36
*
37
****************************************************************************************/
38
39
#ifndef _EEPROM_I2C_H_
40
#define _EEPROM_I2C_H_
41
42
typedef struct
43
{
44
uint8 address_bits; /* number of bits needed to address memory: 7, 8 or 16 */
45
uint16 size_mask; /* depends on the max size of the memory (in bytes) */
46
uint16 pagewrite_mask; /* depends on the maximal number of bytes that can be written in a single write cycle */
47
uint32 sda_in_adr; /* 68000 memory address mapped to SDA_IN */
48
uint32 sda_out_adr; /* 68000 memory address mapped to SDA_OUT */
49
uint32 scl_adr; /* 68000 memory address mapped to SCL */
50
uint8 sda_in_bit; /* bit offset for SDA_IN */
51
uint8 sda_out_bit; /* bit offset for SDA_OUT */
52
uint8 scl_bit; /* bit offset for SCL */
53
} T_CONFIG_I2C;
54
55
typedef enum
56
{
57
STAND_BY = 0,
58
WAIT_STOP,
59
GET_SLAVE_ADR,
60
GET_WORD_ADR_7BITS,
61
GET_WORD_ADR_HIGH,
62
GET_WORD_ADR_LOW,
63
WRITE_DATA,
64
READ_DATA
65
} T_STATE_I2C;
66
67
typedef struct
68
{
69
uint8 sda; /* current /SDA line state */
70
uint8 scl; /* current /SCL line state */
71
uint8 old_sda; /* previous /SDA line state */
72
uint8 old_scl; /* previous /SCL line state */
73
uint8 cycles; /* current operation cycle number (0-9) */
74
uint8 rw; /* operation type (1:READ, 0:WRITE) */
75
uint16 slave_mask; /* device address (shifted by the memory address width)*/
76
uint16 word_address; /* memory address */
77
T_STATE_I2C state; /* current operation state */
78
T_CONFIG_I2C config; /* EEPROM characteristics for this game */
79
} T_EEPROM_I2C;
80
81
extern T_EEPROM_I2C eeprom_i2c;
82
83
/* Function prototypes */
84
extern void eeprom_i2c_init();
85
86
#endif
87
88