4 Copyright 2008, 2009 Michel Pollet <buserror@gmail.com>
6 This file is part of simavr.
8 simavr is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 simavr is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with simavr. If not, see <http://www.gnu.org/licenses/>.
36 // add port number to get the real IRQ
37 #define AVR_IOCTL_TWI_GETIRQ(_name) AVR_IOCTL_DEF('t','w','i',(_name))
38 // return a pointer to the slave structure related to this TWI port
39 #define AVR_IOCTL_TWI_GETSLAVE(_name) AVR_IOCTL_DEF('t','w','s',(_name))
40 // retutn this twi interface "master" bus
41 #define AVR_IOCTL_TWI_GETBUS(_name) AVR_IOCTL_DEF('t','w','b',(_name))
43 typedef struct avr_twi_t {
47 twi_slave_t slave; // when we are a slave, to be attached to some bus
48 twi_bus_t bus; // when we are a master, to attach slaves to
50 avr_regbit_t disabled; // bit in the PRR
52 avr_io_addr_t r_twbr; // bit rate register
53 avr_io_addr_t r_twcr; // control register
54 avr_io_addr_t r_twsr; // status register
55 avr_io_addr_t r_twar; // address register (slave)
56 avr_io_addr_t r_twamr; // address mask register
57 avr_io_addr_t r_twdr; // data register
59 avr_regbit_t twen; // twi enable bit
60 avr_regbit_t twea; // enable acknowledge bit
61 avr_regbit_t twsta; // start condition
62 avr_regbit_t twsto; // stop condition
63 avr_regbit_t twwc; // write collision
65 avr_regbit_t twsr; // status registers, (5 bits)
66 avr_regbit_t twps; // prescaler bits (2 bits)
68 avr_int_vector_t twi; // spi interrupt
71 void avr_twi_init(avr_t * avr, avr_twi_t * port);
73 #endif /* AVR_TWI_H_ */