YAHAL
Yet Another Hardware Abstraction Library
Loading...
Searching...
No Matches
gpio_rp2350.h
1// ---------------------------------------------
2// This file is part of
3// _ _ __ _ _ __ __
4// ( \/ ) /__\ ( )_( ) /__\ ( )
5// \ / /(__)\ ) _ ( /(__)\ )(__
6// (__)(__)(__)(_) (_)(__)(__)(____)
7//
8// Yet Another HW Abstraction Library
9// Copyright (C) Andreas Terstegge
10// BSD Licensed (see file LICENSE)
11//
12// ---------------------------------------------
13//
14// GPIO driver for RP2350. Supports open-source and
15// open-drain modes as well as interrupts.
16//
17#ifndef GPIO_RP2350_H
18#define GPIO_RP2350_H
19
20#include "gpio_interface.h"
21#include <cassert>
22
23namespace GPIO {
24// additional gpio modes
25 const gpio_mode_t DRIVE_2mA = 0x0000;
26 const gpio_mode_t DRIVE_4mA = 0x0400;
27 const gpio_mode_t DRIVE_8mA = 0x0800;
28 const gpio_mode_t DRIVE_12mA = 0x0c00;
29 const gpio_mode_t INPUT_INVERT = 0x1000;
30}
31
32extern "C" {
33void IO_IRQ_BANK0_Handler(void);
34}
35
37public:
38 explicit gpio_rp2350(gpio_pin_t gpio = 0xffff);
39 ~gpio_rp2350() override = default;
40
41 // No copy, assignment is value passing
42 gpio_rp2350 (const gpio_rp2350&) = delete;
43 gpio_rp2350& operator= (const gpio_rp2350 & lhs) {
44 this->gpioWrite(lhs.operator bool());
45 return *this;
46 };
47
48 // Get and Set the GPIO number during runtime
49 void setGpio(gpio_pin_t gpio) override;
50 gpio_pin_t getGpio() const override;
51
52 // Generic GPIO methods
53 void gpioMode (gpio_mode_t mode) override;
54 bool gpioRead () const override;
55 void gpioWrite (bool value) override;
56 void gpioToggle() override;
57
58 // Interrupt handling
59 void gpioAttachIrq (gpio_mode_t mode,
60 function<void()> handler) override;
61 void gpioDetachIrq () override;
62 void gpioEnableIrq () override;
63 void gpioDisableIrq() override;
64
65 // RP2350 specific methods
66 void setSEL (uint8_t sel) const;
67 void setMode(gpio_mode_t mode);
68
69 using gpio_interface::operator =;
70 using gpio_interface::operator bool;
71
72 // IRQ handlers are our best friends
73 friend void IO_IRQ_BANK0_Handler(void);
74
75private:
76 gpio_pin_t _gpio;
77 bool _open_source {false};
78 bool _open_drain {false};
79 bool _high_gpio {false};
80 uint32_t _mask {0};
81
82 static function<void()> _intHandler[48];
83 static uint8_t _irqConfig [48];
84};
85
86#endif // GPIO_RP2350_H