diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2018-11-14 10:23:56 -0500 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2018-11-14 10:23:56 -0500 |
commit | f3c4deb1abedc38ff91d9c77e0b7e086d2246329 (patch) | |
tree | 730b606678bd6066d66561bf0a46d7e2509e08b7 /src/lpc176x/i2c.c | |
parent | f973886dacdbd516845d48fc5a434f113c16e84b (diff) | |
download | kutter-f3c4deb1abedc38ff91d9c77e0b7e086d2246329.tar.gz kutter-f3c4deb1abedc38ff91d9c77e0b7e086d2246329.tar.xz kutter-f3c4deb1abedc38ff91d9c77e0b7e086d2246329.zip |
lpc176x: Convert i2c code to use standard i2ccmds.c
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/lpc176x/i2c.c')
-rw-r--r-- | src/lpc176x/i2c.c | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/src/lpc176x/i2c.c b/src/lpc176x/i2c.c index 76c5b738..50081d50 100644 --- a/src/lpc176x/i2c.c +++ b/src/lpc176x/i2c.c @@ -7,6 +7,7 @@ #include "LPC17xx.h" // LPC_I2C1 #include "board/misc.h" // timer_is_before #include "command.h" // DECL_COMMAND +#include "gpio.h" // i2c_setup #include "internal.h" // gpio_peripheral #include "sched.h" // sched_shutdown @@ -37,6 +38,15 @@ i2c_init(void) LPC_I2C1->I2CONSET = IF_ENA; } +struct i2c_config +i2c_setup(uint32_t bus, uint32_t rate, uint8_t addr) +{ + if (bus) + shutdown("Unsupported i2c bus"); + i2c_init(); + return (struct i2c_config){ .addr=addr }; +} + static void i2c_wait(uint32_t bit, uint32_t timeout) { @@ -78,23 +88,21 @@ i2c_stop(uint32_t timeout) i2c_wait(IF_STOP, timeout); } -static void -i2c_send(uint8_t *data, int data_len) +void +i2c_write(struct i2c_config config, uint8_t write_len, uint8_t *write) { - i2c_init(); uint32_t timeout = timer_read_time() + timer_from_us(5000); i2c_start(timeout); - while (data_len--) - i2c_send_byte(*data++, timeout); + i2c_send_byte(config.addr, timeout); + while (write_len--) + i2c_send_byte(*write++, timeout); i2c_stop(timeout); } -// This provides just enough functionality to program an MCP4451 chip void -command_i2c_send(uint32_t *args) +i2c_read(struct i2c_config config, uint8_t reg_len, uint8_t *reg + , uint8_t read_len, uint8_t *read) { - uint8_t data_len = args[0], *data = (void*)(size_t)args[1]; - i2c_send(data, data_len); + shutdown("i2c_read not supported on lpc176x"); } -DECL_COMMAND(command_i2c_send, "i2c_send data=%*s"); |