1313
1414#include <pbdrv/config.h>
1515#include <pbio/error.h>
16+ #include <pbio/os.h>
1617#include <pbio/port.h>
1718#include <contiki.h>
1819
@@ -30,18 +31,37 @@ typedef struct _pbdrv_i2c_dev_t pbdrv_i2c_dev_t;
3031pbio_error_t pbdrv_i2c_get_instance (uint8_t id , pbdrv_i2c_dev_t * * i2c_dev );
3132
3233/**
33- * Does an I2C operation. To be replaced .
34+ * Does an I2C operation. To be integrated with higher-level code .
3435 *
35- * Doesn't do anything yet. This is a placeholder so someone knowledgable with
36- * EV3 I2C has a starting point without setting up all the boilerplate.
37- *
38- * @param [in] i2c_dev The I2C device.
39- * @param [in] operation Dummy parameter.
40- * @return ::PBIO_SUCCESS on success.
36+ * @param [in] state Protothread state for async operation.
37+ * @param [in] i2c_dev The I2C device.
38+ * @param [in] dev_addr I2C device address (unshifted).
39+ * @param [in] wdata Data to be sent to the device.
40+ * Can be null if \p wlen is 0.
41+ * @param [in] wlen Length of \p wdata.
42+ * If this is 0 and \p rlen is also 0,
43+ * an empty "ping" will be sent, consisting of
44+ * only a device address (with R/nW = 0).
45+ * If this is 0 but \p rlen is not 0,
46+ * a read transaction will be sent.
47+ * If this is not 0 and \p rlen is not 0,
48+ * a write will be sent followed by a read in
49+ * a single transaction.
50+ * @param [out] rdata Buffer for data read from the device.
51+ * Can be null if \p rlen is 0.
52+ * @param [in] rlen Size of \p rdata.
53+ * @param [in] nxt_quirk Whether to use NXT I2C transaction quirk.
54+ * @return ::PBIO_SUCCESS on success.
4155 */
42- pbio_error_t pbdrv_i2c_placeholder_operation (pbdrv_i2c_dev_t * i2c_dev , const char * operation );
43-
44- // Delete above and add read/write functions here. See I2C driver for examples, also protothreads.
56+ pbio_error_t pbdrv_i2c_write_then_read (
57+ pbio_os_state_t * state ,
58+ pbdrv_i2c_dev_t * i2c_dev ,
59+ uint8_t dev_addr ,
60+ const uint8_t * wdata ,
61+ size_t wlen ,
62+ uint8_t * rdata ,
63+ size_t rlen ,
64+ bool nxt_quirk );
4565
4666#else // PBDRV_CONFIG_I2C
4767
@@ -50,7 +70,15 @@ static inline pbio_error_t pbdrv_i2c_get_instance(uint8_t id, pbdrv_i2c_dev_t **
5070 return PBIO_ERROR_NOT_SUPPORTED ;
5171}
5272
53- static inline pbio_error_t pbdrv_i2c_placeholder_operation (pbdrv_i2c_dev_t * i2c_dev , const char * operation ) {
73+ static inline pbio_error_t pbdrv_i2c_write_then_read (
74+ pbio_os_state_t * state ,
75+ pbdrv_i2c_dev_t * i2c_dev ,
76+ uint8_t dev_addr ,
77+ const uint8_t * wdata ,
78+ size_t wlen ,
79+ uint8_t * rdata ,
80+ size_t rlen ,
81+ bool nxt_quirk ) {
5482 return PBIO_ERROR_NOT_SUPPORTED ;
5583}
5684
0 commit comments