diff options
Diffstat (limited to 'esp8266')
-rw-r--r-- | esp8266/Makefile | 1 | ||||
-rw-r--r-- | esp8266/esp8266.ld | 1 | ||||
-rw-r--r-- | esp8266/modmachine.c | 3 | ||||
-rw-r--r-- | esp8266/modmachinespi.c | 71 | ||||
-rw-r--r-- | esp8266/modpyb.h | 1 | ||||
-rw-r--r-- | esp8266/modpybhspi.c | 2 | ||||
-rw-r--r-- | esp8266/modpybspi.c | 4 |
7 files changed, 79 insertions, 4 deletions
diff --git a/esp8266/Makefile b/esp8266/Makefile index 22591f209b..0b498602f2 100644 --- a/esp8266/Makefile +++ b/esp8266/Makefile @@ -78,6 +78,7 @@ SRC_C = \ modpybrtc.c \ modpybadc.c \ modpybuart.c \ + modmachinespi.c \ modpybspi.c \ modpybhspi.c \ modesp.c \ diff --git a/esp8266/esp8266.ld b/esp8266/esp8266.ld index 6c89858070..dec3bf5a30 100644 --- a/esp8266/esp8266.ld +++ b/esp8266/esp8266.ld @@ -141,6 +141,7 @@ SECTIONS *modpybadc.o(.literal*, .text*) *modpybuart.o(.literal*, .text*) *modpybi2c.o(.literal*, .text*) + *modmachinespi.o(.literal*, .text*) *modpybspi.o(.literal*, .text*) *modpybhspi.o(.literal*, .text*) *hspi.o(.literal*, .text*) diff --git a/esp8266/modmachine.c b/esp8266/modmachine.c index 624ce2ac56..7672834aac 100644 --- a/esp8266/modmachine.c +++ b/esp8266/modmachine.c @@ -251,8 +251,9 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_ADC), MP_ROM_PTR(&pyb_adc_type) }, { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&pyb_uart_type) }, { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&machine_i2c_type) }, - { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&pyb_spi_type) }, + { MP_ROM_QSTR(MP_QSTR_SoftSPI), MP_ROM_PTR(&pyb_spi_type) }, { MP_ROM_QSTR(MP_QSTR_HSPI), MP_ROM_PTR(&pyb_hspi_type) }, + { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&machine_spi_type) }, // wake abilities { MP_ROM_QSTR(MP_QSTR_DEEPSLEEP), MP_ROM_INT(MACHINE_WAKE_DEEPSLEEP) }, 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, +}; diff --git a/esp8266/modpyb.h b/esp8266/modpyb.h index 0eec556b15..45d0bb8cfd 100644 --- a/esp8266/modpyb.h +++ b/esp8266/modpyb.h @@ -11,6 +11,7 @@ extern const mp_obj_type_t pyb_uart_type; extern const mp_obj_type_t pyb_i2c_type; extern const mp_obj_type_t pyb_spi_type; extern const mp_obj_type_t pyb_hspi_type; +extern const mp_obj_type_t machine_spi_type; MP_DECLARE_CONST_FUN_OBJ(pyb_info_obj); diff --git a/esp8266/modpybhspi.c b/esp8266/modpybhspi.c index ad78c83fd8..f80fbae00a 100644 --- a/esp8266/modpybhspi.c +++ b/esp8266/modpybhspi.c @@ -106,7 +106,7 @@ STATIC void pyb_hspi_init_helper(pyb_hspi_obj_t *self, size_t n_args, const mp_o spi_mode(HSPI, self->phase, self->polarity); } -STATIC 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) { +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) { mp_arg_check_num(n_args, n_kw, 0, MP_OBJ_FUN_ARGS_MAX, true); pyb_hspi_obj_t *self = m_new_obj(pyb_hspi_obj_t); self->base.type = &pyb_hspi_type; diff --git a/esp8266/modpybspi.c b/esp8266/modpybspi.c index c2bcc33edc..fafe3b2fa5 100644 --- a/esp8266/modpybspi.c +++ b/esp8266/modpybspi.c @@ -131,7 +131,7 @@ STATIC void pyb_spi_init_helper(pyb_spi_obj_t *self, size_t n_args, const mp_obj mp_hal_pin_input(self->miso); } -STATIC 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_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, 0, MP_OBJ_FUN_ARGS_MAX, true); pyb_spi_obj_t *self = m_new_obj(pyb_spi_obj_t); self->base.type = &pyb_spi_type; @@ -215,7 +215,7 @@ STATIC MP_DEFINE_CONST_DICT(pyb_spi_locals_dict, pyb_spi_locals_dict_table); const mp_obj_type_t pyb_spi_type = { { &mp_type_type }, - .name = MP_QSTR_SPI, + .name = MP_QSTR_SoftSPI, .print = pyb_spi_print, .make_new = pyb_spi_make_new, .locals_dict = (mp_obj_dict_t*)&pyb_spi_locals_dict, |