LCOV - code coverage report
Current view: top level - AP_HAL - GPIO.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 3 17 17.6 %
Date: 2026-09-09 11:02:08 Functions: 3 12 25.0 %

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include <stdint.h>
       4             : 
       5             : #include "AP_HAL_Namespace.h"
       6             : 
       7             : #define HAL_GPIO_INPUT  0
       8             : #define HAL_GPIO_OUTPUT 1
       9             : #define HAL_GPIO_ALT    2
      10             : 
      11             : class AP_HAL::DigitalSource {
      12             : public:
      13             :     virtual void    mode(uint8_t output) = 0;
      14             :     virtual uint8_t read() = 0;
      15             :     virtual void    write(uint8_t value) = 0;
      16             :     virtual void    toggle() = 0;
      17             : };
      18             : 
      19             : class AP_HAL::PWMSource {
      20             : public:
      21             : 
      22             :     // Destructor detaches interrupt
      23             :     ~PWMSource();
      24             : 
      25             :     bool set_pin(int16_t new_pin, const char *subsystem);
      26             :     int16_t pin() const { return _pin; }  // returns pin this is attached to
      27             : 
      28             :     uint16_t get_pwm_us();            // return last measured PWM input
      29             :     uint16_t get_pwm_avg_us();        // return average PWM since last call to get_pwm_avg_us
      30             : 
      31             : private:
      32             :     uint16_t _irq_value_us;         // last calculated pwm value (irq copy)
      33             :     uint32_t _pulse_start_us;       // system time of start of pulse
      34             :     int16_t _pin = -1;
      35             : 
      36             :     uint32_t _irq_value_us_sum;     // for get_pwm_avg_us
      37             :     uint32_t _irq_value_us_count;   // for get_pwm_avg_us
      38             : 
      39             :     bool interrupt_attached;
      40             : 
      41             :     // PWM input handling
      42             :     void irq_handler(uint8_t pin,
      43             :                      bool pin_state,
      44             :                      uint32_t timestamp);
      45             : };
      46             : 
      47             : class AP_HAL::GPIO {
      48             : public:
      49        2193 :     GPIO() {}
      50             :     virtual void    init() = 0;
      51             :     virtual void    pinMode(uint8_t pin, uint8_t output) = 0;
      52             : 
      53             :     // optional interface on some boards
      54           0 :     virtual void    pinMode(uint8_t pin, uint8_t output, uint8_t alt) {};
      55             : 
      56             :     virtual uint8_t read(uint8_t pin) = 0;
      57             :     virtual void    write(uint8_t pin, uint8_t value) = 0;
      58             :     virtual void    toggle(uint8_t pin) = 0;
      59           0 :     virtual bool    valid_pin(uint8_t pin) const { return true; }
      60             : 
      61             :     // return servo channel associated with GPIO pin.  Returns true on success and fills in servo_ch argument
      62             :     // servo_ch uses zero-based indexing
      63         492 :     virtual bool    pin_to_servo_channel(uint8_t pin, uint8_t& servo_ch) const { return false; }
      64             : 
      65             :     // allow for save and restore of pin settings
      66           0 :     virtual bool    get_mode(uint8_t pin, uint32_t &mode) { return false; }
      67           0 :     virtual void    set_mode(uint8_t pin, uint32_t mode) {}
      68             : 
      69             :     /* Alternative interface: */
      70             :     virtual AP_HAL::DigitalSource* channel(uint16_t n) = 0;
      71             : 
      72             :     enum INTERRUPT_TRIGGER_TYPE {
      73             :         INTERRUPT_NONE,
      74             :         INTERRUPT_FALLING,
      75             :         INTERRUPT_RISING,
      76             :         INTERRUPT_BOTH,
      77             :     };
      78             : 
      79             :     /* Interrupt interface: */
      80             :     //                                ret , pin    , state,timestamp
      81             :     // where:
      82             :     //    ret indicates the functor must return void
      83             :     //    pin is the pin which has triggered the interrupt
      84             :     //    state is the new state of the pin
      85             :     //    timestamp is the time in microseconds the interrupt occurred
      86             :     FUNCTOR_TYPEDEF(irq_handler_fn_t, void, uint8_t, bool, uint32_t);
      87           0 :     virtual bool    attach_interrupt(uint8_t pin,
      88             :                                      irq_handler_fn_t fn,
      89             :                                      INTERRUPT_TRIGGER_TYPE mode) {
      90           0 :         return false;
      91             :     }
      92             : 
      93           0 :     virtual bool    attach_interrupt(uint8_t pin,
      94             :                                      AP_HAL::Proc proc,
      95             :                                      INTERRUPT_TRIGGER_TYPE mode) {
      96           0 :         return false;
      97             :     }
      98           0 :     bool detach_interrupt(uint8_t pin) {
      99           0 :         if (attach_interrupt(pin, (irq_handler_fn_t)nullptr, AP_HAL::GPIO::INTERRUPT_NONE)) {
     100           0 :             return true;
     101             :         }
     102           0 :         return attach_interrupt(pin, (AP_HAL::Proc)nullptr, AP_HAL::GPIO::INTERRUPT_NONE);
     103             :     }
     104             : 
     105             :     /*
     106             :       block waiting for a pin to change. A timeout of 0 means wait
     107             :       forever. Return true on pin change, false on timeout
     108             :      */
     109           0 :     virtual bool wait_pin(uint8_t pin, INTERRUPT_TRIGGER_TYPE mode, uint32_t timeout_us) { return false; }
     110             : 
     111             :     /* return true if USB cable is connected */
     112             :     virtual bool    usb_connected(void) = 0;
     113             : 
     114             :     // optional timer tick
     115           0 :     virtual void timer_tick(void) {};
     116             : 
     117             :     // Run arming checks
     118       73934 :     virtual bool arming_checks(size_t buflen, char *buffer) const { return true; }
     119             : 
     120             : };

Generated by: LCOV version 1.14