-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cpu/lpc2387: implement periph/i2c #13037
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See inline comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All comments resolved. However, I guess the compiler will not be able to deduce that in _next_buffer() the value of the local variable uint8_t buf_cur
is always 0. I think you can safe some ROM if you just set it to 0
rather then reading it from ctx[dev].buf_cur
.
Maybe you should also call the function _second_buffer()
or _switch_to_snd_buf()
, so that it is clear that this function has the precondition that ctx[dev].buf_cur == 0
.
cpu/lpc2387/periph/i2c.c
Outdated
static struct i2c_ctx { | ||
mutex_t lock; | ||
mutex_t tx_done; | ||
uint8_t *buf[TRX_BUFS_MAX]; | ||
uint8_t *buf_end[TRX_BUFS_MAX]; | ||
uint8_t *cur; | ||
uint8_t *end; | ||
int res; | ||
uint8_t addr[TRX_BUFS_MAX]; | ||
uint8_t buf_num; | ||
uint8_t buf_cur; | ||
} ctx[I2C_NUMOF]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about
static struct i2c_ctx {
/* ..., same as above */
} ctx[I2C_NUMOF] = {
{ .lock = MUTEX_INIT, .tx_done = MUTEX_INIT },
{ .lock = MUTEX_INIT, .tx_done = MUTEX_INIT }
};
That would get rid of the call to mutex_init()
. If you take the suggestion, please squash that right in. Otherwise, just squash. I'll do one round of testing and then finally this should get in.
Sorry for the long stall. I have a lot to do recently...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needed some additional #ifdefs
that made it less pretty, but still saves about 200 bytes of ROM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like a good trade off :-) Please squash!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you drop this by accident, or do you favor getting rid of the #ifdef
s over the saved ROM size?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I simply forgot about it - added it now.
With USEMODULE=i2c_scan make -C examples/default
the difference is only 48 bytes, but it's something :)
And it makes i2c_init()
simpler, which should ease adaption to #13421
OK, I tested
|
Can you drop the last fix? It turns out that this is not needed when the bug in the ina2xx driver is fixed. ( |
b292c68
to
8335474
Compare
Alright! |
Then I'd say no :-) Can you rebase and squash? I'll give it one last test to be sure. |
8335474
to
7e75689
Compare
Rebase and squashed |
@fabian18 want to give this a try too? 😃 |
I tested
|
8dbf959
to
44f18d0
Compare
rebased to fix missing header in |
Please squash. |
The lpc23xx MCU has up to three I2C interfaces. This adds a driver for it. The peripheral works in interrupt mode, each change of the state machine will generate an interrupt. The response to the states are laid out in the data sheet. This replaces the old driver that was removed in c560e28
I2C is not used by any chip on the board, but I2C2 is availiable on the JP3 connector (shared with UART2). - SDA: P0.10 - SCL: P0.11
The pins for I2C0 and I2C1 are available on the board, nothing is wired up to them.
We need that header file for the ARRAY_SIZE() macro.
1287075
to
00131bb
Compare
squashed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK
Thank you all for reviewing, testing and merging 😄 |
Contribution description
This adds a driver for the I2C master interface of the lpc23xx family of SoCs.
The driver operates in interrupt mode, for every change of the internal state machine an interrupt is generated. The data sheet lays out the required operations for each state change.
It doesn't seem to be possible to stop the state machine advancing without sending a stop condition, so I couldn't use the generic implementations of
i2c_read_regs()
/i2c_write_regs()
but had to implement them in the driver using two transmit buffers. (One for the register address, one for the payload).Testing procedure
Unfortunately msba2 doesn't have any i2c chips connected on board.
Initially I thought sht11 was i2c, but in fact it's own bit-banging protocol.
The only i2c capable pins that are available as headers are on JP3:
A basic test would be to add
USEMODULE += i2c_scan
toexamples/default
.That's still boring, so let's hook something up to it.
I used the mcb2388 with a Tiny RTC module (DS1307, AT24C32 - #11929) as well as a GY-85 9-DOF (ADXL345, ITG3200 - #10092, HMC5883 - #10083)
The chips show up in
i2c_scan
, I've successfully rantests/driver_at24cxxx
tests/driver_adxl345
tests/driver_itg320x
Issues/PRs references
replacement for the driver removed in #6521
addresses #4693