LCOV - code coverage report
Current view: top level - extmod - machine_pinbase.c (source / functions) Hit Total Coverage
Test: unix_coverage_v1.19.1-722-g1b774b373.info Lines: 19 19 100.0 %
Date: 2022-11-29 09:02:29 Functions: 2 2 100.0 %
Branches: 4 5 80.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * This file is part of the MicroPython project, http://micropython.org/
       3                 :            :  *
       4                 :            :  * The MIT License (MIT)
       5                 :            :  *
       6                 :            :  * Copyright (c) 2016 Paul Sokolovsky
       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 "py/mpconfig.h"
      28                 :            : #if MICROPY_PY_MACHINE
      29                 :            : 
      30                 :            : #include "py/obj.h"
      31                 :            : #include "py/runtime.h"
      32                 :            : #include "extmod/virtpin.h"
      33                 :            : #include "extmod/machine_pinbase.h"
      34                 :            : 
      35                 :            : // PinBase class
      36                 :            : 
      37                 :            : // As this is abstract class, its instance is null.
      38                 :            : // But there should be an instance, as the rest of instance code
      39                 :            : // expects that there will be concrete object for inheritance.
      40                 :            : typedef struct _mp_pinbase_t {
      41                 :            :     mp_obj_base_t base;
      42                 :            : } mp_pinbase_t;
      43                 :            : 
      44                 :            : STATIC const mp_pinbase_t pinbase_singleton = {
      45                 :            :     .base = { &machine_pinbase_type },
      46                 :            : };
      47                 :            : 
      48                 :         14 : STATIC mp_obj_t pinbase_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
      49                 :         14 :     (void)type;
      50                 :         14 :     (void)n_args;
      51                 :         14 :     (void)n_kw;
      52                 :         14 :     (void)args;
      53                 :         14 :     return MP_OBJ_FROM_PTR(&pinbase_singleton);
      54                 :            : }
      55                 :            : 
      56                 :            : mp_uint_t pinbase_ioctl(mp_obj_t obj, mp_uint_t request, uintptr_t arg, int *errcode);
      57                 :         99 : mp_uint_t pinbase_ioctl(mp_obj_t obj, mp_uint_t request, uintptr_t arg, int *errcode) {
      58                 :         99 :     (void)errcode;
      59      [ +  +  - ]:         99 :     switch (request) {
      60                 :         91 :         case MP_PIN_READ: {
      61                 :         91 :             mp_obj_t dest[2];
      62                 :         91 :             mp_load_method(obj, MP_QSTR_value, dest);
      63                 :         91 :             return mp_obj_get_int(mp_call_method_n_kw(0, 0, dest));
      64                 :            :         }
      65                 :          8 :         case MP_PIN_WRITE: {
      66                 :          8 :             mp_obj_t dest[3];
      67                 :          8 :             mp_load_method(obj, MP_QSTR_value, dest);
      68         [ +  + ]:          8 :             dest[2] = (arg == 0 ? mp_const_false : mp_const_true);
      69                 :          8 :             mp_call_method_n_kw(1, 0, dest);
      70                 :          8 :             return 0;
      71                 :            :         }
      72                 :            :     }
      73                 :            :     return -1;
      74                 :            : }
      75                 :            : 
      76                 :            : STATIC const mp_pin_p_t pinbase_pin_p = {
      77                 :            :     .ioctl = pinbase_ioctl,
      78                 :            : };
      79                 :            : 
      80                 :            : MP_DEFINE_CONST_OBJ_TYPE(
      81                 :            :     machine_pinbase_type,
      82                 :            :     MP_QSTR_PinBase,
      83                 :            :     MP_TYPE_FLAG_NONE,
      84                 :            :     make_new, pinbase_make_new,
      85                 :            :     protocol, &pinbase_pin_p
      86                 :            :     );
      87                 :            : 
      88                 :            : #endif // MICROPY_PY_MACHINE

Generated by: LCOV version 1.15-5-g462f71d