LCOV - code coverage report
Current view: top level - zephyr/drivers/misc/pio_rpi_pico - pio_rpi_pico.h Coverage Total Hit
Test: new.info Lines: 100.0 % 10 10
Test Date: 2025-09-05 16:43:28

            Line data    Source code
       1            1 : /*
       2              :  * Copyright (c) 2023 Tokita, Hiroshi <tokita.hiroshi@fujitsu.com>
       3              :  * Copyright (c) 2023 Yonatan Schachter
       4              :  * Copyright (c) 2023 Ionut Pavel <iocapa@iocapa.com>
       5              :  *
       6              :  * SPDX-License-Identifier: Apache-2.0
       7              :  */
       8              : 
       9              : /**
      10              :  * @file
      11              :  * @brief Header file for Raspberry Pi Pico PIO driver
      12              :  * @ingroup pio_rpi_pico_interface
      13              :  */
      14              : 
      15              : #ifndef ZEPHYR_DRIVERS_MISC_PIO_PICO_RPI_PIO_PICO_RPI_H_
      16              : #define ZEPHYR_DRIVERS_MISC_PIO_PICO_RPI_PIO_PICO_RPI_H_
      17              : 
      18              : /**
      19              :  * @brief Raspberry Pi Pico PIO driver APIs
      20              :  * @defgroup pio_rpi_pico_interface Raspberry Pi Pico PIO Driver APIs
      21              :  * @ingroup misc_interfaces
      22              :  *
      23              :  * @{
      24              :  */
      25              : 
      26              : #include <zephyr/devicetree/gpio.h>
      27              : 
      28              : #include <hardware/pio.h>
      29              : 
      30              : /**
      31              :  * @brief Utility macro to define a PIO program. The program is a list
      32              :  *        of 16 bit instructions, generated by the pioasm tool.
      33              :  *
      34              :  * @param name Name of the program.
      35              :  * @param wrap_target Wrap target as specified by the PIO program.
      36              :  * @param wrap Wrap source as specified by the PIO program.
      37              :  * @param ... Comma separated list of PIO instructions.
      38              :  */
      39            1 : #define RPI_PICO_PIO_DEFINE_PROGRAM(name, wrap_target, wrap, ...)       \
      40              :         static const uint32_t name ## _wrap_target = wrap_target;       \
      41              :         static const uint32_t name ## _wrap = wrap;                     \
      42              :         static const uint16_t name ## _program_instructions[] = {       \
      43              :                 __VA_ARGS__                                             \
      44              :         };                                                              \
      45              :         static const struct pio_program name ## _program = {            \
      46              :                 .instructions = name ## _program_instructions,          \
      47              :                 .length = ARRAY_SIZE(name ## _program_instructions),    \
      48              :                 .origin = -1,                                           \
      49              :         }
      50              : 
      51              : /**
      52              :  * @brief Utility macro to get the wrap target of a program.
      53              :  *
      54              :  * @param name Name of the program.
      55              :  */
      56            1 : #define RPI_PICO_PIO_GET_WRAP_TARGET(name) name ## _wrap_target
      57              : 
      58              : /**
      59              :  * @brief Utility macro to get the wrap source of a program.
      60              :  *
      61              :  * @param name Name of the program.
      62              :  */
      63            1 : #define RPI_PICO_PIO_GET_WRAP(name) name ## _wrap
      64              : 
      65              : /**
      66              :  * @brief Utility macro to get a pointer to a PIO program.
      67              :  *
      68              :  * @param name Name of the program.
      69              :  */
      70            1 : #define RPI_PICO_PIO_GET_PROGRAM(name) &name ## _program
      71              : 
      72              : /**
      73              :  * @brief Get a pin number from a pinctrl / group name and index
      74              :  *
      75              :  * Example devicetree fragment(s):
      76              :  *
      77              :  * @code{.dts}
      78              :  *      pinctrl {
      79              :  *              pio_child_default: pio_child_default {
      80              :  *                      tx_gpio {
      81              :  *                              pinmux = <PIO0_P0>, <PIO0_P2>;
      82              :  *                      };
      83              :  *
      84              :  *                      rx_gpio {
      85              :  *                              pinmux = <PIO0_P1>;
      86              :  *                              input-enable;
      87              :  *                      };
      88              :  *              };
      89              :  *      };
      90              :  * @endcode
      91              :  *
      92              :  * @code{.dts}
      93              :  *      pio {
      94              :  *              status = "okay";
      95              :  *              c: child {
      96              :  *                      pinctrl-0 = <&pio_child_default>;
      97              :  *                      pinctrl-names = "default";
      98              :  *              };
      99              :  *      };
     100              :  * @endcode
     101              :  *
     102              :  * Example usage:
     103              :  *
     104              :  * @code{.c}
     105              :  *      DT_RPI_PICO_PIO_PIN_BY_NAME(node, default, 0, tx_gpio, 0) // 0
     106              :  *      DT_RPI_PICO_PIO_PIN_BY_NAME(node, default, 0, tx_gpio, 1) // 2
     107              :  *      DT_RPI_PICO_PIO_PIN_BY_NAME(node, default, 0, rx_gpio, 0) // 1
     108              :  * @endcode
     109              :  *
     110              :  * @param node_id node identifier
     111              :  * @param p_name pinctrl name
     112              :  * @param p_idx pinctrl index
     113              :  * @param g_name group name
     114              :  * @param g_idx group index
     115              :  * @return pin number
     116              :  */
     117            1 : #define DT_RPI_PICO_PIO_PIN_BY_NAME(node_id, p_name, p_idx, g_name, g_idx)                      \
     118              :         RP2_GET_PIN_NUM(DT_PROP_BY_IDX(                                                         \
     119              :                 DT_CHILD(DT_PINCTRL_BY_NAME(node_id, p_name, p_idx), g_name), pinmux, g_idx))
     120              : 
     121              : /**
     122              :  * @brief Get a pin number from a pinctrl / group name and index
     123              :  *
     124              :  * @param inst instance number
     125              :  * @param p_name pinctrl name
     126              :  * @param p_idx pinctrl index
     127              :  * @param g_name group name
     128              :  * @param g_idx group index
     129              :  * @return pin number
     130              :  *
     131              :  * @see DT_RPI_PICO_PIO_PIN_BY_NAME
     132              :  */
     133            1 : #define DT_INST_RPI_PICO_PIO_PIN_BY_NAME(inst, p_name, p_idx, g_name, g_idx)                    \
     134              :         DT_RPI_PICO_PIO_PIN_BY_NAME(DT_DRV_INST(inst), p_name, p_idx, g_name, g_idx)
     135              : 
     136              : /**
     137              :  * @brief Get the pin number of a pin by its name.
     138              :  *
     139              :  * @param inst instance number
     140              :  * @param name name of the pin (e.g. tx, rx, sck).
     141              :  */
     142            1 : #define DT_INST_PIO_PIN_BY_NAME(inst, name) \
     143              :         DT_PIO_PIN_BY_NAME(DT_DRV_INST(inst), name)
     144              : 
     145              : /**
     146              :  * Get PIO object
     147              :  *
     148              :  * @param dev Pointer to device structure for rpi_pio device instance
     149              :  * @return PIO object
     150              :  */
     151            1 : inline PIO pio_rpi_pico_get_pio(const struct device *dev)
     152              : {
     153              :         return *(PIO *)(dev->config);
     154              : }
     155              : 
     156              : /**
     157              :  * Allocate a state machine.
     158              :  *
     159              :  * @param dev Pointer to device structure for rpi_pio device instance
     160              :  * @param sm Pointer to store allocated state machine
     161              :  * @retval 0 on success
     162              :  * @retval -EBUSY if no state machines were available
     163              :  */
     164            1 : int pio_rpi_pico_allocate_sm(const struct device *dev, size_t *sm);
     165              : 
     166              : /**
     167              :  * @}
     168              :  */
     169              : 
     170              : #endif /* ZEPHYR_DRIVERS_MISC_PIO_PICO_RPI_PIO_PICO_RPI_H_ */
        

Generated by: LCOV version 2.0-1