LCOV - code coverage report
Current view: top level - extmod - machine_pinbase.c (source / functions) Hit Total Coverage
Test: unix_coverage_v1.24.0-7-g548babf8a.info Lines: 19 19 100.0 %
Date: 2024-10-30 09:06:48 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/runtime.h"
      28                 :            : 
      29                 :            : #if MICROPY_PY_MACHINE_PIN_BASE
      30                 :            : 
      31                 :            : #include "extmod/modmachine.h"
      32                 :            : #include "extmod/virtpin.h"
      33                 :            : 
      34                 :            : // PinBase class
      35                 :            : 
      36                 :            : // As this is abstract class, its instance is null.
      37                 :            : // But there should be an instance, as the rest of instance code
      38                 :            : // expects that there will be concrete object for inheritance.
      39                 :            : typedef struct _mp_pinbase_t {
      40                 :            :     mp_obj_base_t base;
      41                 :            : } mp_pinbase_t;
      42                 :            : 
      43                 :            : static const mp_pinbase_t pinbase_singleton = {
      44                 :            :     .base = { &machine_pinbase_type },
      45                 :            : };
      46                 :            : 
      47                 :         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) {
      48                 :         14 :     (void)type;
      49                 :         14 :     (void)n_args;
      50                 :         14 :     (void)n_kw;
      51                 :         14 :     (void)args;
      52                 :         14 :     return MP_OBJ_FROM_PTR(&pinbase_singleton);
      53                 :            : }
      54                 :            : 
      55                 :            : mp_uint_t pinbase_ioctl(mp_obj_t obj, mp_uint_t request, uintptr_t arg, int *errcode);
      56                 :        265 : mp_uint_t pinbase_ioctl(mp_obj_t obj, mp_uint_t request, uintptr_t arg, int *errcode) {
      57                 :        265 :     (void)errcode;
      58      [ +  +  - ]:        265 :     switch (request) {
      59                 :        257 :         case MP_PIN_READ: {
      60                 :        257 :             mp_obj_t dest[2];
      61                 :        257 :             mp_load_method(obj, MP_QSTR_value, dest);
      62                 :        257 :             return mp_obj_get_int(mp_call_method_n_kw(0, 0, dest));
      63                 :            :         }
      64                 :          8 :         case MP_PIN_WRITE: {
      65                 :          8 :             mp_obj_t dest[3];
      66                 :          8 :             mp_load_method(obj, MP_QSTR_value, dest);
      67         [ +  + ]:          8 :             dest[2] = (arg == 0 ? mp_const_false : mp_const_true);
      68                 :          8 :             mp_call_method_n_kw(1, 0, dest);
      69                 :          8 :             return 0;
      70                 :            :         }
      71                 :            :     }
      72                 :            :     return -1;
      73                 :            : }
      74                 :            : 
      75                 :            : static const mp_pin_p_t pinbase_pin_p = {
      76                 :            :     .ioctl = pinbase_ioctl,
      77                 :            : };
      78                 :            : 
      79                 :            : MP_DEFINE_CONST_OBJ_TYPE(
      80                 :            :     machine_pinbase_type,
      81                 :            :     MP_QSTR_PinBase,
      82                 :            :     MP_TYPE_FLAG_NONE,
      83                 :            :     make_new, pinbase_make_new,
      84                 :            :     protocol, &pinbase_pin_p
      85                 :            :     );
      86                 :            : 
      87                 :            : #endif // MICROPY_PY_MACHINE_PIN_BASE

Generated by: LCOV version 1.15-5-g462f71d