Skip to content

Commit 6bfbae8

Browse files
committed
pbio/drv/i2c/i2c_ev3.c: Actually initialize I2C
This calls the I2C init function from core.c and removes the platform data which is unneeded with how we're using the PRU.
1 parent 1fcb1af commit 6bfbae8

File tree

3 files changed

+10
-36
lines changed

3 files changed

+10
-36
lines changed

lib/pbio/drv/core.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "clock/clock.h"
1919
#include "counter/counter.h"
2020
#include "display/display.h"
21+
#include "i2c/i2c.h"
2122
#include "imu/imu.h"
2223
#include "led/led_array.h"
2324
#include "led/led.h"
@@ -49,6 +50,7 @@ void pbdrv_init(void) {
4950
pbdrv_charger_init();
5051
pbdrv_counter_init();
5152
pbdrv_display_init();
53+
pbdrv_i2c_init();
5254
pbdrv_imu_init();
5355
pbdrv_led_array_init();
5456
pbdrv_led_init();

lib/pbio/drv/i2c/i2c_ev3.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
#include <pbio/util.h>
1717

1818
#include <pbdrv/i2c.h>
19-
#include "i2c_ev3.h"
19+
20+
#include "../rproc/rproc_ev3.h"
2021

2122
#define DEBUG 1
2223
#if DEBUG
@@ -31,21 +32,19 @@
3132
#endif
3233

3334
struct _pbdrv_i2c_dev_t {
34-
/** Platform-specific data */
35-
const pbdrv_i2c_ev3_platform_data_t *pdata;
36-
//
37-
// TODO: i2c state goes here.
38-
//
35+
bool init;
36+
uint8_t pru_i2c_idx;
3937
};
4038

4139
static pbdrv_i2c_dev_t i2c_devs[PBDRV_CONFIG_I2C_EV3_NUM_DEV];
40+
_Static_assert(PBDRV_CONFIG_I2C_EV3_NUM_DEV <= PBDRV_RPROC_EV3_PRU1_NUM_I2C_CHANNELS);
4241

4342
pbio_error_t pbdrv_i2c_get_instance(uint8_t id, pbdrv_i2c_dev_t **i2c_dev) {
4443
if (id >= PBDRV_CONFIG_I2C_EV3_NUM_DEV) {
4544
return PBIO_ERROR_INVALID_ARG;
4645
}
4746
pbdrv_i2c_dev_t *dev = &i2c_devs[id];
48-
if (!dev->pdata) {
47+
if (!dev->init) {
4948
// has not been initialized yet
5049
return PBIO_ERROR_AGAIN;
5150
}
@@ -60,9 +59,9 @@ pbio_error_t pbdrv_i2c_placeholder_operation(pbdrv_i2c_dev_t *i2c_dev, const cha
6059

6160
void pbdrv_i2c_init(void) {
6261
for (int i = 0; i < PBDRV_CONFIG_I2C_EV3_NUM_DEV; i++) {
63-
const pbdrv_i2c_ev3_platform_data_t *pdata = &pbdrv_i2c_ev3_platform_data[i];
6462
pbdrv_i2c_dev_t *i2c = &i2c_devs[i];
65-
i2c->pdata = pdata;
63+
i2c->pru_i2c_idx = i;
64+
i2c->init = true;
6665
}
6766
}
6867

lib/pbio/drv/i2c/i2c_ev3.h

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)