From 0d8f8210e5decb4870f77b5cd0e5325cb803a3af Mon Sep 17 00:00:00 2001 From: Barry Carter Date: Wed, 5 Sep 2012 00:08:10 +0100 Subject: Added I2C slave echo example in examples folder. Using another maple, write a byte and then read. Slight tidy up. Reformatted CREDITS file to be in correct order. Added a note about buffer overrun Signed-off-by:- Barry Carter --- libmaple/i2c.c | 4 ++++ libmaple/include/libmaple/i2c.h | 1 + 2 files changed, 5 insertions(+) (limited to 'libmaple') diff --git a/libmaple/i2c.c b/libmaple/i2c.c index 6c609d9..bbbf123 100644 --- a/libmaple/i2c.c +++ b/libmaple/i2c.c @@ -458,6 +458,10 @@ void _i2c_irq_handler(i2c_dev *dev) { if (sr1 & I2C_SR1_RXNE) { if (dev->config_flags & I2C_SLAVE_USE_RX_BUFFER) { /* Fill the buffer with the contents of the data register */ + /* These is potential for buffer overflow here, so we should + * really store the size of the array. This is expensive in + * the ISR so left out for now. We must trust the implementor! + */ dev->i2c_slave_msg->data[dev->i2c_slave_msg->xferred++] = dev->regs->DR; dev->i2c_slave_msg->length++; } diff --git a/libmaple/include/libmaple/i2c.h b/libmaple/include/libmaple/i2c.h index 5a9da58..fbb4c09 100644 --- a/libmaple/include/libmaple/i2c.h +++ b/libmaple/include/libmaple/i2c.h @@ -210,6 +210,7 @@ typedef struct i2c_msg { #define I2C_SLAVE_DUAL_ADDRESS 0x40 // Enable the dual slave address scheme #define I2C_SLAVE_GENERAL_CALL 0x80 // Enable the general call on address 0x00 void i2c_master_enable(i2c_dev *dev, uint32 flags); +void i2c_slave_enable(i2c_dev *dev, uint32 flags); #define I2C_ERROR_PROTOCOL (-1) #define I2C_ERROR_TIMEOUT (-2) -- cgit v1.2.3