I2C: use pinio.h to handle pins.
This removes the need for four user configuration options.
This commit is contained in:
parent
6ef9e1a2ee
commit
194e5d5b98
7
i2c.c
7
i2c.c
|
|
@ -27,6 +27,7 @@
|
|||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <util/twi.h>
|
||||
#include "pinio.h"
|
||||
|
||||
|
||||
#if defined I2C_MASTER_MODE && defined I2C_SLAVE_MODE
|
||||
|
|
@ -94,8 +95,10 @@ void i2c_init(uint8_t address) {
|
|||
|
||||
#ifdef I2C_MASTER_MODE
|
||||
#ifdef I2C_ENABLE_PULLUPS
|
||||
I2C_DDR &= ~((1 << I2C_SCL_PIN) | (1 << I2C_SDA_PIN));
|
||||
I2C_PORT |= (1 << I2C_SCL_PIN) | (1 << I2C_SDA_PIN);
|
||||
SET_INPUT(SCL);
|
||||
PULLUP_ON(SCL);
|
||||
SET_INPUT(SDA);
|
||||
PULLUP_ON(SDA);
|
||||
#endif /* I2C_ENABLE_PULLUPS */
|
||||
|
||||
/**
|
||||
|
|
|
|||
16
i2c.h
16
i2c.h
|
|
@ -12,25 +12,23 @@
|
|||
// Uncomment if we use EEPROM chips.
|
||||
//#define I2C_EEPROM_SUPPORT
|
||||
|
||||
// Bus speed. Maximum is said to be 400000.
|
||||
#define I2C_BITRATE 100000
|
||||
#define I2C_PORT PORTC
|
||||
#define I2C_DDR DDRC
|
||||
|
||||
#define I2C_SCL_PIN 0
|
||||
#define I2C_SDA_PIN 1
|
||||
// Comment out if there are external pullups.
|
||||
#define I2C_ENABLE_PULLUPS
|
||||
|
||||
#define I2C_BUFFER_SIZE 4
|
||||
#ifdef I2C_EEPROM_SUPPORT
|
||||
// Depends on EEPROM type, usually it is 1 or 2 bytes.
|
||||
#define I2C_PAGE_ADDRESS_SIZE 2
|
||||
#endif /* I2C_EEPROM_SUPPORT */
|
||||
|
||||
#ifdef I2C_SLAVE_MODE
|
||||
#define I2C_SLAVE_RX_BUFFER_SIZE 1
|
||||
#define I2C_SLAVE_TX_BUFFER_SIZE 1
|
||||
#endif /* I2C_SLAVE_MODE */
|
||||
|
||||
#ifdef I2C_EEPROM_SUPPORT
|
||||
// Depends on EEPROM type, usually it is 1 or 2 bytes.
|
||||
#define I2C_PAGE_ADDRESS_SIZE 2
|
||||
#endif /* I2C_EEPROM_SUPPORT */
|
||||
|
||||
|
||||
void i2c_init(uint8_t address);
|
||||
void i2c_send(uint8_t address, uint8_t* block, uint8_t tx_len);
|
||||
|
|
|
|||
Loading…
Reference in New Issue