|
| 1 | +/* |
| 2 | + * This file is part of the MicroPython project, http://micropython.org/ |
| 3 | + * |
| 4 | + * The MIT License (MIT) |
| 5 | + * |
| 6 | + * Copyright (c) 2016 Damien P. George |
| 7 | + * |
| 8 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | + * of this software and associated documentation files (the "Software"), to deal |
| 10 | + * in the Software without restriction, including without limitation the rights |
| 11 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 | + * copies of the Software, and to permit persons to whom the Software is |
| 13 | + * furnished to do so, subject to the following conditions: |
| 14 | + * |
| 15 | + * The above copyright notice and this permission notice shall be included in |
| 16 | + * all copies or substantial portions of the Software. |
| 17 | + * |
| 18 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 21 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 24 | + * THE SOFTWARE. |
| 25 | + */ |
| 26 | + |
| 27 | +#include <stdio.h> |
| 28 | +#include <stdint.h> |
| 29 | +#include <string.h> |
| 30 | + |
| 31 | +#include "ets_sys.h" |
| 32 | +#include "etshal.h" |
| 33 | +#include "ets_alt_task.h" |
| 34 | + |
| 35 | +#include "py/runtime.h" |
| 36 | +#include "py/stream.h" |
| 37 | +#include "py/mphal.h" |
| 38 | + |
| 39 | + |
| 40 | +mp_obj_t pyb_spi_make_new(const mp_obj_type_t *type, size_t n_args, |
| 41 | + size_t n_kw, const mp_obj_t *args); |
| 42 | +mp_obj_t pyb_hspi_make_new(const mp_obj_type_t *type, size_t n_args, |
| 43 | + size_t n_kw, const mp_obj_t *args); |
| 44 | + |
| 45 | + |
| 46 | +STATIC mp_obj_t machine_spi_make_new(const mp_obj_type_t *type, size_t n_args, |
| 47 | + size_t n_kw, const mp_obj_t *args) { |
| 48 | + mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); |
| 49 | + switch (mp_obj_get_int(args[0])) { |
| 50 | + case -1: |
| 51 | + return pyb_spi_make_new(type, n_args - 1, n_kw, args + 1); |
| 52 | + case 0: |
| 53 | + return pyb_hspi_make_new(type, n_args - 1, n_kw, args + 1); |
| 54 | + default: |
| 55 | + nlr_raise(mp_obj_new_exception_msg_varg( |
| 56 | + &mp_type_ValueError, "no such SPI peripheral")); |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | + |
| 61 | +STATIC const mp_rom_map_elem_t machine_spi_locals_dict_table[] = {}; |
| 62 | + |
| 63 | +STATIC MP_DEFINE_CONST_DICT(machine_spi_locals_dict, |
| 64 | + machine_spi_locals_dict_table); |
| 65 | + |
| 66 | +const mp_obj_type_t machine_spi_type = { |
| 67 | + { &mp_type_type }, |
| 68 | + .name = MP_QSTR_SPI, |
| 69 | + .make_new = machine_spi_make_new, |
| 70 | + .locals_dict = (mp_obj_dict_t*)&machine_spi_locals_dict, |
| 71 | +}; |
0 commit comments