summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastian Muszytowski <sebastian@muszytowski.net>2016-01-22 16:04:25 +0100
committerSebastian Muszytowski <sebastian@muszytowski.net>2016-01-22 16:04:25 +0100
commita4d13d607e5d7d6308c52f7a184290916ddd1296 (patch)
treea41170afd180000063b6187535c1f8e1578edb9c /src
parentd607d6234c2f78ed3896ea101872334e7ffa5240 (diff)
parentd1d0e300d9c3a7d6289afcb0bfc544f5d9e81eee (diff)
Merge branch 'master' of github.com:blinkenrocket/firmware
Diffstat (limited to 'src')
-rw-r--r--src/display.cc56
-rw-r--r--src/display.h10
-rw-r--r--src/main.cc3
-rw-r--r--src/modem.cc66
-rw-r--r--src/modem.h8
-rw-r--r--src/system.cc1
6 files changed, 89 insertions, 55 deletions
diff --git a/src/display.cc b/src/display.cc
index 4215983..b0bc636 100644
--- a/src/display.cc
+++ b/src/display.cc
@@ -9,7 +9,19 @@
Display display;
-uint8_t teststr[] = {'O', 'h', 'a', 'i', '!', 0};
+Display::Display()
+{
+ disp_buf[0] = 0xff;
+ disp_buf[1] = 0xfb;
+ disp_buf[2] = 0xdd;
+ disp_buf[3] = 0xfd;
+ disp_buf[4] = 0xdd;
+ disp_buf[5] = 0xfb;
+ disp_buf[6] = 0xff;
+ disp_buf[7] = 0xff;
+ char_pos = -1;
+ scroll_delay = 400;
+}
void Display::disable()
{
@@ -30,24 +42,9 @@ void Display::enable()
TIMSK0 = _BV(TOIE0);
}
-/*
- * Draws a single display column. This function should be called at least once
- * per millisecond.
- *
- * Current configuration:
- * Called every 256 microseconds. The whole display is refreshed every 2048us,
- * giving a refresh rate of ~500Hz
- */
-ISR(TIMER0_OVF_vect)
+void Display::multiplex()
{
- static uint8_t active_col = 0;
- static uint16_t scroll = 0;
-
- static uint8_t disp_buf[] = {0xff,0xfb,0xdd,0xfd,0xdd,0xfb,0xff,0xff};
-
- static uint8_t str_pos = 0;
- static int8_t char_pos = -1;
-
+ static uint16_t scroll;
uint8_t i, glyph_len;
uint8_t *glyph_addr;
@@ -62,7 +59,7 @@ ISR(TIMER0_OVF_vect)
if (++active_col == 8)
active_col = 0;
- if (++scroll == 512) {
+ if (++scroll == scroll_delay) {
scroll = 0;
for (i = 0; i < 7; i++) {
@@ -89,3 +86,24 @@ ISR(TIMER0_OVF_vect)
}
}
}
+
+void Display::reset()
+{
+ for (int i = 0; i < 8; i++)
+ disp_buf[i] = 0xff;
+ str_pos = 0;
+ char_pos = -1;
+}
+
+/*
+ * Draws a single display column. This function should be called at least once
+ * per millisecond.
+ *
+ * Current configuration:
+ * Called every 256 microseconds. The whole display is refreshed every 2048us,
+ * giving a refresh rate of ~500Hz
+ */
+ISR(TIMER0_OVF_vect)
+{
+ display.multiplex();
+}
diff --git a/src/display.h b/src/display.h
index d239e18..666648a 100644
--- a/src/display.h
+++ b/src/display.h
@@ -5,10 +5,18 @@
#include <stdlib.h>
class Display {
+ private:
+ uint16_t scroll_delay;
+ uint8_t active_col;
+ uint8_t disp_buf[8];
+ uint8_t str_pos;
+ int8_t char_pos;
public:
- Display() {};
+ Display();
void enable(void);
void disable(void);
+ void multiplex(void);
+ void reset(void);
char string[128];
};
diff --git a/src/main.cc b/src/main.cc
index f665e18..9558109 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -25,7 +25,8 @@ int main (void)
display.string[2] = 'a';
display.string[3] = 'i';
display.string[4] = '!';
- display.string[5] = 0;
+ display.string[5] = ' ';
+ display.string[6] = 0;
display.enable();
modem.enable();
diff --git a/src/modem.cc b/src/modem.cc
index 2eae685..e9cddb7 100644
--- a/src/modem.cc
+++ b/src/modem.cc
@@ -11,26 +11,22 @@
#include <stdlib.h>
#include "modem.h"
-/* Ring buffer global variables */
-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() {
- return modem_buffer_head - modem_buffer_tail;
+ return buffer_head - buffer_tail;
}
/*
* Store 1 byte in ringbuffer
*/
-static inline void modem_buffer_put(const uint8_t c) {
+inline void Modem::buffer_put(const uint8_t c) {
if (modem.buffer_available() != MODEM_BUFFER_SIZE) {
- modem_buffer[modem_buffer_head++ % MODEM_BUFFER_SIZE] = c;
- }
+ buffer[buffer_head++ % MODEM_BUFFER_SIZE] = c;
+ }
}
/*
@@ -39,15 +35,37 @@ static inline void modem_buffer_put(const uint8_t c) {
uint8_t Modem::buffer_get() {
uint8_t b = 0;
if (buffer_available() != 0) {
- b = modem_buffer[modem_buffer_tail++ % MODEM_BUFFER_SIZE];
+ b = buffer[buffer_tail++ % MODEM_BUFFER_SIZE];
}
return b;
}
/*
- * Pin Change Interrupt Vector. This is The Modem.
+ * Start the modem by enabling Pin Change Interrupts & Timer
*/
-ISR(PCINT3_vect) {
+void Modem::enable() {
+ /* Enable R1 */
+ DDRA |= _BV(PA3);
+ PORTA |= _BV(PA3);
+
+ /* Modem pin as input */
+ MODEM_DDR &= ~_BV(MODEM_PIN);
+
+ /* Enable Pin Change Interrupts and PCINT for MODEM_PIN */
+ MODEM_PCMSK |= _BV(MODEM_PCINT);
+ PCICR |= _BV(MODEM_PCIE);
+
+ /* Timer: TCCR1: CS10 and CS11 bits: 8MHz clock with Prescaler 64 = 125kHz timer clock */
+ TCCR1B = _BV(CS11) | _BV(CS10);
+}
+
+void Modem::disable()
+{
+ PORTA &= ~_BV(PA3);
+ DDRA &= ~_BV(PA3);
+}
+
+void Modem::receive() {
/* Static variables instead of globals to keep scope inside ISR */
static uint8_t modem_bit = 0;
static uint8_t modem_bitlen = 0;
@@ -76,31 +94,13 @@ ISR(PCINT3_vect) {
/* Check if we received complete byte and store it in ring buffer */
if (!(++modem_bit % 0x08)) {
- modem_buffer_put(modem_byte);
+ buffer_put(modem_byte);
}
}
/*
- * Start the modem by enabling Pin Change Interrupts & Timer
+ * Pin Change Interrupt Vector. This is The Modem.
*/
-void Modem::enable() {
- /* Enable R1 */
- DDRA |= _BV(PA3);
- PORTA |= _BV(PA3);
-
- /* Modem pin as input */
- MODEM_DDR &= ~_BV(MODEM_PIN);
-
- /* Enable Pin Change Interrupts and PCINT for MODEM_PIN */
- MODEM_PCMSK |= _BV(MODEM_PCINT);
- PCICR |= _BV(MODEM_PCIE);
-
- /* Timer: TCCR1: CS10 and CS11 bits: 8MHz clock with Prescaler 64 = 125kHz timer clock */
- TCCR1B = _BV(CS11) | _BV(CS10);
-}
-
-void Modem::disable()
-{
- PORTA &= ~_BV(PA3);
- DDRA &= ~_BV(PA3);
+ISR(PCINT3_vect) {
+ modem.receive();
}
diff --git a/src/modem.h b/src/modem.h
index a37d7d8..18273f0 100644
--- a/src/modem.h
+++ b/src/modem.h
@@ -11,7 +11,7 @@
#include <stdlib.h>
/* Modem ring buffer size must be power of 2 */
-#define MODEM_BUFFER_SIZE 4
+#define MODEM_BUFFER_SIZE 8
/* Modem defines */
#define MODEM_SYNC_LEN 42
@@ -23,12 +23,18 @@
#define MODEM_DDR DDRA
class Modem {
+ private:
+ uint8_t buffer_head;
+ uint8_t buffer_tail;
+ uint8_t buffer[MODEM_BUFFER_SIZE];
+ void buffer_put(const uint8_t c);
public:
Modem() {};
uint8_t buffer_available(void);
uint8_t buffer_get(void);
void enable(void);
void disable(void);
+ void receive(void);
};
extern Modem modem;
diff --git a/src/system.cc b/src/system.cc
index 340615d..6c44a30 100644
--- a/src/system.cc
+++ b/src/system.cc
@@ -75,6 +75,7 @@ void System::loop()
i = 0;
} else if (modem_char == 0) {
i = 0;
+ display.reset();
}
}
}