summaryrefslogtreecommitdiffstatshomepage
path: root/extmod/machine_spi.h
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-09-01 15:07:20 +1000
committerDamien George <damien.p.george@gmail.com>2016-09-01 15:07:20 +1000
commit0823c1baf864f2e8fd60e49a5e42a958fd89ff43 (patch)
treec5b9792e978600f7ca5b603d82ee015b1047eca2 /extmod/machine_spi.h
parent9c04ef2a6772cabbd92abe6c826b56cc04a1a7b8 (diff)
downloadmicropython-0823c1baf864f2e8fd60e49a5e42a958fd89ff43.tar.gz
micropython-0823c1baf864f2e8fd60e49a5e42a958fd89ff43.zip
extmod: Add machine_spi with generic SPI C-protocol and helper methods.
The idea is that all ports can use these helper methods and only need to provide initialisation of the SPI bus, as well as a single transfer function. The coding pattern follows the stream protocol and helper methods.
Diffstat (limited to 'extmod/machine_spi.h')
-rw-r--r--extmod/machine_spi.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/extmod/machine_spi.h b/extmod/machine_spi.h
new file mode 100644
index 0000000000..26d716fc11
--- /dev/null
+++ b/extmod/machine_spi.h
@@ -0,0 +1,42 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2016 Damien P. George
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef MICROPY_INCLUDED_EXTMOD_MACHINE_SPI_H
+#define MICROPY_INCLUDED_EXTMOD_MACHINE_SPI_H
+
+#include "py/obj.h"
+
+// SPI protocol
+typedef struct _mp_machine_spi_p_t {
+ void (*transfer)(mp_obj_base_t *obj, size_t slen, const uint8_t *src, size_t dlen, uint8_t *dest);
+} mp_machine_spi_p_t;
+
+MP_DECLARE_CONST_FUN_OBJ(mp_machine_spi_read_obj);
+MP_DECLARE_CONST_FUN_OBJ(mp_machine_spi_readinto_obj);
+MP_DECLARE_CONST_FUN_OBJ(mp_machine_spi_write_obj);
+MP_DECLARE_CONST_FUN_OBJ(mp_machine_spi_write_readinto_obj);
+
+#endif // MICROPY_INCLUDED_EXTMOD_MACHINE_SPI_H