Skip to content

Commit 219a980

Browse files
author
Marti Bolivar
committed
Revert "I2C slave support cleanups."
This reverts commit 39cd07a. Reverting pull request #54, which breaks examples/i2c-mcp4725-dac.cpp. Signed-off-by: Marti Bolivar <[email protected]>
1 parent 32df297 commit 219a980

File tree

3 files changed

+9
-46
lines changed

3 files changed

+9
-46
lines changed

libmaple/i2c.c

+5-35
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,9 @@
2828
/**
2929
* @file libmaple/i2c.c
3030
* @author Perry Hung <[email protected]>
31-
* @author Barry Carter <[email protected]>
3231
* @brief Inter-Integrated Circuit (I2C) support.
3332
*
34-
* Master and Slave supported
35-
* Slave code added Barry Carter 2012
33+
* Currently, only master mode is supported.
3634
*/
3735

3836
#include "i2c_private.h"
@@ -220,26 +218,6 @@ void i2c_master_enable(i2c_dev *dev, uint32 flags) {
220218
dev->state = I2C_STATE_IDLE;
221219
}
222220

223-
/**
224-
* @brief Initialize an I2C device as slave (and master)
225-
* @param dev Device to enable
226-
* @param flags Bitwise or of the following I2C options:
227-
* I2C_FAST_MODE: 400 khz operation,
228-
* I2C_DUTY_16_9: 16/9 Tlow/Thigh duty cycle (only applicable for
229-
* fast mode),
230-
* I2C_BUS_RESET: Reset the bus and clock out any hung slaves on
231-
* initialization,
232-
* I2C_10BIT_ADDRESSING: Enable 10-bit addressing,
233-
* I2C_REMAP: (deprecated, STM32F1 only) Remap I2C1 to SCL/PB8
234-
* SDA/PB9.
235-
* I2C_SLAVE_DUAL_ADDRESS: Slave can respond on 2 i2C addresses
236-
* I2C_SLAVE_GENERAL_CALL: SLA+W broadcast to all general call
237-
* listeners on bus. Addr 0x00
238-
* I2C_SLAVE_USE_RX_BUFFER: Use a buffer to receive the incoming
239-
* data. Callback at end of recv
240-
* I2C_SLAVE_USE_TX_BUFFER: Use a buffer to transmit data.
241-
* Callback will be called before tx
242-
*/
243221
void i2c_slave_enable(i2c_dev *dev, uint32 flags) {
244222
i2c_disable(dev);
245223
i2c_master_enable(dev, dev->config_flags | flags);
@@ -344,10 +322,11 @@ void _i2c_irq_handler(i2c_dev *dev) {
344322
*/
345323
dev->timestamp = systick_uptime();
346324

347-
/*
348-
* Add Slave support
325+
/* Add Slave support
326+
* Barry Carter 2012
327+
349328
*/
350-
329+
351330
/* Check to see if MSL master slave bit is set */
352331
if ((sr2 & I2C_SR2_MSL) != I2C_SR2_MSL) { /* 0 = slave mode 1 = master */
353332

@@ -480,15 +459,6 @@ void _i2c_irq_handler(i2c_dev *dev) {
480459
/* The callback with the data will happen on a NACK of the last data byte.
481460
* This is handled in the error IRQ (AF bit)
482461
*/
483-
/* Handle the case where the master misbehaves by sending no NACK */
484-
if (dev->state != I2C_STATE_IDLE) {
485-
if (dev->state == I2C_STATE_SL_RX) {
486-
if (dev->i2c_slave_recv_callback != NULL) (*(dev->i2c_slave_recv_callback))(dev->i2c_slave_msg);
487-
}
488-
else {
489-
if (dev->i2c_slave_transmit_callback != NULL) (*(dev->i2c_slave_transmit_callback))(dev->i2c_slave_msg);
490-
}
491-
}
492462
}
493463

494464
sr1 = sr2 = 0;

libmaple/include/libmaple/i2c.h

+3-10
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,12 @@
2929
* @file libmaple/include/libmaple/i2c.h
3030
* @brief Inter-Integrated Circuit (I2C) peripheral support
3131
*
32-
* Supports Master and Slave.
33-
* Master Usage notes:
32+
* Currently master-only. Usage notes:
3433
*
3534
* - Enable an I2C device with i2c_master_enable().
3635
* - Initialize an array of struct i2c_msg to suit the bus
3736
* transactions (reads/writes) you wish to perform.
3837
* - Call i2c_master_xfer() to do the work.
39-
*
40-
* Slave Usage notes:
41-
* - Enable I2C slave by calling i2c_slave_enable().
42-
* Check flags for usage. Enabling master also enabled slave.
43-
* - initialise the i2c_msg struct and the data buffer
44-
* - initialise the callback functions
4538
*/
4639

4740
#ifndef _LIBMAPLE_I2C_H_
@@ -208,7 +201,7 @@ typedef struct i2c_msg {
208201
#define I2C_SLAVE_USE_RX_BUFFER 0x10 // Use a buffered message when doing a slave recv
209202
#define I2C_SLAVE_USE_TX_BUFFER 0x20 // Use a buffered message when doing a slave transmit
210203
#define I2C_SLAVE_DUAL_ADDRESS 0x40 // Enable the dual slave address scheme
211-
#define I2C_SLAVE_GENERAL_CALL 0x80 // Enable the general call on address 0x00
204+
#define I2C_SLAVE_GENERAL_CALL 0x80 // Enable the dual slave address scheme
212205
void i2c_master_enable(i2c_dev *dev, uint32 flags);
213206

214207
#define I2C_ERROR_PROTOCOL (-1)
@@ -418,7 +411,7 @@ static inline void i2c_set_trise(i2c_dev *dev, uint32 trise) {
418411
dev->regs->TRISE = trise;
419412
}
420413

421-
/*
414+
/* Barry Carter
422415
* Slave support
423416
*/
424417

libmaple/include/libmaple/i2c_common.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ typedef struct i2c_dev {
9393
volatile i2c_state state; /**< Device state */
9494
uint32 config_flags; /**< Configuration flags */
9595

96-
/*
96+
/* Barry Carter
9797
* Slave implementation. Callback functions in this struct allow
9898
* for a separate callback function for each I2C unit available onboard
9999
*/

0 commit comments

Comments
 (0)