From 7c6e90299de97b51f6ba17d1a50cedb824d0c82f Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Sat, 5 May 2018 18:35:39 +0200 Subject: Add gpio::is_set() to read from _latch register, update command parsing --- hal/pin.hpp | 12 ++++++++++-- hal/pin.tpp | 6 ++++++ hal/uart.hpp | 5 +++++ hal/uart.tpp | 15 +++++++++++++-- 4 files changed, 34 insertions(+), 4 deletions(-) (limited to 'hal') diff --git a/hal/pin.hpp b/hal/pin.hpp index bbb80dc..ab9d3ad 100644 --- a/hal/pin.hpp +++ b/hal/pin.hpp @@ -17,12 +17,19 @@ class gpio public: virtual ~gpio() {} - // digital functions + // digital mode methods virtual void set_mode(unsigned m) = 0; + + // digital output methods virtual void set(unsigned s) = 0; - virtual unsigned read() const = 0; + virtual unsigned is_set() const = 0; virtual void toggle() = 0; + // digital input methods + virtual unsigned read() const = 0; + + // TODO: analog mode methods + protected: gpio() {} }; @@ -47,6 +54,7 @@ public: void set_mode(mode m); unsigned read() const; + unsigned is_set() const; void set(unsigned s); void set(state s); diff --git a/hal/pin.tpp b/hal/pin.tpp index 42d03de..527ba0a 100644 --- a/hal/pin.tpp +++ b/hal/pin.tpp @@ -51,6 +51,12 @@ unsigned io_pin::read() const return (*_port & (1< +unsigned io_pin::is_set() const +{ + return (*_latch & (1< void io_pin::set(unsigned s) { diff --git a/hal/uart.hpp b/hal/uart.hpp index b1dce29..65062f6 100644 --- a/hal/uart.hpp +++ b/hal/uart.hpp @@ -62,6 +62,11 @@ namespace uart template void initialize(); +#if 0 + template + void set_baudrate(long baud); +#endif + // the following functions have been inlined // template diff --git a/hal/uart.tpp b/hal/uart.tpp index 0ecd615..359722e 100644 --- a/hal/uart.tpp +++ b/hal/uart.tpp @@ -193,8 +193,9 @@ io_pin<3> led_green(&LATBbits, &TRISBbits, &PORTBbits); void __ISR(_UART_1_VECTOR, IPL1AUTO) usart_1_isr() { if (IFS1bits.U1RXIF) { - // debug + #ifdef DEBUG led_blue.toggle(); + #endif // wait for data to be available while (!U1STAbits.URXDA); @@ -213,10 +214,12 @@ void __ISR(_UART_1_VECTOR, IPL1AUTO) usart_1_isr() } // on each interrupt call, send one character else if (IFS1bits.U1TXIF) { + #ifdef DEBUG + led_green.toggle(); + #endif // disable TX interrupt flag IEC1bits.U1TXIE = 0; - led_green.toggle(); // write data U1TXREG = static_cast(uart::tx_buffer<1>().front()); @@ -298,6 +301,14 @@ namespace uart CFGCONbits.IOLOCK = 1; // lock PPS hw::reglock(); } + +#if 0 + template<> + void set_baudrate<1>(long baud) + { + + } +#endif } #endif \ No newline at end of file -- cgit v1.2.1