diff options
author | Daniel Friesel <derf@finalrewind.org> | 2016-01-15 16:51:19 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2016-01-15 16:51:19 +0100 |
commit | ab36943fa7276d20f8b6e14ae2352db0a3daec04 (patch) | |
tree | 25a2ec3c792c68760103619ba77ffc1137dbcf33 /src | |
parent | 9e66404e8e704037aff06713ed0cdfa43fc1b220 (diff) |
C++-ize modem code (a little bit)
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cc | 7 | ||||
-rw-r--r-- | src/modem.cc (renamed from src/modem.c) | 15 | ||||
-rw-r--r-- | src/modem.h | 18 |
3 files changed, 27 insertions, 13 deletions
diff --git a/src/main.cc b/src/main.cc index c51483d..9bf9f4e 100644 --- a/src/main.cc +++ b/src/main.cc @@ -5,6 +5,7 @@ #include <stdlib.h> #include "font2.h" +#include "modem.h" #define SHUTDOWN_THRESHOLD 2048 @@ -89,6 +90,10 @@ void System::loop() else { want_shutdown = 0; } + + if (modem.buffer_available()) { + disp[0] = modem.buffer_get(); + } } int main (void) @@ -158,6 +163,8 @@ int main (void) disp[31] = 0x00; #endif + modem.init(); + sei(); while (1) { diff --git a/src/modem.c b/src/modem.cc index dbe9d35..6020a15 100644 --- a/src/modem.c +++ b/src/modem.cc @@ -13,10 +13,12 @@ static volatile uint8_t modem_buffer_head = 0, modem_buffer_tail = 0; static volatile uint8_t modem_buffer[MODEM_BUFFER_SIZE]; +Modem modem; + /* * Returns number of available bytes in ringbuffer or 0 if empty */ -uint8_t modem_buffer_available() { +uint8_t Modem::buffer_available() { return modem_buffer_head - modem_buffer_tail; } @@ -24,7 +26,7 @@ uint8_t modem_buffer_available() { * Store 1 byte in ringbuffer */ static inline void modem_buffer_put(const uint8_t c) { - if (modem_buffer_available() != MODEM_BUFFER_SIZE) { + if (modem.buffer_available() != MODEM_BUFFER_SIZE) { modem_buffer[modem_buffer_head++ % MODEM_BUFFER_SIZE] = c; } } @@ -32,9 +34,9 @@ static inline void modem_buffer_put(const uint8_t c) { /* * Fetch 1 byte from ringbuffer */ -uint8_t modem_buffer_get() { +uint8_t Modem::buffer_get() { uint8_t b = 0; - if (modem_buffer_available() != 0) { + if (buffer_available() != 0) { b = modem_buffer[modem_buffer_tail++ % MODEM_BUFFER_SIZE]; } return b; @@ -79,7 +81,7 @@ ISR(PCINT3_vect) { /* * Start the modem by enabling Pin Change Interrupts & Timer */ -void modem_init() { +void Modem::init() { /* Modem pin as input */ MODEM_DDR &= ~(1 << MODEM_PIN); @@ -89,7 +91,4 @@ void modem_init() { /* Timer: TCCR1: CS10 and CS11 bits: 8MHz clock with Prescaler 64 = 125kHz timer clock */ TCCR1B = _BV(CS11) | _BV(CS10); - - /* Enable interrupts */ - sei(); } diff --git a/src/modem.h b/src/modem.h index d538c22..c02101c 100644 --- a/src/modem.h +++ b/src/modem.h @@ -4,7 +4,8 @@ * License: LGPLv3, see COPYING, and COPYING.LESSER -files for more info */ -#pragma once +#ifndef MODEM_H_ +#define MODEM_H_ #include <avr/interrupt.h> #include <stdlib.h> @@ -18,7 +19,14 @@ #define MODEM_PIN PCINT24 #define MODEM_DDR DDRA -/* Public funtions */ -uint8_t modem_buffer_available(); -uint8_t modem_buffer_get(); -void modem_init(); +class Modem { + public: + Modem() {}; + uint8_t buffer_available(void); + uint8_t buffer_get(void); + void init(void); +}; + +extern Modem modem; + +#endif /* MODEM_H_ */ |