X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;ds=sidebyside;f=keyboard%2Fergodox%2Ftwimaster.c;h=a4dc5c11ad2525c6574cfa41b3384eead29f54ff;hb=39da065913380c89246e6f788e1be772947c470e;hp=f0d850c25710efb1ee67269d2f9edfb261fedc96;hpb=cfc23836e5f9571056d3710b8580c1f27b91ed54;p=max%2Ftmk_keyboard.git diff --git a/keyboard/ergodox/twimaster.c b/keyboard/ergodox/twimaster.c index f0d850c2..a4dc5c11 100644 --- a/keyboard/ergodox/twimaster.c +++ b/keyboard/ergodox/twimaster.c @@ -1,202 +1,202 @@ -/************************************************************************* -* Title: I2C master library using hardware TWI interface -* Author: Peter Fleury http://jump.to/fleury -* File: $Id: twimaster.c,v 1.3 2005/07/02 11:14:21 Peter Exp $ -* Software: AVR-GCC 3.4.3 / avr-libc 1.2.3 -* Target: any AVR device with hardware TWI -* Usage: API compatible with I2C Software Library i2cmaster.h -**************************************************************************/ -#include -#include - -#include - - -/* define CPU frequency in Mhz here if not defined in Makefile */ -#ifndef F_CPU -#define F_CPU 4000000UL -#endif - -/* I2C clock in Hz */ -#define SCL_CLOCK 100000L - - -/************************************************************************* - Initialization of the I2C bus interface. Need to be called only once -*************************************************************************/ -void i2c_init(void) -{ - /* initialize TWI clock: 100 kHz clock, TWPS = 0 => prescaler = 1 */ - - TWSR = 0; /* no prescaler */ - TWBR = ((F_CPU/SCL_CLOCK)-16)/2; /* must be > 10 for stable operation */ - -}/* i2c_init */ - - -/************************************************************************* - Issues a start condition and sends address and transfer direction. - return 0 = device accessible, 1= failed to access device -*************************************************************************/ -unsigned char i2c_start(unsigned char address) -{ - uint8_t twst; - - // send START condition - TWCR = (1< http://jump.to/fleury +* File: $Id: twimaster.c,v 1.3 2005/07/02 11:14:21 Peter Exp $ +* Software: AVR-GCC 3.4.3 / avr-libc 1.2.3 +* Target: any AVR device with hardware TWI +* Usage: API compatible with I2C Software Library i2cmaster.h +**************************************************************************/ +#include +#include + +#include + + +/* define CPU frequency in Mhz here if not defined in Makefile */ +#ifndef F_CPU +#define F_CPU 4000000UL +#endif + +/* I2C clock in Hz */ +#define SCL_CLOCK 100000L + + +/************************************************************************* + Initialization of the I2C bus interface. Need to be called only once +*************************************************************************/ +void i2c_init(void) +{ + /* initialize TWI clock: 100 kHz clock, TWPS = 0 => prescaler = 1 */ + + TWSR = 0; /* no prescaler */ + TWBR = ((F_CPU/SCL_CLOCK)-16)/2; /* must be > 10 for stable operation */ + +}/* i2c_init */ + + +/************************************************************************* + Issues a start condition and sends address and transfer direction. + return 0 = device accessible, 1= failed to access device +*************************************************************************/ +unsigned char i2c_start(unsigned char address) +{ + uint8_t twst; + + // send START condition + TWCR = (1<