|
|
@@ -0,0 +1,95 @@
|
|
|
+/*
|
|
|
+ * This file is part of the MicroPython project, http://micropython.org/
|
|
|
+ *
|
|
|
+ * The MIT License (MIT)
|
|
|
+ *
|
|
|
+ * Copyright (c) 2018 SummerGift <zhangyuan@rt-thread.com>
|
|
|
+ *
|
|
|
+ * 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 <string.h>
|
|
|
+
|
|
|
+#include "py/runtime.h"
|
|
|
+#include "py/mphal.h"
|
|
|
+#include "extmod/machine_spi.h"
|
|
|
+
|
|
|
+#ifdef MICROPYTHON_USING_MACHINE_SPI
|
|
|
+
|
|
|
+/******************************************************************************/
|
|
|
+// Implementation of hard SPI for machine module
|
|
|
+
|
|
|
+typedef struct _spi_t {
|
|
|
+} spi_t;
|
|
|
+
|
|
|
+typedef struct _machine_hard_spi_obj_t {
|
|
|
+ mp_obj_base_t base;
|
|
|
+ const spi_t *spi;
|
|
|
+} machine_hard_spi_obj_t;
|
|
|
+
|
|
|
+
|
|
|
+STATIC void machine_hard_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
|
|
+ machine_hard_spi_obj_t *self = (machine_hard_spi_obj_t*)self_in;
|
|
|
+}
|
|
|
+
|
|
|
+mp_obj_t machine_hard_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
|
|
+}
|
|
|
+
|
|
|
+STATIC void machine_hard_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
|
|
+ machine_hard_spi_obj_t *self = (machine_hard_spi_obj_t*)self_in;
|
|
|
+
|
|
|
+ enum { ARG_baudrate, ARG_polarity, ARG_phase, ARG_bits, ARG_firstbit };
|
|
|
+ static const mp_arg_t allowed_args[] = {
|
|
|
+ { MP_QSTR_baudrate, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} },
|
|
|
+ { MP_QSTR_polarity, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} },
|
|
|
+ { MP_QSTR_phase, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} },
|
|
|
+ { MP_QSTR_bits, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} },
|
|
|
+ { MP_QSTR_firstbit, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} },
|
|
|
+ };
|
|
|
+ mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
|
|
+ mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+STATIC void machine_hard_spi_deinit(mp_obj_base_t *self_in) {
|
|
|
+ machine_hard_spi_obj_t *self = (machine_hard_spi_obj_t*)self_in;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+STATIC void machine_hard_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) {
|
|
|
+}
|
|
|
+
|
|
|
+STATIC const mp_machine_spi_p_t machine_hard_spi_p = {
|
|
|
+ .init = machine_hard_spi_init,
|
|
|
+ .deinit = machine_hard_spi_deinit,
|
|
|
+ .transfer = machine_hard_spi_transfer,
|
|
|
+};
|
|
|
+
|
|
|
+const mp_obj_type_t machine_hard_spi_type = {
|
|
|
+ { &mp_type_type },
|
|
|
+ .name = MP_QSTR_SPI,
|
|
|
+ .print = machine_hard_spi_print,
|
|
|
+ .make_new = machine_hard_spi_make_new, // delegate to master constructor
|
|
|
+ .protocol = &machine_hard_spi_p,
|
|
|
+ .locals_dict = (mp_obj_t)&mp_machine_spi_locals_dict,
|
|
|
+};
|
|
|
+
|
|
|
+#endif // MICROPYTHON_USING_MACHINE_SPI
|
|
|
+
|