From 3fddb519f01ca53f1fd6f5c24e154912b25d1138 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Tue, 17 Jul 2018 09:57:10 +0200 Subject: Move include/$arch to include/arch/$arch to be consistent with src/ hierarchy --- include/arch/arduino-nano/driver/gpio.h | 111 ++++++++++++++++++++++++++++++ include/arch/arduino-nano/driver/i2c.h | 19 +++++ include/arch/arduino-nano/driver/stdin.h | 24 +++++++ include/arch/arduino-nano/driver/stdout.h | 19 +++++ include/arch/arduino-nano/driver/uptime.h | 29 ++++++++ 5 files changed, 202 insertions(+) create mode 100644 include/arch/arduino-nano/driver/gpio.h create mode 100644 include/arch/arduino-nano/driver/i2c.h create mode 100644 include/arch/arduino-nano/driver/stdin.h create mode 100644 include/arch/arduino-nano/driver/stdout.h create mode 100644 include/arch/arduino-nano/driver/uptime.h (limited to 'include/arch/arduino-nano/driver') diff --git a/include/arch/arduino-nano/driver/gpio.h b/include/arch/arduino-nano/driver/gpio.h new file mode 100644 index 0000000..6acf977 --- /dev/null +++ b/include/arch/arduino-nano/driver/gpio.h @@ -0,0 +1,111 @@ +#ifndef GPIO_H +#define GPIO_H + +#include + +class GPIO { + private: + GPIO(const GPIO ©); + + public: + GPIO () {} + + enum Pin : unsigned char { + 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, + pc6 = 22, + pd0 = 24, + pd1 = 25, + pd2 = 26, + pd3 = 27, + pd4 = 28, + pd5 = 29, + pd6 = 30, + pd7 = 31 + }; + + inline void setup() { + DDRB = _BV(PB5); + } + inline void led_on(unsigned char id) { + PORTB |= _BV(PB5); + } + inline void led_off(unsigned char id) { + PORTB &= ~_BV(PB5); + } + inline void led_toggle(unsigned char id) { + PINB = _BV(PB5); + } + inline void input(unsigned char const pin) { + if (pin < 8) { + } 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) { + if (pin < 8) { + } 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 unsigned char read(unsigned char const pin) { + if (pin < 8) { + } + 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) { + } 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); + } + } + } +}; + +extern GPIO gpio; + +#endif diff --git a/include/arch/arduino-nano/driver/i2c.h b/include/arch/arduino-nano/driver/i2c.h new file mode 100644 index 0000000..6d6ea66 --- /dev/null +++ b/include/arch/arduino-nano/driver/i2c.h @@ -0,0 +1,19 @@ +#ifndef I2C_H +#define I2C_H + +class I2C { + private: + I2C(const I2C ©); + + 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/arduino-nano/driver/stdin.h b/include/arch/arduino-nano/driver/stdin.h new file mode 100644 index 0000000..6462e0c --- /dev/null +++ b/include/arch/arduino-nano/driver/stdin.h @@ -0,0 +1,24 @@ +#ifndef STANDARDINPUT_H +#define STANDARDINPUT_H + +class StandardInput { + private: + StandardInput(const StandardInput ©); + char buffer[8]; + unsigned char write_pos, read_pos; + + public: + StandardInput() : write_pos(0), read_pos(0) {} + void setup(); + bool hasKey(); + char getKey(); + + inline void addKey(char key) { + buffer[write_pos++] = key; + write_pos %= 8; + } +}; + +extern StandardInput kin; + +#endif diff --git a/include/arch/arduino-nano/driver/stdout.h b/include/arch/arduino-nano/driver/stdout.h new file mode 100644 index 0000000..2eb669d --- /dev/null +++ b/include/arch/arduino-nano/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 ©); + + public: + StandardOutput () {} + void setup(); + + virtual void put(char c) override; +}; + +extern StandardOutput kout; + +#endif diff --git a/include/arch/arduino-nano/driver/uptime.h b/include/arch/arduino-nano/driver/uptime.h new file mode 100644 index 0000000..86a8bb5 --- /dev/null +++ b/include/arch/arduino-nano/driver/uptime.h @@ -0,0 +1,29 @@ +#ifndef UPTIME_H +#define UPTIME_H + +#include + +class Uptime { + private: + Uptime(const Uptime ©); +#ifdef TIMER_S + uint8_t seconds; +#endif + + public: +#ifdef TIMER_S + Uptime () : seconds(0) {} +#else + Uptime () {} +#endif + inline uint8_t get_cycles() { return TCNT0; } + inline uint8_t get_us() { return TCNT2/2; } +#ifdef TIMER_S + inline uint8_t get_s() { return seconds; } + inline void tick_s() { seconds++; } +#endif +}; + +extern Uptime uptime; + +#endif -- cgit v1.2.3