YAHAL
Yet Another Hardware Abstraction Library
Loading...
Searching...
No Matches
uart_rp2040.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// UART driver for RP2040.
15//
16#ifndef _UART_RP2040_H_
17#define _UART_RP2040_H_
18
19#include <cstdint>
20#include "uart_interface.h"
21#include "gpio_rp2040.h"
22#include "RP2040.h"
23#include "board.h"
24
25using namespace _UART0_;
26using namespace _UART1_;
27
28extern "C" {
29void UART0_IRQ_Handler(void);
30void UART1_IRQ_Handler(void);
31}
32
34public:
35 explicit uart_rp2040(
36 gpio_pin_t tx_pin = BC_UART_TX,
37 gpio_pin_t rx_pin = BC_UART_RX,
38 uint32_t baud = 115200,
39 uart_mode_t mode = UART::BITS_8 |
40 UART::NO_PARITY |
41 UART::STOPBITS_1);
42 ~uart_rp2040() override;
43
44 // Basic read/write operations on a UART
45 bool available() override;
46 char getc() override;
47 void putc(char c) override;
48 int puts(const char *s);
49
50 void uartMode(uart_mode_t mode) override;
51 void setBaudrate(uint32_t) override;
52 void sendBreak(uint16_t ms) override;
53 void setDTR(bool dtr) override;
54 void setRTS(bool rts) override;
55
56 // Interrupt handling
57 void uartAttachIrq (function<void(char)> f) override;
58 void uartDetachIrq () override;
59 void uartEnableIrq () override;
60 void uartDisableIrq() override;
61
62 // FIFO control
63 void enableFIFO(bool) override;
64
65 // The IRQ handlers are our friends :)
66 friend void UART0_IRQ_Handler(void);
67 friend void UART1_IRQ_Handler(void);
68
69private:
70 bool _init;
71 void init();
72
73 static int8_t _uart_tx_pins[2][4];
74
75 static function<void(char)> _intHandler[2];
76
77 UART0_t * _uart;
78 UART0_t * _uart_set;
79 UART0_t * _uart_clr;
80 int _index;
81 gpio_rp2040 _tx;
82 gpio_rp2040 _rx;
83 uint32_t _baud;
84 uart_mode_t _mode;
85};
86
87#endif // _UART_RP2040_H_
CMSIS-Core(M) Device Peripheral Access Layer Header File for Device RP2040.