41 enum { type = type_i2c_bus };
68 static void put_byte(
unsigned char x );
77 static void write(
unsigned char address,
unsigned const char *data,
int n ){
80 for(
int i = 0; i < n; i++ ){
92 static void read(
unsigned char address,
unsigned char *data,
int n ){
95 for(
int i = 0; i < n; i++ ){
116 unsigned int frequency = 1 * bmptk::MHz
122 ( (
int)extern_scl::type == bmptk::type_pin_out )
123 | ( (
int)extern_scl::type == bmptk::type_pin_in_out )
124 | ( (
int)extern_scl::type == bmptk::type_pin_oc ),
125 "scl must be a pin_out, pin_in_out or a pin_oc"
128 ( (
int)extern_sda::type == bmptk::type_pin_out )
129 | ( (
int)extern_sda::type == bmptk::type_pin_in_out )
130 | ( (
int)extern_sda::type == bmptk::type_pin_oc ),
131 "sda must be a pin_out, pin_in_out or a pin_oc"
138 static void delay_half_period(){
140 epoch +=
bmptk::s / ( 2 * frequency );
146 static void put_bit(
bool x ){
155 static bool get_bit(){
198 bool ack = ! get_bit();
214 for(
int i = 0; i < 8; i++ ){
215 put_bit( ( x & 0x80 ) != 0 );
222 unsigned char result = 0;
223 for(
int i = 0; i < 8; i++ ){
224 result = result << 1;