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 --- Makefile | 2 +- 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 +++++++ include/arch/esp8266/driver/gpio.h | 30 +++++++ include/arch/esp8266/driver/stdin.h | 24 +++++ include/arch/esp8266/driver/stdout.h | 61 +++++++++++++ include/arch/esp8266/driver/uptime.h | 28 ++++++ include/arch/esp8266/user_config.h | 5 ++ include/arch/msp430fr5969lp/driver/adc.h | 17 ++++ include/arch/msp430fr5969lp/driver/gpio.h | 130 ++++++++++++++++++++++++++++ include/arch/msp430fr5969lp/driver/i2c.h | 19 ++++ include/arch/msp430fr5969lp/driver/spi_b.h | 18 ++++ include/arch/msp430fr5969lp/driver/stdin.h | 24 +++++ include/arch/msp430fr5969lp/driver/stdout.h | 19 ++++ include/arch/msp430fr5969lp/driver/uptime.h | 30 +++++++ include/arch/posix/driver/gpio.h | 19 ++++ include/arch/posix/driver/stdout.h | 20 +++++ include/arch/posix/driver/uptime.h | 19 ++++ include/arduino-nano/driver/gpio.h | 111 ------------------------ include/arduino-nano/driver/i2c.h | 19 ---- include/arduino-nano/driver/stdin.h | 24 ----- include/arduino-nano/driver/stdout.h | 19 ---- include/arduino-nano/driver/uptime.h | 29 ------- include/esp8266/driver/gpio.h | 30 ------- include/esp8266/driver/stdin.h | 24 ----- include/esp8266/driver/stdout.h | 61 ------------- include/esp8266/driver/uptime.h | 28 ------ include/esp8266/user_config.h | 5 -- include/msp430fr5969lp/driver/adc.h | 17 ---- include/msp430fr5969lp/driver/gpio.h | 130 ---------------------------- include/msp430fr5969lp/driver/i2c.h | 19 ---- include/msp430fr5969lp/driver/spi_b.h | 18 ---- include/msp430fr5969lp/driver/stdin.h | 24 ----- include/msp430fr5969lp/driver/stdout.h | 19 ---- include/msp430fr5969lp/driver/uptime.h | 30 ------- include/posix/driver/gpio.h | 19 ---- include/posix/driver/stdout.h | 20 ----- include/posix/driver/uptime.h | 19 ---- src/arch/arduino-nano/Makefile.inc | 1 - src/arch/esp8266/Makefile.inc | 2 +- src/arch/msp430fr5969lp/Makefile.inc | 2 +- src/arch/posix/Makefile.inc | 1 - 45 files changed, 668 insertions(+), 670 deletions(-) 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 create mode 100644 include/arch/esp8266/driver/gpio.h create mode 100644 include/arch/esp8266/driver/stdin.h create mode 100644 include/arch/esp8266/driver/stdout.h create mode 100644 include/arch/esp8266/driver/uptime.h create mode 100644 include/arch/esp8266/user_config.h create mode 100644 include/arch/msp430fr5969lp/driver/adc.h create mode 100644 include/arch/msp430fr5969lp/driver/gpio.h create mode 100644 include/arch/msp430fr5969lp/driver/i2c.h create mode 100644 include/arch/msp430fr5969lp/driver/spi_b.h create mode 100644 include/arch/msp430fr5969lp/driver/stdin.h create mode 100644 include/arch/msp430fr5969lp/driver/stdout.h create mode 100644 include/arch/msp430fr5969lp/driver/uptime.h create mode 100644 include/arch/posix/driver/gpio.h create mode 100644 include/arch/posix/driver/stdout.h create mode 100644 include/arch/posix/driver/uptime.h delete mode 100644 include/arduino-nano/driver/gpio.h delete mode 100644 include/arduino-nano/driver/i2c.h delete mode 100644 include/arduino-nano/driver/stdin.h delete mode 100644 include/arduino-nano/driver/stdout.h delete mode 100644 include/arduino-nano/driver/uptime.h delete mode 100644 include/esp8266/driver/gpio.h delete mode 100644 include/esp8266/driver/stdin.h delete mode 100644 include/esp8266/driver/stdout.h delete mode 100644 include/esp8266/driver/uptime.h delete mode 100644 include/esp8266/user_config.h delete mode 100644 include/msp430fr5969lp/driver/adc.h delete mode 100644 include/msp430fr5969lp/driver/gpio.h delete mode 100644 include/msp430fr5969lp/driver/i2c.h delete mode 100644 include/msp430fr5969lp/driver/spi_b.h delete mode 100644 include/msp430fr5969lp/driver/stdin.h delete mode 100644 include/msp430fr5969lp/driver/stdout.h delete mode 100644 include/msp430fr5969lp/driver/uptime.h delete mode 100644 include/posix/driver/gpio.h delete mode 100644 include/posix/driver/stdout.h delete mode 100644 include/posix/driver/uptime.h diff --git a/Makefile b/Makefile index b7089b4..e5dc27d 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ default: build/system.elf -INCLUDES = -Iinclude +INCLUDES = -Iinclude -Iinclude/arch/${arch} COMMON_FLAGS = -g -Os -Wall -Wextra -fno-rtti CFLAGS = -std=c99 CXXFLAGS = -std=c++14 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 diff --git a/include/arch/esp8266/driver/gpio.h b/include/arch/esp8266/driver/gpio.h new file mode 100644 index 0000000..3db5d9d --- /dev/null +++ b/include/arch/esp8266/driver/gpio.h @@ -0,0 +1,30 @@ +#ifndef GPIO_H +#define GPIO_H + +class GPIO { + private: + GPIO(const GPIO ©); + + public: + GPIO () {} + + enum Pin : unsigned char { + d3 = 0, tx, d4, rx, d2, d1, + d6 = 12, d7, d5, d8, + d0 = 16 + }; + + void setup(); + void led_on(unsigned char id); + void led_off(unsigned char id); + void led_toggle(unsigned char id); + void input(unsigned char const pin); + void input(unsigned char const pin, bool pullup); + void output(unsigned char const pin); + unsigned char read(unsigned char const pin); + void write(unsigned char const pin, unsigned char value); +}; + +extern GPIO gpio; + +#endif diff --git a/include/arch/esp8266/driver/stdin.h b/include/arch/esp8266/driver/stdin.h new file mode 100644 index 0000000..6462e0c --- /dev/null +++ b/include/arch/esp8266/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/esp8266/driver/stdout.h b/include/arch/esp8266/driver/stdout.h new file mode 100644 index 0000000..038de2e --- /dev/null +++ b/include/arch/esp8266/driver/stdout.h @@ -0,0 +1,61 @@ +#ifndef STANDARDOUTPUT_H +#define STANDARDOUTPUT_H + +class StandardOutput { + private: + StandardOutput(const StandardOutput ©); + char digit_buffer[sizeof(long long) * 8]; + unsigned char base; + + public: + StandardOutput (); + void setup(); + + void put(char c); + void write(const char *s); + void flush() {} + void printf_uint8(unsigned char num); + void printf_float(float num); + + StandardOutput & operator<<(char c); + StandardOutput & operator<<(unsigned char c); + StandardOutput & operator<<(unsigned short number); + StandardOutput & operator<<(short number); + StandardOutput & operator<<(unsigned int number); + StandardOutput & operator<<(int number); + StandardOutput & operator<<(unsigned long number); + StandardOutput & operator<<(long number); + StandardOutput & operator<<(unsigned long long number); + StandardOutput & operator<<(long long number); + StandardOutput & operator<<(void *pointer); + StandardOutput & operator<<(const char *text); + StandardOutput & operator<<(StandardOutput & (*fun) (StandardOutput &)); + + void setBase(unsigned char b); +}; + + +// ENDL: new line character (and flush) +StandardOutput & endl(StandardOutput & os); + +// BIN: print numbers in binary form. +StandardOutput & bin(StandardOutput & os); + +// OCT: print numbers in octal form. +StandardOutput & oct(StandardOutput & os); + +// DEC: print numbers in decimal form. +StandardOutput & dec(StandardOutput & os); + +// HEX: print numbers in hexadecimal form. +StandardOutput & hex(StandardOutput & os); + +// FLUSH: flush StandardOutput buffer +StandardOutput & flush(StandardOutput & os); + +// TERM: zero-termination +StandardOutput & term(StandardOutput & os); + +extern StandardOutput kout; + +#endif diff --git a/include/arch/esp8266/driver/uptime.h b/include/arch/esp8266/driver/uptime.h new file mode 100644 index 0000000..21740c9 --- /dev/null +++ b/include/arch/esp8266/driver/uptime.h @@ -0,0 +1,28 @@ +#ifndef UPTIME_H +#define UPTIME_H + +extern "C" { +#include "osapi.h" +#include "user_interface.h" +} +#include "c_types.h" + +class Uptime { + private: + Uptime(const Uptime ©); + + public: + Uptime () {} + inline uint32_t get_us() { return system_get_time(); } + + inline uint32_t get_cycles() + { + uint32_t ccount; + asm volatile ("esync; rsr %0,ccount":"=a" (ccount)); + return ccount; + } +}; + +extern Uptime uptime; + +#endif diff --git a/include/arch/esp8266/user_config.h b/include/arch/esp8266/user_config.h new file mode 100644 index 0000000..529fb46 --- /dev/null +++ b/include/arch/esp8266/user_config.h @@ -0,0 +1,5 @@ +/* + * required by ESP8266 SDK's osapi.h + * + * Intentionally left blank. + */ diff --git a/include/arch/msp430fr5969lp/driver/adc.h b/include/arch/msp430fr5969lp/driver/adc.h new file mode 100644 index 0000000..d93aed4 --- /dev/null +++ b/include/arch/msp430fr5969lp/driver/adc.h @@ -0,0 +1,17 @@ +#ifndef ADC_H +#define ADC_H + +class ADC { + private: + ADC(ADC const ©); + + public: + ADC() {} + + float getTemp(); + float getVCC(); +}; + +extern ADC adc; + +#endif diff --git a/include/arch/msp430fr5969lp/driver/gpio.h b/include/arch/msp430fr5969lp/driver/gpio.h new file mode 100644 index 0000000..caed74a --- /dev/null +++ b/include/arch/msp430fr5969lp/driver/gpio.h @@ -0,0 +1,130 @@ +#ifndef GPIO_H +#define GPIO_H + +#include + +class GPIO { + private: + GPIO(const GPIO ©); + + public: + GPIO () {} + + enum Pin : unsigned char { + p1_0 = 0, p1_1, p1_2, p1_3, p1_4, p1_5, p1_6, p1_7, + p2_0, p2_1, p2_2, p2_3, p2_4, p2_5, p2_6, p2_7, + p3_0, p3_1, p3_2, p3_3, p3_4, p3_5, p3_6, p3_7, + p4_0, p4_1, p4_2, p4_3, p4_4, p4_5, p4_6, p4_7, + pj_0, pj_1, pj_2, pj_3, pj_4, pj_5, pj_6, pj_7, + PIN_INVALID + }; + + inline void setup() { + P1OUT = 0; + P2OUT = 0; + P3OUT = 0; + P4OUT = 0; + P1DIR = BIT0; + P2DIR = 0; + P3DIR = 0; + P4DIR = BIT6; + } + inline void led_on(unsigned char id) { + if (id == 0) { + P1OUT |= BIT0; + } else { + P4OUT |= BIT6; + } + } + inline void led_off(unsigned char id) { + if (id == 0) { + P1OUT &= ~BIT0; + } else { + P4OUT &= ~BIT6; + } + } + inline void led_toggle(unsigned char id) { + if (id == 0) { + P1OUT ^= BIT0; + } else { + P4OUT ^= BIT6; + } + } + inline void input(unsigned char const pin) { + if (pin < p2_0) { + P1DIR &= ~(1 << pin); + } else if (pin < p3_0) { + P2DIR &= ~(1 << (pin - p2_0)); + } else if (pin < p4_0) { + P3DIR &= ~(1 << (pin - p3_0)); + } else if (pin < pj_0) { + P4DIR &= ~(1 << (pin - p4_0)); + } else if (pin < PIN_INVALID) { + PJDIR &= ~(1 << (pin - pj_0)); + } + } + inline void output(unsigned char const pin) { + if (pin < p2_0) { + P1DIR |= (1 << pin); + } else if (pin < p3_0) { + P2DIR |= (1 << (pin - p2_0)); + } else if (pin < p4_0) { + P3DIR |= (1 << (pin - p3_0)); + } else if (pin < pj_0) { + P4DIR |= (1 << (pin - p4_0)); + } else if (pin < PIN_INVALID) { + PJDIR |= (1 << (pin - pj_0)); + } + } + inline unsigned char read(unsigned char const pin) { + if (pin < p2_0) { + return P1IN & (1 << pin); + } else if (pin < p3_0) { + return P2IN & (1 << (pin - p2_0)); + } else if (pin < p4_0) { + return P3IN & (1 << (pin - p3_0)); + } else if (pin < pj_0) { + return P4IN & (1 << (pin - p4_0)); + } else if (pin < PIN_INVALID) { + return PJIN & (1 << (pin - pj_0)); + } + return 0; + } + inline void write(unsigned char const pin, unsigned char value) { + if (pin < p2_0) { + if (value) { + P1OUT |= (1 << pin); + } else { + P1OUT &= ~(1 << pin); + } + } else if (pin < p3_0) { + if (value) { + P2OUT |= (1 << (pin - p2_0)); + } else { + P2OUT &= ~(1 << (pin - p2_0)); + } + } else if (pin < p4_0) { + if (value) { + P3OUT |= (1 << (pin - p3_0)); + } else { + P3OUT &= ~(1 << (pin - p3_0)); + } + } else if (pin < pj_0) { + if (value) { + P4OUT |= (1 << (pin - p4_0)); + } else { + P4OUT &= ~(1 << (pin - p4_0)); + } + } else if (pin < PIN_INVALID) { + if (value) { + PJOUT |= (1 << (pin - pj_0)); + } else { + PJOUT &= ~(1 << (pin - pj_0)); + } + } + } +}; + +extern GPIO gpio; + +#endif diff --git a/include/arch/msp430fr5969lp/driver/i2c.h b/include/arch/msp430fr5969lp/driver/i2c.h new file mode 100644 index 0000000..6d6ea66 --- /dev/null +++ b/include/arch/msp430fr5969lp/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/msp430fr5969lp/driver/spi_b.h b/include/arch/msp430fr5969lp/driver/spi_b.h new file mode 100644 index 0000000..4be7346 --- /dev/null +++ b/include/arch/msp430fr5969lp/driver/spi_b.h @@ -0,0 +1,18 @@ +#ifndef SPI_H +#define SPI_H + +class SPI { + private: + SPI(const SPI ©); + + public: + SPI () {} + void setup(); + signed char xmit( + unsigned char tx_len, unsigned char *tx_buf, + unsigned char rx_len, unsigned char *rx_buf); +}; + +extern SPI spi; + +#endif diff --git a/include/arch/msp430fr5969lp/driver/stdin.h b/include/arch/msp430fr5969lp/driver/stdin.h new file mode 100644 index 0000000..6462e0c --- /dev/null +++ b/include/arch/msp430fr5969lp/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/msp430fr5969lp/driver/stdout.h b/include/arch/msp430fr5969lp/driver/stdout.h new file mode 100644 index 0000000..2eb669d --- /dev/null +++ b/include/arch/msp430fr5969lp/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/msp430fr5969lp/driver/uptime.h b/include/arch/msp430fr5969lp/driver/uptime.h new file mode 100644 index 0000000..3a52840 --- /dev/null +++ b/include/arch/msp430fr5969lp/driver/uptime.h @@ -0,0 +1,30 @@ +#ifndef UPTIME_H +#define UPTIME_H + +#include +#include + +class Uptime { + private: + Uptime(const Uptime ©); +#ifdef TIMER_S + uint16_t seconds; +#endif + + public: +#ifdef TIMER_S + Uptime () : seconds(0) {} +#else + Uptime () {} +#endif + inline uint16_t get_us() { return TA0R; } + inline uint16_t get_cycles() { return TA2R; } +#ifdef TIMER_S + inline uint16_t get_s() { return seconds; } + inline void tick_s() { seconds++; } +#endif +}; + +extern Uptime uptime; + +#endif diff --git a/include/arch/posix/driver/gpio.h b/include/arch/posix/driver/gpio.h new file mode 100644 index 0000000..0995729 --- /dev/null +++ b/include/arch/posix/driver/gpio.h @@ -0,0 +1,19 @@ +#ifndef GPIO_H +#define GPIO_H + +class GPIO { + private: + GPIO(const GPIO ©); + unsigned char ledstate; + + public: + GPIO () : ledstate(0) {} + void setup() {} + void led_on(unsigned char id); + void led_off(unsigned char id); + void led_toggle(unsigned char id); +}; + +extern GPIO gpio; + +#endif diff --git a/include/arch/posix/driver/stdout.h b/include/arch/posix/driver/stdout.h new file mode 100644 index 0000000..b21ad56 --- /dev/null +++ b/include/arch/posix/driver/stdout.h @@ -0,0 +1,20 @@ +#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; + virtual void flush() override; +}; + +extern StandardOutput kout; + +#endif diff --git a/include/arch/posix/driver/uptime.h b/include/arch/posix/driver/uptime.h new file mode 100644 index 0000000..93711b9 --- /dev/null +++ b/include/arch/posix/driver/uptime.h @@ -0,0 +1,19 @@ +#ifndef UPTIME_H +#define UPTIME_H + +#include + +class Uptime { + private: + Uptime(const Uptime ©); + + public: + Uptime () {} + uint64_t get_s(); + uint64_t get_us(); + uint64_t get_cycles(); +}; + +extern Uptime uptime; + +#endif diff --git a/include/arduino-nano/driver/gpio.h b/include/arduino-nano/driver/gpio.h deleted file mode 100644 index 6acf977..0000000 --- a/include/arduino-nano/driver/gpio.h +++ /dev/null @@ -1,111 +0,0 @@ -#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/arduino-nano/driver/i2c.h b/include/arduino-nano/driver/i2c.h deleted file mode 100644 index 6d6ea66..0000000 --- a/include/arduino-nano/driver/i2c.h +++ /dev/null @@ -1,19 +0,0 @@ -#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/arduino-nano/driver/stdin.h b/include/arduino-nano/driver/stdin.h deleted file mode 100644 index 6462e0c..0000000 --- a/include/arduino-nano/driver/stdin.h +++ /dev/null @@ -1,24 +0,0 @@ -#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/arduino-nano/driver/stdout.h b/include/arduino-nano/driver/stdout.h deleted file mode 100644 index 2eb669d..0000000 --- a/include/arduino-nano/driver/stdout.h +++ /dev/null @@ -1,19 +0,0 @@ -#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/arduino-nano/driver/uptime.h b/include/arduino-nano/driver/uptime.h deleted file mode 100644 index 86a8bb5..0000000 --- a/include/arduino-nano/driver/uptime.h +++ /dev/null @@ -1,29 +0,0 @@ -#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 diff --git a/include/esp8266/driver/gpio.h b/include/esp8266/driver/gpio.h deleted file mode 100644 index 3db5d9d..0000000 --- a/include/esp8266/driver/gpio.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef GPIO_H -#define GPIO_H - -class GPIO { - private: - GPIO(const GPIO ©); - - public: - GPIO () {} - - enum Pin : unsigned char { - d3 = 0, tx, d4, rx, d2, d1, - d6 = 12, d7, d5, d8, - d0 = 16 - }; - - void setup(); - void led_on(unsigned char id); - void led_off(unsigned char id); - void led_toggle(unsigned char id); - void input(unsigned char const pin); - void input(unsigned char const pin, bool pullup); - void output(unsigned char const pin); - unsigned char read(unsigned char const pin); - void write(unsigned char const pin, unsigned char value); -}; - -extern GPIO gpio; - -#endif diff --git a/include/esp8266/driver/stdin.h b/include/esp8266/driver/stdin.h deleted file mode 100644 index 6462e0c..0000000 --- a/include/esp8266/driver/stdin.h +++ /dev/null @@ -1,24 +0,0 @@ -#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/esp8266/driver/stdout.h b/include/esp8266/driver/stdout.h deleted file mode 100644 index 038de2e..0000000 --- a/include/esp8266/driver/stdout.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef STANDARDOUTPUT_H -#define STANDARDOUTPUT_H - -class StandardOutput { - private: - StandardOutput(const StandardOutput ©); - char digit_buffer[sizeof(long long) * 8]; - unsigned char base; - - public: - StandardOutput (); - void setup(); - - void put(char c); - void write(const char *s); - void flush() {} - void printf_uint8(unsigned char num); - void printf_float(float num); - - StandardOutput & operator<<(char c); - StandardOutput & operator<<(unsigned char c); - StandardOutput & operator<<(unsigned short number); - StandardOutput & operator<<(short number); - StandardOutput & operator<<(unsigned int number); - StandardOutput & operator<<(int number); - StandardOutput & operator<<(unsigned long number); - StandardOutput & operator<<(long number); - StandardOutput & operator<<(unsigned long long number); - StandardOutput & operator<<(long long number); - StandardOutput & operator<<(void *pointer); - StandardOutput & operator<<(const char *text); - StandardOutput & operator<<(StandardOutput & (*fun) (StandardOutput &)); - - void setBase(unsigned char b); -}; - - -// ENDL: new line character (and flush) -StandardOutput & endl(StandardOutput & os); - -// BIN: print numbers in binary form. -StandardOutput & bin(StandardOutput & os); - -// OCT: print numbers in octal form. -StandardOutput & oct(StandardOutput & os); - -// DEC: print numbers in decimal form. -StandardOutput & dec(StandardOutput & os); - -// HEX: print numbers in hexadecimal form. -StandardOutput & hex(StandardOutput & os); - -// FLUSH: flush StandardOutput buffer -StandardOutput & flush(StandardOutput & os); - -// TERM: zero-termination -StandardOutput & term(StandardOutput & os); - -extern StandardOutput kout; - -#endif diff --git a/include/esp8266/driver/uptime.h b/include/esp8266/driver/uptime.h deleted file mode 100644 index 21740c9..0000000 --- a/include/esp8266/driver/uptime.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef UPTIME_H -#define UPTIME_H - -extern "C" { -#include "osapi.h" -#include "user_interface.h" -} -#include "c_types.h" - -class Uptime { - private: - Uptime(const Uptime ©); - - public: - Uptime () {} - inline uint32_t get_us() { return system_get_time(); } - - inline uint32_t get_cycles() - { - uint32_t ccount; - asm volatile ("esync; rsr %0,ccount":"=a" (ccount)); - return ccount; - } -}; - -extern Uptime uptime; - -#endif diff --git a/include/esp8266/user_config.h b/include/esp8266/user_config.h deleted file mode 100644 index 529fb46..0000000 --- a/include/esp8266/user_config.h +++ /dev/null @@ -1,5 +0,0 @@ -/* - * required by ESP8266 SDK's osapi.h - * - * Intentionally left blank. - */ diff --git a/include/msp430fr5969lp/driver/adc.h b/include/msp430fr5969lp/driver/adc.h deleted file mode 100644 index d93aed4..0000000 --- a/include/msp430fr5969lp/driver/adc.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef ADC_H -#define ADC_H - -class ADC { - private: - ADC(ADC const ©); - - public: - ADC() {} - - float getTemp(); - float getVCC(); -}; - -extern ADC adc; - -#endif diff --git a/include/msp430fr5969lp/driver/gpio.h b/include/msp430fr5969lp/driver/gpio.h deleted file mode 100644 index caed74a..0000000 --- a/include/msp430fr5969lp/driver/gpio.h +++ /dev/null @@ -1,130 +0,0 @@ -#ifndef GPIO_H -#define GPIO_H - -#include - -class GPIO { - private: - GPIO(const GPIO ©); - - public: - GPIO () {} - - enum Pin : unsigned char { - p1_0 = 0, p1_1, p1_2, p1_3, p1_4, p1_5, p1_6, p1_7, - p2_0, p2_1, p2_2, p2_3, p2_4, p2_5, p2_6, p2_7, - p3_0, p3_1, p3_2, p3_3, p3_4, p3_5, p3_6, p3_7, - p4_0, p4_1, p4_2, p4_3, p4_4, p4_5, p4_6, p4_7, - pj_0, pj_1, pj_2, pj_3, pj_4, pj_5, pj_6, pj_7, - PIN_INVALID - }; - - inline void setup() { - P1OUT = 0; - P2OUT = 0; - P3OUT = 0; - P4OUT = 0; - P1DIR = BIT0; - P2DIR = 0; - P3DIR = 0; - P4DIR = BIT6; - } - inline void led_on(unsigned char id) { - if (id == 0) { - P1OUT |= BIT0; - } else { - P4OUT |= BIT6; - } - } - inline void led_off(unsigned char id) { - if (id == 0) { - P1OUT &= ~BIT0; - } else { - P4OUT &= ~BIT6; - } - } - inline void led_toggle(unsigned char id) { - if (id == 0) { - P1OUT ^= BIT0; - } else { - P4OUT ^= BIT6; - } - } - inline void input(unsigned char const pin) { - if (pin < p2_0) { - P1DIR &= ~(1 << pin); - } else if (pin < p3_0) { - P2DIR &= ~(1 << (pin - p2_0)); - } else if (pin < p4_0) { - P3DIR &= ~(1 << (pin - p3_0)); - } else if (pin < pj_0) { - P4DIR &= ~(1 << (pin - p4_0)); - } else if (pin < PIN_INVALID) { - PJDIR &= ~(1 << (pin - pj_0)); - } - } - inline void output(unsigned char const pin) { - if (pin < p2_0) { - P1DIR |= (1 << pin); - } else if (pin < p3_0) { - P2DIR |= (1 << (pin - p2_0)); - } else if (pin < p4_0) { - P3DIR |= (1 << (pin - p3_0)); - } else if (pin < pj_0) { - P4DIR |= (1 << (pin - p4_0)); - } else if (pin < PIN_INVALID) { - PJDIR |= (1 << (pin - pj_0)); - } - } - inline unsigned char read(unsigned char const pin) { - if (pin < p2_0) { - return P1IN & (1 << pin); - } else if (pin < p3_0) { - return P2IN & (1 << (pin - p2_0)); - } else if (pin < p4_0) { - return P3IN & (1 << (pin - p3_0)); - } else if (pin < pj_0) { - return P4IN & (1 << (pin - p4_0)); - } else if (pin < PIN_INVALID) { - return PJIN & (1 << (pin - pj_0)); - } - return 0; - } - inline void write(unsigned char const pin, unsigned char value) { - if (pin < p2_0) { - if (value) { - P1OUT |= (1 << pin); - } else { - P1OUT &= ~(1 << pin); - } - } else if (pin < p3_0) { - if (value) { - P2OUT |= (1 << (pin - p2_0)); - } else { - P2OUT &= ~(1 << (pin - p2_0)); - } - } else if (pin < p4_0) { - if (value) { - P3OUT |= (1 << (pin - p3_0)); - } else { - P3OUT &= ~(1 << (pin - p3_0)); - } - } else if (pin < pj_0) { - if (value) { - P4OUT |= (1 << (pin - p4_0)); - } else { - P4OUT &= ~(1 << (pin - p4_0)); - } - } else if (pin < PIN_INVALID) { - if (value) { - PJOUT |= (1 << (pin - pj_0)); - } else { - PJOUT &= ~(1 << (pin - pj_0)); - } - } - } -}; - -extern GPIO gpio; - -#endif diff --git a/include/msp430fr5969lp/driver/i2c.h b/include/msp430fr5969lp/driver/i2c.h deleted file mode 100644 index 6d6ea66..0000000 --- a/include/msp430fr5969lp/driver/i2c.h +++ /dev/null @@ -1,19 +0,0 @@ -#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/msp430fr5969lp/driver/spi_b.h b/include/msp430fr5969lp/driver/spi_b.h deleted file mode 100644 index 4be7346..0000000 --- a/include/msp430fr5969lp/driver/spi_b.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef SPI_H -#define SPI_H - -class SPI { - private: - SPI(const SPI ©); - - public: - SPI () {} - void setup(); - signed char xmit( - unsigned char tx_len, unsigned char *tx_buf, - unsigned char rx_len, unsigned char *rx_buf); -}; - -extern SPI spi; - -#endif diff --git a/include/msp430fr5969lp/driver/stdin.h b/include/msp430fr5969lp/driver/stdin.h deleted file mode 100644 index 6462e0c..0000000 --- a/include/msp430fr5969lp/driver/stdin.h +++ /dev/null @@ -1,24 +0,0 @@ -#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/msp430fr5969lp/driver/stdout.h b/include/msp430fr5969lp/driver/stdout.h deleted file mode 100644 index 2eb669d..0000000 --- a/include/msp430fr5969lp/driver/stdout.h +++ /dev/null @@ -1,19 +0,0 @@ -#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/msp430fr5969lp/driver/uptime.h b/include/msp430fr5969lp/driver/uptime.h deleted file mode 100644 index 3a52840..0000000 --- a/include/msp430fr5969lp/driver/uptime.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef UPTIME_H -#define UPTIME_H - -#include -#include - -class Uptime { - private: - Uptime(const Uptime ©); -#ifdef TIMER_S - uint16_t seconds; -#endif - - public: -#ifdef TIMER_S - Uptime () : seconds(0) {} -#else - Uptime () {} -#endif - inline uint16_t get_us() { return TA0R; } - inline uint16_t get_cycles() { return TA2R; } -#ifdef TIMER_S - inline uint16_t get_s() { return seconds; } - inline void tick_s() { seconds++; } -#endif -}; - -extern Uptime uptime; - -#endif diff --git a/include/posix/driver/gpio.h b/include/posix/driver/gpio.h deleted file mode 100644 index 0995729..0000000 --- a/include/posix/driver/gpio.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef GPIO_H -#define GPIO_H - -class GPIO { - private: - GPIO(const GPIO ©); - unsigned char ledstate; - - public: - GPIO () : ledstate(0) {} - void setup() {} - void led_on(unsigned char id); - void led_off(unsigned char id); - void led_toggle(unsigned char id); -}; - -extern GPIO gpio; - -#endif diff --git a/include/posix/driver/stdout.h b/include/posix/driver/stdout.h deleted file mode 100644 index b21ad56..0000000 --- a/include/posix/driver/stdout.h +++ /dev/null @@ -1,20 +0,0 @@ -#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; - virtual void flush() override; -}; - -extern StandardOutput kout; - -#endif diff --git a/include/posix/driver/uptime.h b/include/posix/driver/uptime.h deleted file mode 100644 index 93711b9..0000000 --- a/include/posix/driver/uptime.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef UPTIME_H -#define UPTIME_H - -#include - -class Uptime { - private: - Uptime(const Uptime ©); - - public: - Uptime () {} - uint64_t get_s(); - uint64_t get_us(); - uint64_t get_cycles(); -}; - -extern Uptime uptime; - -#endif diff --git a/src/arch/arduino-nano/Makefile.inc b/src/arch/arduino-nano/Makefile.inc index bceecad..b97ae16 100644 --- a/src/arch/arduino-nano/Makefile.inc +++ b/src/arch/arduino-nano/Makefile.inc @@ -5,7 +5,6 @@ PROGRAMMER ?= usbasp PORT = /dev/ttyUSB0 BAUD = 57600 -INCLUDES += -Iinclude/arduino-nano COMMON_FLAGS += -mmcu=${MCU} -DF_CPU=16000000UL -DMULTIPASS_ARCH_arduino_nano COMMON_FLAGS += -DMULTIPASS_ARCH_HAS_I2C diff --git a/src/arch/esp8266/Makefile.inc b/src/arch/esp8266/Makefile.inc index 33df2b2..8deaa95 100644 --- a/src/arch/esp8266/Makefile.inc +++ b/src/arch/esp8266/Makefile.inc @@ -15,7 +15,7 @@ ifeq (${aspectc}, 1) CXX = ag++ -r build/repo.acp -v 0 --c_compiler ${TOOLCHAIN_BASE}/xtensa-lx106-elf-g++ -p . --Xcompiler endif -INCLUDES += -Iinclude/esp8266 -I${SDK_BASE}/include +INCLUDES += -I${SDK_BASE}/include COMMON_FLAGS += -nostdlib -mlongcalls -D__ets__ -DICACHE_FLASH -DMULTIPASS_ARCH_esp8266 CXXFLAGS = -std=c++11 LDFLAGS += -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static diff --git a/src/arch/msp430fr5969lp/Makefile.inc b/src/arch/msp430fr5969lp/Makefile.inc index 3b8fcd1..5512cb9 100644 --- a/src/arch/msp430fr5969lp/Makefile.inc +++ b/src/arch/msp430fr5969lp/Makefile.inc @@ -3,7 +3,7 @@ CPU = 430x MCU = msp430fr5969 -INCLUDES += -Iinclude/msp430fr5969lp -I/opt/msp430/ti/gcc/include +INCLUDES += -I/opt/msp430/ti/gcc/include COMMON_FLAGS += -mcpu=${CPU} -mmcu=${MCU} -DMULTIPASS_ARCH_msp430fr5969lp COMMON_FLAGS += -DMULTIPASS_ARCH_HAS_I2C diff --git a/src/arch/posix/Makefile.inc b/src/arch/posix/Makefile.inc index a706314..03402bc 100644 --- a/src/arch/posix/Makefile.inc +++ b/src/arch/posix/Makefile.inc @@ -7,7 +7,6 @@ ifeq (${aspectc}, 1) CXX = ag++ -r build/repo.acp -v 0 -p . --Xcompiler endif -INCLUDES += -Iinclude/posix TARGETS += src/arch/posix/arch.cc src/arch/posix/driver/gpio.cc TARGETS += src/arch/posix/driver/stdout.cc src/arch/posix/driver/uptime.cc -- cgit v1.2.3