00001
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 #ifndef _TWI_H_
00046 #define _TWI_H_
00047
00048 #include <avr32/io.h>
00049
00050 #include "compiler.h"
00051
00054
00055 #define TWI_SUCCESS 0
00056 #define TWI_INVALID_ARGUMENT -1
00057 #define TWI_ARBITRATION_LOST -2
00058 #define TWI_NO_CHIP_FOUND -3
00059 #define TWI_RECEIVE_OVERRUN -4
00060 #define TWI_RECEIVE_NACK -5
00061 #define TWI_SEND_OVERRUN -6
00062 #define TWI_SEND_NACK -7
00064
00065
00069 typedef struct
00070 {
00072 unsigned long pba_hz;
00074 unsigned long speed;
00076 char chip;
00077 } twi_options_t;
00078
00082 typedef struct
00083 {
00085 char chip;
00087 unsigned int addr;
00089 int addr_length;
00091 void *buffer;
00093 unsigned int length;
00094 } twi_package_t;
00095
00096 #ifndef AVR32_TWI_180_H_INCLUDED
00097
00101 typedef struct
00102 {
00104 void (*rx)(U8);
00106 U8 (*tx)(void);
00108 void (*stop)(void);
00109 } twi_slave_fct_t;
00110
00111 #endif
00112
00113
00121 extern int twi_master_init(volatile avr32_twi_t *twi, const twi_options_t *opt);
00122
00123 #ifndef AVR32_TWI_180_H_INCLUDED
00124
00133 extern int twi_slave_init(volatile avr32_twi_t *twi, const twi_options_t *opt, const twi_slave_fct_t *slave_fct);
00134
00135 #endif
00136
00144 extern int twi_probe(volatile avr32_twi_t *twi, char chip_addr);
00145
00152 extern void twi_disable_interrupt(volatile avr32_twi_t *twi);
00153
00162 extern int twi_master_read(volatile avr32_twi_t *twi, const twi_package_t *package);
00163
00172 extern int twi_master_write(volatile avr32_twi_t *twi, const twi_package_t *package);
00173
00174
00175 #endif // _TWI_H_