From 96546c79c0e931c89e4ac60a154b669925d5d34d Mon Sep 17 00:00:00 2001 From: Jason Date: Tue, 5 Jun 2018 12:43:20 -0700 Subject: Adding SX60 work by amnobis and configurator settings (#3122) * Add SX60 * Add config maps and layouts as well as readmes. * cleanup and fixes * correct readme * add missing closing commenty tag * Changing includes to QMK_KEYBOARD_H * Update settings.json Remove config change that was added automatically by vscode. * Update readme.md fix readme formatting --- keyboards/sx60/twimaster.c | 207 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 207 insertions(+) create mode 100644 keyboards/sx60/twimaster.c (limited to 'keyboards/sx60/twimaster.c') diff --git a/keyboards/sx60/twimaster.c b/keyboards/sx60/twimaster.c new file mode 100644 index 0000000000..30d8c24bf0 --- /dev/null +++ b/keyboards/sx60/twimaster.c @@ -0,0 +1,207 @@ +/************************************************************************* +* 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 Hz here if not defined in Makefile */ +#ifndef F_CPU +#define F_CPU 16000000UL +#endif + +/* I2C clock in Hz */ +#define SCL_CLOCK 400000L + + +/************************************************************************* + Initialization of the I2C bus interface. Need to be called only once +*************************************************************************/ +void i2c_init(void) +{ + /* initialize TWI clock + * minimal values in Bit Rate Register (TWBR) and minimal Prescaler + * bits in the TWI Status Register should give us maximal possible + * I2C bus speed - about 444 kHz + * + * for more details, see 20.5.2 in ATmega16/32 secification + */ + + TWSR = 0; /* no prescaler */ + TWBR = 10; /* 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<