PICSimLab - Programmable IC Simulator Laboratory 0.9.2
PICSimLab - API
Loading...
Searching...
No Matches
bitbang_i2c.h
1/* ########################################################################
2
3 PICSimLab - Programmable IC Simulator Laboratory
4
5 ########################################################################
6
7 Copyright (c) : 2020-2024 Luis Claudio GambĂ´a Lopes <lcgamboa@yahoo.com>
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
12 any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
23 For e-mail suggestions : lcgamboa@yahoo.com
24 ######################################################################## */
25
26#ifndef BITBANG_I2C
27#define BITBANG_I2C
28
29class board;
30
31// operation status
32#define I2C_IDLE 0x00
33#define I2C_START 0x01
34#define I2C_STOP 0x02
35#define I2C_ADDR 0x04
36#define I2C_DATAW 0x08
37#define I2C_DATAR 0x10
38
39typedef struct {
40 unsigned char addr; // device addr
41 unsigned char addr_mask; // addr mask
42 unsigned char datab; // input data shift register
43 unsigned char datas; // output data shift register
44 unsigned char sclo; // previous scl
45 unsigned char sdao; // previous sda
46 unsigned char ret; // last returned value
47 unsigned char bit; // bit counter
48 unsigned char byte; // byte counter
49 unsigned char status; // operation status
50 unsigned char datar; // data receveid
51 unsigned char data_reading; // reading operation
52 // Controller
53 board* pboard;
54 int TimerID;
55 unsigned char ctrl_on;
56 unsigned char scl_pin;
57 unsigned char scl_value;
58 unsigned char sda_pin;
59 unsigned char sda_value;
60 unsigned char sda_dir;
61 unsigned char clkpc; // clock phase counter
62 unsigned char ack;
64
65void bitbang_i2c_init(bitbang_i2c_t* i2c, const unsigned char addr, const unsigned char addr_mask = 0xFE);
66void bitbang_i2c_rst(bitbang_i2c_t* i2c);
67void bitbang_i2c_set_addr(bitbang_i2c_t* i2c, const unsigned char addr);
68unsigned char bitbang_i2c_get_status(bitbang_i2c_t* i2c);
69void bitbang_i2c_send(bitbang_i2c_t* i2c, const unsigned char data);
70
71// peripheral
72unsigned char bitbang_i2c_io(bitbang_i2c_t* i2c, const unsigned char scl, const unsigned char sda);
73
74// controller
75void bitbang_i2c_ctrl_init(bitbang_i2c_t* i2c, board* pboard);
76void bitbang_i2c_ctrl_end(bitbang_i2c_t* i2c);
77
78void bitbang_i2c_ctrl_start(bitbang_i2c_t* i2c);
79void bitbang_i2c_ctrl_restart(bitbang_i2c_t* i2c);
80void bitbang_i2c_ctrl_stop(bitbang_i2c_t* i2c);
81void bitbang_i2c_ctrl_write(bitbang_i2c_t* i2c, const unsigned char data);
82void bitbang_i2c_ctrl_read(bitbang_i2c_t* i2c);
83
84#endif // BITBANG_I2C
Board class.
Definition board.h:111
Definition bitbang_i2c.h:39