1.1 --- a/pkg/devices/lib/gpio/include/gpio.h Tue Apr 30 01:31:23 2024 +0200
1.2 +++ b/pkg/devices/lib/gpio/include/gpio.h Tue Apr 30 01:32:10 2024 +0200
1.3 @@ -30,6 +30,7 @@
1.4
1.5 #pragma once
1.6
1.7 +#include <l4/sys/err.h>
1.8 #include <l4/vbus/vbus_gpio.h>
1.9 #include <stdint.h>
1.10
1.11 @@ -64,7 +65,39 @@
1.12
1.13 class Gpio_chip
1.14 {
1.15 +protected:
1.16 + unsigned _nr_pins;
1.17 +
1.18 + // Convenience method for obtaining the bit corresponding to a pin.
1.19 +
1.20 + l4_uint32_t _pin_bit(unsigned pin)
1.21 + { return 1 << (pin & 31); }
1.22 +
1.23 + // Convenience method for obtaining the bit position of a pin.
1.24 +
1.25 + unsigned _pin_shift(unsigned pin)
1.26 + { return pin % 32; }
1.27 +
1.28 + // Permit only "aligned" accesses to registers.
1.29 +
1.30 + unsigned _reg_offset_check(unsigned pin_offset) const
1.31 + {
1.32 + switch (pin_offset)
1.33 + {
1.34 + case 0:
1.35 + return 0;
1.36 +
1.37 + default:
1.38 + throw -L4_EINVAL;
1.39 + }
1.40 + }
1.41 +
1.42 public:
1.43 + explicit Gpio_chip(unsigned nr_pins)
1.44 + : _nr_pins(nr_pins)
1.45 + {
1.46 + }
1.47 +
1.48 /// Modes used for setup()
1.49 enum Fix_mode
1.50 {
1.51 @@ -89,14 +122,12 @@
1.52 Function_irq,
1.53 };
1.54
1.55 - virtual void request(unsigned pin) = 0;
1.56 - virtual void free(unsigned pin) = 0;
1.57 -
1.58 /**
1.59 * \brief Request number of pins from GPIO chip
1.60 * \return Number of pins of this GPIO chip
1.61 */
1.62 - virtual unsigned nr_pins() const = 0;
1.63 + virtual unsigned nr_pins() const
1.64 + { return _nr_pins; }
1.65
1.66 /**
1.67 * \brief Generic (platform independent) setup for a pin.