aboutsummaryrefslogtreecommitdiff
path: root/main/i2c.h
diff options
context:
space:
mode:
authorThomasintAnker <thomasintanker1@gmail.com>2024-05-18 20:48:50 +0200
committerThomasintAnker <thomasintanker1@gmail.com>2024-05-18 20:48:50 +0200
commit56440df6b9810dbbc4b33171030970fa2fbe1ca1 (patch)
tree9a227b9397ca4fa464165fc4836ba8dd22275202 /main/i2c.h
parent1152ec32b6086c153dc41da59c9c451aa4465995 (diff)
Base i2c master functions
Diffstat (limited to 'main/i2c.h')
-rw-r--r--main/i2c.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/main/i2c.h b/main/i2c.h
new file mode 100644
index 0000000..d12bca1
--- /dev/null
+++ b/main/i2c.h
@@ -0,0 +1,36 @@
+#pragma once
+// https://github.com/raspberrypi/pico-examples/tree/master/i2c
+
+#include <stddef.h>
+#include <stdint.h>
+
+#define SDA_PIN 16
+#define SCL_PIN 17
+
+/**
+ * \brief initialize all required gpio for i2c usage on the pico
+ *
+ * This functions only initializes the standard gpio required to start i2c
+ * communications.
+ *
+ * \note Tasks shouldn't depend on any other module in the main controller
+ */
+void init_i2c();
+
+/**
+ * \brief read data from addr with length len from i2c bus.
+ *
+ * This functions reads data from a specific address on the i2c bus,
+ * the output var will hold the data which was read from said address with
+ * length len.
+ */
+int read_i2c(uint8_t addr, uint8_t *output, size_t len);
+
+/**
+ * \brief write data to addr with length len from i2c bus.
+ *
+ * This functions writes data to a specific address on the i2c bus,
+ * the input var holds the data which will be written to the given
+ * address with length len.
+ */
+int write_i2c(uint8_t addr, uint8_t *input, size_t len);