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
00046
00047
00048 #ifndef _TWI_H_
00049 #define _TWI_H_
00050
00051 #include <avr32/io.h>
00052
00053 #include "compiler.h"
00054
00057
00058 #define TWI_SUCCESS 0
00059 #define TWI_INVALID_ARGUMENT -1
00060 #define TWI_ARBITRATION_LOST -2
00061 #define TWI_NO_CHIP_FOUND -3
00062 #define TWI_RECEIVE_OVERRUN -4
00063 #define TWI_RECEIVE_NACK -5
00064 #define TWI_SEND_OVERRUN -6
00065 #define TWI_SEND_NACK -7
00066 #define TWI_BUSY -8
00068
00069
00073 typedef struct
00074 {
00076 unsigned long pba_hz;
00078 unsigned long speed;
00080 char chip;
00081 } twi_options_t;
00082
00086 typedef struct
00087 {
00089 char chip;
00091 unsigned int addr;
00093 int addr_length;
00095 void *buffer;
00097 unsigned int length;
00098 } twi_package_t;
00099
00100 #ifndef AVR32_TWI_180_H_INCLUDED
00101
00105 typedef struct
00106 {
00108 void (*rx)(U8);
00110 U8 (*tx)(void);
00112 void (*stop)(void);
00113 } twi_slave_fct_t;
00114
00115 #endif
00116
00117
00125 extern int twi_master_init(volatile avr32_twi_t *twi, const twi_options_t *opt);
00126
00127 #ifndef AVR32_TWI_180_H_INCLUDED
00128
00137 extern int twi_slave_init(volatile avr32_twi_t *twi, const twi_options_t *opt, const twi_slave_fct_t *slave_fct);
00138
00139 #endif
00140
00148 extern int twi_probe(volatile avr32_twi_t *twi, char chip_addr);
00149
00156 extern void twi_disable_interrupt(volatile avr32_twi_t *twi);
00157
00166 extern int twi_master_read(volatile avr32_twi_t *twi, const twi_package_t *package);
00167
00176 extern int twi_master_write(volatile avr32_twi_t *twi, const twi_package_t *package);
00177
00188 extern int twi_master_write_ex(volatile avr32_twi_t *twi, const twi_package_t *package);
00189
00195 extern Bool twi_is_busy(void);
00196
00197
00198 #endif // _TWI_H_