summaryrefslogtreecommitdiffstatshomepage
path: root/esp8266/modmachinespi.c
diff options
context:
space:
mode:
authorRadomir Dopieralski <openstack@sheep.art.pl>2016-08-19 18:55:07 +0200
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2016-08-19 21:19:59 +0300
commitd076fae2194fc1b1cacc1c6d09012baa12ee93a5 (patch)
tree0b2529ff0084d35842c15a3bc5dfe7f8edbfabc5 /esp8266/modmachinespi.c
parent8e7dfea803f618beaa2ad976dff0b196e449d5d9 (diff)
downloadmicropython-d076fae2194fc1b1cacc1c6d09012baa12ee93a5.tar.gz
micropython-d076fae2194fc1b1cacc1c6d09012baa12ee93a5.zip
esp8266/modmachinespi: Add a factory method for SoftSPI/HSPI
Diffstat (limited to 'esp8266/modmachinespi.c')
-rw-r--r--esp8266/modmachinespi.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/esp8266/modmachinespi.c b/esp8266/modmachinespi.c
new file mode 100644
index 0000000000..1c6a373698
--- /dev/null
+++ b/esp8266/modmachinespi.c
@@ -0,0 +1,71 @@
+/*
+ * 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.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+
+#include "ets_sys.h"
+#include "etshal.h"
+#include "ets_alt_task.h"
+
+#include "py/runtime.h"
+#include "py/stream.h"
+#include "py/mphal.h"
+
+
+mp_obj_t pyb_spi_make_new(const mp_obj_type_t *type, size_t n_args,
+ size_t n_kw, const mp_obj_t *args);
+mp_obj_t pyb_hspi_make_new(const mp_obj_type_t *type, size_t n_args,
+ size_t n_kw, const mp_obj_t *args);
+
+
+STATIC mp_obj_t machine_spi_make_new(const mp_obj_type_t *type, size_t n_args,
+ size_t n_kw, const mp_obj_t *args) {
+ mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
+ switch (mp_obj_get_int(args[0])) {
+ case -1:
+ return pyb_spi_make_new(type, n_args - 1, n_kw, args + 1);
+ case 0:
+ return pyb_hspi_make_new(type, n_args - 1, n_kw, args + 1);
+ default:
+ nlr_raise(mp_obj_new_exception_msg_varg(
+ &mp_type_ValueError, "no such SPI peripheral"));
+ }
+}
+
+
+STATIC const mp_rom_map_elem_t machine_spi_locals_dict_table[] = {};
+
+STATIC MP_DEFINE_CONST_DICT(machine_spi_locals_dict,
+ machine_spi_locals_dict_table);
+
+const mp_obj_type_t machine_spi_type = {
+ { &mp_type_type },
+ .name = MP_QSTR_SPI,
+ .make_new = machine_spi_make_new,
+ .locals_dict = (mp_obj_dict_t*)&machine_spi_locals_dict,
+};