summaryrefslogtreecommitdiff
path: root/include/arch/blinkenrocket
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2018-08-08 14:59:02 +0200
committerDaniel Friesel <derf@finalrewind.org>2018-08-08 14:59:02 +0200
commite7f1024732ee9bac13fbf2e2439106f9f3577db7 (patch)
tree16e52dac6be007b3ca6b0f38f3226a12fb828bc7 /include/arch/blinkenrocket
parent4a2747f0c508cd5af830c14e43ffeaf3fe25e4e7 (diff)
Add Blinkenrocket arch
Diffstat (limited to 'include/arch/blinkenrocket')
-rw-r--r--include/arch/blinkenrocket/driver/gpio.h178
-rw-r--r--include/arch/blinkenrocket/driver/i2c.h19
-rw-r--r--include/arch/blinkenrocket/driver/stdout.h19
-rw-r--r--include/arch/blinkenrocket/driver/uptime.h28
4 files changed, 244 insertions, 0 deletions
diff --git a/include/arch/blinkenrocket/driver/gpio.h b/include/arch/blinkenrocket/driver/gpio.h
new file mode 100644
index 0000000..be6eb38
--- /dev/null
+++ b/include/arch/blinkenrocket/driver/gpio.h
@@ -0,0 +1,178 @@
+#ifndef GPIO_H
+#define GPIO_H
+
+#include <avr/io.h>
+
+class GPIO {
+ private:
+ GPIO(const GPIO &copy);
+
+ public:
+ GPIO () {}
+
+ enum Pin : unsigned char {
+ pa0 = 0,
+ pa1 = 1,
+ pa2 = 2,
+ pa3 = 3,
+ pb0 = 8,
+ pb1 = 9,
+ pb2 = 10,
+ pb3 = 11,
+ pb4 = 12,
+ pb5 = 13,
+ pb6 = 14,
+ pb7 = 15,
+ pc0 = 16,
+ pc1 = 17,
+ pc2 = 18,
+ pc3 = 19,
+ pc4 = 20,
+ pc5 = 21,
+ pc7 = 23,
+ pd0 = 24,
+ pd1 = 25,
+ pd2 = 26,
+ pd3 = 27,
+ pd4 = 28,
+ pd5 = 29,
+ pd6 = 30,
+ pd7 = 31
+ };
+
+ inline void setup() {
+ PORTB = 0;
+ DDRB = 0;
+ PORTD = 0x7f;
+ DDRD = 0xff;
+ }
+ inline void led_on(unsigned char id) {
+ PORTB |= _BV(id);
+ }
+ inline void led_off(unsigned char id) {
+ PORTB &= ~_BV(id);
+ }
+ inline void led_toggle(unsigned char id) {
+ PORTB ^= _BV(id);
+ }
+ inline void input(unsigned char const pin) {
+ if (pin < 8) {
+ DDRA &= ~_BV(pin);
+ } else if (pin < 16) {
+ DDRB &= ~_BV(pin - 8);
+ } else if (pin < 24) {
+ DDRC &= ~_BV(pin - 16);
+ } else if (pin < 32) {
+ DDRD &= ~_BV(pin - 24);
+ }
+ }
+ inline void input(unsigned char const pin, unsigned char const pull) {
+ if (pin < 8) {
+ DDRA &= ~_BV(pin);
+ PORTA |= _BV(pin);
+ } else if (pin < 16) {
+ DDRB &= ~_BV(pin - 8);
+ PORTB |= _BV(pin - 8);
+ } else if (pin < 24) {
+ DDRC &= ~_BV(pin - 16);
+ PORTC |= _BV(pin - 16);
+ } else if (pin < 32) {
+ DDRD &= ~_BV(pin - 24);
+ PORTD |= _BV(pin - 24);
+ }
+ }
+ inline void output(unsigned char const pin) {
+ if (pin < 8) {
+ DDRA |= _BV(pin);
+ } else if (pin < 16) {
+ DDRB |= _BV(pin - 8);
+ } else if (pin < 24) {
+ DDRC |= _BV(pin - 16);
+ } else if (pin < 32) {
+ DDRD |= _BV(pin - 24);
+ }
+ }
+ inline void output(unsigned char const pin, unsigned char const value) {
+ if (pin < 8) {
+ PORTA = value ? (PORTA | _BV(pin)) : (PORTA & ~_BV(pin));
+ DDRA |= _BV(pin);
+ } else if (pin < 16) {
+ PORTB = value ? (PORTB | _BV(pin - 8)) : (PORTB & ~_BV(pin - 8));
+ DDRB |= _BV(pin - 8);
+ } else if (pin < 24) {
+ PORTC = value ? (PORTC | _BV(pin - 16)) : (PORTC & ~_BV(pin - 16));
+ DDRC |= _BV(pin - 16);
+ } else if (pin < 32) {
+ PORTD = value ? (PORTD | _BV(pin - 24)) : (PORTD & ~_BV(pin - 24));
+ DDRD |= _BV(pin - 24);
+ }
+ }
+ inline unsigned char read(unsigned char const pin) {
+ if (pin < 8) {
+ return (PINA & _BV(pin));
+ }
+ if (pin < 16) {
+ return (PINB & _BV(pin - 8));
+ }
+ if (pin < 24) {
+ return (PINC & _BV(pin - 16));
+ }
+ if (pin < 32) {
+ return (PIND & _BV(pin - 24));
+ }
+ return 0;
+ }
+ inline void write(unsigned char const pin, unsigned char value) {
+ if (pin < 8) {
+ if (value) {
+ PORTA |= _BV(pin);
+ } else {
+ PORTA &= ~_BV(pin);
+ }
+ } else if (pin < 16) {
+ if (value) {
+ PORTB |= _BV(pin - 8);
+ } else {
+ PORTB &= ~_BV(pin - 8);
+ }
+ } else if (pin < 24) {
+ if (value) {
+ PORTB |= _BV(pin - 16);
+ } else {
+ PORTB &= ~_BV(pin - 16);
+ }
+ } else if (pin < 32) {
+ if (value) {
+ PORTB |= _BV(pin - 24);
+ } else {
+ PORTB &= ~_BV(pin - 24);
+ }
+ }
+ }
+ /*
+ inline void enable_int(unsigned char const pin) {
+ if (pin < 8) {
+ } else if (pin < 16) {
+ PCMSK0 |= _BV(pin - 8);
+ } else if (pin < 24) {
+ PCMSK1 |= _BV(pin - 16);
+ } else if (pin < 32) {
+ PCMSK2 |= _BV(pin - 24);
+ }
+ }
+ inline void disable_int(unsigned char const pin) {
+ if (pin < 8) {
+ } else if (pin < 16) {
+ PCMSK0 &= ~_BV(pin - 8);
+ } else if (pin < 24) {
+ PCMSK1 &= ~_BV(pin - 16);
+ } else if (pin < 32) {
+ PCMSK2 &= ~_BV(pin - 24);
+ }
+ }
+ */
+};
+
+extern GPIO gpio;
+
+#endif
diff --git a/include/arch/blinkenrocket/driver/i2c.h b/include/arch/blinkenrocket/driver/i2c.h
new file mode 100644
index 0000000..6d6ea66
--- /dev/null
+++ b/include/arch/blinkenrocket/driver/i2c.h
@@ -0,0 +1,19 @@
+#ifndef I2C_H
+#define I2C_H
+
+class I2C {
+ private:
+ I2C(const I2C &copy);
+
+ public:
+ I2C () {}
+ signed char setup();
+ void scan(unsigned int *results);
+ signed char xmit(unsigned char address,
+ unsigned char tx_len, unsigned char *tx_buf,
+ unsigned char rx_len, unsigned char *rx_buf);
+};
+
+extern I2C i2c;
+
+#endif
diff --git a/include/arch/blinkenrocket/driver/stdout.h b/include/arch/blinkenrocket/driver/stdout.h
new file mode 100644
index 0000000..2eb669d
--- /dev/null
+++ b/include/arch/blinkenrocket/driver/stdout.h
@@ -0,0 +1,19 @@
+#ifndef STANDARDOUTPUT_H
+#define STANDARDOUTPUT_H
+
+#include "object/outputstream.h"
+
+class StandardOutput : public OutputStream {
+ private:
+ StandardOutput(const StandardOutput &copy);
+
+ public:
+ StandardOutput () {}
+ void setup();
+
+ virtual void put(char c) override;
+};
+
+extern StandardOutput kout;
+
+#endif
diff --git a/include/arch/blinkenrocket/driver/uptime.h b/include/arch/blinkenrocket/driver/uptime.h
new file mode 100644
index 0000000..d5fdd2e
--- /dev/null
+++ b/include/arch/blinkenrocket/driver/uptime.h
@@ -0,0 +1,28 @@
+#ifndef UPTIME_H
+#define UPTIME_H
+
+#include <avr/io.h>
+
+class Uptime {
+ private:
+ Uptime(const Uptime &copy);
+#ifdef TIMER_S
+ uint8_t seconds;
+#endif
+
+ public:
+#ifdef TIMER_S
+ Uptime () : seconds(0) {}
+#else
+ Uptime () {}
+#endif
+ inline uint8_t get_cycles() { return TCNT0; }
+#ifdef TIMER_S
+ inline uint8_t get_s() { return seconds; }
+ inline void tick_s() { seconds++; }
+#endif
+};
+
+extern Uptime uptime;
+
+#endif