diff options
author | Nao Pross <naopross@thearcway.org> | 2018-05-05 18:35:39 +0200 |
---|---|---|
committer | Nao Pross <naopross@thearcway.org> | 2018-05-05 18:35:39 +0200 |
commit | 7c6e90299de97b51f6ba17d1a50cedb824d0c82f (patch) | |
tree | 2a032bbec8a11e1b5f7a189ff2750936982576fc /hal | |
parent | Fix split() (diff) | |
download | SAMLiquidSmoke-7c6e90299de97b51f6ba17d1a50cedb824d0c82f.tar.gz SAMLiquidSmoke-7c6e90299de97b51f6ba17d1a50cedb824d0c82f.zip |
Add gpio::is_set() to read from _latch register, update command parsing
Diffstat (limited to '')
-rw-r--r-- | hal/pin.hpp | 12 | ||||
-rw-r--r-- | hal/pin.tpp | 6 | ||||
-rw-r--r-- | hal/uart.hpp | 5 | ||||
-rw-r--r-- | hal/uart.tpp | 15 |
4 files changed, 34 insertions, 4 deletions
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 @@ -52,6 +52,12 @@ unsigned io_pin<bit>::read() const } template<unsigned bit> +unsigned io_pin<bit>::is_set() const +{ + return (*_latch & (1<<bit)) ? 1 : 0; +} + +template<unsigned bit> void io_pin<bit>::set(unsigned s) { if (s > 0) 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<unsigned dev> void initialize(); +#if 0 + template<unsigned dev> + void set_baudrate(long baud); +#endif + // the following functions have been inlined // template<unsigned dev> 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<decltype(U1TXREG)>(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 |